From 8817c42cb5711753e0cdb39b80396b9153f9f9f3 Mon Sep 17 00:00:00 2001 From: guopeian Date: Thu, 24 Jun 2021 17:11:28 +0800 Subject: [PATCH] fix ut --- .../aicpu/aicpu_node_executor.cc | 59 +++++++++++-------- .../node_executor/aicpu/aicpu_node_executor.h | 4 +- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc b/ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc index 3f3c33c0..51b587b8 100755 --- a/ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc +++ b/ge/hybrid/node_executor/aicpu/aicpu_node_executor.cc @@ -772,34 +772,41 @@ Status AicpuNodeTask::SetMemCopyTask(const domi::TaskDef &task_def) { } GELOGD("Start to set memcpy task for node[%s].", node_name_.c_str()); - const domi::KernelExDef &kernel_def = task_def.kernel_ex(); - if (kernel_def.args_size() > sizeof(STR_FWK_OP_KERNEL)) { - GELOGE(PARAM_INVALID, "[Check][Size]sizeof STR_FWK_OP_KERNEL is:%lu, but args_size:%d is bigger", - sizeof(STR_FWK_OP_KERNEL), kernel_def.args_size()); - REPORT_INNER_ERROR("E19999", "sizeof STR_FWK_OP_KERNEL is:%lu, but args_size:%d is bigger.", - sizeof(STR_FWK_OP_KERNEL), kernel_def.args_size()); - return PARAM_INVALID; - } - STR_FWK_OP_KERNEL aicpu_task = {0}; - auto sec_ret = memcpy_s(&aicpu_task, sizeof(STR_FWK_OP_KERNEL), - kernel_def.args().data(), kernel_def.args_size()); - if (sec_ret != EOK) { - GELOGE(FAILED, "[Update][aicpu_task] failed, ret: %d", sec_ret); - REPORT_CALL_ERROR("E19999", "update aicpu_task failed, ret: %d.", sec_ret); - return FAILED; - } - - GE_CHK_STATUS_RET(AllocTensorBuffer(kernel_def.task_info_size(), copy_workspace_buf_), - "[Alloc][TensorBuffer] for Node[%s] to copy task workspace buf, size=%u.", - node_name_.c_str(), kernel_def.task_info_size()); + const domi::KernelDef &kernel_def = task_def.kernel(); + auto &memcpy_args = kernel_def.args(); + uint32_t memcpy_args_size = kernel_def.args_size(); + GE_IF_BOOL_EXEC(memcpy_args.size() != memcpy_args_size, + REPORT_INNER_ERROR("E19999", "MemCopy task def args.size=%zu, but args_size=%u not equal.", + memcpy_args.size(), memcpy_args_size); + GELOGE(FAILED, "[Check][Size]MemCopy task def args.size=%zu, but args_size=%u not equal.", + memcpy_args.size(), memcpy_args_size); + return FAILED;); + GE_IF_BOOL_EXEC(memcpy_args_size < sizeof(aicpu::AicpuParamHead), + REPORT_INNER_ERROR("E19999", + "Task def args_size=%u is less than aicpu param head len=%zu.", + memcpy_args_size, sizeof(aicpu::AicpuParamHead)); + GELOGE(FAILED, + "[Check][Size] Task def args_size=%u is less than aicpu param head len=%zu.", + memcpy_args_size, sizeof(aicpu::AicpuParamHead)); + return FAILED;); - GE_CHK_RT_RET(rtMemcpy(copy_workspace_buf_->GetData(), kernel_def.task_info_size(), - kernel_def.task_info().data(), kernel_def.task_info_size(), RT_MEMCPY_HOST_TO_DEVICE)); + std::unique_ptr memcpy_task; + memcpy_task.reset(new(std::nothrow) uint8_t[memcpy_args_size]()); + GE_IF_BOOL_EXEC(memcpy_task == nullptr, + REPORT_INNER_ERROR("E19999", "new memory failed for Node[MemCopy], task_size[%u].", + memcpy_args_size); + GELOGE(FAILED, "[Malloc][Memory] failed for Node[MemCopy], task_size[%u].", + memcpy_args_size); + return FAILED;); - aicpu_task.fwkKernelBase.fwk_kernel.inputOutputAddr = reinterpret_cast(copy_ioaddr_dev_->GetData()); - aicpu_task.fwkKernelBase.fwk_kernel.workspaceBaseAddr = reinterpret_cast(copy_workspace_buf_->GetData()); - aicpu_task.fwkKernelBase.fwk_kernel.extInfoAddr = 0; - aicpu_task.fwkKernelBase.fwk_kernel.extInfoLen = 0; + errno_t sec_ret = memcpy_s(memcpy_task.get(), memcpy_args_size, memcpy_args.c_str(), memcpy_args.size()); + GE_IF_BOOL_EXEC(sec_ret != EOK, + REPORT_INNER_ERROR("E19999", + "memcpy_s argc_ failed for Node[MemCopy], ret: %d", sec_ret); + GELOGE(INTERNAL_ERROR, + "[Update][args] failed for Node[MemCopy], ret: %d", sec_ret); + return sec_ret;); + GE_CHK_RT_RET(rtMemcpy(copy_task_args_buf_->GetData(), sizeof(STR_FWK_OP_KERNEL), &aicpu_task, sizeof(STR_FWK_OP_KERNEL), RT_MEMCPY_HOST_TO_DEVICE)); diff --git a/ge/hybrid/node_executor/aicpu/aicpu_node_executor.h b/ge/hybrid/node_executor/aicpu/aicpu_node_executor.h index 331ae543..45541d84 100644 --- a/ge/hybrid/node_executor/aicpu/aicpu_node_executor.h +++ b/ge/hybrid/node_executor/aicpu/aicpu_node_executor.h @@ -98,8 +98,6 @@ class AicpuNodeTaskBase : public NodeTask { std::unique_ptr copy_input_src_dev_; std::unique_ptr copy_input_dst_dev_; bool need_sync_ = false; - - std::unique_ptr copy_workspace_buf_; }; class AicpuTfNodeTask : public AicpuNodeTaskBase { @@ -148,6 +146,8 @@ class AicpuTfNodeTask : public AicpuNodeTaskBase { // input and output addr, device mem std::unique_ptr input_output_addr_; + + std::unique_ptr copy_workspace_buf_; }; class AicpuNodeTask : public AicpuNodeTaskBase {