From 71788dcc5006dc9bd59b890338d3fc07c7323e05 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 24 Nov 2020 23:20:33 +0800 Subject: [PATCH 1/3] No session in tf_singleop_task and add cpu kernels cache. --- .../task_info/kernel_task_info.cc | 31 +++++++++++++++- ge/hybrid/node_executor/aicpu/aicpu_ext_info.cc | 36 ++++++++++++++++++ ge/hybrid/node_executor/aicpu/aicpu_ext_info.h | 8 ++++ .../node_executor/aicpu/aicpu_node_executor.cc | 43 +++++++++++++--------- .../node_executor/aicpu/aicpu_node_executor.h | 2 +- ge/single_op/single_op.cc | 12 ------ ge/single_op/single_op.h | 4 -- ge/single_op/single_op_model.cc | 32 ++++++++-------- ge/single_op/single_op_model.h | 4 +- ge/single_op/task/aicpu_kernel_task_builder.cc | 4 +- ge/single_op/task/aicpu_kernel_task_builder.h | 2 +- ge/single_op/task/aicpu_task_builder.cc | 14 +++---- ge/single_op/task/aicpu_task_builder.h | 2 +- ge/single_op/task/op_task.cc | 12 ++++-- ge/single_op/task/op_task.h | 2 +- 15 files changed, 138 insertions(+), 70 deletions(-) diff --git a/ge/graph/load/new_model_manager/task_info/kernel_task_info.cc b/ge/graph/load/new_model_manager/task_info/kernel_task_info.cc index beef6933..010f90a8 100755 --- a/ge/graph/load/new_model_manager/task_info/kernel_task_info.cc +++ b/ge/graph/load/new_model_manager/task_info/kernel_task_info.cc @@ -31,6 +31,7 @@ #include "runtime/kernel.h" #include "super_kernel/super_kernel.h" #include "super_kernel/super_kernel_factory.h" +#include "cce/aicpu_engine_struct.h" namespace { const uint8_t kL2LoadToDdr = 1; @@ -958,12 +959,40 @@ Status KernelTaskInfo::InitAicpuTaskExtInfo(const std::string &ext_info) { if (ext_info.empty()) { return SUCCESS; } + + std::unique_ptr copy_ext_info; + copy_ext_info.reset(new(std::nothrow)uint8_t[ext_info.size()]); + GE_CHECK_NOTNULL(copy_ext_info); + auto sec_ret = memcpy_s(copy_ext_info.get(), ext_info.size(), ext_info.c_str(), ext_info.size()); + if (sec_ret != EOK) { + GELOGE(FAILED, "memcpy failed, ret: %d", sec_ret); + return FAILED; + } + + auto ext_info_data = copy_ext_info.get(); + size_t offset = 0; + while (offset + sizeof(aicpu::FWKAdapter::ExtInfo) <= ext_info.size()) { + auto aicpu_ext_info = reinterpret_cast(ext_info_data + offset); + GELOGD("Ext infoType=%d, infoLen=%u.", aicpu_ext_info->infoType, aicpu_ext_info->infoLen); + if (aicpu_ext_info->infoType == aicpu::FWKAdapter::FWK_ADPT_EXT_SESSION_INFO) { + GE_CHK_BOOL_RET_STATUS(aicpu_ext_info->infoLen == sizeof(SessionInfo), PARAM_INVALID, + "Parse ext session info failed as infoLen must be %zu but %u.", + sizeof(SessionInfo), aicpu_ext_info->infoLen); + SessionInfo *session_info = reinterpret_cast(aicpu_ext_info->infoMsg); + session_info->sessionId = davinci_model_->GetSessionId(); + session_info->sessFlag = true; + GELOGD("Update aicpu_task ext_info session_info session_id is %lu", session_info->sessionId); + } + offset += sizeof(aicpu::FWKAdapter::ExtInfo); + offset += aicpu_ext_info->infoLen; + } + auto rt_ret = rtMalloc(&aicpu_ext_info_addr_, ext_info.size(), RT_MEMORY_HBM); if (rt_ret != RT_ERROR_NONE) { GELOGE(RT_FAILED, "rtMalloc ext_info error: 0x%X, size=%zu", rt_ret, ext_info.size()); return RT_ERROR_TO_GE_STATUS(rt_ret); } - rt_ret = rtMemcpy(aicpu_ext_info_addr_, ext_info.size(), ext_info.c_str(), ext_info.size(), RT_MEMCPY_HOST_TO_DEVICE); + rt_ret = rtMemcpy(aicpu_ext_info_addr_, ext_info.size(), ext_info_data, ext_info.size(), RT_MEMCPY_HOST_TO_DEVICE); if (rt_ret != RT_ERROR_NONE) { GELOGE(RT_FAILED, "rtMemcpy ext_info error: 0x%X, size=%zu", rt_ret, ext_info.size()); return RT_ERROR_TO_GE_STATUS(rt_ret); diff --git a/ge/hybrid/node_executor/aicpu/aicpu_ext_info.cc b/ge/hybrid/node_executor/aicpu/aicpu_ext_info.cc index 3974e29b..d7837144 100644 --- a/ge/hybrid/node_executor/aicpu/aicpu_ext_info.cc +++ b/ge/hybrid/node_executor/aicpu/aicpu_ext_info.cc @@ -57,6 +57,9 @@ Status AicpuExtInfoHandler::Parse(const std::string &ext_info) { case aicpu::FWKAdapter::FWK_ADPT_EXT_OUTPUT_SHAPE: GE_CHK_STATUS_RET(ParseExtOutputShape(aicpu_ext_info), "Parse ext output shape failed."); break; + case aicpu::FWKAdapter::FWK_ADPT_EXT_SESSION_INFO: + GE_CHK_STATUS_RET(ParseExtSessionInfo(aicpu_ext_info), "Parse ext session info failed."); + break; default: GELOGD("Node[%s] ignore infoType=%d, infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoType, aicpu_ext_info->infoLen); @@ -123,6 +126,39 @@ Status AicpuExtInfoHandler::ParseExtOutputShape(AicpuExtInfo *aicpu_ext_info) { return SUCCESS; } +Status AicpuExtInfoHandler::ParseExtSessionInfo(AicpuExtInfo *aicpu_ext_info) { + GE_CHK_BOOL_RET_STATUS(aicpu_ext_info->infoLen == sizeof(AicpuSessionInfo), PARAM_INVALID, + "Node[%s] parse ext session info failed as infoLen must be %zu but %u.", + node_name_.c_str(), sizeof(SessionInfo), aicpu_ext_info->infoLen); + + session_info_ = reinterpret_cast(aicpu_ext_info->infoMsg); + GELOGI("Node[%s] parse session info success infoLen=%u.", node_name_.c_str(), aicpu_ext_info->infoLen); + return SUCCESS; +} + +Status AicpuExtInfoHandler::UpdateSessionInfo(uint64_t session_id, uint64_t kernel_id, bool sess_flag) { + if (session_info_ == nullptr) { + GELOGD("There is no session info in ext_info, no need update."); + return SUCCESS; + } + + session_info_->sessionId = session_id; + session_info_->kernelId = kernel_id; + session_info_->sessFlag = sess_flag; + return SUCCESS; +} + +Status AicpuExtInfoHandler::UpdateSessionInfoSessionId(uint64_t session_id) { + if (session_info_ == nullptr) { + GELOGD("There is no session info in ext_info, no need update."); + return SUCCESS; + } + + session_info_->sessionId = session_id; + session_info_->sessFlag = true; + return SUCCESS; +} + Status AicpuExtInfoHandler::UpdateInputShapeAndType(uint32_t input_index, const GeTensorDesc &input_desc) { GE_CHECK_LE(input_index, input_num_); const auto &shape = input_desc.GetShape(); diff --git a/ge/hybrid/node_executor/aicpu/aicpu_ext_info.h b/ge/hybrid/node_executor/aicpu/aicpu_ext_info.h index 9c867cdc..2defba8f 100644 --- a/ge/hybrid/node_executor/aicpu/aicpu_ext_info.h +++ b/ge/hybrid/node_executor/aicpu/aicpu_ext_info.h @@ -19,6 +19,7 @@ #include "external/ge/ge_api_error_codes.h" #include "cce/fwk_adpt_struct.h" +#include "cce/aicpu_engine_struct.h" #include "graph/op_desc.h" #include "graph/ge_tensor.h" @@ -26,6 +27,7 @@ namespace ge { namespace hybrid { using AicpuShapeAndType = aicpu::FWKAdapter::ShapeAndType; using AicpuExtInfo = aicpu::FWKAdapter::ExtInfo; +using AicpuSessionInfo = SessionInfo; class AicpuExtInfoHandler { public: @@ -51,6 +53,10 @@ class AicpuExtInfoHandler { Status UpdateOutputShapeAndType(uint32_t output_index, const GeTensorDesc &output_desc); + Status UpdateSessionInfo(uint64_t session_id, uint64_t kernel_id, bool sess_flag); + + Status UpdateSessionInfoSessionId(uint64_t session_id); + Status GetOutputShapeAndType(uint32_t output_index, GeShape &shape, DataType &data_type); private: @@ -58,6 +64,7 @@ class AicpuExtInfoHandler { Status ParseExtShapeType(AicpuExtInfo *aicpu_ext_info); Status ParseExtInputShape(AicpuExtInfo *aicpu_ext_info); Status ParseExtOutputShape(AicpuExtInfo *aicpu_ext_info); + Status ParseExtSessionInfo(AicpuExtInfo *aicpu_ext_info); static Status UpdateShapeAndType(const GeShape &shape, DataType data_type, @@ -72,6 +79,7 @@ class AicpuExtInfoHandler { const uint32_t input_num_; const uint32_t output_num_; UnknowShapeOpType unknown_type_; + AicpuSessionInfo *session_info_ = nullptr; std::unique_ptr ext_info_; size_t ext_info_len_ = 0; diff --git a/ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc b/ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc index 61af55dd..d921c57c 100755 --- a/ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc +++ b/ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc @@ -40,29 +40,36 @@ Status AicpuNodeTaskBase::AllocTensorBuffer(size_t size, std::unique_ptris_dynamic) { - // dynamic node must have ext info - GE_CHK_STATUS_RET(aicpu_ext_handle_.Parse(kernel_ext_info), - "Node[%s] parse kernel ext info failed, kernel_ext_info_size=%zu.", - node_name_.c_str(), kernel_ext_info.size()); - } - - // if no ext info no need copy to device. +Status AicpuNodeTaskBase::InitExtInfo(const std::string &kernel_ext_info, int64_t session_id) { if (kernel_ext_info.empty()) { - GELOGI("Node[%s] kernel_ext_info is empty, no need copy to device, is_dynamic=%s.", - node_name_.c_str(), node_item_->is_dynamic ? "true" : "false"); - return SUCCESS; + if (node_item_->is_dynamic) { + // dynamic node must have ext info + GELOGE(PARAM_INVALID, "Node[%s] parse ext info failed as ext info is empty.", node_name_.c_str()); + return PARAM_INVALID; + } else { + // if no ext info no need copy to device. + GELOGI("Node[%s] kernel_ext_info is empty, no need copy to device, is_dynamic=%s.", + node_name_.c_str(), node_item_->is_dynamic ? "true" : "false"); + return SUCCESS; + } } + GE_CHK_STATUS_RET(aicpu_ext_handle_.Parse(kernel_ext_info), + "Node[%s] parse kernel ext info failed, kernel_ext_info_size=%zu.", + node_name_.c_str(), kernel_ext_info.size()); + GELOGD("To update aicpu_task ext_info session_info session_id to %lu", session_id); + GE_CHK_STATUS_RET(aicpu_ext_handle_.UpdateSessionInfoSessionId(session_id), + "UpdateSessionInfoSessionId failed."); + // copy task args buf - GE_CHK_STATUS_RET(AllocTensorBuffer(kernel_ext_info.size(), ext_info_addr_dev_), + GE_CHK_STATUS_RET(AllocTensorBuffer(aicpu_ext_handle_.GetExtInfoLen(), ext_info_addr_dev_), "Node[%s] alloc kernel_ext_info buf failed, size=%zu", - node_name_.c_str(), kernel_ext_info.size()); + node_name_.c_str(), aicpu_ext_handle_.GetExtInfoLen()); // copy default ext info to device GE_CHK_RT_RET(rtMemcpy(ext_info_addr_dev_->GetData(), ext_info_addr_dev_->GetSize(), - kernel_ext_info.data(), kernel_ext_info.size(), RT_MEMCPY_HOST_TO_DEVICE)); + aicpu_ext_handle_.GetExtInfo(), aicpu_ext_handle_.GetExtInfoLen(), + RT_MEMCPY_HOST_TO_DEVICE)); return SUCCESS; } @@ -290,7 +297,8 @@ Status AicpuTfNodeTask::Init(const HybridModel &model) { node_name_.c_str(), kernel_ext_info.size(), kernel_ext_info_size); // init ext info - GE_CHK_STATUS_RET(InitExtInfo(kernel_ext_info), "Node[%s] init ext info failed.", node_name_.c_str()); + uint64_t ext_session_id = model.GetSessionId(); + GE_CHK_STATUS_RET(InitExtInfo(kernel_ext_info, ext_session_id), "Node[%s] init ext info failed.", node_name_.c_str()); GE_CHK_STATUS_RET(InitForDependComputeTask(), "Node[%s] init for depend compute task failed.", node_name_.c_str()); // build fwk_op_kernel. @@ -679,7 +687,8 @@ Status AicpuNodeTask::Init(const HybridModel &model) { "Node[%s] task def kernel_ext_info.size=%zu, but kernel_ext_info_size=%u.", node_name.c_str(), kernel_ext_info.size(), kernel_ext_info_size); - GE_CHK_STATUS_RET(InitExtInfo(kernel_ext_info), "Node[%s] init ext info failed.", node_name.c_str()); + uint64_t ext_session_id = model.GetSessionId(); + GE_CHK_STATUS_RET(InitExtInfo(kernel_ext_info, ext_session_id), "Node[%s] init ext info failed.", node_name.c_str()); if (ext_info_addr_dev_ == nullptr) { aicpu_param_head->extInfoLength = 0; diff --git a/ge/hybrid/node_executor/aicpu/aicpu_node_executor.h b/ge/hybrid/node_executor/aicpu/aicpu_node_executor.h index 7caabd66..b984cc86 100644 --- a/ge/hybrid/node_executor/aicpu/aicpu_node_executor.h +++ b/ge/hybrid/node_executor/aicpu/aicpu_node_executor.h @@ -43,7 +43,7 @@ class AicpuNodeTaskBase : public NodeTask { Status ExecuteAsync(TaskContext &context, std::function done_callback) override; protected: - virtual Status InitExtInfo(const std::string &kernel_ext_info); + virtual Status InitExtInfo(const std::string &kernel_ext_info, int64_t session_id); virtual Status UpdateExtInfo(); diff --git a/ge/single_op/single_op.cc b/ge/single_op/single_op.cc index 7a199eac..371d7110 100755 --- a/ge/single_op/single_op.cc +++ b/ge/single_op/single_op.cc @@ -44,8 +44,6 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY SingleOp::~SingleOp() { delete task; task = nullptr; } - GELOGI("SingleOp destory sessionId = %lu", aicpu_session_id_); - ModelManager::GetInstance()->DestroyAicpuSession(aicpu_session_id_); } Status SingleOp::ValidateArgs(const std::vector &inputs, const std::vector &outputs) { @@ -180,17 +178,11 @@ void SingleOp::SetStream(rtStream_t stream) { stream_ = stream; } -void SingleOp::SetSessionID(uint64_t session_id) { - aicpu_session_id_ = session_id; -} - DynamicSingleOp::DynamicSingleOp(uintptr_t resource_id, std::mutex *stream_mutex, rtStream_t stream) : resource_id_(resource_id), stream_mutex_(stream_mutex), stream_(stream) { } DynamicSingleOp::~DynamicSingleOp() { - GELOGI("DynamicSingleOp destory sessionId = %lu", aicpu_session_id_); - ModelManager::GetInstance()->DestroyAicpuSession(aicpu_session_id_); } Status DynamicSingleOp::ValidateParams(const vector &input_desc, @@ -299,8 +291,4 @@ Status DynamicSingleOp::ExecuteAsync(const vector &input_desc, return ACL_ERROR_GE_OP_TASK_TYPE_INVALID; } } - -void DynamicSingleOp::SetSessionID(uint64_t session_id) { - aicpu_session_id_ = session_id; -} } // namespace ge diff --git a/ge/single_op/single_op.h b/ge/single_op/single_op.h index bd671017..14ef8ce1 100755 --- a/ge/single_op/single_op.h +++ b/ge/single_op/single_op.h @@ -37,7 +37,6 @@ class SingleOp { Status ExecuteAsync(const std::vector &inputs, const std::vector &outputs); void SetStream(rtStream_t stream); - void SetSessionID(uint64_t session_id); private: Status ValidateArgs(const std::vector &inputs, const std::vector &outputs); @@ -52,7 +51,6 @@ class SingleOp { std::vector output_addr_list_; std::vector output_sizes_; std::vector args_; - uint64_t aicpu_session_id_ = 0; std::vector tasks_; std::vector> arg_table_; @@ -66,7 +64,6 @@ class DynamicSingleOp { const std::vector &inputs, std::vector &output_desc, std::vector &outputs); - void SetSessionID(uint64_t session_id); private: friend class SingleOpModel; @@ -89,7 +86,6 @@ class DynamicSingleOp { rtStream_t stream_ = nullptr; size_t num_inputs_ = 0; size_t num_outputs_ = 0; - uint64_t aicpu_session_id_ = 0; }; } // namespace ge #endif // GE_SINGLE_OP_SINGLE_OP_H_ diff --git a/ge/single_op/single_op_model.cc b/ge/single_op/single_op_model.cc index 65eb58be..49968f4f 100755 --- a/ge/single_op/single_op_model.cc +++ b/ge/single_op/single_op_model.cc @@ -32,7 +32,7 @@ #include "task/aicpu_kernel_task_builder.h" #include "task/tbe_task_builder.h" -static std::atomic aicpu_sessionid(0); +static std::atomic aicpu_kernel_id(0); using domi::TaskDef; using std::unique_ptr; @@ -252,7 +252,9 @@ Status SingleOpModel::BuildTaskList(SingleOp &single_op) { } else if (kernel_type == cce::ccKernelType::AI_CPU || kernel_type == cce::ccKernelType::CUST_AI_CPU) { GELOGD("Building AICPU_CC task"); OpTask *task = nullptr; - auto ret = BuildCpuKernelTask(task_def.kernel(), &task); + uint64_t singleop_kernel_id = aicpu_kernel_id++; + GELOGI("Build singleOp CCTask, kernel_id = %lu", singleop_kernel_id); + auto ret = BuildCpuKernelTask(task_def.kernel(), &task, singleop_kernel_id); if (ret != SUCCESS) { return ret; } @@ -265,14 +267,13 @@ Status SingleOpModel::BuildTaskList(SingleOp &single_op) { GELOGD("Building AICPU_TF task"); AiCpuTask *aicpu_task = nullptr; bool depend_compute_flag = false; - uint64_t singleop_sessionid = aicpu_sessionid++; - GELOGI("Build singleOp, sessionId = %lu", singleop_sessionid); - auto ret = BuildKernelExTask(task_def.kernel_ex(), &aicpu_task, false, depend_compute_flag, singleop_sessionid); + uint64_t singleop_kernel_id = aicpu_kernel_id++; + GELOGI("Build singleOp TfTask, kernel_id = %lu", singleop_kernel_id); + auto ret = BuildKernelExTask(task_def.kernel_ex(), &aicpu_task, false, depend_compute_flag, singleop_kernel_id); if (ret != SUCCESS) { return ret; } single_op.tasks_.emplace_back(aicpu_task); - single_op.SetSessionID(singleop_sessionid); } else { // skip GELOGD("Skip task type: %d", static_cast(task_type)); @@ -329,7 +330,7 @@ Status SingleOpModel::BuildKernelTask(const domi::KernelDef &kernel_def, TbeOpTa } Status SingleOpModel::BuildKernelExTask(const domi::KernelExDef &kernel_def, AiCpuTask **task, - bool dynamic_flag, bool& depend_compute_flag, uint64_t session_id) { + bool dynamic_flag, bool& depend_compute_flag, uint64_t kernel_id) { auto iter = op_list_.find(kernel_def.op_index()); if (iter == op_list_.end()) { GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "op desc not found. op index = %u", kernel_def.op_index()); @@ -342,7 +343,7 @@ Status SingleOpModel::BuildKernelExTask(const domi::KernelExDef &kernel_def, AiC return ACL_ERROR_GE_MEMORY_ALLOCATION; } auto builder = AiCpuTaskBuilder(iter->second->GetOpDesc(), kernel_def); - auto ret = builder.BuildTask(*aicpu_task, model_params_, dynamic_flag, session_id); + auto ret = builder.BuildTask(*aicpu_task, model_params_, dynamic_flag, kernel_id); if (ret != SUCCESS) { GELOGE(ret, "build aicpu_TF op task failed"); return ret; @@ -353,7 +354,7 @@ Status SingleOpModel::BuildKernelExTask(const domi::KernelExDef &kernel_def, AiC return SUCCESS; } -Status SingleOpModel::BuildCpuKernelTask(const domi::KernelDef &kernel_def, OpTask **task) { +Status SingleOpModel::BuildCpuKernelTask(const domi::KernelDef &kernel_def, OpTask **task, uint64_t kernel_id) { const auto &context = kernel_def.context(); auto iter = op_list_.find(context.op_index()); if (iter == op_list_.end()) { @@ -367,7 +368,7 @@ Status SingleOpModel::BuildCpuKernelTask(const domi::KernelDef &kernel_def, OpTa } auto builder = AiCpuCCTaskBuilder(iter->second->GetOpDesc(), kernel_def); - auto ret = builder.BuildTask(*aicpucc_task); + auto ret = builder.BuildTask(*aicpucc_task, kernel_id); if (ret != SUCCESS) { GELOGE(ret, "build aicpu_CC op task failed"); return ret; @@ -396,7 +397,9 @@ Status SingleOpModel::BuildModelTaskKernel(const TaskDef &task_def, DynamicSingl } else if (kernel_type == cce::ccKernelType::AI_CPU || kernel_type == cce::ccKernelType::CUST_AI_CPU) { GELOGD("Building AICPU_CC task"); OpTask *task = nullptr; - GE_CHK_STATUS_RET_NOLOG(BuildCpuKernelTask(task_def.kernel(), &task)); + uint64_t dynamic_singleop_kernel_id = aicpu_kernel_id++; + GELOGI("Build dynamic singleOp CCTask, kernel_id = %lu", dynamic_singleop_kernel_id); + GE_CHK_STATUS_RET_NOLOG(BuildCpuKernelTask(task_def.kernel(), &task, dynamic_singleop_kernel_id)); single_op.op_task_.reset(task); } else { GELOGE(ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID, @@ -430,10 +433,10 @@ Status SingleOpModel::BuildTaskListForDynamicOp(DynamicSingleOp &single_op) { GELOGD("Building AICPU_TF task"); AiCpuTask *aicpu_task = nullptr; bool depend_compute_flag = false; - uint64_t dynamic_singleop_sessionid = aicpu_sessionid++; - GELOGI("Build dynamic singleOp, sessionId = %lu", dynamic_singleop_sessionid); + uint64_t dynamic_singleop_kernel_id = aicpu_kernel_id++; + GELOGI("Build dynamic singleOp TfTask, kernel_id = %lu", dynamic_singleop_kernel_id); GE_CHK_STATUS_RET_NOLOG(BuildKernelExTask(task_def.kernel_ex(), &aicpu_task, true, - depend_compute_flag, dynamic_singleop_sessionid)); + depend_compute_flag, dynamic_singleop_kernel_id)); if (depend_compute_flag) { if (i >= tasks.size() - 1) { GELOGE(ACL_ERROR_GE_PARAM_INVALID, "The copy task of the fourth operator was not found."); @@ -444,7 +447,6 @@ Status SingleOpModel::BuildTaskListForDynamicOp(DynamicSingleOp &single_op) { GE_CHK_STATUS_RET_NOLOG(aicpu_task->SetMemCopyTask(copy_task_def.kernel_ex())); } single_op.op_task_.reset(aicpu_task); - single_op.SetSessionID(dynamic_singleop_sessionid); } else { // skip GELOGD("Skip task type: %d", static_cast(task_type)); diff --git a/ge/single_op/single_op_model.h b/ge/single_op/single_op_model.h index 2e6b37dc..50aeb7ab 100755 --- a/ge/single_op/single_op_model.h +++ b/ge/single_op/single_op_model.h @@ -69,8 +69,8 @@ class SingleOpModel { Status BuildTaskListForDynamicOp(DynamicSingleOp &dynamic_single_op); Status BuildKernelTask(const domi::KernelDef &kernel_def, TbeOpTask **task); Status BuildKernelExTask(const domi::KernelExDef &kernel_def, AiCpuTask **task, - bool dynamic_flag, bool& depend_compute_flag, uint64_t session_id); - Status BuildCpuKernelTask(const domi::KernelDef &kernel_def, OpTask **task); + bool dynamic_flag, bool& depend_compute_flag, uint64_t kernel_id); + Status BuildCpuKernelTask(const domi::KernelDef &kernel_def, OpTask **task, uint64_t kernel_id); Status BuildModelTaskKernel(const domi::TaskDef &task_def, DynamicSingleOp &single_op); static void ParseOpModelParams(ModelHelper &model_helper, SingleOpModelParam ¶m); diff --git a/ge/single_op/task/aicpu_kernel_task_builder.cc b/ge/single_op/task/aicpu_kernel_task_builder.cc index 8e140a6f..26f6a166 100755 --- a/ge/single_op/task/aicpu_kernel_task_builder.cc +++ b/ge/single_op/task/aicpu_kernel_task_builder.cc @@ -46,7 +46,7 @@ Status AiCpuCCTaskBuilder::SetKernelArgs(AiCpuCCTask &task) { return SUCCESS; } -Status AiCpuCCTaskBuilder::BuildTask(AiCpuCCTask &task) { +Status AiCpuCCTaskBuilder::BuildTask(AiCpuCCTask &task, uint64_t kernel_id) { auto ret = SetKernelArgs(task); if (ret != SUCCESS) { return ret; @@ -76,7 +76,7 @@ Status AiCpuCCTaskBuilder::BuildTask(AiCpuCCTask &task) { "task def kernel_ext_info.size=%zu, but kernel_ext_info_size=%u.", kernel_ext_info.size(), kernel_ext_info_size); - ret = task.SetExtInfoAndType(kernel_ext_info); + ret = task.SetExtInfoAndType(kernel_ext_info, kernel_id); if (ret != SUCCESS) { GELOGE(ret, "Init ext info failed."); return ret; diff --git a/ge/single_op/task/aicpu_kernel_task_builder.h b/ge/single_op/task/aicpu_kernel_task_builder.h index f9ca0530..e77e3c10 100755 --- a/ge/single_op/task/aicpu_kernel_task_builder.h +++ b/ge/single_op/task/aicpu_kernel_task_builder.h @@ -30,7 +30,7 @@ class AiCpuCCTaskBuilder { explicit AiCpuCCTaskBuilder(const OpDescPtr &op_desc, const domi::KernelDef &kernel_def); ~AiCpuCCTaskBuilder() = default; - Status BuildTask(AiCpuCCTask &task); + Status BuildTask(AiCpuCCTask &task, uint64_t kernel_id); private: Status SetKernelArgs(AiCpuCCTask &task); diff --git a/ge/single_op/task/aicpu_task_builder.cc b/ge/single_op/task/aicpu_task_builder.cc index 468fee86..d91bba17 100755 --- a/ge/single_op/task/aicpu_task_builder.cc +++ b/ge/single_op/task/aicpu_task_builder.cc @@ -111,7 +111,7 @@ namespace ge { } Status AiCpuTaskBuilder::BuildTask(ge::AiCpuTask &task, const SingleOpModelParam ¶m, - bool dynamic_flag, uint64_t session_id) { + bool dynamic_flag, uint64_t kernel_id) { GE_CHK_STATUS_RET_NOLOG(InitWorkspaceAndIO(&task.io_addr_, &task.workspace_addr_, param, dynamic_flag)); STR_FWK_OP_KERNEL fwk_op_kernel = {0}; @@ -130,7 +130,7 @@ namespace ge { GE_CHK_BOOL_RET_STATUS(kernel_ext_info.size() == kernel_ext_info_size, FAILED, "task def kernel_ext_info.size=%zu, but kernel_ext_info_size=%u.", kernel_ext_info.size(), kernel_ext_info_size); - GE_CHK_STATUS_RET(task.SetExtInfoAndType(kernel_ext_info), "Init ext info failed."); + GE_CHK_STATUS_RET(task.SetExtInfoAndType(kernel_ext_info, kernel_id), "Init ext info failed."); if (task.ext_info_addr_dev_ != nullptr) { fwk_op_kernel.fwkKernelBase.fwk_kernel.extInfoAddr = reinterpret_cast(task.ext_info_addr_dev_); @@ -138,13 +138,9 @@ namespace ge { } GE_CHK_STATUS_RET(task.InitForSummaryAndCopy(), "AiCpuTask init for summary and copy task failed."); - // Create session - fwk_op_kernel.fwkKernelBase.fwk_kernel.sessionID = session_id; - GELOGI("Begin to CreateAicpuSession, session id: %lu", session_id); - GE_CHECK_NOTNULL(ModelManager::GetInstance()); - GE_IF_BOOL_EXEC(ModelManager::GetInstance()->CreateAicpuSession(session_id) != SUCCESS, - GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "CreateAicpuSession error. session id: %lu", session_id); - return ACL_ERROR_GE_INTERNAL_ERROR;) + fwk_op_kernel.fwkKernelBase.fwk_kernel.sessionID = ULLONG_MAX; + fwk_op_kernel.fwkKernelBase.fwk_kernel.kernelID = kernel_id; + fwk_op_kernel.fwkKernelBase.fwk_kernel.opType = aicpu::FWKAdapter::FWKOperateType::FWK_ADPT_KERNEL_RUN_NO_SESS; ret = SetKernelArgs(&task.args_, fwk_op_kernel); if (ret != SUCCESS) { return ret; diff --git a/ge/single_op/task/aicpu_task_builder.h b/ge/single_op/task/aicpu_task_builder.h index 6dcd7a0f..4669e118 100755 --- a/ge/single_op/task/aicpu_task_builder.h +++ b/ge/single_op/task/aicpu_task_builder.h @@ -29,7 +29,7 @@ namespace ge { AiCpuTaskBuilder(const OpDescPtr &op_desc, const domi::KernelExDef &kernel_def); ~AiCpuTaskBuilder() = default; - Status BuildTask(AiCpuTask &task, const SingleOpModelParam ¶m, bool dynamic_flag, uint64_t session_id); + Status BuildTask(AiCpuTask &task, const SingleOpModelParam ¶m, bool dynamic_flag, uint64_t kernel_id); private: static Status SetKernelArgs(void **args, STR_FWK_OP_KERNEL &kernel); diff --git a/ge/single_op/task/op_task.cc b/ge/single_op/task/op_task.cc index 30d4d311..1b4b23ff 100755 --- a/ge/single_op/task/op_task.cc +++ b/ge/single_op/task/op_task.cc @@ -245,7 +245,7 @@ AiCpuBaseTask::~AiCpuBaseTask() { } } -Status AiCpuBaseTask::SetExtInfoAndType(const std::string &kernel_ext_info) { +Status AiCpuBaseTask::SetExtInfoAndType(const std::string &kernel_ext_info, uint64_t kernel_id) { if (kernel_ext_info.empty()) { GELOGI("Kernel_ext_info is empty, no need copy to device."); return SUCCESS; @@ -268,9 +268,13 @@ Status AiCpuBaseTask::SetExtInfoAndType(const std::string &kernel_ext_info) { return ret; } - GE_CHK_RT_RET(rtMalloc(&ext_info_addr_dev_, kernel_ext_info.size(), RT_MEMORY_HBM)); - GE_CHK_RT_RET(rtMemcpy(ext_info_addr_dev_, kernel_ext_info.size(), - kernel_ext_info.data(), kernel_ext_info.size(), RT_MEMCPY_HOST_TO_DEVICE)); + GE_CHK_STATUS_RET(aicpu_ext_handle_->UpdateSessionInfo(ULLONG_MAX, kernel_id, false), + "UpdateSessionInfo failed."); + + GE_CHK_RT_RET(rtMalloc(&ext_info_addr_dev_, aicpu_ext_handle_->GetExtInfoLen(), RT_MEMORY_HBM)); + GE_CHK_RT_RET(rtMemcpy(ext_info_addr_dev_, aicpu_ext_handle_->GetExtInfoLen(), + aicpu_ext_handle_->GetExtInfo(), aicpu_ext_handle_->GetExtInfoLen(), + RT_MEMCPY_HOST_TO_DEVICE)); return SUCCESS; } diff --git a/ge/single_op/task/op_task.h b/ge/single_op/task/op_task.h index 1b4d9c02..bf8316f6 100644 --- a/ge/single_op/task/op_task.h +++ b/ge/single_op/task/op_task.h @@ -132,7 +132,7 @@ class AiCpuBaseTask : public OpTask { const UnknowShapeOpType GetUnknownType() const { return unknown_type_; } protected: - Status SetExtInfoAndType(const std::string &kernel_ext_info); + Status SetExtInfoAndType(const std::string &kernel_ext_info, uint64_t kernel_id); Status UpdateExtInfo(const std::vector &input_desc, std::vector &output_desc, From 77f6792ee91182bc10dc2c0b96c1a2970fb59aae Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 24 Nov 2020 23:44:45 +0800 Subject: [PATCH 2/3] add metadef. --- metadef | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadef b/metadef index a464149d..89590b34 160000 --- a/metadef +++ b/metadef @@ -1 +1 @@ -Subproject commit a464149d95257e7514859b198444fb341dc40786 +Subproject commit 89590b3405f6c5714997c07f81470764ac66635b From f4cedd32d7b26709185bb1593e0bdc63e7d62dea Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 25 Nov 2020 00:32:08 +0800 Subject: [PATCH 3/3] add head file. --- third_party/fwkacllib/inc/cce/aicpu_engine_struct.h | 6 ++++++ third_party/fwkacllib/inc/cce/fwk_adpt_struct.h | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/third_party/fwkacllib/inc/cce/aicpu_engine_struct.h b/third_party/fwkacllib/inc/cce/aicpu_engine_struct.h index d61c981d..a5f43be9 100644 --- a/third_party/fwkacllib/inc/cce/aicpu_engine_struct.h +++ b/third_party/fwkacllib/inc/cce/aicpu_engine_struct.h @@ -40,6 +40,12 @@ typedef struct { } fwkKernelBase; } __attribute__((packed)) STR_FWK_OP_KERNEL; +struct SessionInfo { + uint64_t sessionId; + uint64_t kernelId; + bool sessFlag; +} __attribute__((packed)); + #ifdef __cplusplus } #endif diff --git a/third_party/fwkacllib/inc/cce/fwk_adpt_struct.h b/third_party/fwkacllib/inc/cce/fwk_adpt_struct.h index 957117cc..79d94023 100644 --- a/third_party/fwkacllib/inc/cce/fwk_adpt_struct.h +++ b/third_party/fwkacllib/inc/cce/fwk_adpt_struct.h @@ -48,7 +48,8 @@ enum FWKOperateType { FWK_ADPT_KERNEL_RUN, FWK_ADPT_KERNEL_DESTROY, FWK_ADPT_SESSION_DESTROY, - FWK_ADPT_SINGLE_OP_RUN + FWK_ADPT_SINGLE_OP_RUN, + FWK_ADPT_KERNEL_RUN_NO_SESS, }; // Extend Info type for task @@ -58,6 +59,7 @@ enum FWKTaskExtInfoType { FWK_ADPT_EXT_OUTPUT_SHAPE, FWK_ADPT_EXT_UPDATE_ADDR, FWK_ADPT_EXT_OP_NAME, + FWK_ADPT_EXT_SESSION_INFO, FWK_ADPT_EXT_INVALID };