Browse Source

fitx

pull/1985/head
guopeian 3 years ago
parent
commit
79366ad1e8
2 changed files with 104 additions and 0 deletions
  1. +1
    -0
      tests/ut/ge/CMakeLists.txt
  2. +103
    -0
      tests/ut/ge/hybrid/node_executor/aicpu/aicpu_node_executor_unittest.cc

+ 1
- 0
tests/ut/ge/CMakeLists.txt View File

@@ -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"


+ 103
- 0
tests/ut/ge/hybrid/node_executor/aicpu/aicpu_node_executor_unittest.cc View File

@@ -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 <gtest/gtest.h>
#include <gmock/gmock.h>
#include <vector>

#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<GeRootModel>(graph);
HybridModel hybrid_model(ge_root_model);
std::unique_ptr<NodeItem> 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<uint32_t>(sizeof(AicpuParamHead)) + 2 * static_cast<uint32_t>(sizeof(uint64_t));
std::string node_task_args;
AicpuParamHead node_param_head = {node_param_len, 2, 0, 0};
node_task_args.append(reinterpret_cast<const char *>(&node_param_head), sizeof(AicpuParamHead));
node_task_args.append(2 * static_cast<uint32_t>(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<uint32_t>(sizeof(AicpuParamHead)) + static_cast<uint32_t>(sizeof(uint64_t));
std::string copy_task_args;
AicpuParamHead copy_param_head = {copy_param_len, 1, 0, 0};
copy_task_args.append(reinterpret_cast<const char *>(&copy_param_head), sizeof(AicpuParamHead));
copy_task_args.append(static_cast<uint32_t>(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

Loading…
Cancel
Save