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.6 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 std;
  29. class UtestGeProfilinganager : public testing::Test {
  30. protected:
  31. void SetUp() override {}
  32. void TearDown() override {}
  33. };
  34. class TestReporter : public Msprof::Engine::Reporter {
  35. public:
  36. TestReporter() {}
  37. ~TestReporter() {}
  38. public:
  39. int Report(const Msprof::Engine::ReporterData *data) { return 0; }
  40. int Flush() { return 0; }
  41. };
  42. class TestPluginIntf : public Msprof::Engine::PluginIntf {
  43. public:
  44. TestPluginIntf() {}
  45. ~TestPluginIntf() {}
  46. public:
  47. int Init(const Msprof::Engine::Reporter *reporter) { return 0; }
  48. int UnInit() { return 0; }
  49. };
  50. TEST_F(UtestGeProfilinganager, init_success) {
  51. setenv("PROFILING_MODE", "true", true);
  52. Options options;
  53. options.device_id = 0;
  54. options.job_id = "0";
  55. string profiling_config;
  56. ProfilingManager::Instance().SetProfilingConfig(profiling_config);
  57. Status ret = ProfilingManager::Instance().Init(options);
  58. EXPECT_EQ(ret, ge::SUCCESS);
  59. }
  60. TEST_F(UtestGeProfilinganager, start_profiling_success) {
  61. int32_t iter_num = 1;
  62. setenv("PROFILING_MODE", "true", true);
  63. setenv("PROFILING_OPTIONS", "training_trace", true);
  64. Options options;
  65. string profiling_config;
  66. ProfilingManager::Instance().SetProfilingConfig(profiling_config);
  67. Status ret = ProfilingManager::Instance().Init(options);
  68. EXPECT_EQ(ret, ge::SUCCESS);
  69. ret = ProfilingManager::Instance().StartProfiling(iter_num, 0);
  70. EXPECT_EQ(ret, ge::SUCCESS);
  71. setenv("PROFILING_OPTIONS", "op_trance", true);
  72. ret = ProfilingManager::Instance().Init(options);
  73. EXPECT_EQ(ret, ge::SUCCESS);
  74. ret = ProfilingManager::Instance().StartProfiling(iter_num, 0);
  75. EXPECT_EQ(ret, ge::SUCCESS);
  76. }
  77. TEST_F(UtestGeProfilinganager, stop_profiling_success) {
  78. int32_t iter_num = 1;
  79. Options options;
  80. TestReporter test_reporter;
  81. string profiling_config;
  82. ProfilingManager::Instance().SetProfilingConfig(profiling_config);
  83. Status ret = 0;
  84. setenv("PROFILING_OPTIONS", "op_trance", true);
  85. ret = ProfilingManager::Instance().Init(options);
  86. EXPECT_EQ(ret, ge::SUCCESS);
  87. ret = ProfilingManager::Instance().StartProfiling(iter_num, 0);
  88. EXPECT_EQ(ret, ge::SUCCESS);
  89. ProfilingManager::Instance().StopProfiling();
  90. }
  91. TEST_F(UtestGeProfilinganager, plugin_impl_success) {
  92. PluginImpl plugin_Impl("FMK");
  93. TestReporter test_reporter;
  94. Msprof::Engine::Reporter *reporter_ptr = &test_reporter;
  95. plugin_Impl.Init(reporter_ptr);
  96. plugin_Impl.UnInit();
  97. }
  98. TEST_F(UtestGeProfilinganager, profiling_engine_impl_success) {
  99. ProfilingEngineImpl profiling_engine_impl;
  100. Msprof::Engine::PluginIntf *plugin_ptr = new TestPluginIntf();
  101. profiling_engine_impl.ReleasePlugin(plugin_ptr);
  102. Msprof::Engine::PluginIntf *ptr = profiling_engine_impl.CreatePlugin();
  103. delete ptr;
  104. ptr = nullptr;
  105. }
  106. TEST_F(UtestGeProfilinganager, set_profilng_cfg_success) {
  107. string profiling_config = "profiling_mode: true";
  108. ProfilingManager::Instance().SetProfilingConfig(profiling_config);
  109. }
  110. TEST_F(UtestGeProfilinganager, init_from_cfg_success0) {
  111. Options options;
  112. string profiling_config =
  113. "{\"startCfg\":[{\"deviceID\":\"0\",\"features\":[{\"name\":\"op_trace\",\"conf\":\"2\"}]}]}";
  114. ProfilingManager::Instance().SetProfilingConfig(profiling_config);
  115. Status ret = ProfilingManager::Instance().Init(options);
  116. EXPECT_EQ(ret, ge::SUCCESS);
  117. }
  118. TEST_F(UtestGeProfilinganager, init_from_cfg_success1) {
  119. Options options;
  120. string profiling_config =
  121. "{\"startCfg\":[{\"deviceID\":\"0\",\"features\":[{\"name\":\"test_trace\"}],\"jobID\":\"1231231231\"}]}";
  122. ProfilingManager::Instance().SetProfilingConfig(profiling_config);
  123. Status ret = ProfilingManager::Instance().Init(options);
  124. EXPECT_EQ(ret, ge::SUCCESS);
  125. }

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