From b1c70681ec2711f6990fe134ac67187c716bf690 Mon Sep 17 00:00:00 2001 From: taoxiangdong Date: Sat, 12 Dec 2020 18:54:04 +0800 Subject: [PATCH] Update some diff from yellow zone --- ge/graph/build/model_builder.cc | 53 ++++++++++--------- ge/graph/build/model_builder.h | 4 +- .../load/new_model_manager/davinci_model.cc | 2 +- .../load/new_model_manager/model_manager.cc | 31 ++++++++--- .../load/new_model_manager/model_manager.h | 2 +- 5 files changed, 57 insertions(+), 35 deletions(-) diff --git a/ge/graph/build/model_builder.cc b/ge/graph/build/model_builder.cc index 3c36d4ee..1eb758c3 100755 --- a/ge/graph/build/model_builder.cc +++ b/ge/graph/build/model_builder.cc @@ -581,15 +581,11 @@ Status ModelBuilder::SaveDataToModel(ge::Model &model, ge::GeModel &ge_model) { // Add TBE Kernels and custom aicpu op bin std::set tbe_name_set; std::set aicpu_name_set; - std::vector aicpu_optype_list; - std::vector aicpu_tf_optype_list; - std::set aicpu_optype_set; - std::set aicpu_tf_optype_set; for (const ge::NodePtr &n : compute_graph_->GetNodes(compute_graph_->GetGraphUnknownFlag())) { auto node_op_desc = n->GetOpDesc(); GE_IF_BOOL_EXEC(node_op_desc == nullptr, continue); // check aicpu op type - (void)CheckAicpuOp(node_op_desc, aicpu_optype_set, aicpu_tf_optype_set); + (void)CollectCheckAicpuAttr(node_op_desc, aicpu_optype_set, aicpu_tf_optype_set); TBEKernelPtr tbe_kernel = node_op_desc->TryGetExtAttr(ge::OP_EXTATTR_NAME_TBE_KERNEL, TBEKernelPtr()); if (tbe_kernel == nullptr) { std::string kernel_name; @@ -611,24 +607,7 @@ Status ModelBuilder::SaveDataToModel(ge::Model &model, ge::GeModel &ge_model) { tbe_kernel_store_.AddTBEKernel(tbe_kernel); } - if (ge::AttrUtils::GetListStr(ge_model, "needCheckCpu", aicpu_optype_list)) { - GELOGI("Already have aicpu optype size: %zu", aicpu_optype_list.size()); - aicpu_optype_set.insert(aicpu_optype_list.begin(), aicpu_optype_list.end()); - } - - if (ge::AttrUtils::GetListStr(ge_model, "needCheckTf", aicpu_tf_optype_list)) { - GELOGI("Already have aicpu tf optype size: %zu", aicpu_tf_optype_list.size()); - aicpu_tf_optype_set.insert(aicpu_tf_optype_list.begin(), aicpu_tf_optype_list.end()); - } - - // reset list with set - aicpu_optype_list.assign(aicpu_optype_set.begin(), aicpu_optype_set.end()); - aicpu_tf_optype_list.assign(aicpu_tf_optype_set.begin(), aicpu_tf_optype_set.end()); - GELOGI("Check Aicpu op types ComputeGraph: %s aicpu_optype_set: %zu, aicpu_optype_list: %zu, aicpu_tf_optype_set: %zu, aicpu_tf_optype_list:%zu.", - compute_graph_->GetName().c_str(), aicpu_optype_set.size(), aicpu_optype_list.size(), aicpu_tf_optype_set.size(), aicpu_tf_optype_list.size()); - GE_CHK_BOOL_EXEC(ge::AttrUtils::SetListStr(model, "needCheckCpu", aicpu_optype_list), return FAILED, "Set attr needCheckCpu fail."); - - GE_CHK_BOOL_EXEC(ge::AttrUtils::SetListStr(model, "needCheckTf", aicpu_tf_optype_list), return FAILED, "Set attr needCheckTf fail."); + (void)SetModelAicpuCheckAttr(model); for (const ge::NodePtr &n : compute_graph_->GetNodes(compute_graph_->GetGraphUnknownFlag())) { auto node_op_desc = n->GetOpDesc(); @@ -822,7 +801,7 @@ Status ModelBuilder::CompileSingleOp() { return ge::SUCCESS; } -Status ModelBuilder::CheckAicpuOp(const OpDescPtr &op_desc, std::set &cpue_check_set, std::set &tf_engine_set) { +Status ModelBuilder::CollectCheckAicpuAttr(const OpDescPtr &op_desc, std::set &cpue_check_set, std::set &tf_engine_set) { GE_CHECK_NOTNULL(op_desc); std::string aicpu_optype; bool has_attr_check_cpu = ge::AttrUtils::GetStr(op_desc, "needCheckCpu", aicpu_optype); @@ -840,4 +819,30 @@ Status ModelBuilder::CheckAicpuOp(const OpDescPtr &op_desc, std::set aicpu_optype_list; + std::vector aicpu_tf_optype_list; + std::set aicpu_optype_set; + std::set aicpu_tf_optype_set; + if (ge::AttrUtils::GetListStr(&model, "needCheckCpu", aicpu_optype_list)) { + GELOGI("Already have aicpu optype size: %zu", aicpu_optype_list.size()); + aicpu_optype_set.insert(aicpu_optype_list.begin(), aicpu_optype_list.end()); + } + + if (ge::AttrUtils::GetListStr(&model, "needCheckTf", aicpu_tf_optype_list)) { + GELOGI("Already have aicpu tf optype size: %zu", aicpu_tf_optype_list.size()); + aicpu_tf_optype_set.insert(aicpu_tf_optype_list.begin(), aicpu_tf_optype_list.end()); + } + + // reset list with set + aicpu_optype_list.assign(aicpu_optype_set.begin(), aicpu_optype_set.end()); + aicpu_tf_optype_list.assign(aicpu_tf_optype_set.begin(), aicpu_tf_optype_set.end()); + GELOGI("Check Aicpu op types ComputeGraph: %s aicpu_optype_set: %zu, aicpu_optype_list: %zu, aicpu_tf_optype_set: %zu, aicpu_tf_optype_list:%zu.", + compute_graph_->GetName().c_str(), aicpu_optype_set.size(), aicpu_optype_list.size(), aicpu_tf_optype_set.size(), aicpu_tf_optype_list.size()); + GE_CHK_BOOL_EXEC(ge::AttrUtils::SetListStr(&model, "needCheckCpu", aicpu_optype_list), return FAILED, "Set attr needCheckCpu fail."); + + GE_CHK_BOOL_EXEC(ge::AttrUtils::SetListStr(&model, "needCheckTf", aicpu_tf_optype_list), return FAILED, "Set attr needCheckTf fail."); + return SUCCESS; +} } // namespace ge diff --git a/ge/graph/build/model_builder.h b/ge/graph/build/model_builder.h index 8efd76e9..e4dfbf0f 100644 --- a/ge/graph/build/model_builder.h +++ b/ge/graph/build/model_builder.h @@ -83,7 +83,9 @@ class ModelBuilder { Status CompileSingleOp(); - Status CheckAicpuOp(const OpDescPtr &op_desc, std::set &cpue_check_set, std::set &tf_engine_set); + Status CollectCheckAicpuAttr(const OpDescPtr &op_desc, std::set &cpue_check_set, std::set &tf_engine_set); + + Status SetModelCheckAicpuAttr(ge::Model &model); uint64_t session_id_; diff --git a/ge/graph/load/new_model_manager/davinci_model.cc b/ge/graph/load/new_model_manager/davinci_model.cc index fceadc32..d1ea833a 100755 --- a/ge/graph/load/new_model_manager/davinci_model.cc +++ b/ge/graph/load/new_model_manager/davinci_model.cc @@ -485,7 +485,7 @@ Status DavinciModel::DoTaskSink() { GE_CHK_STATUS_RET(ModelManager::GetInstance()->LaunchCustAicpuSo(), "Launch cust aicpu so failed."); - GE_CHK_STATUS_RET(ModelManager::GetInstance()->CheckAicpuOp(ge_model_), "Check aicpu op type failed."); + GE_CHK_STATUS_RET(ModelManager::GetInstance()->CheckAicpuOpList(ge_model_), "Check aicpu op type failed."); GE_CHK_STATUS_RET(InitEntryTask(), "InitEntryTask failed."); diff --git a/ge/graph/load/new_model_manager/model_manager.cc b/ge/graph/load/new_model_manager/model_manager.cc index 7a7afe5d..5973b030 100755 --- a/ge/graph/load/new_model_manager/model_manager.cc +++ b/ge/graph/load/new_model_manager/model_manager.cc @@ -54,6 +54,7 @@ const char *const kDeleteCustOp = "deleteCustOp"; const int kTimeSpecNano = 1000000000; const int kTimeSpecMiro = 1000000; const int kSessionMaxBias = 100; +const int kOpNameMaxSize = 100; struct CustAicpuSoBuf { uint64_t kernelSoBuf; uint32_t kernelSoBufLen; @@ -1540,7 +1541,7 @@ Status ModelManager::LaunchKernelCheckAicpuOp(std::vector &aicpu_op std::vector res_ret_code_list; if (aicpu_optype_list.empty() && aicpu_tf_optype_list.empty()) { - GELOGI("No need to check aicpu optype."); + GELOGI("No need to check aicpu op type."); return SUCCESS; } @@ -1624,7 +1625,7 @@ Status ModelManager::LaunchKernelCheckAicpuOp(std::vector &aicpu_op op_check_info_req.offSetLen = sizeof(SysOpCheckInfo); op_check_info_req.sysOpInfoList = reinterpret_cast(reinterpret_cast(d_req_op_list)); - op_check_info_res.opListNum = op_nums; + op_check_info_res.opListNum = 0; op_check_info_res.returnCodeList = reinterpret_cast(reinterpret_cast(d_ret_code_list)); op_check_info_res.sysOpInfoList = reinterpret_cast(reinterpret_cast(d_res_op_list)); @@ -1636,7 +1637,7 @@ Status ModelManager::LaunchKernelCheckAicpuOp(std::vector &aicpu_op } allocated_mem.push_back(args); GE_CHK_RT(rtMemcpy(args, sizeof(SysOpCheckInfo), &op_check_info_req, sizeof(SysOpCheckInfo), RT_MEMCPY_HOST_TO_DEVICE)); - GE_CHK_RT(rtMemcpy(reinterpret_cast(reinterpret_cast(reinterpret_cast(args)) + op_check_info_req.offSetLen), sizeof(SysOpCheckResp), &op_check_info_res, sizeof(SysOpCheckResp), RT_MEMCPY_HOST_TO_DEVICE)); + GE_CHK_RT(rtMemcpy(reinterpret_cast(reinterpret_cast(args) + op_check_info_req.offSetLen), sizeof(SysOpCheckResp), &op_check_info_res, sizeof(SysOpCheckResp), RT_MEMCPY_HOST_TO_DEVICE)); GE_CHK_RT(rtStreamCreate(&stream, 0)); GE_CHK_RT(rtCpuKernelLaunch(nullptr, kernel_name.c_str(), 1, args, args_size, nullptr, stream)); @@ -1648,8 +1649,7 @@ Status ModelManager::LaunchKernelCheckAicpuOp(std::vector &aicpu_op } // Check the response - void *d_op_check_info_res = reinterpret_cast(reinterpret_cast(reinterpret_cast(args)) + op_check_info_req.offSetLen); - op_check_info_res = {}; + void *d_op_check_info_res = reinterpret_cast(reinterpret_cast(args) + op_check_info_req.offSetLen); GE_CHK_RT(rtMemcpy(&op_check_info_res, sizeof(SysOpCheckResp), d_op_check_info_res, sizeof(SysOpCheckResp), RT_MEMCPY_DEVICE_TO_HOST)); std::function callback = [&]() { for (auto mem : allocated_mem) { @@ -1658,25 +1658,40 @@ Status ModelManager::LaunchKernelCheckAicpuOp(std::vector &aicpu_op GE_CHK_RT(rtStreamDestroy(stream)); }; + if (op_check_info_res.isWithoutJson) { + GELOGI("No need to check aicpu in this scenoria."); + GE_MAKE_GUARD(release, callback); + return SUCCESS; + } uint64_t res_op_nums = op_check_info_res.opListNum; + GELOGI("Check aicpu type, is without json: %d, res op num: %lu.", op_check_info_res.isWithoutJson, res_op_nums); if (res_op_nums != 0) { + res_ret_code_list.clear(); + res_ret_code_list.resize(res_op_nums); + res_aicpu_op_info_list.clear(); + res_aicpu_op_info_list.resize(res_op_nums); GE_CHK_RT(rtMemcpy(res_ret_code_list.data(), sizeof(ReturnCode) * res_op_nums, reinterpret_cast(reinterpret_cast(op_check_info_res.returnCodeList)), sizeof(ReturnCode) * res_op_nums, RT_MEMCPY_DEVICE_TO_HOST)); GE_CHK_RT(rtMemcpy(res_aicpu_op_info_list.data(), sizeof(SysOpInfo) * res_op_nums, reinterpret_cast(reinterpret_cast(op_check_info_res.sysOpInfoList)), sizeof(SysOpInfo) * res_op_nums, RT_MEMCPY_DEVICE_TO_HOST)); if (res_ret_code_list.size() != res_aicpu_op_info_list.size() || res_ret_code_list.size() != res_op_nums) { GELOGE(FAILED, "Number of retcode is not equal to number of op type."); GE_MAKE_GUARD(release, callback); + return FAILED; } - std::string fail_reason = "Check aicpu op_type failed. details: "; + std::string fail_reason; for (uint32_t i = 0; i < res_op_nums; i++) { ReturnCode ret_code = res_ret_code_list.at(i); SysOpInfo aicpu_info = res_aicpu_op_info_list.at(i); + GELOGI("Not surpport aicpu op type: %lu, kernel_type:%d, opLen:%d, ret_code:%d", aicpu_info.opType, aicpu_info.kernelsType, aicpu_info.opLen, ret_code); std::vector op_name; + op_name.clear(); + op_name.resize(kOpNameMaxSize); GE_CHK_RT(rtMemcpy(op_name.data(), aicpu_info.opLen, reinterpret_cast(aicpu_info.opType), aicpu_info.opLen, RT_MEMCPY_DEVICE_TO_HOST)); std::string kernel_type = (static_cast(aicpu_info.kernelsType) == TF_KERNEL) ? "TF_KERNEL" : "CPU_KERNEL"; string op_name_str(op_name.data()); - fail_reason += "op_type: " + op_name_str + " kernel_type: " + kernel_type + " " + to_string(static_cast(ret_code)) + "<0: op_type, 1: format, 2: datatype> not support."; + fail_reason += "op_type: " + op_name_str + " kernel_type: " + kernel_type + " ret code:" + to_string(static_cast(ret_code)) + "<0: op_type, 1: format, 2: datatype> \n"; } - GELOGE(FAILED, "%s", fail_reason.c_str()); + fail_reason += "not support."; + GELOGE(FAILED, "Check aicpu op_type failed. details: %s", fail_reason.c_str()); GE_MAKE_GUARD(release, callback); return FAILED; } diff --git a/ge/graph/load/new_model_manager/model_manager.h b/ge/graph/load/new_model_manager/model_manager.h index 4463b3ef..f1f404b5 100755 --- a/ge/graph/load/new_model_manager/model_manager.h +++ b/ge/graph/load/new_model_manager/model_manager.h @@ -297,7 +297,7 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ModelManager { ge::Status LaunchKernelCheckAicpuOp(std::vector &aicpu_optype_list, std::vector &aicpu_tf_optype_list); - ge::Status CheckAicpuOp(GeModelPtr ge_model); + ge::Status CheckAicpuOpList(GeModelPtr ge_model); ge::Status GetOrigInputInfo(uint32_t model_id, uint32_t index, OriginInputInfo &orig_input_info);