From: @youui Reviewed-by: @wqtshg,@xchu42,@ji_chen Signed-off-by: @ji_chentags/v1.2.0
@@ -1289,8 +1289,8 @@ Status ModelManager::CreateAicpuSession(uint64_t session_id) { | |||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
Status ModelManager::LoadCustAicpuSo(const OpDescPtr &op_desc, const string &so_name) { | |||||
GELOGI("LoadCustAicpuSo in, op name %s, so name %s", op_desc->GetName().c_str(), so_name.c_str()); | |||||
Status ModelManager::LoadCustAicpuSo(const OpDescPtr &op_desc, const string &so_name, bool &loaded) { | |||||
GELOGD("LoadCustAicpuSo in, op name %s, so name %s", op_desc->GetName().c_str(), so_name.c_str()); | |||||
std::lock_guard<std::mutex> lock(cust_aicpu_mutex_); | std::lock_guard<std::mutex> lock(cust_aicpu_mutex_); | ||||
CustAICPUKernelPtr aicpu_kernel = op_desc->TryGetExtAttr(OP_EXTATTR_CUSTAICPU_KERNEL, CustAICPUKernelPtr()); | CustAICPUKernelPtr aicpu_kernel = op_desc->TryGetExtAttr(OP_EXTATTR_CUSTAICPU_KERNEL, CustAICPUKernelPtr()); | ||||
if (aicpu_kernel == nullptr) { | if (aicpu_kernel == nullptr) { | ||||
@@ -1313,18 +1313,24 @@ Status ModelManager::LoadCustAicpuSo(const OpDescPtr &op_desc, const string &so_ | |||||
std::map<string, CustAICPUKernelPtr> new_so_name; | std::map<string, CustAICPUKernelPtr> new_so_name; | ||||
new_so_name.insert({so_name, aicpu_kernel}); | new_so_name.insert({so_name, aicpu_kernel}); | ||||
cust_aicpu_so_[resource_id] = new_so_name; | cust_aicpu_so_[resource_id] = new_so_name; | ||||
GELOGI("LoadCustAicpuSo new aicpu so resource id %lu", resource_id); | |||||
loaded = false; | |||||
GELOGD("LoadCustAicpuSo new aicpu so name %s, resource id %lu", so_name.c_str(), resource_id); | |||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
auto it_so_name = it->second.find(so_name); | auto it_so_name = it->second.find(so_name); | ||||
if (it_so_name == it->second.end()) { | if (it_so_name == it->second.end()) { | ||||
it->second.insert({so_name, aicpu_kernel}); | it->second.insert({so_name, aicpu_kernel}); | ||||
GELOGI("LoadCustAicpuSo add aicpu so resource id %lu", resource_id); | |||||
loaded = false; | |||||
GELOGD("LoadCustAicpuSo add aicpu so name %s, resource id %lu", so_name.c_str(), resource_id); | |||||
return SUCCESS; | |||||
} | } | ||||
loaded = true; | |||||
GELOGD("LoadCustAicpuSo so name %s has been loaded.", so_name.c_str()); | |||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
Status ModelManager::LaunchKernelCustAicpuSo(const string &kernel_name) { | Status ModelManager::LaunchKernelCustAicpuSo(const string &kernel_name) { | ||||
GELOGD("Aicpu kernel launch task in, kernel name %s.", kernel_name.c_str()); | |||||
std::lock_guard<std::mutex> lock(cust_aicpu_mutex_); | std::lock_guard<std::mutex> lock(cust_aicpu_mutex_); | ||||
if (cust_aicpu_so_.size() == 0) return SUCCESS; | if (cust_aicpu_so_.size() == 0) return SUCCESS; | ||||
// get current context | // get current context | ||||
@@ -289,7 +289,7 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ModelManager { | |||||
ge::Status DestroyAicpuSessionForInfer(uint32_t model_id); | ge::Status DestroyAicpuSessionForInfer(uint32_t model_id); | ||||
ge::Status LoadCustAicpuSo(const OpDescPtr &op_desc, const string &so_name); | |||||
ge::Status LoadCustAicpuSo(const OpDescPtr &op_desc, const string &so_name, bool &loaded); | |||||
ge::Status LaunchCustAicpuSo(); | ge::Status LaunchCustAicpuSo(); | ||||
@@ -875,7 +875,9 @@ Status KernelTaskInfo::InitAicpuTask(uint32_t op_index, const domi::KernelDef &k | |||||
} | } | ||||
if (kernel_type_ == ccKernelType::CUST_AI_CPU) { | if (kernel_type_ == ccKernelType::CUST_AI_CPU) { | ||||
GE_CHK_STATUS_RET(ModelManager::GetInstance()->LoadCustAicpuSo(op_desc, so_name_), "launch cust aicpu so failed"); | |||||
bool loaded = false; | |||||
GE_CHK_STATUS_RET(ModelManager::GetInstance()->LoadCustAicpuSo(op_desc, so_name_, loaded), | |||||
"launch cust aicpu so failed"); | |||||
} | } | ||||
// copy args to new host memory | // copy args to new host memory | ||||
@@ -25,7 +25,7 @@ Status SuperKernel::Launch(rtStream_t stream, uint32_t dump_flag) { | |||||
const void *args[] = {this->GetNavTablePtr(), | const void *args[] = {this->GetNavTablePtr(), | ||||
reinterpret_cast<const void *>(static_cast<uintptr_t>(this->GetNavTableSize()))}; | reinterpret_cast<const void *>(static_cast<uintptr_t>(this->GetNavTableSize()))}; | ||||
rtError_t rt_ret = rtMalloc(reinterpret_cast<void **>(device_args_addr_), sizeof(args), RT_MEMORY_HBM); | |||||
rtError_t rt_ret = rtMalloc(reinterpret_cast<void **>(&device_args_addr_), sizeof(args), RT_MEMORY_HBM); | |||||
GE_IF_BOOL_EXEC(rt_ret != RT_ERROR_NONE, GELOGE(RT_FAILED, "rtMalloc failied. error: 0x%X", rt_ret); | GE_IF_BOOL_EXEC(rt_ret != RT_ERROR_NONE, GELOGE(RT_FAILED, "rtMalloc failied. error: 0x%X", rt_ret); | ||||
return RT_ERROR_TO_GE_STATUS(rt_ret);) | return RT_ERROR_TO_GE_STATUS(rt_ret);) | ||||
rt_ret = rtMemcpy(reinterpret_cast<void *>(device_args_addr_), sizeof(args), (void *)args, sizeof(args), | rt_ret = rtMemcpy(reinterpret_cast<void *>(device_args_addr_), sizeof(args), (void *)args, sizeof(args), | ||||
@@ -644,8 +644,12 @@ Status AicpuNodeTask::Init(const HybridModel &model) { | |||||
const auto &context = kernel_def.context(); | const auto &context = kernel_def.context(); | ||||
auto kernel_type = static_cast<ccKernelType>(context.kernel_type()); | auto kernel_type = static_cast<ccKernelType>(context.kernel_type()); | ||||
if (kernel_type == ccKernelType::CUST_AI_CPU) { | if (kernel_type == ccKernelType::CUST_AI_CPU) { | ||||
GE_CHK_STATUS_RET(ModelManager::GetInstance()->LoadCustAicpuSo(op_desc, so_name), "load cust aicpu so failed."); | |||||
GE_CHK_STATUS_RET(ModelManager::GetInstance()->LaunchCustAicpuSo(), "Launch cust aicpu so failed."); | |||||
bool loaded = false; | |||||
GE_CHK_STATUS_RET(ModelManager::GetInstance()->LoadCustAicpuSo(op_desc, so_name, loaded), | |||||
"load cust aicpu so failed."); | |||||
if (!loaded) { | |||||
GE_CHK_STATUS_RET(ModelManager::GetInstance()->LaunchCustAicpuSo(), "Launch cust aicpu so failed."); | |||||
} | |||||
} | } | ||||
GE_CHK_BOOL_RET_STATUS(args.size() == args_size_, FAILED, | GE_CHK_BOOL_RET_STATUS(args.size() == args_size_, FAILED, | ||||
@@ -62,8 +62,12 @@ Status AiCpuCCTaskBuilder::BuildTask(AiCpuCCTask &task, uint64_t kernel_id) { | |||||
if (kernel_type == ccKernelType::CUST_AI_CPU) { | if (kernel_type == ccKernelType::CUST_AI_CPU) { | ||||
task.is_custom_ = true; | task.is_custom_ = true; | ||||
task.dump_flag_ |= RT_KERNEL_CUSTOM_AICPU; | task.dump_flag_ |= RT_KERNEL_CUSTOM_AICPU; | ||||
GE_CHK_STATUS_RET(ModelManager::GetInstance()->LoadCustAicpuSo(op_desc_, so_name), "launch cust aicpu so failed"); | |||||
GE_CHK_STATUS_RET(ModelManager::GetInstance()->LaunchCustAicpuSo(), "launch cust aicpu so failed."); | |||||
bool loaded = false; | |||||
GE_CHK_STATUS_RET(ModelManager::GetInstance()->LoadCustAicpuSo(op_desc_, so_name, loaded), | |||||
"launch cust aicpu so failed"); | |||||
if (!loaded) { | |||||
GE_CHK_STATUS_RET(ModelManager::GetInstance()->LaunchCustAicpuSo(), "launch cust aicpu so failed."); | |||||
} | |||||
} | } | ||||
task.num_inputs_ = op_desc_->GetInputsSize(); | task.num_inputs_ = op_desc_->GetInputsSize(); | ||||