parent
1d354d1e29
commit
1db59ce1bc
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,101 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
/**
|
||||
* Copyright 2019-2020 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 "graph/load/model_manager/model_utils.h"
|
||||
#include "graph/utils/graph_utils.h"
|
||||
#include "runtime/rt.h"
|
||||
|
||||
#define protected public
|
||||
#define private public
|
||||
#include "single_op/single_op_model.h"
|
||||
#include "single_op/task/tbe_task_builder.h"
|
||||
#include "single_op/task/op_task.h"
|
||||
#include "single_op/task/tbe_task_builder.h"
|
||||
#include "external/register/op_tiling_registry.h"
|
||||
#undef private
|
||||
#undef protected
|
||||
|
||||
using namespace std;
|
||||
using namespace testing;
|
||||
using namespace ge;
|
||||
using namespace optiling;
|
||||
|
||||
class UtestSingleOpTask : public testing::Test {
|
||||
protected:
|
||||
void SetUp() {}
|
||||
|
||||
void TearDown() {}
|
||||
};
|
||||
|
||||
TEST_F(UtestSingleOpTask, test_build_kernel_task) {
|
||||
string model_data_str = "123456789";
|
||||
SingleOpModel model("model", model_data_str.c_str(), model_data_str.size());
|
||||
model.input_offset_list_.push_back(0);
|
||||
model.input_sizes_.push_back(16);
|
||||
|
||||
model.output_offset_list_.push_back(0);
|
||||
model.output_sizes_.push_back(16);
|
||||
|
||||
auto graph = make_shared<ComputeGraph>("graph");
|
||||
auto op_desc = make_shared<OpDesc>("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);
|
||||
|
||||
vector<int64_t> shape{16, 16};
|
||||
GeShape ge_shape(shape);
|
||||
GeTensorDesc desc(ge_shape);
|
||||
op_desc->AddInputDesc(desc);
|
||||
op_desc->AddOutputDesc(desc);
|
||||
auto node = graph->AddNode(op_desc);
|
||||
|
||||
std::mutex stream_mu_;
|
||||
rtStream_t stream_ = nullptr;
|
||||
StreamResource stream_resource(0);
|
||||
SingleOp single_op(&stream_resource, &stream_mu_, stream_);
|
||||
|
||||
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));
|
||||
model.op_list_[1] = node;
|
||||
|
||||
TbeOpTask task_tmp;
|
||||
TbeOpTask *task = &task_tmp;
|
||||
ASSERT_EQ(model.BuildKernelTask(task_def, &task), SUCCESS);
|
||||
vector<GeTensorDesc> input_desc;
|
||||
vector<DataBuffer> input_buffers;
|
||||
vector<GeTensorDesc> output_desc;
|
||||
vector<DataBuffer> output_buffers;
|
||||
task->node_ = node;
|
||||
OpTilingFunc op_tiling_func = [](const TeOpParas &, const OpCompileInfo &, OpRunInfo &) -> bool {return true;};
|
||||
OpTilingRegistryInterf("Add", op_tiling_func);
|
||||
ge::AttrUtils::SetStr(op_desc, "compile_info_key", "op_compile_info_key");
|
||||
ge::AttrUtils::SetStr(op_desc, "compile_info_json", "op_compile_info_json");
|
||||
char c = '0';
|
||||
char* buffer = &c;
|
||||
task->tiling_buffer_ = buffer;
|
||||
task->max_tiling_size_ = 64;
|
||||
task->tiling_data_ = "tiling_data";
|
||||
task->arg_size_ = 64;
|
||||
uint8_t task_args{0};
|
||||
task->args_.reset(&task_args);
|
||||
|
||||
ASSERT_EQ(task->LaunchKernel(input_desc, input_buffers, output_desc, output_buffers, stream_), SUCCESS);
|
||||
char handle_tmp = '0';
|
||||
char *handle = &handle_tmp;
|
||||
task->SetHandle(handle);
|
||||
ASSERT_EQ(task->LaunchKernel(input_desc, input_buffers, output_desc, output_buffers, stream_), SUCCESS);
|
||||
}
|
Loading…
Reference in new issue