You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ge_profiling_manager_unittest.cc 4.9 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /**
  2. * Copyright 2019-2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <bits/stdc++.h>
  17. #include <dirent.h>
  18. #include <gtest/gtest.h>
  19. #include <fstream>
  20. #include <map>
  21. #include <string>
  22. #define protected public
  23. #define private public
  24. #include "common/profiling/profiling_manager.h"
  25. #undef protected
  26. #undef private
  27. using namespace ge;
  28. using namespace domi;
  29. using namespace std;
  30. class UTEST_ge_profiling_manager : public testing::Test {
  31. protected:
  32. void SetUp() override {}
  33. void TearDown() override {}
  34. };
  35. class TestReporter : public Msprof::Engine::Reporter {
  36. public:
  37. TestReporter() {}
  38. ~TestReporter() {}
  39. public:
  40. int Report(const Msprof::Engine::ReporterData *data) { return 0; }
  41. int Flush() { return 0; }
  42. };
  43. class TestPluginIntf : public Msprof::Engine::PluginIntf {
  44. public:
  45. TestPluginIntf() {}
  46. ~TestPluginIntf() {}
  47. public:
  48. int Init(const Msprof::Engine::Reporter *reporter) { return 0; }
  49. int UnInit() { return 0; }
  50. };
  51. TEST_F(UTEST_ge_profiling_manager, init_success) {
  52. setenv("PROFILING_MODE", "true", true);
  53. Options options_;
  54. options_.device_id = 0;
  55. options_.job_id = 0;
  56. string profiling_config;
  57. ProfilingManager::Instance().SetProfilingConfig(profiling_config);
  58. Status ret = ProfilingManager::Instance().Init(options_);
  59. EXPECT_EQ(ret, ge::SUCCESS);
  60. }
  61. TEST_F(UTEST_ge_profiling_manager, StartProfiling_success) {
  62. int32_t iter_num = 1;
  63. setenv("PROFILING_MODE", "true", true);
  64. setenv("PROFILING_OPTIONS", "training_trace", true);
  65. Options options_;
  66. string profiling_config;
  67. ProfilingManager::Instance().SetProfilingConfig(profiling_config);
  68. Status ret = ProfilingManager::Instance().Init(options_);
  69. EXPECT_EQ(ret, ge::SUCCESS);
  70. ret = ProfilingManager::Instance().StartProfiling(iter_num);
  71. EXPECT_EQ(ret, ge::SUCCESS);
  72. setenv("PROFILING_OPTIONS", "op_trance", true);
  73. ret = ProfilingManager::Instance().Init(options_);
  74. EXPECT_EQ(ret, ge::SUCCESS);
  75. ret = ProfilingManager::Instance().StartProfiling(iter_num);
  76. EXPECT_EQ(ret, ge::SUCCESS);
  77. }
  78. TEST_F(UTEST_ge_profiling_manager, StopProfiling_success) {
  79. int32_t iter_num = 1;
  80. Options options_;
  81. TestReporter test_reporter;
  82. string profiling_config;
  83. ProfilingManager::Instance().SetProfilingConfig(profiling_config);
  84. Status ret = 0;
  85. setenv("PROFILING_OPTIONS", "op_trance", true);
  86. ret = ProfilingManager::Instance().Init(options_);
  87. EXPECT_EQ(ret, ge::SUCCESS);
  88. ret = ProfilingManager::Instance().StartProfiling(iter_num);
  89. EXPECT_EQ(ret, ge::SUCCESS);
  90. ProfilingManager::Instance().StopProfiling();
  91. }
  92. TEST_F(UTEST_ge_profiling_manager, ReportProfilingData_success) {
  93. map<uint32_t, string> op_task_id_map;
  94. op_task_id_map[0] = "conv";
  95. op_task_id_map.insert(pair<uint32_t, string>(1, "mul"));
  96. ProfilingManager::Instance().ReportProfilingData(op_task_id_map);
  97. }
  98. TEST_F(UTEST_ge_profiling_manager, PluginImpl_success) {
  99. PluginImpl plugin_Impl("FMK");
  100. TestReporter test_reporter;
  101. Msprof::Engine::Reporter *reporter_ptr = &test_reporter;
  102. plugin_Impl.Init(reporter_ptr);
  103. plugin_Impl.UnInit();
  104. }
  105. TEST_F(UTEST_ge_profiling_manager, ProfilingEngineImpl_success) {
  106. ProfilingEngineImpl profilingEngineImpl;
  107. Msprof::Engine::PluginIntf *plugin_ptr = new TestPluginIntf();
  108. profilingEngineImpl.ReleasePlugin(plugin_ptr);
  109. Msprof::Engine::PluginIntf *ptr = profilingEngineImpl.CreatePlugin();
  110. delete ptr;
  111. ptr = nullptr;
  112. }
  113. TEST_F(UTEST_ge_profiling_manager, SetProfilngCfg_success) {
  114. string profiling_config = "profiling_mode: true";
  115. ProfilingManager::Instance().SetProfilingConfig(profiling_config);
  116. }
  117. TEST_F(UTEST_ge_profiling_manager, InitFromCfg_success0) {
  118. Options options_;
  119. string profiling_config =
  120. "{\"startCfg\":[{\"deviceID\":\"0\",\"features\":[{\"name\":\"op_trace\",\"conf\":\"2\"}]}]}";
  121. ProfilingManager::Instance().SetProfilingConfig(profiling_config);
  122. Status ret = ProfilingManager::Instance().Init(options_);
  123. EXPECT_EQ(ret, ge::SUCCESS);
  124. }
  125. TEST_F(UTEST_ge_profiling_manager, InitFromCfg_success1) {
  126. Options options_;
  127. string profiling_config =
  128. "{\"startCfg\":[{\"deviceID\":\"0\",\"features\":[{\"name\":\"test_trace\"}],\"jobID\":\"1231231231\"}]}";
  129. ProfilingManager::Instance().SetProfilingConfig(profiling_config);
  130. Status ret = ProfilingManager::Instance().Init(options_);
  131. EXPECT_EQ(ret, ge::SUCCESS);
  132. }

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示