You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.4 KiB
101 lines
3.4 KiB
4 years ago
|
/**
|
||
|
* Copyright 2019-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 <vector>
|
||
|
|
||
|
#include "runtime/rt.h"
|
||
|
|
||
|
#define protected public
|
||
|
#define private public
|
||
|
#include "hybrid/model/hybrid_model_builder.h"
|
||
|
#include "hybrid/model/hybrid_model.h"
|
||
|
#include "model/ge_model.h"
|
||
|
#include "model/ge_root_model.h"
|
||
|
|
||
|
#include "hybrid/node_executor/aicore/aicore_op_task.h"
|
||
|
#include "framework/common/taskdown_common.h"
|
||
|
#include "framework/common/debug/log.h"
|
||
|
#include "graph/ge_context.h"
|
||
|
#include "hybrid/executor/hybrid_execution_context.h"
|
||
|
#include "hybrid/node_executor/aicore/aicore_task_builder.h"
|
||
|
#include "graph/load/model_manager/tbe_handle_store.h"
|
||
|
#include "graph/types.h"
|
||
|
|
||
|
#undef private
|
||
|
#undef protected
|
||
|
|
||
|
using namespace std;
|
||
|
using namespace testing;
|
||
|
using namespace ge;
|
||
|
|
||
|
class UtestGeHybrid : public testing::Test {
|
||
|
protected:
|
||
|
void SetUp() {}
|
||
|
|
||
|
void TearDown() {}
|
||
|
};
|
||
|
|
||
|
static ge::OpDescPtr CreateOpDesc(string name = "", string type = "") {
|
||
|
auto op_desc = std::make_shared<ge::OpDesc>(name, type);
|
||
|
op_desc->SetStreamId(0);
|
||
|
op_desc->SetId(0);
|
||
|
|
||
|
op_desc->SetWorkspace({});
|
||
|
;
|
||
|
op_desc->SetWorkspaceBytes({});
|
||
|
op_desc->SetInputOffset({});
|
||
|
op_desc->SetOutputOffset({});
|
||
|
|
||
|
ge::AttrUtils::SetStr(op_desc, ge::TVM_ATTR_NAME_MAGIC, "RT_DEV_BINARY_MAGIC_ELF_AIVEC");
|
||
|
bool support_dynamic = true;
|
||
|
ge::AttrUtils::GetBool(op_desc, "support_dynamicshape", support_dynamic);
|
||
|
return op_desc;
|
||
|
}
|
||
|
|
||
|
TEST_F(UtestGeHybrid, aicore_op_task_init_success) {
|
||
|
// build aicore task
|
||
|
auto aicore_task = std::unique_ptr<hybrid::AiCoreOpTask>(new(std::nothrow)hybrid::AiCoreOpTask());
|
||
|
domi::TaskDef task_def;
|
||
|
task_def.set_type(RT_MODEL_TASK_ALL_KERNEL);
|
||
|
domi::KernelDefWithHandle *kernel_with_handle = task_def.mutable_kernel_with_handle();
|
||
|
kernel_with_handle->set_original_kernel_key("");
|
||
|
kernel_with_handle->set_node_info("");
|
||
|
kernel_with_handle->set_block_dim(32);
|
||
|
kernel_with_handle->set_args_size(64);
|
||
|
string args(64, '1');
|
||
|
kernel_with_handle->set_args(args.data(), 64);
|
||
|
domi::KernelContext *context = kernel_with_handle->mutable_context();
|
||
|
context->set_op_index(1);
|
||
|
context->set_kernel_type(2); // ccKernelType::TE
|
||
|
uint16_t args_offset[9] = {0};
|
||
|
context->set_args_offset(args_offset, 9 * sizeof(uint16_t));
|
||
|
|
||
|
OpDescPtr op_desc = CreateOpDesc("Add", "Add");
|
||
|
std::vector<char> kernelBin;
|
||
|
TBEKernelPtr tbe_kernel = std::make_shared<ge::OpKernelBin>("name/Add", std::move(kernelBin));
|
||
|
op_desc->SetExtAttr(ge::OP_EXTATTR_NAME_TBE_KERNEL, tbe_kernel);
|
||
|
std::string kernel_name("kernel/Add");
|
||
|
AttrUtils::SetStr(op_desc, op_desc->GetName() + "_kernelname", kernel_name);
|
||
|
ASSERT_EQ(aicore_task->InitWithTaskDef(*op_desc.get(), task_def), SUCCESS);
|
||
|
rtStream_t stream = nullptr;
|
||
|
rtStreamCreate(&stream, 0);
|
||
|
ASSERT_EQ(aicore_task->LaunchKernel(stream), SUCCESS);
|
||
|
char *handle = "";
|
||
|
aicore_task->handle_ = handle;
|
||
|
aicore_task->tiling_key_ = 1;
|
||
|
ASSERT_EQ(aicore_task->LaunchKernel(stream), SUCCESS);
|
||
|
}
|