From: @zhao_zhixuan Reviewed-by: @xchu42,@ji_chen Signed-off-by: @ji_chentags/v1.1.0
@@ -31,6 +31,7 @@ | |||||
#include "runtime/kernel.h" | #include "runtime/kernel.h" | ||||
#include "super_kernel/super_kernel.h" | #include "super_kernel/super_kernel.h" | ||||
#include "super_kernel/super_kernel_factory.h" | #include "super_kernel/super_kernel_factory.h" | ||||
#include "cce/aicpu_engine_struct.h" | |||||
namespace { | namespace { | ||||
const uint8_t kL2LoadToDdr = 1; | const uint8_t kL2LoadToDdr = 1; | ||||
@@ -958,12 +959,40 @@ Status KernelTaskInfo::InitAicpuTaskExtInfo(const std::string &ext_info) { | |||||
if (ext_info.empty()) { | if (ext_info.empty()) { | ||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
std::unique_ptr<uint8_t[]> 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<aicpu::FWKAdapter::ExtInfo *>(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<SessionInfo *>(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); | auto rt_ret = rtMalloc(&aicpu_ext_info_addr_, ext_info.size(), RT_MEMORY_HBM); | ||||
if (rt_ret != RT_ERROR_NONE) { | if (rt_ret != RT_ERROR_NONE) { | ||||
GELOGE(RT_FAILED, "rtMalloc ext_info error: 0x%X, size=%zu", rt_ret, ext_info.size()); | GELOGE(RT_FAILED, "rtMalloc ext_info error: 0x%X, size=%zu", rt_ret, ext_info.size()); | ||||
return RT_ERROR_TO_GE_STATUS(rt_ret); | 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) { | if (rt_ret != RT_ERROR_NONE) { | ||||
GELOGE(RT_FAILED, "rtMemcpy ext_info error: 0x%X, size=%zu", rt_ret, ext_info.size()); | GELOGE(RT_FAILED, "rtMemcpy ext_info error: 0x%X, size=%zu", rt_ret, ext_info.size()); | ||||
return RT_ERROR_TO_GE_STATUS(rt_ret); | return RT_ERROR_TO_GE_STATUS(rt_ret); | ||||
@@ -57,6 +57,9 @@ Status AicpuExtInfoHandler::Parse(const std::string &ext_info) { | |||||
case aicpu::FWKAdapter::FWK_ADPT_EXT_OUTPUT_SHAPE: | case aicpu::FWKAdapter::FWK_ADPT_EXT_OUTPUT_SHAPE: | ||||
GE_CHK_STATUS_RET(ParseExtOutputShape(aicpu_ext_info), "Parse ext output shape failed."); | GE_CHK_STATUS_RET(ParseExtOutputShape(aicpu_ext_info), "Parse ext output shape failed."); | ||||
break; | break; | ||||
case aicpu::FWKAdapter::FWK_ADPT_EXT_SESSION_INFO: | |||||
GE_CHK_STATUS_RET(ParseExtSessionInfo(aicpu_ext_info), "Parse ext session info failed."); | |||||
break; | |||||
default: | default: | ||||
GELOGD("Node[%s] ignore infoType=%d, infoLen=%u.", | GELOGD("Node[%s] ignore infoType=%d, infoLen=%u.", | ||||
node_name_.c_str(), aicpu_ext_info->infoType, aicpu_ext_info->infoLen); | 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; | 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<AicpuSessionInfo *>(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) { | Status AicpuExtInfoHandler::UpdateInputShapeAndType(uint32_t input_index, const GeTensorDesc &input_desc) { | ||||
GE_CHECK_LE(input_index, input_num_); | GE_CHECK_LE(input_index, input_num_); | ||||
const auto &shape = input_desc.GetShape(); | const auto &shape = input_desc.GetShape(); | ||||
@@ -19,6 +19,7 @@ | |||||
#include "external/ge/ge_api_error_codes.h" | #include "external/ge/ge_api_error_codes.h" | ||||
#include "cce/fwk_adpt_struct.h" | #include "cce/fwk_adpt_struct.h" | ||||
#include "cce/aicpu_engine_struct.h" | |||||
#include "graph/op_desc.h" | #include "graph/op_desc.h" | ||||
#include "graph/ge_tensor.h" | #include "graph/ge_tensor.h" | ||||
@@ -26,6 +27,7 @@ namespace ge { | |||||
namespace hybrid { | namespace hybrid { | ||||
using AicpuShapeAndType = aicpu::FWKAdapter::ShapeAndType; | using AicpuShapeAndType = aicpu::FWKAdapter::ShapeAndType; | ||||
using AicpuExtInfo = aicpu::FWKAdapter::ExtInfo; | using AicpuExtInfo = aicpu::FWKAdapter::ExtInfo; | ||||
using AicpuSessionInfo = SessionInfo; | |||||
class AicpuExtInfoHandler { | class AicpuExtInfoHandler { | ||||
public: | public: | ||||
@@ -51,6 +53,10 @@ class AicpuExtInfoHandler { | |||||
Status UpdateOutputShapeAndType(uint32_t output_index, const GeTensorDesc &output_desc); | 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); | Status GetOutputShapeAndType(uint32_t output_index, GeShape &shape, DataType &data_type); | ||||
private: | private: | ||||
@@ -58,6 +64,7 @@ class AicpuExtInfoHandler { | |||||
Status ParseExtShapeType(AicpuExtInfo *aicpu_ext_info); | Status ParseExtShapeType(AicpuExtInfo *aicpu_ext_info); | ||||
Status ParseExtInputShape(AicpuExtInfo *aicpu_ext_info); | Status ParseExtInputShape(AicpuExtInfo *aicpu_ext_info); | ||||
Status ParseExtOutputShape(AicpuExtInfo *aicpu_ext_info); | Status ParseExtOutputShape(AicpuExtInfo *aicpu_ext_info); | ||||
Status ParseExtSessionInfo(AicpuExtInfo *aicpu_ext_info); | |||||
static Status UpdateShapeAndType(const GeShape &shape, | static Status UpdateShapeAndType(const GeShape &shape, | ||||
DataType data_type, | DataType data_type, | ||||
@@ -72,6 +79,7 @@ class AicpuExtInfoHandler { | |||||
const uint32_t input_num_; | const uint32_t input_num_; | ||||
const uint32_t output_num_; | const uint32_t output_num_; | ||||
UnknowShapeOpType unknown_type_; | UnknowShapeOpType unknown_type_; | ||||
AicpuSessionInfo *session_info_ = nullptr; | |||||
std::unique_ptr<uint8_t[]> ext_info_; | std::unique_ptr<uint8_t[]> ext_info_; | ||||
size_t ext_info_len_ = 0; | size_t ext_info_len_ = 0; | ||||
@@ -40,29 +40,36 @@ Status AicpuNodeTaskBase::AllocTensorBuffer(size_t size, std::unique_ptr<TensorB | |||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
Status AicpuNodeTaskBase::InitExtInfo(const std::string &kernel_ext_info) { | |||||
if (node_item_->is_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()) { | 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 | // 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[%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 | // copy default ext info to device | ||||
GE_CHK_RT_RET(rtMemcpy(ext_info_addr_dev_->GetData(), ext_info_addr_dev_->GetSize(), | 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; | return SUCCESS; | ||||
} | } | ||||
@@ -290,7 +297,8 @@ Status AicpuTfNodeTask::Init(const HybridModel &model) { | |||||
node_name_.c_str(), kernel_ext_info.size(), kernel_ext_info_size); | node_name_.c_str(), kernel_ext_info.size(), kernel_ext_info_size); | ||||
// init ext info | // 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()); | GE_CHK_STATUS_RET(InitForDependComputeTask(), "Node[%s] init for depend compute task failed.", node_name_.c_str()); | ||||
// build fwk_op_kernel. | // 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[%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); | 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) { | if (ext_info_addr_dev_ == nullptr) { | ||||
aicpu_param_head->extInfoLength = 0; | aicpu_param_head->extInfoLength = 0; | ||||
@@ -43,7 +43,7 @@ class AicpuNodeTaskBase : public NodeTask { | |||||
Status ExecuteAsync(TaskContext &context, std::function<void()> done_callback) override; | Status ExecuteAsync(TaskContext &context, std::function<void()> done_callback) override; | ||||
protected: | 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(); | virtual Status UpdateExtInfo(); | ||||
@@ -44,8 +44,6 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY SingleOp::~SingleOp() { | |||||
delete task; | delete task; | ||||
task = nullptr; | task = nullptr; | ||||
} | } | ||||
GELOGI("SingleOp destory sessionId = %lu", aicpu_session_id_); | |||||
ModelManager::GetInstance()->DestroyAicpuSession(aicpu_session_id_); | |||||
} | } | ||||
Status SingleOp::ValidateArgs(const std::vector<DataBuffer> &inputs, const std::vector<DataBuffer> &outputs) { | Status SingleOp::ValidateArgs(const std::vector<DataBuffer> &inputs, const std::vector<DataBuffer> &outputs) { | ||||
@@ -180,17 +178,11 @@ void SingleOp::SetStream(rtStream_t stream) { | |||||
stream_ = 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) | DynamicSingleOp::DynamicSingleOp(uintptr_t resource_id, std::mutex *stream_mutex, rtStream_t stream) | ||||
: resource_id_(resource_id), stream_mutex_(stream_mutex), stream_(stream) { | : resource_id_(resource_id), stream_mutex_(stream_mutex), stream_(stream) { | ||||
} | } | ||||
DynamicSingleOp::~DynamicSingleOp() { | DynamicSingleOp::~DynamicSingleOp() { | ||||
GELOGI("DynamicSingleOp destory sessionId = %lu", aicpu_session_id_); | |||||
ModelManager::GetInstance()->DestroyAicpuSession(aicpu_session_id_); | |||||
} | } | ||||
Status DynamicSingleOp::ValidateParams(const vector<GeTensorDesc> &input_desc, | Status DynamicSingleOp::ValidateParams(const vector<GeTensorDesc> &input_desc, | ||||
@@ -299,8 +291,4 @@ Status DynamicSingleOp::ExecuteAsync(const vector<GeTensorDesc> &input_desc, | |||||
return ACL_ERROR_GE_OP_TASK_TYPE_INVALID; | return ACL_ERROR_GE_OP_TASK_TYPE_INVALID; | ||||
} | } | ||||
} | } | ||||
void DynamicSingleOp::SetSessionID(uint64_t session_id) { | |||||
aicpu_session_id_ = session_id; | |||||
} | |||||
} // namespace ge | } // namespace ge |
@@ -37,7 +37,6 @@ class SingleOp { | |||||
Status ExecuteAsync(const std::vector<DataBuffer> &inputs, const std::vector<DataBuffer> &outputs); | Status ExecuteAsync(const std::vector<DataBuffer> &inputs, const std::vector<DataBuffer> &outputs); | ||||
void SetStream(rtStream_t stream); | void SetStream(rtStream_t stream); | ||||
void SetSessionID(uint64_t session_id); | |||||
private: | private: | ||||
Status ValidateArgs(const std::vector<DataBuffer> &inputs, const std::vector<DataBuffer> &outputs); | Status ValidateArgs(const std::vector<DataBuffer> &inputs, const std::vector<DataBuffer> &outputs); | ||||
@@ -52,7 +51,6 @@ class SingleOp { | |||||
std::vector<void *> output_addr_list_; | std::vector<void *> output_addr_list_; | ||||
std::vector<size_t> output_sizes_; | std::vector<size_t> output_sizes_; | ||||
std::vector<uintptr_t> args_; | std::vector<uintptr_t> args_; | ||||
uint64_t aicpu_session_id_ = 0; | |||||
std::vector<OpTask *> tasks_; | std::vector<OpTask *> tasks_; | ||||
std::vector<std::vector<uintptr_t *>> arg_table_; | std::vector<std::vector<uintptr_t *>> arg_table_; | ||||
@@ -66,7 +64,6 @@ class DynamicSingleOp { | |||||
const std::vector<DataBuffer> &inputs, | const std::vector<DataBuffer> &inputs, | ||||
std::vector<GeTensorDesc> &output_desc, | std::vector<GeTensorDesc> &output_desc, | ||||
std::vector<DataBuffer> &outputs); | std::vector<DataBuffer> &outputs); | ||||
void SetSessionID(uint64_t session_id); | |||||
private: | private: | ||||
friend class SingleOpModel; | friend class SingleOpModel; | ||||
@@ -89,7 +86,6 @@ class DynamicSingleOp { | |||||
rtStream_t stream_ = nullptr; | rtStream_t stream_ = nullptr; | ||||
size_t num_inputs_ = 0; | size_t num_inputs_ = 0; | ||||
size_t num_outputs_ = 0; | size_t num_outputs_ = 0; | ||||
uint64_t aicpu_session_id_ = 0; | |||||
}; | }; | ||||
} // namespace ge | } // namespace ge | ||||
#endif // GE_SINGLE_OP_SINGLE_OP_H_ | #endif // GE_SINGLE_OP_SINGLE_OP_H_ |
@@ -32,7 +32,7 @@ | |||||
#include "task/aicpu_kernel_task_builder.h" | #include "task/aicpu_kernel_task_builder.h" | ||||
#include "task/tbe_task_builder.h" | #include "task/tbe_task_builder.h" | ||||
static std::atomic<std::uint64_t> aicpu_sessionid(0); | |||||
static std::atomic<std::uint64_t> aicpu_kernel_id(0); | |||||
using domi::TaskDef; | using domi::TaskDef; | ||||
using std::unique_ptr; | 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) { | } else if (kernel_type == cce::ccKernelType::AI_CPU || kernel_type == cce::ccKernelType::CUST_AI_CPU) { | ||||
GELOGD("Building AICPU_CC task"); | GELOGD("Building AICPU_CC task"); | ||||
OpTask *task = nullptr; | 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) { | if (ret != SUCCESS) { | ||||
return ret; | return ret; | ||||
} | } | ||||
@@ -265,14 +267,13 @@ Status SingleOpModel::BuildTaskList(SingleOp &single_op) { | |||||
GELOGD("Building AICPU_TF task"); | GELOGD("Building AICPU_TF task"); | ||||
AiCpuTask *aicpu_task = nullptr; | AiCpuTask *aicpu_task = nullptr; | ||||
bool depend_compute_flag = false; | 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) { | if (ret != SUCCESS) { | ||||
return ret; | return ret; | ||||
} | } | ||||
single_op.tasks_.emplace_back(aicpu_task); | single_op.tasks_.emplace_back(aicpu_task); | ||||
single_op.SetSessionID(singleop_sessionid); | |||||
} else { | } else { | ||||
// skip | // skip | ||||
GELOGD("Skip task type: %d", static_cast<int>(task_type)); | GELOGD("Skip task type: %d", static_cast<int>(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, | 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()); | auto iter = op_list_.find(kernel_def.op_index()); | ||||
if (iter == op_list_.end()) { | if (iter == op_list_.end()) { | ||||
GELOGE(ACL_ERROR_GE_INTERNAL_ERROR, "op desc not found. op index = %u", kernel_def.op_index()); | 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; | return ACL_ERROR_GE_MEMORY_ALLOCATION; | ||||
} | } | ||||
auto builder = AiCpuTaskBuilder(iter->second->GetOpDesc(), kernel_def); | 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) { | if (ret != SUCCESS) { | ||||
GELOGE(ret, "build aicpu_TF op task failed"); | GELOGE(ret, "build aicpu_TF op task failed"); | ||||
return ret; | return ret; | ||||
@@ -353,7 +354,7 @@ Status SingleOpModel::BuildKernelExTask(const domi::KernelExDef &kernel_def, AiC | |||||
return SUCCESS; | 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(); | const auto &context = kernel_def.context(); | ||||
auto iter = op_list_.find(context.op_index()); | auto iter = op_list_.find(context.op_index()); | ||||
if (iter == op_list_.end()) { | 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 builder = AiCpuCCTaskBuilder(iter->second->GetOpDesc(), kernel_def); | ||||
auto ret = builder.BuildTask(*aicpucc_task); | |||||
auto ret = builder.BuildTask(*aicpucc_task, kernel_id); | |||||
if (ret != SUCCESS) { | if (ret != SUCCESS) { | ||||
GELOGE(ret, "build aicpu_CC op task failed"); | GELOGE(ret, "build aicpu_CC op task failed"); | ||||
return ret; | 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) { | } else if (kernel_type == cce::ccKernelType::AI_CPU || kernel_type == cce::ccKernelType::CUST_AI_CPU) { | ||||
GELOGD("Building AICPU_CC task"); | GELOGD("Building AICPU_CC task"); | ||||
OpTask *task = nullptr; | 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); | single_op.op_task_.reset(task); | ||||
} else { | } else { | ||||
GELOGE(ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID, | GELOGE(ACL_ERROR_GE_OP_KERNEL_TYPE_INVALID, | ||||
@@ -430,10 +433,10 @@ Status SingleOpModel::BuildTaskListForDynamicOp(DynamicSingleOp &single_op) { | |||||
GELOGD("Building AICPU_TF task"); | GELOGD("Building AICPU_TF task"); | ||||
AiCpuTask *aicpu_task = nullptr; | AiCpuTask *aicpu_task = nullptr; | ||||
bool depend_compute_flag = false; | 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, | 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 (depend_compute_flag) { | ||||
if (i >= tasks.size() - 1) { | if (i >= tasks.size() - 1) { | ||||
GELOGE(ACL_ERROR_GE_PARAM_INVALID, "The copy task of the fourth operator was not found."); | 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())); | GE_CHK_STATUS_RET_NOLOG(aicpu_task->SetMemCopyTask(copy_task_def.kernel_ex())); | ||||
} | } | ||||
single_op.op_task_.reset(aicpu_task); | single_op.op_task_.reset(aicpu_task); | ||||
single_op.SetSessionID(dynamic_singleop_sessionid); | |||||
} else { | } else { | ||||
// skip | // skip | ||||
GELOGD("Skip task type: %d", static_cast<int>(task_type)); | GELOGD("Skip task type: %d", static_cast<int>(task_type)); | ||||
@@ -69,8 +69,8 @@ class SingleOpModel { | |||||
Status BuildTaskListForDynamicOp(DynamicSingleOp &dynamic_single_op); | Status BuildTaskListForDynamicOp(DynamicSingleOp &dynamic_single_op); | ||||
Status BuildKernelTask(const domi::KernelDef &kernel_def, TbeOpTask **task); | Status BuildKernelTask(const domi::KernelDef &kernel_def, TbeOpTask **task); | ||||
Status BuildKernelExTask(const domi::KernelExDef &kernel_def, AiCpuTask **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); | Status BuildModelTaskKernel(const domi::TaskDef &task_def, DynamicSingleOp &single_op); | ||||
static void ParseOpModelParams(ModelHelper &model_helper, SingleOpModelParam ¶m); | static void ParseOpModelParams(ModelHelper &model_helper, SingleOpModelParam ¶m); | ||||
@@ -46,7 +46,7 @@ Status AiCpuCCTaskBuilder::SetKernelArgs(AiCpuCCTask &task) { | |||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
Status AiCpuCCTaskBuilder::BuildTask(AiCpuCCTask &task) { | |||||
Status AiCpuCCTaskBuilder::BuildTask(AiCpuCCTask &task, uint64_t kernel_id) { | |||||
auto ret = SetKernelArgs(task); | auto ret = SetKernelArgs(task); | ||||
if (ret != SUCCESS) { | if (ret != SUCCESS) { | ||||
return ret; | return ret; | ||||
@@ -76,7 +76,7 @@ Status AiCpuCCTaskBuilder::BuildTask(AiCpuCCTask &task) { | |||||
"task def kernel_ext_info.size=%zu, but kernel_ext_info_size=%u.", | "task def kernel_ext_info.size=%zu, but kernel_ext_info_size=%u.", | ||||
kernel_ext_info.size(), kernel_ext_info_size); | 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) { | if (ret != SUCCESS) { | ||||
GELOGE(ret, "Init ext info failed."); | GELOGE(ret, "Init ext info failed."); | ||||
return ret; | return ret; | ||||
@@ -30,7 +30,7 @@ class AiCpuCCTaskBuilder { | |||||
explicit AiCpuCCTaskBuilder(const OpDescPtr &op_desc, const domi::KernelDef &kernel_def); | explicit AiCpuCCTaskBuilder(const OpDescPtr &op_desc, const domi::KernelDef &kernel_def); | ||||
~AiCpuCCTaskBuilder() = default; | ~AiCpuCCTaskBuilder() = default; | ||||
Status BuildTask(AiCpuCCTask &task); | |||||
Status BuildTask(AiCpuCCTask &task, uint64_t kernel_id); | |||||
private: | private: | ||||
Status SetKernelArgs(AiCpuCCTask &task); | Status SetKernelArgs(AiCpuCCTask &task); | ||||
@@ -111,7 +111,7 @@ namespace ge { | |||||
} | } | ||||
Status AiCpuTaskBuilder::BuildTask(ge::AiCpuTask &task, const SingleOpModelParam ¶m, | 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)); | GE_CHK_STATUS_RET_NOLOG(InitWorkspaceAndIO(&task.io_addr_, &task.workspace_addr_, param, dynamic_flag)); | ||||
STR_FWK_OP_KERNEL fwk_op_kernel = {0}; | 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, | 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.", | "task def kernel_ext_info.size=%zu, but kernel_ext_info_size=%u.", | ||||
kernel_ext_info.size(), kernel_ext_info_size); | 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) { | if (task.ext_info_addr_dev_ != nullptr) { | ||||
fwk_op_kernel.fwkKernelBase.fwk_kernel.extInfoAddr = reinterpret_cast<uintptr_t>(task.ext_info_addr_dev_); | fwk_op_kernel.fwkKernelBase.fwk_kernel.extInfoAddr = reinterpret_cast<uintptr_t>(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."); | 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); | ret = SetKernelArgs(&task.args_, fwk_op_kernel); | ||||
if (ret != SUCCESS) { | if (ret != SUCCESS) { | ||||
return ret; | return ret; | ||||
@@ -29,7 +29,7 @@ namespace ge { | |||||
AiCpuTaskBuilder(const OpDescPtr &op_desc, const domi::KernelExDef &kernel_def); | AiCpuTaskBuilder(const OpDescPtr &op_desc, const domi::KernelExDef &kernel_def); | ||||
~AiCpuTaskBuilder() = default; | ~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: | private: | ||||
static Status SetKernelArgs(void **args, STR_FWK_OP_KERNEL &kernel); | static Status SetKernelArgs(void **args, STR_FWK_OP_KERNEL &kernel); | ||||
@@ -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()) { | if (kernel_ext_info.empty()) { | ||||
GELOGI("Kernel_ext_info is empty, no need copy to device."); | GELOGI("Kernel_ext_info is empty, no need copy to device."); | ||||
return SUCCESS; | return SUCCESS; | ||||
@@ -268,9 +268,13 @@ Status AiCpuBaseTask::SetExtInfoAndType(const std::string &kernel_ext_info) { | |||||
return ret; | 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; | return SUCCESS; | ||||
} | } | ||||
@@ -132,7 +132,7 @@ class AiCpuBaseTask : public OpTask { | |||||
const UnknowShapeOpType GetUnknownType() const { return unknown_type_; } | const UnknowShapeOpType GetUnknownType() const { return unknown_type_; } | ||||
protected: | 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<GeTensorDesc> &input_desc, | Status UpdateExtInfo(const std::vector<GeTensorDesc> &input_desc, | ||||
std::vector<GeTensorDesc> &output_desc, | std::vector<GeTensorDesc> &output_desc, | ||||
@@ -1 +1 @@ | |||||
Subproject commit a464149d95257e7514859b198444fb341dc40786 | |||||
Subproject commit 89590b3405f6c5714997c07f81470764ac66635b |
@@ -40,6 +40,12 @@ typedef struct { | |||||
} fwkKernelBase; | } fwkKernelBase; | ||||
} __attribute__((packed)) STR_FWK_OP_KERNEL; | } __attribute__((packed)) STR_FWK_OP_KERNEL; | ||||
struct SessionInfo { | |||||
uint64_t sessionId; | |||||
uint64_t kernelId; | |||||
bool sessFlag; | |||||
} __attribute__((packed)); | |||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||
} | } | ||||
#endif | #endif | ||||
@@ -48,7 +48,8 @@ enum FWKOperateType { | |||||
FWK_ADPT_KERNEL_RUN, | FWK_ADPT_KERNEL_RUN, | ||||
FWK_ADPT_KERNEL_DESTROY, | FWK_ADPT_KERNEL_DESTROY, | ||||
FWK_ADPT_SESSION_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 | // Extend Info type for task | ||||
@@ -58,6 +59,7 @@ enum FWKTaskExtInfoType { | |||||
FWK_ADPT_EXT_OUTPUT_SHAPE, | FWK_ADPT_EXT_OUTPUT_SHAPE, | ||||
FWK_ADPT_EXT_UPDATE_ADDR, | FWK_ADPT_EXT_UPDATE_ADDR, | ||||
FWK_ADPT_EXT_OP_NAME, | FWK_ADPT_EXT_OP_NAME, | ||||
FWK_ADPT_EXT_SESSION_INFO, | |||||
FWK_ADPT_EXT_INVALID | FWK_ADPT_EXT_INVALID | ||||
}; | }; | ||||