From 79366ad1e8cff40b5fc7ce8a1e662caf74dc57b6 Mon Sep 17 00:00:00 2001 From: guopeian Date: Sat, 17 Jul 2021 15:39:09 +0800 Subject: [PATCH] fitx --- tests/ut/ge/CMakeLists.txt | 1 + .../aicpu/aicpu_node_executor_unittest.cc | 103 +++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 tests/ut/ge/hybrid/node_executor/aicpu/aicpu_node_executor_unittest.cc diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index 42fa6128..b4787304 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -733,6 +733,7 @@ set(HYBRID_TEST_FILES "hybrid/node_executor/node_executor_unittest.cc" "hybrid/node_executor/rts/rts_node_task_unittest.cc" "hybrid/node_executor/host_cpu/host_cpu_node_task_unittest.cc" + "hybrid/node_executor/aicpu/aicpu_node_executor_unittest.cc" "hybrid/node_executor/ge_local/ge_local_node_executor_unittest.cc" "hybrid/node_executor/hccl/hccl_node_executor_unittest.cc" "hybrid/executor/hybrid_model_async_executor_unittest.cc" diff --git a/tests/ut/ge/hybrid/node_executor/aicpu/aicpu_node_executor_unittest.cc b/tests/ut/ge/hybrid/node_executor/aicpu/aicpu_node_executor_unittest.cc new file mode 100644 index 00000000..a71df6b1 --- /dev/null +++ b/tests/ut/ge/hybrid/node_executor/aicpu/aicpu_node_executor_unittest.cc @@ -0,0 +1,103 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#define private public +#define protected public +#include "hybrid/executor/subgraph_context.h" +#include "hybrid/node_executor/aicpu/aicpu_node_executor.h" +#include "model/ge_root_model.h" +#include "graph/passes/graph_builder_utils.h" +#include "aicpu/common/aicpu_task_struct.h" +#include "graph/manager/graph_mem_manager.h" +#undef private +#undef protected + +using namespace std; +using namespace testing; + +namespace ge { +using namespace hybrid; + +namespace { +struct AicpuTaskStruct { + aicpu::AicpuParamHead head; + uint64_t io_addrp[2]; +}__attribute__((packed)); +} // namespace + +class UtestAiCpuNodeTask : public testing::Test { + protected: + void SetUp() {} + void TearDown() {} +}; + +TEST_F(UtestAiCpuNodeTask, test_load) { + ut::GraphBuilder builder = ut::GraphBuilder("graph"); + auto node = builder.AddNode("Data", "Data", 1, 1); + auto graph = builder.GetGraph(); + + GeRootModelPtr ge_root_model = std::make_shared(graph); + HybridModel hybrid_model(ge_root_model); + std::unique_ptr node_item; + ASSERT_EQ(NodeItem::Create(node, node_item), SUCCESS); + node_item->shape_inference_type = 4; + hybrid_model.node_items_[node] = std::move(node_item); + domi::TaskDef node_task; + node_task.set_type(RT_MODEL_TASK_KERNEL); + domi::KernelDef *node_kernel_def = node_task.mutable_kernel(); + node_kernel_def->set_so_name("libcpu_kernels.so"); + node_kernel_def->set_kernel_name("RunCpuKernel"); + node_kernel_def->set_kernel_ext_info_size(0); + uint32_t nod_param_len = static_cast(sizeof(AicpuParamHead)) + 2 * static_cast(sizeof(uint64_t)); + std::string node_task_args; + AicpuParamHead node_param_head = {node_param_len, 2, 0, 0}; + node_task_args.append(reinterpret_cast(&node_param_head), sizeof(AicpuParamHead)); + node_task_args.append(2 * static_cast(sizeof(uint64_t), ' '); + node_kernel_def->set_args(node_task_args.data(), node_param_len); + node_kernel_def->set_args_size(param_len); + domi::KernelContext *node_context = node_kernel_def->mutable_context(); + node_context->set_op_index(0); + node_context->set_kernel_type(cce::ccKernelType::AI_CPU); + + domi::TaskDef copy_task; + copy_task.set_type(RT_MODEL_TASK_KERNEL); + domi::KernelDef *copy_kernel_def = copy_task.mutable_kernel(); + copy_kernel_def->set_so_name("libcpu_kernels.so"); + copy_task_def->set_kernel_name("RunCpuKernel"); + copy_task_def->set_kernel_ext_info_size(0); + uint32_t copy_param_len = static_cast(sizeof(AicpuParamHead)) + static_cast(sizeof(uint64_t)); + std::string copy_task_args; + AicpuParamHead copy_param_head = {copy_param_len, 1, 0, 0}; + copy_task_args.append(reinterpret_cast(©_param_head), sizeof(AicpuParamHead)); + copy_task_args.append(static_cast(sizeof(uint64_t), ' '); + copy_task_def->set_args(copy_task_args.data(), node_param_len); + copy_task_def->set_args_size(param_len); + domi::KernelContext *copy_context = copy_task_def->mutable_context(); + copy_context->set_op_index(0); + copy_context->set_kernel_type(cce::ccKernelType::AI_CPU); + + hybrid_model.task_defs_[node] = {node_task, copy_task}; + hybrid_model.node_items_[node]->num_inputs = 1; + hybrid_model.node_items_[node]->num_outputs = 1; + NodeTaskPtr task = nullptr; + AiCpuNodeExecutor node_executor; + ASSERT_EQ(node_executor.LoadTask(hybrid_model, node, task), SUCCESS); +} +} // namespace ge