Pre Merge pull request !1314 from zhengyuanhua/master

pull/1314/MERGE
zhengyuanhua 4 years ago committed by Gitee
commit 0047410731

@ -31,7 +31,7 @@ const char *const kFpPoint = "fp_point";
const char *const kBpPoint = "bp_point"; const char *const kBpPoint = "bp_point";
#ifdef DAVINCI_SUPPORT_PROFILING #ifdef DAVINCI_SUPPORT_PROFILING
const size_t kReportMaxLen = 2048; const size_t kReportMaxLen = 1024;
const int32_t kMaxDeviceNum = 256; const int32_t kMaxDeviceNum = 256;
const uint32_t kInteval = 2; const uint32_t kInteval = 2;
const std::string kConfigNumsdev = "devNums"; const std::string kConfigNumsdev = "devNums";
@ -293,21 +293,25 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ReportDa
ReporterData reporter_data{}; ReporterData reporter_data{};
int ret = -1; int ret = -1;
int32_t cb_ret = -1; int32_t cb_ret = -1;
size_t index = data.size() / kReportMaxLen; size_t report_max_len = kReportMaxLen;
#ifdef ONLY_COMPILE_OPEN_SRC
report_max_len = reporter_max_len_;
#endif
size_t index = data.size() / report_max_len;
if (index >= 1) { if (index >= 1) {
reporter_data.deviceId = device_id; reporter_data.deviceId = device_id;
ret = memcpy_s(reporter_data.tag, MSPROF_ENGINE_MAX_TAG_LEN + 1, tag_name.c_str(), tag_name.size()); ret = memcpy_s(reporter_data.tag, MSPROF_ENGINE_MAX_TAG_LEN + 1, tag_name.c_str(), tag_name.size());
GE_IF_BOOL_EXEC(ret != EOK, GELOGE(ret, "Report data tag [%s] memcpy error!", tag_name.c_str()); return;); GE_IF_BOOL_EXEC(ret != EOK, GELOGE(ret, "Report data tag [%s] memcpy error!", tag_name.c_str()); return;);
for (size_t i = 0; i < index; ++i) { for (size_t i = 0; i < index; ++i) {
reporter_data.data = (unsigned char *)data.c_str() + kReportMaxLen * i; reporter_data.data = (unsigned char *)data.c_str() + report_max_len * i;
reporter_data.dataLen = kReportMaxLen; reporter_data.dataLen = report_max_len;
cb_ret = CallMsprofReport(reporter_data); cb_ret = CallMsprofReport(reporter_data);
GE_IF_BOOL_EXEC(cb_ret != 0, GELOGE(cb_ret, "Reporter data [%s] failed, ret:%d", tag_name.c_str(), cb_ret); GE_IF_BOOL_EXEC(cb_ret != 0, GELOGE(cb_ret, "Reporter data [%s] failed, ret:%d", tag_name.c_str(), cb_ret);
return;); return;);
} }
reporter_data.dataLen = data.size() - kReportMaxLen * index; reporter_data.dataLen = data.size() - report_max_len * index;
if (reporter_data.dataLen != 0) { if (reporter_data.dataLen != 0) {
reporter_data.data = (unsigned char *)data.c_str() + kReportMaxLen * index; reporter_data.data = (unsigned char *)data.c_str() + report_max_len * index;
cb_ret = CallMsprofReport(reporter_data); cb_ret = CallMsprofReport(reporter_data);
GE_IF_BOOL_EXEC(cb_ret != 0, GELOGE(cb_ret, "Reporter data [%s] failed, ret:%d", tag_name.c_str(), cb_ret); GE_IF_BOOL_EXEC(cb_ret != 0, GELOGE(cb_ret, "Reporter data [%s] failed, ret:%d", tag_name.c_str(), cb_ret);
return;); return;);
@ -745,15 +749,33 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ProfilingManager::Profilin
return execute_model_prof_on; return execute_model_prof_on;
} }
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::PluginInit() const { FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::PluginInit() {
if (prof_cb_.msprofReporterCallback == nullptr) { if (prof_cb_.msprofReporterCallback == nullptr) {
GELOGE(ge::PARAM_INVALID, "MsprofReporterCallback callback is nullptr."); GELOGE(ge::PARAM_INVALID, "MsprofReporterCallback callback is nullptr.");
return ge::PARAM_INVALID; return ge::PARAM_INVALID;
} }
return prof_cb_.msprofReporterCallback( int32_t cb_ret = prof_cb_.msprofReporterCallback(
static_cast<uint32_t>(MsprofReporterModuleId::MSPROF_MODULE_FRAMEWORK), static_cast<uint32_t>(MsprofReporterModuleId::MSPROF_MODULE_FRAMEWORK),
static_cast<uint32_t>(MsprofReporterCallbackType::MSPROF_REPORTER_INIT), static_cast<uint32_t>(MsprofReporterCallbackType::MSPROF_REPORTER_INIT),
nullptr, 0); nullptr, 0);
if (cb_ret != MSPROF_ERROR_NONE) {
REPORT_CALL_ERROR("E19999", "Profiling reporter init failed, ret = %d.", cb_ret);
GELOGE(INTERNAL_ERROR, "[Init][ProfilingReporter] profiling init failed, ret = %d.", cb_ret);
return INTERNAL_ERROR;
}
#ifdef ONLY_COMPILE_OPEN_SRC
cb_ret = prof_cb_.msprofReporterCallback(
static_cast<uint32_t>(MsprofReporterModuleId::MSPROF_MODULE_FRAMEWORK),
static_cast<uint32_t>(MsprofReporterCallbackType::MSPROF_REPORTER_DATA_MAX_LEN),
&reporter_max_len_, sizeof(uint32_t));
if (cb_ret != MSPROF_ERROR_NONE) {
REPORT_CALL_ERROR("E19999", "Get profiling reporter data max len failed, ret = %d.", cb_ret);
GELOGE(INTERNAL_ERROR, "[Init][ProfilingReporter] Get profiling reporter data max len failed, ret = %d.", cb_ret);
return INTERNAL_ERROR;
}
#endif
return SUCCESS;
} }
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::PluginUnInit() const { FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::PluginUnInit() const {

@ -88,7 +88,7 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ProfilingManager {
void ProfilingTaskDescInfo(uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info, void ProfilingTaskDescInfo(uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info,
const int32_t &device_id); const int32_t &device_id);
void ProfilingOpInputOutInfo(const TaskDescInfo &task, Json &task_json); void ProfilingOpInputOutInfo(const TaskDescInfo &task, Json &task_json);
Status PluginInit() const; Status PluginInit();
void PluginUnInit() const; void PluginUnInit() const;
Status CallMsprofReport(ReporterData &reporter_data) const; Status CallMsprofReport(ReporterData &reporter_data) const;
struct MsprofCallback &GetMsprofCallback() { return prof_cb_; } struct MsprofCallback &GetMsprofCallback() { return prof_cb_; }
@ -119,6 +119,7 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ProfilingManager {
MsprofCallback prof_cb_; MsprofCallback prof_cb_;
std::string fp_point_; std::string fp_point_;
std::string bp_point_; std::string bp_point_;
uint32_t reporter_max_len_ = 0;
}; };
} // namespace ge } // namespace ge
#endif // GE_COMMON_PROFILING_PROFILING_MANAGER_H_ #endif // GE_COMMON_PROFILING_PROFILING_MANAGER_H_

@ -37,6 +37,10 @@ class UtestGeProfilinganager : public testing::Test {
void TearDown() override {} void TearDown() override {}
}; };
int32_t ReporterCallback(uint32_t moduleId, uint32_t type, void *data, uint32_t len) {
return -1;
}
TEST_F(UtestGeProfilinganager, init_success) { TEST_F(UtestGeProfilinganager, init_success) {
setenv("PROFILING_MODE", "true", true); setenv("PROFILING_MODE", "true", true);
Options options; Options options;
@ -53,16 +57,24 @@ TEST_F(UtestGeProfilinganager, init_success) {
} }
TEST_F(UtestGeProfilinganager, ParseOptions) { TEST_F(UtestGeProfilinganager, ParseOptions) {
setenv("PROFILING_MODE", "true", true); setenv("PROFILING_MODE", "true", true);
Options options; Options options;
options.device_id = 0; options.device_id = 0;
options.job_id = "0"; options.job_id = "0";
options.profiling_mode = "1"; 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"})"; 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);
}
struct MsprofGeOptions prof_conf = {{ 0 }}; TEST_F(UtestGeProfilinganager, plungin_init_) {
ProfilingManager::Instance().prof_cb_.msprofReporterCallback = ReporterCallback;
Status ret = ProfilingManager::Instance().ParseOptions(options.profiling_options); Status ret = ProfilingManager::Instance().PluginInit();
EXPECT_EQ(ret, ge::SUCCESS); EXPECT_EQ(ret, INTERNAL_ERROR);
ProfilingManager::Instance().prof_cb_.msprofReporterCallback = nullptr;
} }

Loading…
Cancel
Save