diff --git a/ge/common/profiling/ge_profiling.cc b/ge/common/profiling/ge_profiling.cc index 6ec1143c..6f7a32f5 100644 --- a/ge/common/profiling/ge_profiling.cc +++ b/ge/common/profiling/ge_profiling.cc @@ -25,15 +25,15 @@ namespace { const uint32_t kDeviceListIndex = 3; -const std::string kDeviceNums = "devNums"; -const std::string kDeviceIdList = "devIdList"; -const std::string kProfilingInit = "prof_init"; -const std::string kProfilingFinalize = "prof_finalize"; -const std::string kProfilingStart = "prof_start"; -const std::string kProfilingStop = "prof_stop"; -const std::string kProfModelSubscribe = "prof_model_subscribe"; -const std::string kProfModelUnsubscribe = "prof_model_cancel_subscribe"; -const std::string kRtSetDeviceRegName = "profiling"; +const char *const kDeviceNums = "devNums"; +const char *const kDeviceIdList = "devIdList"; +const char *const kProfilingInit = "prof_init"; +const char *const kProfilingFinalize = "prof_finalize"; +const char *const kProfilingStart = "prof_start"; +const char *const kProfilingStop = "prof_stop"; +const char *const kProfModelSubscribe = "prof_model_subscribe"; +const char *const kProfModelUnsubscribe = "prof_model_cancel_subscribe"; +const char *const kRtSetDeviceRegName = "profiling"; const std::map kProfCommandTypeMap = { {kProfCommandhandleInit, kProfilingInit}, @@ -216,6 +216,28 @@ ge::Status ProfCommandHandle(ProfCommandHandleType type, void *data, uint32_t le return ge::SUCCESS; } -GE_FUNC_VISIBILITY ge::Status ProfSetStepInfo(uint64_t index_id, uint16_t tag_id, rtStream_t stream) { - return ge::SUCCESS; +ge::Status ProfSetStepInfo(uint64_t index_id, uint16_t tag_id, rtStream_t stream) { + static int32_t is_first_run = 1; + int32_t device_id = 0; + constexpr uint64_t kModelId = 4294967295; + ge::Status rt_ret = rtGetDevice(&device_id); + if (rt_ret != RT_ERROR_NONE) { + GELOGE(rt_ret, "[Get][LogicDeviceId]Failed, ret 0x%X", rt_ret); + REPORT_CALL_ERROR("E19999", "Get logic device id failed, ret 0x%X", rt_ret); + return ge::FAILED; + } + if (is_first_run && tag_id == 0) { + GE_CHK_STATUS_RET_NOLOG( + ge::ProfilingManager::Instance().ProfileStepInfo(index_id, kModelId, tag_id, stream, device_id)); + is_first_run = 0; + return ge::SUCCESS; + } + if (!is_first_run && tag_id == 1) { + GE_CHK_STATUS_RET_NOLOG( + ge::ProfilingManager::Instance().ProfileStepInfo(index_id, kModelId, tag_id, stream, device_id)); + is_first_run = 1; + return ge::SUCCESS; + } + + return ge::FAILED; } diff --git a/tests/ut/ge/profiling/ge_profiling_manager_unittest.cc b/tests/ut/ge/profiling/ge_profiling_manager_unittest.cc index 9c615317..2ab29555 100644 --- a/tests/ut/ge/profiling/ge_profiling_manager_unittest.cc +++ b/tests/ut/ge/profiling/ge_profiling_manager_unittest.cc @@ -25,6 +25,7 @@ #define private public #include "common/profiling/profiling_manager.h" #include "graph/ge_local_context.h" +#include "inc/framework/common/profiling/ge_profiling.h" #undef protected #undef private @@ -65,7 +66,6 @@ TEST_F(UtestGeProfilinganager, ParseOptions) { options.profiling_mode = "1"; options.profiling_options = R"({"result_path":"/data/profiling","training_trace":"on","task_trace":"on","aicpu_trace":"on","fp_point":"Data_0","bp_point":"addn","ai_core_metrics":"ResourceConflictRatio"})"; - struct MsprofGeOptions prof_conf = {{ 0 }}; Status ret = ProfilingManager::Instance().ParseOptions(options.profiling_options); EXPECT_EQ(ret, ge::SUCCESS); EXPECT_EQ(ProfilingManager::Instance().is_training_trace_, true); @@ -115,4 +115,20 @@ TEST_F(UtestGeProfilinganager, get_fp_bp_point_empty) { ProfilingManager::Instance().GetFpBpPoint(fp_point, bp_point); EXPECT_EQ(fp_point, ""); EXPECT_EQ(bp_point, ""); -} \ No newline at end of file +} + +TEST_F(UtestGeProfilinganager, set_step_info_success) { + uint64_t index_id = 0; + auto stream = (rtStream_t)0x1; + Status ret = ProfSetStepInfo(index_id, 0, stream); + EXPECT_EQ(ret, ge::SUCCESS); + ret = ProfSetStepInfo(index_id, 1, stream); + EXPECT_EQ(ret, ge::SUCCESS); +} + +TEST_F(UtestGeProfilinganager, set_step_info_failed) { + uint64_t index_id = 0; + auto stream = (rtStream_t)0x1; + Status ret = ProfSetStepInfo(index_id, 1, stream); + EXPECT_EQ(ret, ge::FAILED); +}