From: @zhangxiaokun9 Reviewed-by: @xchu42,@wqtshg,@ji_chen Signed-off-by: @ji_chentags/v1.2.0
| @@ -209,19 +209,6 @@ bool IsDynmaicDimsSizeMatchModel(const vector<uint64_t> cur_dynamic_dims, | |||||
| namespace ge { | namespace ge { | ||||
| bool GeExecutor::isInit_ = false; | bool GeExecutor::isInit_ = false; | ||||
| class ModelListenerAdapter : public ModelListener { | |||||
| public: | |||||
| domi::Status OnComputeDone(uint32_t model_id, uint32_t dataIndex, uint32_t resultCode, | |||||
| std::vector<ge::OutputTensorInfo> &outputs) { | |||||
| if (listener == nullptr) { | |||||
| GELOGE(ge::FAILED, "listener is null."); | |||||
| return FAILED; | |||||
| } | |||||
| return listener->OnComputeDone(model_id, dataIndex, resultCode, outputs); | |||||
| } | |||||
| std::shared_ptr<ge::ModelListener> listener; | |||||
| }; | |||||
| static void InitOpsProtoManger() { | static void InitOpsProtoManger() { | ||||
| string opsproto_path; | string opsproto_path; | ||||
| @@ -573,60 +560,6 @@ Status GeExecutor::SetDynamicAippData(uint32_t model_id, void *dynamic_input_add | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| // Load model | |||||
| Status GeExecutor::LoadModelOffline(uint32_t &model_id, const std::string &path, const std::string &key, | |||||
| int32_t priority, std::shared_ptr<ge::ModelListener> listener) { | |||||
| GELOGI("load model offline begin."); | |||||
| if (!isInit_) { | |||||
| GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); | |||||
| return ACL_ERROR_GE_EXEC_NOT_INIT; | |||||
| } | |||||
| string filePath = RealPath(path.c_str()); | |||||
| if (filePath.empty()) { | |||||
| GELOGE(ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID, | |||||
| "File path is invalid. please check your text file '%s'.", path.c_str()); | |||||
| return ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID; | |||||
| } | |||||
| std::shared_ptr<ModelListenerAdapter> listener_adapter = MakeShared<ModelListenerAdapter>(); | |||||
| if (listener_adapter == nullptr) { | |||||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "ModelListenerAdapter make shared failed!"); | |||||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||||
| } | |||||
| listener_adapter->listener = listener; | |||||
| Status ret = GraphLoader::LoadModelFromFile(path, key, priority, listener_adapter, model_id); | |||||
| if (ret != SUCCESS) { | |||||
| GELOGE(ret, "[GeExecutor] LoadModelFromFile failed"); | |||||
| return ACL_ERROR_GE_LOAD_MODEL; | |||||
| } | |||||
| return SUCCESS; | |||||
| } | |||||
| Status GeExecutor::LoadModel(uint32_t &model_id, const ModelData &model_data, | |||||
| std::shared_ptr<ge::ModelListener> listener) { | |||||
| GELOGI("Load model begin."); | |||||
| if (!isInit_) { | |||||
| GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); | |||||
| return ACL_ERROR_GE_EXEC_NOT_INIT; | |||||
| } | |||||
| std::shared_ptr<ModelListenerAdapter> listener_adapter = MakeShared<ModelListenerAdapter>(); | |||||
| if (listener_adapter == nullptr) { | |||||
| GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "ModelListenerAdapter make shared failed!"); | |||||
| return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||||
| } | |||||
| listener_adapter->listener = listener; | |||||
| Status ret = GraphLoader::LoadModel(model_data, listener_adapter, model_id); | |||||
| if (ret != SUCCESS) { | |||||
| GELOGE(ret, "[GeExecutor] LoadModel failed."); | |||||
| return ACL_ERROR_GE_LOAD_MODEL; | |||||
| } | |||||
| return ret; | |||||
| } | |||||
| Status GeExecutor::UnloadModel(uint32_t model_id) { | Status GeExecutor::UnloadModel(uint32_t model_id) { | ||||
| GELOGD("unload model %u begin.", model_id); | GELOGD("unload model %u begin.", model_id); | ||||
| if (!isInit_) { | if (!isInit_) { | ||||
| @@ -659,21 +592,6 @@ Status GeExecutor::UnloadModel(uint32_t model_id) { | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| Status GeExecutor::RunModel(const ge::RunModelData &input_data, ge::RunModelData &output_data) { | |||||
| GELOGI("run model begin."); | |||||
| if (!isInit_) { | |||||
| GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!"); | |||||
| return ACL_ERROR_GE_EXEC_NOT_INIT; | |||||
| } | |||||
| InputData inputs; | |||||
| GetDomiInputData(input_data, inputs); | |||||
| OutputData outputs; | |||||
| GetDomiOutputData(output_data, outputs); | |||||
| return GraphExecutor::DataInput(inputs, outputs); | |||||
| } | |||||
| // Get input and output descriptor | // Get input and output descriptor | ||||
| Status GeExecutor::GetModelDescInfo(uint32_t model_id, std::vector<ge::TensorDesc> &input_desc, | Status GeExecutor::GetModelDescInfo(uint32_t model_id, std::vector<ge::TensorDesc> &input_desc, | ||||
| std::vector<ge::TensorDesc> &output_desc, bool new_model_desc) { | std::vector<ge::TensorDesc> &output_desc, bool new_model_desc) { | ||||
| @@ -144,63 +144,6 @@ Status GraphLoader::LoadDataFromFile(const std::string &path, const std::string | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| Status GraphLoader::LoadModelFromFile(const std::string &path, const std::string &key_path, int32_t priority, | |||||
| const std::shared_ptr<ModelListener> &listener, uint32_t &model_id) { | |||||
| Status ret; | |||||
| ModelData model_data; | |||||
| ret = LoadDataFromFile(path, key_path, priority, model_data); | |||||
| if (ret != SUCCESS) { | |||||
| GELOGE(ret, "LoadModelFromFile: Load failed. ret = %u", ret); | |||||
| if (model_data.model_data != nullptr) { | |||||
| delete[] static_cast<char *>(model_data.model_data); | |||||
| model_data.model_data = nullptr; | |||||
| } | |||||
| return ret; | |||||
| } | |||||
| ret = LoadModel(model_data, listener, model_id); | |||||
| if (ret != SUCCESS) { | |||||
| GELOGE(ret, "LoadModel: Load failed. ret = %u", ret); | |||||
| if (model_data.model_data != nullptr) { | |||||
| delete[] static_cast<char *>(model_data.model_data); | |||||
| model_data.model_data = nullptr; | |||||
| } | |||||
| } | |||||
| if (model_data.model_data != nullptr) { | |||||
| delete[] static_cast<char *>(model_data.model_data); | |||||
| model_data.model_data = nullptr; | |||||
| } | |||||
| return ret; | |||||
| } | |||||
| Status GraphLoader::LoadModel(const ModelData &model_data, const std::shared_ptr<ModelListener> &listener, | |||||
| uint32_t &model_id) { | |||||
| GELOGI("Load model begin, model_id:%u.", model_id); | |||||
| // For GeOp, Open Device 0 here. | |||||
| GE_CHK_RT_RET(rtSetDevice(0)); | |||||
| auto model_manager = ModelManager::GetInstance(); | |||||
| GE_CHECK_NOTNULL(model_manager); | |||||
| Status ret = model_manager->LoadModelOffline(model_id, model_data, listener); | |||||
| if (ret != SUCCESS) { | |||||
| GE_CHK_RT(rtDeviceReset(0)); | |||||
| GELOGE(ACL_ERROR_GE_LOAD_MODEL, "LoadModel: Load failed."); | |||||
| return ACL_ERROR_GE_LOAD_MODEL; | |||||
| } | |||||
| ret = model_manager->Start(model_id); | |||||
| if (ret != SUCCESS) { | |||||
| if (model_manager->Unload(model_id) != SUCCESS) { | |||||
| GELOGE(ACL_ERROR_GE_UNLOAD_MODEL, "LoadModel: Unload failed while trying to unload after a failed start."); | |||||
| } | |||||
| GELOGE(ret, "LoadModel: Start failed."); | |||||
| return ret; | |||||
| } | |||||
| GELOGI("LoadModel: Start model success, model_id:%u.", model_id); | |||||
| return SUCCESS; | |||||
| } | |||||
| Status GraphLoader::CommandHandle(const Command &command) { | Status GraphLoader::CommandHandle(const Command &command) { | ||||
| try { | try { | ||||
| auto model_manager = ModelManager::GetInstance(); | auto model_manager = ModelManager::GetInstance(); | ||||
| @@ -225,13 +168,13 @@ Status GraphLoader::CommandHandle(const Command &command) { | |||||
| } | } | ||||
| Status GraphLoader::LoadModelFromData(uint32_t &model_id, const ModelData &model_data, void *dev_ptr, | Status GraphLoader::LoadModelFromData(uint32_t &model_id, const ModelData &model_data, void *dev_ptr, | ||||
| size_t memsize, void *weight_ptr, size_t weightsize) { | |||||
| size_t mem_size, void *weight_ptr, size_t weight_size) { | |||||
| GELOGI("Load model begin, model_id:%u.", model_id); | GELOGI("Load model begin, model_id:%u.", model_id); | ||||
| // For ACL, Open Device from App. | // For ACL, Open Device from App. | ||||
| auto model_manager = ModelManager::GetInstance(); | auto model_manager = ModelManager::GetInstance(); | ||||
| GE_CHECK_NOTNULL(model_manager); | GE_CHECK_NOTNULL(model_manager); | ||||
| Status ret = model_manager->LoadModelOffline( | Status ret = model_manager->LoadModelOffline( | ||||
| model_id, model_data, nullptr, dev_ptr, memsize, weight_ptr, weightsize); | |||||
| model_id, model_data, nullptr, dev_ptr, mem_size, weight_ptr, weight_size); | |||||
| if (ret != SUCCESS) { | if (ret != SUCCESS) { | ||||
| GELOGE(ACL_ERROR_GE_LOAD_MODEL, "Load model failed, model_id:%u.", model_id); | GELOGE(ACL_ERROR_GE_LOAD_MODEL, "Load model failed, model_id:%u.", model_id); | ||||
| return ACL_ERROR_GE_LOAD_MODEL; | return ACL_ERROR_GE_LOAD_MODEL; | ||||
| @@ -44,12 +44,6 @@ class GraphLoader { | |||||
| static Status GetMaxUsedMemory(uint32_t model_id, uint64_t &max_size); | static Status GetMaxUsedMemory(uint32_t model_id, uint64_t &max_size); | ||||
| static Status LoadModel(const ModelData &model_data, const std::shared_ptr<ModelListener> &listener, | |||||
| uint32_t &model_id); | |||||
| static Status LoadModelFromFile(const std::string &path, const std::string &key_path, int32_t priority, | |||||
| const std::shared_ptr<ModelListener> &listener, uint32_t &model_id); | |||||
| static Status CommandHandle(const Command &command); | static Status CommandHandle(const Command &command); | ||||
| static Status GetMemoryInfo(int64_t &free); | static Status GetMemoryInfo(int64_t &free); | ||||
| @@ -90,20 +90,18 @@ Status KernelTaskInfo::Init(const domi::TaskDef &task_def, DavinciModel *davinci | |||||
| fusion_op_info_.op_index = context.op_index(); fusion_op_info_.original_op_names = original_op_names; | fusion_op_info_.op_index = context.op_index(); fusion_op_info_.original_op_names = original_op_names; | ||||
| fusion_op_info_.op_name = op_desc_->GetName()); | fusion_op_info_.op_name = op_desc_->GetName()); | ||||
| string session_graph_model_id; | |||||
| davinci_model_->GetUniqueId(op_desc_, session_graph_model_id); | |||||
| // get bin_file_key | |||||
| const char *bin_file_key = davinci_model_->GetRegisterStub(op_desc_->GetName(), session_graph_model_id); | |||||
| // new aicpu kernel(rtCpuKernelLaunch) no need to check function | // new aicpu kernel(rtCpuKernelLaunch) no need to check function | ||||
| if (kernel_type_ == ccKernelType::CCE_AI_CORE) { | if (kernel_type_ == ccKernelType::CCE_AI_CORE) { | ||||
| rtError_t rt_ret; | |||||
| rt_ret = rtGetFunctionByName(const_cast<char *>(kernel_def.stub_func().c_str()), &stub_func_); | |||||
| rtError_t rt_ret = rtGetFunctionByName(const_cast<char *>(kernel_def.stub_func().c_str()), &stub_func_); | |||||
| GE_IF_BOOL_EXEC(rt_ret != RT_ERROR_NONE, GELOGE(RT_FAILED, "execute rtGetFunctionByName failed. stub_func: %s", | GE_IF_BOOL_EXEC(rt_ret != RT_ERROR_NONE, GELOGE(RT_FAILED, "execute rtGetFunctionByName failed. stub_func: %s", | ||||
| kernel_def.stub_func().c_str()); | kernel_def.stub_func().c_str()); | ||||
| return RT_ERROR_TO_GE_STATUS(rt_ret);); | return RT_ERROR_TO_GE_STATUS(rt_ret);); | ||||
| } else if (kernel_type_ == ccKernelType::TE) { | } else if (kernel_type_ == ccKernelType::TE) { | ||||
| rtError_t rt_ret; | |||||
| rt_ret = rtGetFunctionByName(bin_file_key, &stub_func_); | |||||
| // get bin_file_key | |||||
| string session_graph_model_id; | |||||
| davinci_model_->GetUniqueId(op_desc_, session_graph_model_id); | |||||
| const char *bin_file_key = davinci_model_->GetRegisterStub(op_desc_->GetName(), session_graph_model_id); | |||||
| rtError_t rt_ret = rtGetFunctionByName(bin_file_key, &stub_func_); | |||||
| GE_IF_BOOL_EXEC(rt_ret != RT_ERROR_NONE, | GE_IF_BOOL_EXEC(rt_ret != RT_ERROR_NONE, | ||||
| GELOGE(RT_FAILED, "execute rtGetFunctionByName failed. bin_file_key: %s", bin_file_key); | GELOGE(RT_FAILED, "execute rtGetFunctionByName failed. bin_file_key: %s", bin_file_key); | ||||
| return RT_ERROR_TO_GE_STATUS(rt_ret);); | return RT_ERROR_TO_GE_STATUS(rt_ret);); | ||||
| @@ -30,8 +30,6 @@ | |||||
| #include "runtime/base.h" | #include "runtime/base.h" | ||||
| namespace ge { | namespace ge { | ||||
| class ModelListenerAdapter; | |||||
| class SingleOp; | class SingleOp; | ||||
| class DynamicSingleOp; | class DynamicSingleOp; | ||||
| @@ -55,14 +53,8 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY GeExecutor { | |||||
| ge::Status Initialize(); | ge::Status Initialize(); | ||||
| ge::Status Finalize(); | ge::Status Finalize(); | ||||
| // Load model | |||||
| ge::Status LoadModelOffline(uint32_t &model_id, const std::string &path, const std::string &key, int32_t priority, | |||||
| std::shared_ptr<ge::ModelListener> listener); | |||||
| ge::Status UnloadModel(uint32_t modelId); | ge::Status UnloadModel(uint32_t modelId); | ||||
| ge::Status RunModel(const ge::RunModelData &input_data, ge::RunModelData &output_data); | |||||
| // Get input and output descriptor | // Get input and output descriptor | ||||
| ge::Status GetModelDescInfo(uint32_t model_id, std::vector<ge::TensorDesc> &input_desc, | ge::Status GetModelDescInfo(uint32_t model_id, std::vector<ge::TensorDesc> &input_desc, | ||||
| std::vector<ge::TensorDesc> &output_desc, bool new_model_desc = false); | std::vector<ge::TensorDesc> &output_desc, bool new_model_desc = false); | ||||
| @@ -168,9 +160,6 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY GeExecutor { | |||||
| ge::Status GetModelDescInfoForZeroCopy(uint32_t model_id, std::vector<ge::TensorDesc> &input_desc, | ge::Status GetModelDescInfoForZeroCopy(uint32_t model_id, std::vector<ge::TensorDesc> &input_desc, | ||||
| std::vector<ge::TensorDesc> &output_desc); | std::vector<ge::TensorDesc> &output_desc); | ||||
| ge::Status LoadModel(uint32_t &model_id, const ge::ModelData &model_data, | |||||
| std::shared_ptr<ge::ModelListener> listener); | |||||
| ge::Status CommandHandle(const ge::Command &command); | ge::Status CommandHandle(const ge::Command &command); | ||||
| ge::Status SetDump(const DumpConfig &dump_config); | ge::Status SetDump(const DumpConfig &dump_config); | ||||
| @@ -297,8 +286,6 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY GeExecutor { | |||||
| private: | private: | ||||
| static bool isInit_; | static bool isInit_; | ||||
| }; | }; | ||||
| ge::Status ModelInfoParser(const ge::ModelData &model, ge::ModelInfo &model_info); | |||||
| } // namespace ge | } // namespace ge | ||||
| #endif // INC_FRAMEWORK_EXECUTOR_GE_EXECUTOR_H_ | #endif // INC_FRAMEWORK_EXECUTOR_GE_EXECUTOR_H_ | ||||