| @@ -19,6 +19,7 @@ | |||||
| #include <malloc.h> | #include <malloc.h> | ||||
| #include "framework/common/debug/log.h" | #include "framework/common/debug/log.h" | ||||
| #include "framework/common/debug/ge_log.h" | #include "framework/common/debug/ge_log.h" | ||||
| #include "framework/executor/ge_executor.h" | |||||
| #include "common/ge/datatype_util.h" | #include "common/ge/datatype_util.h" | ||||
| #include "proto/ge_api.pb.h" | #include "proto/ge_api.pb.h" | ||||
| #include "graph/model_serialize.h" | #include "graph/model_serialize.h" | ||||
| @@ -161,6 +162,17 @@ Status GEInitializeImpl(const std::map<string, string> &options) { | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| ErrorManager::GetInstance().SetStage(error_message::kInitialize, error_message::kOther); | |||||
| GELOGI("GeExecutor initial."); | |||||
| GE_TIMESTAMP_START(GeExecutorInitialize); | |||||
| ret = GeExecutor::Initialize(options); | |||||
| if (ret != SUCCESS) { | |||||
| GELOGE(ret, "[Init][GeExecutor] GeExecutor initialize failed."); | |||||
| REPORT_CALL_ERROR("E19999", "GeExecutor initialize failed."); | |||||
| return ret; | |||||
| } | |||||
| GE_TIMESTAMP_END(GeExecutorInitialize, "GeExecutor::Initialize"); | |||||
| // 7.check return status, return | // 7.check return status, return | ||||
| if (!g_ge_initialized) { | if (!g_ge_initialized) { | ||||
| // Initialize success, first time calling initialize | // Initialize success, first time calling initialize | ||||
| @@ -213,6 +225,7 @@ Status GEFinalize() { | |||||
| ErrorManager::GetInstance().GenWorkStreamIdDefault(); | ErrorManager::GetInstance().GenWorkStreamIdDefault(); | ||||
| GELOGT(TRACE_INIT, "GEFinalize start"); | GELOGT(TRACE_INIT, "GEFinalize start"); | ||||
| (void)GeExecutor::FinalizeEx(); | |||||
| GELOGI("SessionManager finalization."); | GELOGI("SessionManager finalization."); | ||||
| if (g_session_manager != nullptr) { | if (g_session_manager != nullptr) { | ||||
| (void)g_session_manager->Finalize(); // always success. | (void)g_session_manager->Finalize(); // always success. | ||||
| @@ -82,14 +82,14 @@ ProfilingManager &ProfilingManager::Instance() { | |||||
| return profiling_manager; | return profiling_manager; | ||||
| } | } | ||||
| ge::Status ProfilingManager::Init(const Options &options) { | |||||
| ge::Status ProfilingManager::Init(const string &mode, const string &options, const string &job_id) { | |||||
| #ifdef DAVINCI_SUPPORT_PROFILING | #ifdef DAVINCI_SUPPORT_PROFILING | ||||
| vector<int32_t>().swap(device_id_); | vector<int32_t>().swap(device_id_); | ||||
| subscribe_count_ = 0; | subscribe_count_ = 0; | ||||
| GELOGI("ProfilingManager::Init job_id:%s", options.job_id.c_str()); | |||||
| GELOGI("ProfilingManager::Init job_id:%s", job_id.c_str()); | |||||
| struct MsprofGeOptions prof_conf = {{ 0 }}; | struct MsprofGeOptions prof_conf = {{ 0 }}; | ||||
| Status ret = InitFromOptions(options, prof_conf); | |||||
| Status ret = InitFromOptions(mode, options, job_id, prof_conf); | |||||
| if (ret != SUCCESS) { | if (ret != SUCCESS) { | ||||
| GELOGE(ret, "[Init][Profiling]Failed, error_code %u", ret); | GELOGE(ret, "[Init][Profiling]Failed, error_code %u", ret); | ||||
| REPORT_CALL_ERROR("E19999", "Init profiling failed, error_code %u", ret); | REPORT_CALL_ERROR("E19999", "Init profiling failed, error_code %u", ret); | ||||
| @@ -121,25 +121,52 @@ ge::Status ProfilingManager::Init(const Options &options) { | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| ge::Status ProfilingManager::InitFromOptions(const Options &options, MsprofGeOptions &prof_conf) { | |||||
| void ProfilingManager::Initialize(const map<string, string> &options) { | |||||
| GetContext().Init(); | |||||
| auto it = options.find(OPTION_EXEC_JOB_ID); | |||||
| string job_id = (it != options.end()) ? it->second : ""; | |||||
| it = options.find(OPTION_EXEC_SESSION_ID); | |||||
| string session_id = (it != options.end()) ? it->second : ""; | |||||
| it = options.find(OPTION_EXEC_PROFILING_MODE); | |||||
| string profiling_mode = (it != options.end()) ? it->second : ""; | |||||
| it = options.find(OPTION_EXEC_PROFILING_OPTIONS); | |||||
| string profiling_options = (it != options.end()) ? it->second : ""; | |||||
| GELOGI("Init Profiling. session Id: %s", session_id.c_str()); | |||||
| (void)Init(profiling_mode, profiling_options, job_id); | |||||
| } | |||||
| void ProfilingManager::Finalize() { | |||||
| if (ProfilingOn()) { | |||||
| StopProfiling(); | |||||
| PluginUnInit(); | |||||
| } | |||||
| } | |||||
| ge::Status ProfilingManager::InitFromOptions(const string &profiling_mode, const string &profiling_options, | |||||
| const string &job_id, MsprofGeOptions &prof_conf) { | |||||
| #ifdef DAVINCI_SUPPORT_PROFILING | #ifdef DAVINCI_SUPPORT_PROFILING | ||||
| // enable profiling by env | // enable profiling by env | ||||
| char env_profiling_mode[MMPA_MAX_PATH] = { 0x00 }; | char env_profiling_mode[MMPA_MAX_PATH] = { 0x00 }; | ||||
| is_execute_profiling_ = false; | is_execute_profiling_ = false; | ||||
| if (options.profiling_mode == "1" && !options.profiling_options.empty()) { | |||||
| if (profiling_mode == "1" && !profiling_options.empty()) { | |||||
| // enable profiling by ge option | // enable profiling by ge option | ||||
| if (strncpy_s(prof_conf.options, MSPROF_OPTIONS_DEF_LEN_MAX, options.profiling_options.c_str(), | |||||
| if (strncpy_s(prof_conf.options, MSPROF_OPTIONS_DEF_LEN_MAX, profiling_options.c_str(), | |||||
| MSPROF_OPTIONS_DEF_LEN_MAX - 1) != EOK) { | MSPROF_OPTIONS_DEF_LEN_MAX - 1) != EOK) { | ||||
| GELOGE(INTERNAL_ERROR, "[copy][ProfilingOptions]Failed, options %s", | GELOGE(INTERNAL_ERROR, "[copy][ProfilingOptions]Failed, options %s", | ||||
| options.profiling_options.c_str()); | |||||
| profiling_options.c_str()); | |||||
| REPORT_CALL_ERROR("E19999", "Copy profiling_options %s failed", | REPORT_CALL_ERROR("E19999", "Copy profiling_options %s failed", | ||||
| options.profiling_options.c_str()); | |||||
| profiling_options.c_str()); | |||||
| return INTERNAL_ERROR; | return INTERNAL_ERROR; | ||||
| } | } | ||||
| is_execute_profiling_ = true; | is_execute_profiling_ = true; | ||||
| GELOGI("The profiling in options is %s, %s. origin option: %s", options.profiling_mode.c_str(), prof_conf.options, | |||||
| options.profiling_options.c_str()); | |||||
| GELOGI("The profiling in options is %s, %s. origin option: %s", profiling_mode.c_str(), prof_conf.options, | |||||
| profiling_options.c_str()); | |||||
| } else { | } else { | ||||
| (void)mmGetEnv("PROFILING_MODE", env_profiling_mode, MMPA_MAX_PATH); | (void)mmGetEnv("PROFILING_MODE", env_profiling_mode, MMPA_MAX_PATH); | ||||
| (void)mmGetEnv("PROFILING_OPTIONS", prof_conf.options, MSPROF_OPTIONS_DEF_LEN_MAX); | (void)mmGetEnv("PROFILING_OPTIONS", prof_conf.options, MSPROF_OPTIONS_DEF_LEN_MAX); | ||||
| @@ -166,13 +193,13 @@ ge::Status ProfilingManager::InitFromOptions(const Options &options, MsprofGeOpt | |||||
| return ge::PARAM_INVALID; | return ge::PARAM_INVALID; | ||||
| } | } | ||||
| if (strncpy_s(prof_conf.jobId, MSPROF_OPTIONS_DEF_LEN_MAX, options.job_id.c_str(), MSPROF_OPTIONS_DEF_LEN_MAX - 1) != | |||||
| if (strncpy_s(prof_conf.jobId, MSPROF_OPTIONS_DEF_LEN_MAX, job_id.c_str(), MSPROF_OPTIONS_DEF_LEN_MAX - 1) != | |||||
| EOK) { | EOK) { | ||||
| GELOGE(INTERNAL_ERROR, "[Copy][JobId]Failed, original job_id %s", options.job_id.c_str()); | |||||
| REPORT_CALL_ERROR("E19999", "Copy job_id %s failed", options.job_id.c_str()); | |||||
| GELOGE(INTERNAL_ERROR, "[Copy][JobId]Failed, original job_id %s", job_id.c_str()); | |||||
| REPORT_CALL_ERROR("E19999", "Copy job_id %s failed", job_id.c_str()); | |||||
| return INTERNAL_ERROR; | return INTERNAL_ERROR; | ||||
| } | } | ||||
| GELOGI("Job id: %s, original job id: %s.", prof_conf.jobId, options.job_id.c_str()); | |||||
| GELOGI("Job id: %s, original job id: %s.", prof_conf.jobId, job_id.c_str()); | |||||
| #endif | #endif | ||||
| return ge::SUCCESS; | return ge::SUCCESS; | ||||
| } | } | ||||
| @@ -78,14 +78,17 @@ class ProfilingManager { | |||||
| ProfilingManager(); | ProfilingManager(); | ||||
| virtual ~ProfilingManager(); | virtual ~ProfilingManager(); | ||||
| static ProfilingManager &Instance(); | static ProfilingManager &Instance(); | ||||
| Status Init(const Options &options); | |||||
| void Initialize(const map<string, string> &options); | |||||
| void Finalize(); | |||||
| Status ProfInit(uint64_t module); | Status ProfInit(uint64_t module); | ||||
| Status ProfFinalize(); | Status ProfFinalize(); | ||||
| Status ProfStartProfiling(uint64_t module, const std::map<std::string, std::string> &config_para); | Status ProfStartProfiling(uint64_t module, const std::map<std::string, std::string> &config_para); | ||||
| Status ProfStopProfiling(uint64_t module, const std::map<std::string, std::string> &config_para); | Status ProfStopProfiling(uint64_t module, const std::map<std::string, std::string> &config_para); | ||||
| Status ProfModelSubscribe(uint64_t module, void *model); | Status ProfModelSubscribe(uint64_t module, void *model); | ||||
| Status ProfModelUnsubscribe(void *model); | Status ProfModelUnsubscribe(void *model); | ||||
| void StopProfiling(); | |||||
| bool ProfilingTrainingTraceOn() const { return is_training_trace_; } | bool ProfilingTrainingTraceOn() const { return is_training_trace_; } | ||||
| // report model load profiling data flag, data contain task desc info, step info, model load fusion op info | // report model load profiling data flag, data contain task desc info, step info, model load fusion op info | ||||
| bool ProfilingModelLoadOn() const { return is_load_profiling_; } | bool ProfilingModelLoadOn() const { return is_load_profiling_; } | ||||
| @@ -97,8 +100,7 @@ class 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(); | |||||
| 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_; } | ||||
| void SetMsprofCtrlCallback(MsprofCtrlCallback func) { prof_cb_.msprofCtrlCallback = func; } | void SetMsprofCtrlCallback(MsprofCtrlCallback func) { prof_cb_.msprofCtrlCallback = func; } | ||||
| @@ -118,13 +120,19 @@ class ProfilingManager { | |||||
| Status GetModelIdFromGraph(uint32_t graph_id, uint32_t &model_id); | Status GetModelIdFromGraph(uint32_t graph_id, uint32_t &model_id); | ||||
| private: | private: | ||||
| Status InitFromOptions(const Options &options, MsprofGeOptions &prof_conf); | |||||
| Status Init(const string &mode, const string &options, const string &job_id); | |||||
| Status InitFromOptions(const string &mode, const string &options, const string &job_id, MsprofGeOptions &prof_conf); | |||||
| Status ParseOptions(const std::string &options); | Status ParseOptions(const std::string &options); | ||||
| Status ProfParseParam(const std::map<std::string, std::string> &config_para, int32_t &device_num, | Status ProfParseParam(const std::map<std::string, std::string> &config_para, int32_t &device_num, | ||||
| vector<int32_t> &device_list); | vector<int32_t> &device_list); | ||||
| Status ProfParseDeviceId(const std::map<std::string, std::string> &config_para, | Status ProfParseDeviceId(const std::map<std::string, std::string> &config_para, | ||||
| vector<int32_t> &device_list); | vector<int32_t> &device_list); | ||||
| uint64_t GetProfilingModule(); | uint64_t GetProfilingModule(); | ||||
| void StopProfiling(); | |||||
| Status PluginInit(); | |||||
| void PluginUnInit() const; | |||||
| void UpdateDeviceIdModuleMap(string prof_type, uint64_t module, const vector<int32_t> &device_list); | void UpdateDeviceIdModuleMap(string prof_type, uint64_t module, const vector<int32_t> &device_list); | ||||
| void UpdateSubscribeDeviceModuleMap(std::string prof_type, uint32_t device_id, uint64_t module); | void UpdateSubscribeDeviceModuleMap(std::string prof_type, uint32_t device_id, uint64_t module); | ||||
| void GetOpInputInfo(const OpDescPtr &op, TaskDescInfo &task_desc_info) const; | void GetOpInputInfo(const OpDescPtr &op, TaskDescInfo &task_desc_info) const; | ||||
| @@ -28,6 +28,7 @@ | |||||
| #include "graph/load/model_manager/model_manager.h" | #include "graph/load/model_manager/model_manager.h" | ||||
| #include "graph/manager/graph_mem_manager.h" | #include "graph/manager/graph_mem_manager.h" | ||||
| #include "graph/manager/graph_var_manager.h" | #include "graph/manager/graph_var_manager.h" | ||||
| #include "graph/manager/host_mem_manager.h" | |||||
| #include "single_op/single_op_manager.h" | #include "single_op/single_op_manager.h" | ||||
| #include "graph/load/model_manager/davinci_model.h" | #include "graph/load/model_manager/davinci_model.h" | ||||
| #include "opskernel_manager/ops_kernel_builder_manager.h" | #include "opskernel_manager/ops_kernel_builder_manager.h" | ||||
| @@ -244,13 +245,13 @@ static void InitOpsProtoManager() { | |||||
| GeExecutor::GeExecutor() {} | GeExecutor::GeExecutor() {} | ||||
| Status GeExecutor::Initialize() { | |||||
| GELOGI("Init GeExecutor begin."); | |||||
| Status GeExecutor::Initialize(const std::map<string, string> &options) { | |||||
| if (isInit_) { | if (isInit_) { | ||||
| GELOGW("Already initialized, no need to be initialized again."); | GELOGW("Already initialized, no need to be initialized again."); | ||||
| return ge::SUCCESS; | return ge::SUCCESS; | ||||
| } | } | ||||
| GELOGI("Init GeExecutor begin."); | |||||
| OpTilingManager::GetInstance().LoadSo(); | OpTilingManager::GetInstance().LoadSo(); | ||||
| Status init_hostcpu_engine_status = HostCpuEngine::GetInstance().Initialize(); | Status init_hostcpu_engine_status = HostCpuEngine::GetInstance().Initialize(); | ||||
| @@ -261,46 +262,61 @@ Status GeExecutor::Initialize() { | |||||
| InitOpsProtoManager(); | InitOpsProtoManager(); | ||||
| std::vector<rtMemType_t> mem_type(1, RT_MEMORY_HBM); | |||||
| mem_type.push_back(RT_MEMORY_P2P_DDR); | |||||
| auto ret = MemManager::Instance().Initialize(mem_type); | |||||
| if (ret != SUCCESS) { | |||||
| GELOGE(ret, "[Initialize][MemManager] failed."); | |||||
| return ret; | |||||
| GE_CHK_STATUS_RET(HostMemManager::Instance().Initialize()); | |||||
| const std::vector<rtMemType_t> mem_type({1, RT_MEMORY_HBM, RT_MEMORY_P2P_DDR}); | |||||
| Status status = MemManager::Instance().Initialize(mem_type); | |||||
| if (status != SUCCESS) { | |||||
| GELOGE(status, "[Init][MemManager] MemoryAllocatorManager initialize failed."); | |||||
| REPORT_CALL_ERROR("E19999", "MemManager initialize failed."); | |||||
| return status; | |||||
| } | } | ||||
| GE_CHK_STATUS_RET(OpsKernelBuilderManager::Instance().Initialize({}, false), | GE_CHK_STATUS_RET(OpsKernelBuilderManager::Instance().Initialize({}, false), | ||||
| "[Initialize][OpsKernelBuilderManager] failed."); | "[Initialize][OpsKernelBuilderManager] failed."); | ||||
| // Start profiling | |||||
| Options profiling_options; | |||||
| profiling_options.device_id = 0; | |||||
| // job id need to be set, the value is meaningless; | |||||
| profiling_options.job_id = "1"; | |||||
| ProfilingManager::Instance().Init(profiling_options); | |||||
| const auto &model_manager = ModelManager::GetInstance(); | |||||
| GE_CHECK_NOTNULL(model_manager); | |||||
| status = model_manager->EnableExceptionDump(options); | |||||
| if (status != SUCCESS) { | |||||
| GELOGW("[Init][ModelManager] Enable exception dump failed."); | |||||
| } | |||||
| ProfilingManager::Instance().Initialize(options); | |||||
| isInit_ = true; | isInit_ = true; | ||||
| GELOGI("Init GeExecutor over."); | GELOGI("Init GeExecutor over."); | ||||
| return ge::SUCCESS; | |||||
| return SUCCESS; | |||||
| } | } | ||||
| Status GeExecutor::Finalize() { | |||||
| GELOGI("Uninit GeExecutor begin."); | |||||
| Status GeExecutor::FinalizeEx() { | |||||
| if (isInit_ == false) { | if (isInit_ == false) { | ||||
| GELOGW("GeExecutor has not been initialized."); | GELOGW("GeExecutor has not been initialized."); | ||||
| return ge::SUCCESS; | return ge::SUCCESS; | ||||
| } | } | ||||
| (void) OpsKernelBuilderManager::Instance().Finalize(); | |||||
| GELOGI("Uninit GeExecutor begin."); | |||||
| (void)OpsKernelBuilderManager::Instance().Finalize(); | |||||
| // Stop profiling | |||||
| if (ProfilingManager::Instance().ProfilingOn()) { | |||||
| ProfilingManager::Instance().StopProfiling(); | |||||
| ProfilingManager::Instance().PluginUnInit(); | |||||
| } | |||||
| HostMemManager::Instance().Finalize(); | |||||
| ProfilingManager::Instance().Finalize(); | |||||
| GELOGI("Uninit GeExecutor over."); | GELOGI("Uninit GeExecutor over."); | ||||
| return ge::SUCCESS; | |||||
| return SUCCESS; | |||||
| } | |||||
| Status GeExecutor::Initialize() { | |||||
| // job id need to be set, the value is meaningless; | |||||
| const std::map<string, string> options({ | |||||
| {OPTION_EXEC_JOB_ID, "1"}, {OPTION_EXEC_PROFILING_MODE, ""}, {OPTION_EXEC_PROFILING_OPTIONS, ""} | |||||
| }); | |||||
| return GeExecutor::Initialize(options); | |||||
| } | |||||
| Status GeExecutor::Finalize() { | |||||
| return GeExecutor::FinalizeEx(); | |||||
| } | } | ||||
| Status GeExecutor::SetDynamicBatchSize(uint32_t model_id, void *dynamic_input_addr, uint64_t length, | Status GeExecutor::SetDynamicBatchSize(uint32_t model_id, void *dynamic_input_addr, uint64_t length, | ||||
| @@ -55,26 +55,9 @@ Status ModelExecutor::Initialize(const map<string, string> &options, uint64_t se | |||||
| return MEMALLOC_FAILED; | return MEMALLOC_FAILED; | ||||
| } | } | ||||
| const auto model_manager = ModelManager::GetInstance(); | |||||
| GE_CHECK_NOTNULL(model_manager); | |||||
| Status status = model_manager->EnableExceptionDump(options); | |||||
| if (status != SUCCESS) { | |||||
| return status; | |||||
| } | |||||
| GE_CHK_STATUS_RET(HostMemManager::Instance().Initialize()); | |||||
| const std::vector<rtMemType_t> mem_type({RT_MEMORY_HBM, RT_MEMORY_P2P_DDR}); | |||||
| status = MemManager::Instance().Initialize(mem_type); | |||||
| if (status != SUCCESS) { | |||||
| GELOGE(status, "[Init][MemManager] MemoryAllocatorManager initialize failed."); | |||||
| REPORT_CALL_ERROR("E19999", "MemManager initialize failed."); | |||||
| return status; | |||||
| } | |||||
| size_t total_mem_size = 0; | size_t total_mem_size = 0; | ||||
| GE_CHK_STATUS_RET_NOLOG(GetTotalMemorySize(total_mem_size)); | GE_CHK_STATUS_RET_NOLOG(GetTotalMemorySize(total_mem_size)); | ||||
| status = VarManager::Instance(session_id)->SetMemoryMallocSize(options, total_mem_size); | |||||
| Status status = VarManager::Instance(session_id)->SetMemoryMallocSize(options, total_mem_size); | |||||
| if (status != SUCCESS) { | if (status != SUCCESS) { | ||||
| GELOGE(status, "[Set][MemoryMallocSize] failed."); | GELOGE(status, "[Set][MemoryMallocSize] failed."); | ||||
| REPORT_CALL_ERROR("E19999", "VarManager SetMemoryMallocSize failed, InnerSession:%lu.", session_id_); | REPORT_CALL_ERROR("E19999", "VarManager SetMemoryMallocSize failed, InnerSession:%lu.", session_id_); | ||||
| @@ -112,7 +95,6 @@ Status ModelExecutor::Finalize() { | |||||
| GELOGI("VarManager free var memory."); | GELOGI("VarManager free var memory."); | ||||
| (void)VarManager::Instance(session_id_)->FreeVarMemory(); | (void)VarManager::Instance(session_id_)->FreeVarMemory(); | ||||
| MemManager::Instance().FreeSessionMemory(session_id_); | MemManager::Instance().FreeSessionMemory(session_id_); | ||||
| HostMemManager::Instance().Finalize(); | |||||
| ModelManager::GetInstance()->DestroyAicpuSession(session_id_); | ModelManager::GetInstance()->DestroyAicpuSession(session_id_); | ||||
| return SUCCESS; | return SUCCESS; | ||||
| @@ -623,6 +623,7 @@ rtMemType_t VarManager::GetVarMemType(const int64_t &offset) { | |||||
| void VarManager::SetMemManager(MemoryManager *mem_manager) { | void VarManager::SetMemManager(MemoryManager *mem_manager) { | ||||
| // Better use shared_ptr instead, reconsitution later. | // Better use shared_ptr instead, reconsitution later. | ||||
| GELOGI("Set MemManager to VarManager."); | GELOGI("Set MemManager to VarManager."); | ||||
| std::lock_guard<std::recursive_mutex> lock(mutex_); | |||||
| mem_manager_ = mem_manager; | mem_manager_ = mem_manager; | ||||
| } | } | ||||
| @@ -1,115 +0,0 @@ | |||||
| /** | |||||
| * Copyright 2019-2020 Huawei Technologies Co., Ltd | |||||
| * | |||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| * you may not use this file except in compliance with the License. | |||||
| * You may obtain a copy of the License at | |||||
| * | |||||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||||
| * | |||||
| * Unless required by applicable law or agreed to in writing, software | |||||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| * See the License for the specific language governing permissions and | |||||
| * limitations under the License. | |||||
| */ | |||||
| #include "hybrid/hybrid_davinci_model.h" | |||||
| namespace ge { | |||||
| namespace hybrid { | |||||
| HybridDavinciModel::~HybridDavinciModel() {} | |||||
| std::unique_ptr<HybridDavinciModel> HybridDavinciModel::Create(const GeRootModelPtr &ge_root_model) { | |||||
| return std::unique_ptr<HybridDavinciModel>(new (std::nothrow)HybridDavinciModel()); | |||||
| } | |||||
| Status HybridDavinciModel::Init() { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| Status HybridDavinciModel::Execute(const std::vector<DataBuffer> &inputs, | |||||
| const std::vector<GeTensorDesc> &input_desc, | |||||
| std::vector<DataBuffer> &outputs, | |||||
| std::vector<GeTensorDesc> &output_desc, | |||||
| rtStream_t stream) { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| Status HybridDavinciModel::Execute(const vector<GeTensor> &inputs, vector<GeTensor> &outputs) { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| Status HybridDavinciModel::ModelRunStart() { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| Status HybridDavinciModel::ModelRunStop() { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| Status HybridDavinciModel::EnqueueData(const shared_ptr<InputDataWrapper> &data) { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| void HybridDavinciModel::SetListener(const shared_ptr<ModelListener> &listener) { | |||||
| } | |||||
| void HybridDavinciModel::SetModelId(uint32_t model_id) { | |||||
| } | |||||
| void HybridDavinciModel::SetDeviceId(uint32_t device_id) { | |||||
| } | |||||
| void HybridDavinciModel::SetOmName(const string &om_name) { | |||||
| } | |||||
| uint64_t HybridDavinciModel::GetSessionId() { | |||||
| return 0; | |||||
| } | |||||
| uint32_t HybridDavinciModel::GetDataInputerSize() { | |||||
| return 0; | |||||
| } | |||||
| uint32_t HybridDavinciModel::GetDeviceId() const { | |||||
| return 0; | |||||
| } | |||||
| Status HybridDavinciModel::GetDynamicBatchInfo(std::vector<std::vector<int64_t>> &batch_info, int32_t &dynamic_type) { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| void HybridDavinciModel::GetUserDesignateShapeOrder(std::vector<std::string> &user_input_shape_order) { | |||||
| } | |||||
| void HybridDavinciModel::GetModelAttr(std::vector<std::string> &dynamic_output_shape_info) { | |||||
| } | |||||
| Status HybridDavinciModel::GetInputOutputDescInfo(vector<InputOutputDescInfo> &input_desc, | |||||
| vector<InputOutputDescInfo> &output_desc, | |||||
| std::vector<uint32_t> &input_formats, | |||||
| std::vector<uint32_t> &output_formats) { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| void HybridDavinciModel::SetModelDescVersion(bool is_new_model_desc) { | |||||
| } | |||||
| bool HybridDavinciModel::GetRunningFlag() const { | |||||
| return false; | |||||
| } | |||||
| Status HybridDavinciModel::SetRunAsyncListenerCallback(const RunAsyncCallback &callback) { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| bool HybridDavinciModel::GetOpDescInfo(uint32_t stream_id, uint32_t task_id, OpDescInfo &op_desc_info) const { | |||||
| return true; | |||||
| } | |||||
| Status HybridDavinciModel::GetOpAttr(const std::string &op_name, const std::string &attr_name, | |||||
| std::string &attr_value) const { | |||||
| return UNSUPPORTED; | |||||
| } | |||||
| } // namespace hybrid | |||||
| } // namespace ge | |||||
| @@ -192,7 +192,7 @@ Status GELib::SystemInitialize(const map<string, string> &options) { | |||||
| InitOptions(options); | InitOptions(options); | ||||
| // In train and infer, profiling is always needed. | // In train and infer, profiling is always needed. | ||||
| InitProfiling(this->options_); | |||||
| ProfilingManager::Instance().Initialize(options); | |||||
| // 1.`is_train_mode_` means case: train | // 1.`is_train_mode_` means case: train | ||||
| // 2.`(!is_train_mode_) && (options_.device_id != kDefaultDeviceIdForInfer)` means case: online infer | // 2.`(!is_train_mode_) && (options_.device_id != kDefaultDeviceIdForInfer)` means case: online infer | ||||
| // these two case with logical device id | // these two case with logical device id | ||||
| @@ -204,16 +204,6 @@ Status GELib::SystemInitialize(const map<string, string> &options) { | |||||
| return status; | return status; | ||||
| } | } | ||||
| void GELib::InitProfiling(Options &options) { | |||||
| GELOGI("Init Profiling. session Id: %ld, device id:%d ", options.session_id, options.device_id); | |||||
| std::lock_guard<std::mutex> lock(status_mutex_); | |||||
| GetContext().Init(); | |||||
| // Profiling init | |||||
| if (ProfilingManager::Instance().Init(options) != SUCCESS) { | |||||
| GELOGW("Profiling init failed."); | |||||
| } | |||||
| } | |||||
| void GELib::SetDefaultPrecisionMode(map<string, string> &new_options) { | void GELib::SetDefaultPrecisionMode(map<string, string> &new_options) { | ||||
| auto iter = new_options.find(PRECISION_MODE); | auto iter = new_options.find(PRECISION_MODE); | ||||
| if (iter != new_options.end()) { | if (iter != new_options.end()) { | ||||
| @@ -433,7 +423,7 @@ Status GELib::Finalize() { | |||||
| Analyzer::GetInstance()->Finalize(); | Analyzer::GetInstance()->Finalize(); | ||||
| // Shut down profiling | // Shut down profiling | ||||
| ShutDownProfiling(); | |||||
| ProfilingManager::Instance().Finalize(); | |||||
| if (is_train_mode_ || (options_.device_id != kDefaultDeviceIdForInfer)) { | if (is_train_mode_ || (options_.device_id != kDefaultDeviceIdForInfer)) { | ||||
| GELOGI("System ShutDown."); | GELOGI("System ShutDown."); | ||||
| @@ -463,15 +453,6 @@ Status GELib::Finalize() { | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| void GELib::ShutDownProfiling() { | |||||
| std::lock_guard<std::mutex> lock(status_mutex_); | |||||
| if (ProfilingManager::Instance().ProfilingOn()) { | |||||
| ProfilingManager::Instance().StopProfiling(); | |||||
| ProfilingManager::Instance().PluginUnInit(); | |||||
| } | |||||
| } | |||||
| // Get Singleton Instance | // Get Singleton Instance | ||||
| std::shared_ptr<GELib> GELib::GetInstance() { return instancePtr_; } | std::shared_ptr<GELib> GELib::GetInstance() { return instancePtr_; } | ||||
| @@ -61,12 +61,6 @@ class GE_FUNC_VISIBILITY GELib { | |||||
| // get Initial flag | // get Initial flag | ||||
| bool InitFlag() const { return init_flag_; } | bool InitFlag() const { return init_flag_; } | ||||
| // get TrainMode flag | |||||
| bool IsTrainMode() { return is_train_mode_; } | |||||
| void InitProfiling(Options &options); | |||||
| void ShutDownProfiling(); | |||||
| Status InitSystemWithoutOptions(); | Status InitSystemWithoutOptions(); | ||||
| Status InitSystemWithOptions(Options &options); | Status InitSystemWithOptions(Options &options); | ||||
| Status SystemShutdownWithOptions(const Options &options); | Status SystemShutdownWithOptions(const Options &options); | ||||
| @@ -50,9 +50,26 @@ class GE_FUNC_VISIBILITY GeExecutor { | |||||
| public: | public: | ||||
| GeExecutor(); | GeExecutor(); | ||||
| ~GeExecutor() = default; | ~GeExecutor() = default; | ||||
| ge::Status Initialize(); | ge::Status Initialize(); | ||||
| ge::Status Finalize(); | ge::Status Finalize(); | ||||
| /// | |||||
| /// @ingroup ge | |||||
| /// @brief Initialize global execute environment. | |||||
| /// @param [in] options: environment variables. | |||||
| /// @return init result | |||||
| /// | |||||
| static Status Initialize(const std::map<std::string, std::string> &options); | |||||
| /// | |||||
| /// @ingroup ge | |||||
| /// @brief Finalize global execute environment. | |||||
| /// @param [in] model_id: model id allocate from manager | |||||
| /// @return execute result | |||||
| /// | |||||
| static Status FinalizeEx(); | |||||
| ge::Status UnloadModel(uint32_t modelId); | ge::Status UnloadModel(uint32_t modelId); | ||||
| // Get input and output descriptor | // Get input and output descriptor | ||||
| @@ -249,12 +249,7 @@ set(GRAPH_DAVINCI_MODEL_SRC_FILES | |||||
| "${GE_CODE_DIR}/ge/hybrid/node_executor/aicpu/aicpu_ext_info.cc" | "${GE_CODE_DIR}/ge/hybrid/node_executor/aicpu/aicpu_ext_info.cc" | ||||
| ) | ) | ||||
| set(GRAPH_EXECUTE_COMMON_SRC_FILES | |||||
| "${GE_CODE_DIR}/ge/hybrid/hybrid_davinci_model_stub.cc" | |||||
| ) | |||||
| set(GRAPH_BUILD_COMMON_SRC_FILES | set(GRAPH_BUILD_COMMON_SRC_FILES | ||||
| "${GE_CODE_DIR}/ge/graph/manager/graph_manager.cc" | |||||
| "${GE_CODE_DIR}/ge/client/ge_api.cc" | "${GE_CODE_DIR}/ge/client/ge_api.cc" | ||||
| "${GE_CODE_DIR}/ge/session/inner_session.cc" | "${GE_CODE_DIR}/ge/session/inner_session.cc" | ||||
| "${GE_CODE_DIR}/ge/session/session_manager.cc" | "${GE_CODE_DIR}/ge/session/session_manager.cc" | ||||
| @@ -263,6 +258,7 @@ set(GRAPH_BUILD_COMMON_SRC_FILES | |||||
| "${GE_CODE_DIR}/ge/plugin/engine/dnnengines.cc" | "${GE_CODE_DIR}/ge/plugin/engine/dnnengines.cc" | ||||
| "${GE_CODE_DIR}/ge/plugin/engine/engine_manage.cc" | "${GE_CODE_DIR}/ge/plugin/engine/engine_manage.cc" | ||||
| "${GE_CODE_DIR}/ge/graph/manager/graph_context.cc" | "${GE_CODE_DIR}/ge/graph/manager/graph_context.cc" | ||||
| "${GE_CODE_DIR}/ge/graph/manager/graph_manager.cc" | |||||
| ) | ) | ||||
| set(GRAPH_PASS_COMMON_SRC_FILES | set(GRAPH_PASS_COMMON_SRC_FILES | ||||
| @@ -856,25 +852,6 @@ target_link_libraries(ge_davinci_model PRIVATE | |||||
| json | json | ||||
| ) | ) | ||||
| # build graph execute common | |||||
| add_library(ge_execute_common STATIC ${GRAPH_EXECUTE_COMMON_SRC_FILES} ${PROTO_HDRS}) | |||||
| target_compile_definitions(ge_execute_common PRIVATE | |||||
| google=ascend_private | |||||
| ) | |||||
| target_compile_options(ge_execute_common PRIVATE | |||||
| -g --coverage -fprofile-arcs -ftest-coverage | |||||
| -Werror=format | |||||
| ) | |||||
| target_link_libraries(ge_execute_common PRIVATE | |||||
| $<BUILD_INTERFACE:intf_pub> | |||||
| c_sec | |||||
| json | |||||
| ascend_protobuf | |||||
| ) | |||||
| # build graph build common | # build graph build common | ||||
| add_library(ge_build_common STATIC ${GRAPH_BUILD_COMMON_SRC_FILES} ${PROTO_HDRS}) | add_library(ge_build_common STATIC ${GRAPH_BUILD_COMMON_SRC_FILES} ${PROTO_HDRS}) | ||||
| @@ -953,7 +930,7 @@ target_compile_definitions(ut_libge_multiparts_utest PRIVATE | |||||
| target_link_libraries(ut_libge_multiparts_utest | target_link_libraries(ut_libge_multiparts_utest | ||||
| $<BUILD_INTERFACE:intf_pub> | $<BUILD_INTERFACE:intf_pub> | ||||
| -Wl,--whole-archive | -Wl,--whole-archive | ||||
| ge_davinci_model ge_build_common ge_prepare_common ge_execute_common ge_pass_common ge_ut_common_format ge_ut_common | |||||
| ge_davinci_model ge_build_common ge_prepare_common ge_single_op ge_pass_common ge_ut_common_format ge_ut_common | |||||
| -Wl,--no-whole-archive | -Wl,--no-whole-archive | ||||
| gtest gtest_main gmock gmock_main ${COMMON_SHARED_LIBRARIES} -lrt -ldl -lgcov | gtest gtest_main gmock gmock_main ${COMMON_SHARED_LIBRARIES} -lrt -ldl -lgcov | ||||
| ) | ) | ||||
| @@ -975,7 +952,7 @@ target_compile_options(ut_libge_others_utest PRIVATE | |||||
| target_link_libraries(ut_libge_others_utest | target_link_libraries(ut_libge_others_utest | ||||
| $<BUILD_INTERFACE:intf_pub> | $<BUILD_INTERFACE:intf_pub> | ||||
| -Wl,--whole-archive | -Wl,--whole-archive | ||||
| ge_davinci_model ge_build_common ge_prepare_common ge_pass_common ge_execute_common ge_ut_common ge_ut_common_format | |||||
| ge_davinci_model ge_build_common ge_prepare_common ge_pass_common ge_single_op ge_ut_common ge_ut_common_format | |||||
| -Wl,--no-whole-archive | -Wl,--no-whole-archive | ||||
| gtest gtest_main gmock gmock_main ${COMMON_SHARED_LIBRARIES} -lrt -ldl -lgcov | gtest gtest_main gmock gmock_main ${COMMON_SHARED_LIBRARIES} -lrt -ldl -lgcov | ||||
| ) | ) | ||||
| @@ -995,7 +972,7 @@ target_compile_options(ut_libge_kernel_utest PRIVATE | |||||
| target_link_libraries(ut_libge_kernel_utest | target_link_libraries(ut_libge_kernel_utest | ||||
| $<BUILD_INTERFACE:intf_pub> | $<BUILD_INTERFACE:intf_pub> | ||||
| -Wl,--whole-archive | -Wl,--whole-archive | ||||
| ge_davinci_model ge_build_common ge_prepare_common ge_pass_common ge_execute_common ge_ut_common ge_ut_common_format | |||||
| ge_davinci_model ge_build_common ge_prepare_common ge_pass_common ge_single_op ge_ut_common ge_ut_common_format | |||||
| -Wl,--no-whole-archive | -Wl,--no-whole-archive | ||||
| gtest gtest_main gmock gmock_main ${COMMON_SHARED_LIBRARIES} -lrt -ldl -lgcov | gtest gtest_main gmock gmock_main ${COMMON_SHARED_LIBRARIES} -lrt -ldl -lgcov | ||||
| ) | ) | ||||
| @@ -31,8 +31,6 @@ | |||||
| #include "graph/manager/graph_manager.h" | #include "graph/manager/graph_manager.h" | ||||
| #include "graph/ops_stub.h" | #include "graph/ops_stub.h" | ||||
| #include "inc/framework/omg/omg_inner_types.h" | #include "inc/framework/omg/omg_inner_types.h" | ||||
| #undef protected | |||||
| #undef private | |||||
| using namespace ge; | using namespace ge; | ||||
| using namespace std; | using namespace std; | ||||
| @@ -76,10 +74,21 @@ TEST_F(UtestGeProfilinganager, init_success) { | |||||
| struct MsprofGeOptions prof_conf = {{ 0 }}; | struct MsprofGeOptions prof_conf = {{ 0 }}; | ||||
| Status ret = ProfilingManager::Instance().InitFromOptions(options, prof_conf); | |||||
| Status ret = ProfilingManager::Instance().InitFromOptions(options.profiling_mode, options.profiling_options, options.job_id, prof_conf); | |||||
| EXPECT_EQ(ret, ge::SUCCESS); | EXPECT_EQ(ret, ge::SUCCESS); | ||||
| } | } | ||||
| TEST_F(UtestGeProfilinganager, initialize) { | |||||
| setenv("PROFILING_MODE", "true", true); | |||||
| const std::map<string, string> options({ | |||||
| {OPTION_EXEC_JOB_ID, "0"}, {OPTION_EXEC_PROFILING_MODE, "1"}, {OPTION_EXEC_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"})"} | |||||
| }); | |||||
| ProfilingManager::Instance().Initialize(options); | |||||
| EXPECT_FALSE(ProfilingManager::Instance().is_execute_profiling_); | |||||
| } | |||||
| TEST_F(UtestGeProfilinganager, ParseOptions) { | TEST_F(UtestGeProfilinganager, ParseOptions) { | ||||
| setenv("PROFILING_MODE", "true", true); | setenv("PROFILING_MODE", "true", true); | ||||
| Options options; | Options options; | ||||