From: @taoxiangdong Reviewed-by: Signed-off-by:tags/v1.2.0
| @@ -263,10 +263,10 @@ Status GraphLoader::GetMemoryInfo(int64_t &free) { | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| Status GraphLoader::DestroyAicpuKernel(uint64_t session_id, uint32_t model_id) { | |||||
| Status GraphLoader::DestroyAicpuKernel(uint64_t session_id, uint32_t model_id, uint32_t sub_model_id) { | |||||
| auto model_manager = ModelManager::GetInstance(); | auto model_manager = ModelManager::GetInstance(); | ||||
| GE_CHECK_NOTNULL(model_manager); | GE_CHECK_NOTNULL(model_manager); | ||||
| Status ret = model_manager->DestroyAicpuKernel(session_id, model_id); | |||||
| Status ret = model_manager->DestroyAicpuKernel(session_id, model_id, sub_model_id); | |||||
| if (ret != SUCCESS) { | if (ret != SUCCESS) { | ||||
| GELOGE(ret, "Destroy aicpu kernel failed."); | GELOGE(ret, "Destroy aicpu kernel failed."); | ||||
| return ret; | return ret; | ||||
| @@ -62,7 +62,7 @@ class GraphLoader { | |||||
| const std::vector<GeTensorDesc> &input_desc, OutputData &output_data, | const std::vector<GeTensorDesc> &input_desc, OutputData &output_data, | ||||
| std::vector<GeTensorDesc> &output_desc); | std::vector<GeTensorDesc> &output_desc); | ||||
| static Status DestroyAicpuKernel(uint64_t session_id, uint32_t model_id); | |||||
| static Status DestroyAicpuKernel(uint64_t session_id, uint32_t model_id, uint32_t sub_model_id); | |||||
| static Status DestroyAicpuSessionForInfer(uint32_t model_id); | static Status DestroyAicpuSessionForInfer(uint32_t model_id); | ||||
| @@ -173,6 +173,20 @@ class DavinciModel { | |||||
| /// | /// | ||||
| void SetId(uint32_t model_id) { model_id_ = model_id; } | void SetId(uint32_t model_id) { model_id_ = model_id; } | ||||
| /// | |||||
| /// @ingroup ge | |||||
| /// @brief Get SubModelId | |||||
| /// @return sub model ID | |||||
| /// | |||||
| uint32_t SubModelId() const { return sub_model_id_; } | |||||
| /// | |||||
| /// @ingroup ge | |||||
| /// @brief Get SubModelId | |||||
| /// @return sub model ID | |||||
| /// | |||||
| void SetSubModelId(uint32_t sub_model_id) { sub_model_id_ = sub_model_id; } | |||||
| static void *Run(DavinciModel *model_pointer); | static void *Run(DavinciModel *model_pointer); | ||||
| /// | /// | ||||
| @@ -857,6 +871,7 @@ class DavinciModel { | |||||
| uint32_t model_id_; | uint32_t model_id_; | ||||
| uint32_t runtime_model_id_; | uint32_t runtime_model_id_; | ||||
| uint32_t sub_model_id_ = 0; | |||||
| string name_; | string name_; | ||||
| // used for inference data dump | // used for inference data dump | ||||
| @@ -81,7 +81,8 @@ ModelManager::ModelManager() { | |||||
| session_id_bias_ = 0; | session_id_bias_ = 0; | ||||
| } | } | ||||
| Status ModelManager::KernelLaunchEx(aicpu::FWKAdapter::FWKOperateType op_type, uint64_t session_id, uint32_t model_id) { | |||||
| Status ModelManager::KernelLaunchEx(aicpu::FWKAdapter::FWKOperateType op_type, uint64_t session_id, uint32_t model_id, | |||||
| uint32_t sub_model_id) { | |||||
| STR_FWK_OP_KERNEL param_base = {}; | STR_FWK_OP_KERNEL param_base = {}; | ||||
| void *devicebase = nullptr; | void *devicebase = nullptr; | ||||
| void *aicpu_kernel_addr = nullptr; | void *aicpu_kernel_addr = nullptr; | ||||
| @@ -91,11 +92,12 @@ Status ModelManager::KernelLaunchEx(aicpu::FWKAdapter::FWKOperateType op_type, u | |||||
| param_base.fwkKernelBase.fwk_kernel.sessionID = session_id; | param_base.fwkKernelBase.fwk_kernel.sessionID = session_id; | ||||
| if (op_type == aicpu::FWKAdapter::FWKOperateType::FWK_ADPT_KERNEL_DESTROY) { | if (op_type == aicpu::FWKAdapter::FWKOperateType::FWK_ADPT_KERNEL_DESTROY) { | ||||
| std::vector<uint64_t> v_aicpu_kernel; | std::vector<uint64_t> v_aicpu_kernel; | ||||
| std::string model_key = std::to_string(session_id) + "_" + std::to_string(model_id); | |||||
| std::string model_key = std::to_string(session_id) + "_" + std::to_string(model_id) + "_" + | |||||
| std::to_string(sub_model_id); | |||||
| std::lock_guard<std::recursive_mutex> lock(map_mutex_); | std::lock_guard<std::recursive_mutex> lock(map_mutex_); | ||||
| auto iter = model_aicpu_kernel_.find(model_key); | auto iter = model_aicpu_kernel_.find(model_key); | ||||
| if (iter != model_aicpu_kernel_.end()) { | if (iter != model_aicpu_kernel_.end()) { | ||||
| GELOGD("kernel destroy session_id %lu, model_id %u.", session_id, model_id); | |||||
| GELOGD("kernel destroy session_id %lu, model_id %u, sub_model_id %u..", session_id, model_id, sub_model_id); | |||||
| v_aicpu_kernel = model_aicpu_kernel_.at(model_key); | v_aicpu_kernel = model_aicpu_kernel_.at(model_key); | ||||
| // Insert size of aicpu kernel vector in the first element | // Insert size of aicpu kernel vector in the first element | ||||
| v_aicpu_kernel.insert(v_aicpu_kernel.begin(), v_aicpu_kernel.size()); | v_aicpu_kernel.insert(v_aicpu_kernel.begin(), v_aicpu_kernel.size()); | ||||
| @@ -193,7 +195,7 @@ void ModelManager::DestroyAicpuSession(uint64_t session_id) { | |||||
| GE_CHK_RT(rtSetDevice(static_cast<int32_t>(GetContext().DeviceId()))); | GE_CHK_RT(rtSetDevice(static_cast<int32_t>(GetContext().DeviceId()))); | ||||
| } | } | ||||
| Status ret = KernelLaunchEx(aicpu::FWKAdapter::FWKOperateType::FWK_ADPT_SESSION_DESTROY, session_id, 0); | |||||
| Status ret = KernelLaunchEx(aicpu::FWKAdapter::FWKOperateType::FWK_ADPT_SESSION_DESTROY, session_id, 0, 0); | |||||
| if (ret != SUCCESS) { | if (ret != SUCCESS) { | ||||
| GELOGW("The session: %lu destroy failed.", session_id); | GELOGW("The session: %lu destroy failed.", session_id); | ||||
| } else { | } else { | ||||
| @@ -227,12 +229,14 @@ ge::Status ModelManager::DestroyAicpuSessionForInfer(uint32_t model_id) { | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| ge::Status ModelManager::DestroyAicpuKernel(uint64_t session_id, uint32_t model_id) { | |||||
| ge::Status ModelManager::DestroyAicpuKernel(uint64_t session_id, uint32_t model_id, uint32_t sub_model_id) { | |||||
| GELOGD("destroy aicpu kernel in session_id %lu, model_id %u.", session_id, model_id); | GELOGD("destroy aicpu kernel in session_id %lu, model_id %u.", session_id, model_id); | ||||
| std::lock_guard<std::recursive_mutex> lock(map_mutex_); | std::lock_guard<std::recursive_mutex> lock(map_mutex_); | ||||
| std::string model_key = std::to_string(session_id) + "_" + std::to_string(model_id); | |||||
| std::string model_key = std::to_string(session_id) + "_" + std::to_string(model_id) + "_" + | |||||
| std::to_string(sub_model_id); | |||||
| if (model_aicpu_kernel_.find(model_key) != model_aicpu_kernel_.end()) { | if (model_aicpu_kernel_.find(model_key) != model_aicpu_kernel_.end()) { | ||||
| Status ret = KernelLaunchEx(aicpu::FWKAdapter::FWKOperateType::FWK_ADPT_KERNEL_DESTROY, session_id, model_id); | |||||
| Status ret = KernelLaunchEx(aicpu::FWKAdapter::FWKOperateType::FWK_ADPT_KERNEL_DESTROY, session_id, model_id, | |||||
| sub_model_id); | |||||
| if (ret != SUCCESS) { | if (ret != SUCCESS) { | ||||
| GELOGE(FAILED, "Destroy aicpu kernel failed."); | GELOGE(FAILED, "Destroy aicpu kernel failed."); | ||||
| return FAILED; | return FAILED; | ||||
| @@ -241,10 +245,12 @@ ge::Status ModelManager::DestroyAicpuKernel(uint64_t session_id, uint32_t model_ | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| ge::Status ModelManager::CreateAicpuKernel(uint64_t session_id, uint32_t model_id, uint64_t kernel_id) { | |||||
| ge::Status ModelManager::CreateAicpuKernel(uint64_t session_id, uint32_t model_id, uint32_t sub_model_id, | |||||
| uint64_t kernel_id) { | |||||
| std::lock_guard<std::recursive_mutex> lock(map_mutex_); | std::lock_guard<std::recursive_mutex> lock(map_mutex_); | ||||
| std::vector<uint64_t> v_aicpu_kernel; | std::vector<uint64_t> v_aicpu_kernel; | ||||
| std::string model_key = std::to_string(session_id) + "_" + std::to_string(model_id); | |||||
| std::string model_key = std::to_string(session_id) + "_" + std::to_string(model_id) + "_" + | |||||
| std::to_string(sub_model_id); | |||||
| if (model_aicpu_kernel_.find(model_key) != model_aicpu_kernel_.end()) { | if (model_aicpu_kernel_.find(model_key) != model_aicpu_kernel_.end()) { | ||||
| v_aicpu_kernel = model_aicpu_kernel_.at(model_key); | v_aicpu_kernel = model_aicpu_kernel_.at(model_key); | ||||
| } | } | ||||
| @@ -379,7 +385,8 @@ Status ModelManager::DeleteModel(uint32_t id) { | |||||
| auto hybrid_model_it = hybrid_model_map_.find(id); | auto hybrid_model_it = hybrid_model_map_.find(id); | ||||
| if (it != model_map_.end()) { | if (it != model_map_.end()) { | ||||
| uint64_t session_id = it->second->GetSessionId(); | uint64_t session_id = it->second->GetSessionId(); | ||||
| std::string model_key = std::to_string(session_id) + "_" + std::to_string(id); | |||||
| std::string model_key = std::to_string(session_id) + "_" + std::to_string(id) + "_" + | |||||
| std::to_string(it->second->SubModelId()); | |||||
| auto iter_aicpu_kernel = model_aicpu_kernel_.find(model_key); | auto iter_aicpu_kernel = model_aicpu_kernel_.find(model_key); | ||||
| if (iter_aicpu_kernel != model_aicpu_kernel_.end()) { | if (iter_aicpu_kernel != model_aicpu_kernel_.end()) { | ||||
| (void)model_aicpu_kernel_.erase(iter_aicpu_kernel); | (void)model_aicpu_kernel_.erase(iter_aicpu_kernel); | ||||
| @@ -1218,7 +1225,8 @@ Status ModelManager::ExecuteModel(uint32_t model_id, rtStream_t stream, bool asy | |||||
| // Zero copy is enabled by default, no need to judge. | // Zero copy is enabled by default, no need to judge. | ||||
| uint64_t session_id_davinci = davinci_model->GetSessionId(); | uint64_t session_id_davinci = davinci_model->GetSessionId(); | ||||
| uint32_t model_id_davinci = davinci_model->GetModelId(); | uint32_t model_id_davinci = davinci_model->GetModelId(); | ||||
| Status status = DestroyAicpuKernel(session_id_davinci, model_id_davinci); | |||||
| uint32_t sub_model_id = davinci_model->SubModelId(); | |||||
| Status status = DestroyAicpuKernel(session_id_davinci, model_id_davinci, sub_model_id); | |||||
| if (status != SUCCESS) { | if (status != SUCCESS) { | ||||
| GELOGW("Destroy specified aicpu kernel failed, session id is %lu, model id is %u.", session_id_davinci, | GELOGW("Destroy specified aicpu kernel failed, session id is %lu, model id is %u.", session_id_davinci, | ||||
| model_id_davinci); | model_id_davinci); | ||||
| @@ -1238,7 +1246,7 @@ Status ModelManager::CreateAicpuSession(uint64_t session_id) { | |||||
| auto it = sess_ids_.find(session_id); | auto it = sess_ids_.find(session_id); | ||||
| // never been created by any model | // never been created by any model | ||||
| if (it == sess_ids_.end()) { | if (it == sess_ids_.end()) { | ||||
| Status ret = KernelLaunchEx(aicpu::FWKAdapter::FWKOperateType::FWK_ADPT_SESSION_CREATE, session_id, 0); | |||||
| Status ret = KernelLaunchEx(aicpu::FWKAdapter::FWKOperateType::FWK_ADPT_SESSION_CREATE, session_id, 0, 0); | |||||
| if (ret == SUCCESS) { | if (ret == SUCCESS) { | ||||
| (void)sess_ids_.insert(session_id); | (void)sess_ids_.insert(session_id); | ||||
| GELOGI("The session: %lu create success.", session_id); | GELOGI("The session: %lu create success.", session_id); | ||||
| @@ -259,7 +259,8 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ModelManager { | |||||
| std::shared_ptr<hybrid::HybridDavinciModel> GetHybridModel(uint32_t id); | std::shared_ptr<hybrid::HybridDavinciModel> GetHybridModel(uint32_t id); | ||||
| ge::Status KernelLaunchEx(aicpu::FWKAdapter::FWKOperateType op_type, uint64_t session_id, uint32_t model_id); | |||||
| ge::Status KernelLaunchEx(aicpu::FWKAdapter::FWKOperateType op_type, uint64_t session_id, uint32_t model_id, | |||||
| uint32_t sub_model_id); | |||||
| ge::Status CreateAicpuSession(uint64_t session_id); | ge::Status CreateAicpuSession(uint64_t session_id); | ||||
| @@ -267,9 +268,9 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ModelManager { | |||||
| void DestroyAicpuSession(uint64_t session_id); | void DestroyAicpuSession(uint64_t session_id); | ||||
| ge::Status DestroyAicpuKernel(uint64_t session_id, uint32_t model_id); | |||||
| ge::Status DestroyAicpuKernel(uint64_t session_id, uint32_t model_id, uint32_t sub_model_id); | |||||
| ge::Status CreateAicpuKernel(uint64_t session_id, uint32_t model_id, uint64_t kernel_id); | |||||
| ge::Status CreateAicpuKernel(uint64_t session_id, uint32_t model_id, uint32_t sub_model_id, uint64_t kernel_id); | |||||
| ge::Status DestroyAicpuSessionForInfer(uint32_t model_id); | ge::Status DestroyAicpuSessionForInfer(uint32_t model_id); | ||||
| @@ -85,7 +85,8 @@ Status KernelExTaskInfo::Init(const domi::TaskDef &task_def, DavinciModel *davin | |||||
| // 2.2 Collect aicpu kernel | // 2.2 Collect aicpu kernel | ||||
| uint64_t kernel_id = fwk_op_kernel.fwkKernelBase.fwk_kernel.kernelID; | uint64_t kernel_id = fwk_op_kernel.fwkKernelBase.fwk_kernel.kernelID; | ||||
| GE_IF_BOOL_EXEC(ModelManager::GetInstance()->CreateAicpuKernel(session_id, davinci_model->Id(), kernel_id) != SUCCESS, | |||||
| GE_IF_BOOL_EXEC(ModelManager::GetInstance()->CreateAicpuKernel(session_id, davinci_model->Id(), | |||||
| davinci_model->SubModelId(), kernel_id) != SUCCESS, | |||||
| GELOGE(FAILED, "CreateAicpuKernel error."); | GELOGE(FAILED, "CreateAicpuKernel error."); | ||||
| return FAILED;) | return FAILED;) | ||||
| // 2.3 Create session | // 2.3 Create session | ||||
| @@ -2473,7 +2473,7 @@ Status GraphManager::CheckAndReleaseMemory(const GeModelPtr &ge_model, const Gra | |||||
| GELOGE(RT_FAILED, "[GraphManager:] rtSetDevice failed, modelId=%u, graphId=%u.", model_id, graph_id); | GELOGE(RT_FAILED, "[GraphManager:] rtSetDevice failed, modelId=%u, graphId=%u.", model_id, graph_id); | ||||
| continue; | continue; | ||||
| } | } | ||||
| result = GraphLoader::DestroyAicpuKernel(session_id, model_id); | |||||
| result = GraphLoader::DestroyAicpuKernel(session_id, model_id, 0); | |||||
| if (result != SUCCESS) { | if (result != SUCCESS) { | ||||
| GELOGW("[GraphManager:] destroy aicpu kernel failed when dynamic memory, modelId=%u, graphId=%u.", model_id, | GELOGW("[GraphManager:] destroy aicpu kernel failed when dynamic memory, modelId=%u, graphId=%u.", model_id, | ||||
| graph_id); | graph_id); | ||||
| @@ -127,11 +127,18 @@ Status KnownNodeTask::Init(TaskContext &context) { | |||||
| if (dump_properties.IsDumpOpen()) { | if (dump_properties.IsDumpOpen()) { | ||||
| davinci_model_->SetDumpProperties(dump_properties); | davinci_model_->SetDumpProperties(dump_properties); | ||||
| } | } | ||||
| int32_t device_id = 0; | |||||
| rtError_t rt_ret = rtGetDevice(&device_id); | |||||
| if (rt_ret != RT_ERROR_NONE || device_id < 0) { | |||||
| GELOGE(rt_ret, "Call rtGetDevice failed, ret = 0x%X, device_id = %d.", rt_ret, device_id); | |||||
| return RT_ERROR_TO_GE_STATUS(rt_ret); | |||||
| } | |||||
| davinci_model_->SetDeviceId(device_id); | |||||
| GE_CHK_STATUS_RET(davinci_model_->Init(), "KnownNodeExecutor::InitDavinciModel failed."); | GE_CHK_STATUS_RET(davinci_model_->Init(), "KnownNodeExecutor::InitDavinciModel failed."); | ||||
| load_flag_ = true; | load_flag_ = true; | ||||
| } else { | } else { | ||||
| GE_CHK_STATUS_RET(ModelManager::GetInstance()->DestroyAicpuKernel(davinci_model_->GetSessionId(), | GE_CHK_STATUS_RET(ModelManager::GetInstance()->DestroyAicpuKernel(davinci_model_->GetSessionId(), | ||||
| davinci_model_->Id()), "KnownNodeTask::Init destroy aicpu kernel failed."); | |||||
| davinci_model_->Id(), davinci_model_->SubModelId()), "KnownNodeTask::Init destroy aicpu kernel failed."); | |||||
| } | } | ||||
| GELOGI("[%s] KnownNodeExecutor::Init success.", context.GetNodeName()); | GELOGI("[%s] KnownNodeExecutor::Init success.", context.GetNodeName()); | ||||
| return SUCCESS; | return SUCCESS; | ||||
| @@ -165,8 +172,9 @@ Status KnownNodeExecutor::LoadTask(const HybridModel &model, const NodePtr &node | |||||
| // set known node flag as true | // set known node flag as true | ||||
| davinci_model->SetKnownNode(true); | davinci_model->SetKnownNode(true); | ||||
| davinci_model->SetId(model.GetModelId()); | |||||
| // set model id as root node's node id | // set model id as root node's node id | ||||
| davinci_model->SetId(node->GetOpDesc()->GetId()); | |||||
| davinci_model->SetSubModelId(node->GetOpDesc()->GetId()); | |||||
| GELOGD("KnownNodeExecutor::LoadTask node id %ld.", node->GetOpDesc()->GetId()); | GELOGD("KnownNodeExecutor::LoadTask node id %ld.", node->GetOpDesc()->GetId()); | ||||
| GE_CHK_STATUS_RET(davinci_model->Assign(ge_model), "KnownNodeExecutor::LoadTask davincimodel assign failed."); | GE_CHK_STATUS_RET(davinci_model->Assign(ge_model), "KnownNodeExecutor::LoadTask davincimodel assign failed."); | ||||
| @@ -14,24 +14,23 @@ | |||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #include <cce/compiler_stub.h> | |||||
| #include <gtest/gtest.h> | #include <gtest/gtest.h> | ||||
| #include <cce/compiler_stub.h> | |||||
| #include "common/debug/log.h" | #include "common/debug/log.h" | ||||
| #include "common/l2_cache_optimize.h" | |||||
| #include "common/model_parser/base.h" | #include "common/model_parser/base.h" | ||||
| #include "common/properties_manager.h" | #include "common/properties_manager.h" | ||||
| #include "common/types.h" | #include "common/types.h" | ||||
| #include "common/l2_cache_optimize.h" | |||||
| #define private public | #define private public | ||||
| #define protected public | #define protected public | ||||
| #include "graph/load/new_model_manager/model_manager.h" | |||||
| #include "common/helper/om_file_helper.h" | #include "common/helper/om_file_helper.h" | ||||
| #include "common/op/ge_op_utils.h" | #include "common/op/ge_op_utils.h" | ||||
| #include "graph/load/graph_loader.h" | #include "graph/load/graph_loader.h" | ||||
| #include "graph/load/new_model_manager/davinci_model.h" | #include "graph/load/new_model_manager/davinci_model.h" | ||||
| #include "graph/load/new_model_manager/davinci_model_parser.h" | #include "graph/load/new_model_manager/davinci_model_parser.h" | ||||
| #include "graph/load/new_model_manager/model_manager.h" | |||||
| //#include "new_op_test_utils.h" | //#include "new_op_test_utils.h" | ||||
| #undef private | #undef private | ||||
| #undef protected | #undef protected | ||||
| @@ -60,7 +59,20 @@ TEST_F(UtestModelManagerModelManagerAicpu, checkAicpuOptype) { | |||||
| model_manager.LaunchKernelCheckAicpuOp(aicpu_op_list, aicpu_tf_list); | model_manager.LaunchKernelCheckAicpuOp(aicpu_op_list, aicpu_tf_list); | ||||
| // Load allow listener is null | // Load allow listener is null | ||||
| //EXPECT_EQ(ge::FAILED, mm.LoadModelOffline(model_id, data, nullptr, nullptr)); | |||||
| // EXPECT_EQ(ge::FAILED, mm.LoadModelOffline(model_id, data, nullptr, nullptr)); | |||||
| } | |||||
| TEST_F(UtestModelManagerModelManagerAicpu, DestroyAicpuKernel) { | |||||
| ModelManager model_manager; | |||||
| uint32_t model_id = 0; | |||||
| std::vector<std::string> aicpu_op_list; | |||||
| std::vector<std::string> aicpu_tf_list; | |||||
| aicpu_tf_list.emplace_back("FrameworkOp"); | |||||
| aicpu_tf_list.emplace_back("Unique"); | |||||
| model_manager.DestroyAicpuKernel(0,0,0); | |||||
| // Load allow listener is null | |||||
| // EXPECT_EQ(ge::FAILED, mm.LoadModelOffline(model_id, data, nullptr, nullptr)); | |||||
| } | } | ||||
| } // namespace ge | } // namespace ge | ||||