Browse Source

Delete repeated rtSetDevice

tags/v1.2.0
zhangxiaokun 3 years ago
parent
commit
aaf496e02a
10 changed files with 166 additions and 195 deletions
  1. +8
    -29
      ge/graph/load/model_manager/model_manager.cc
  2. +0
    -2
      ge/graph/load/model_manager/model_manager.h
  3. +5
    -11
      ge/graph/manager/graph_manager.cc
  4. +1
    -1
      ge/graph/manager/graph_manager.h
  5. +15
    -15
      tests/ut/common/graph/testcase/ge_graph/ge_format_refiner_unittest.cc
  6. +9
    -9
      tests/ut/common/graph/testcase/ge_graph/ge_graph_anchor_unittest.cc
  7. +5
    -2
      tests/ut/common/graph/testcase/ge_graph/ge_model_serialize_unittest.cc
  8. +1
    -1
      tests/ut/ge/CMakeLists.txt
  9. +63
    -62
      tests/ut/ge/graph/load/davinci_model_unittest.cc
  10. +59
    -63
      tests/ut/ge/graph/load/model_manager_unittest.cc

+ 8
- 29
ge/graph/load/model_manager/model_manager.cc View File

@@ -270,18 +270,6 @@ ModelManager::~ModelManager() {
GE_IF_BOOL_EXEC(device_count > 0, GE_CHK_RT(rtDeviceReset(0)));
}

///
/// @ingroup domi_ome
/// @brief set Device. If no device available, return failure
/// @return Status run result
/// @author
///
Status ModelManager::SetDevice(int32_t deviceId) const {
GE_CHK_RT_RET(rtSetDevice(deviceId));

return SUCCESS;
}

ge::Status ModelManager::SetDynamicSize(uint32_t model_id, const std::vector<uint64_t> &batch_num,
int32_t dynamic_type) {
std::shared_ptr<DavinciModel> davinci_model = GetModel(model_id);
@@ -322,8 +310,6 @@ Status ModelManager::LoadModelOnline(uint32_t &model_id, const shared_ptr<ge::Ge
return DoLoadHybridModelOnline(model_id, ge_root_model, listener);
}

GE_CHK_STATUS_RET(SetDevice(static_cast<int32_t>(GetContext().DeviceId())), "Set device failed, model id:%u.",
model_id);
mmTimespec timespec = mmGetTickCount();
std::shared_ptr<DavinciModel> davinci_model = MakeShared<DavinciModel>(0, listener);
if (davinci_model == nullptr) {
@@ -360,8 +346,6 @@ Status ModelManager::LoadModelOnline(uint32_t &model_id, const shared_ptr<ge::Ge
GELOGI("Parse model %u success.", model_id);
} while (0);

GE_CHK_RT(rtDeviceReset(static_cast<int32_t>(GetContext().DeviceId())));

return ret;
}

@@ -1055,11 +1039,15 @@ Status ModelManager::LoadModelOffline(uint32_t &model_id, const ModelData &model
ACL_ERROR_GE_PARAM_INVALID, "input key file path %s is invalid, %s", model.key.c_str(), strerror(errno));
GenModelId(&model_id);

shared_ptr<DavinciModel> davinci_model = nullptr;
mmTimespec timespec = mmGetTickCount();

ModelHelper model_helper;
Status ret = model_helper.LoadRootModel(model);
if (ret != SUCCESS) {
GELOGE(ret, "load model failed.");
return ret;
}

if (model_helper.GetModelType()) {
bool is_shape_unknown = false;
GE_CHK_STATUS_RET(model_helper.GetGeRootModel()->CheckIsUnknownShape(is_shape_unknown),
@@ -1068,21 +1056,13 @@ Status ModelManager::LoadModelOffline(uint32_t &model_id, const ModelData &model
return DoLoadHybridModelOnline(model_id, model_helper.GetGeRootModel(), listener);
}
}
if (ret != SUCCESS) {
GELOGE(ret, "load model failed.");
return ret;
}

do {
GeModelPtr ge_model = model_helper.GetGeModel();
try {
davinci_model = std::make_shared<DavinciModel>(model.priority, listener);
} catch (std::bad_alloc &) {
shared_ptr<DavinciModel> davinci_model = MakeShared<DavinciModel>(model.priority, listener);
if (davinci_model == nullptr) {
GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Make shared failed");
return ACL_ERROR_GE_MEMORY_ALLOCATION;
} catch (...) {
GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Make shared failed since other exception raise");
return ACL_ERROR_GE_MEMORY_ALLOCATION;
}
davinci_model->SetProfileTime(MODEL_LOAD_START, (timespec.tv_sec * kTimeSpecNano +
timespec.tv_nsec)); // 1000 ^ 3 converts second to nanosecond
@@ -1122,9 +1102,8 @@ Status ModelManager::LoadModelOffline(uint32_t &model_id, const ModelData &model
InsertModel(model_id, davinci_model);

GELOGI("Parse model %u success.", model_id);
GE_IF_BOOL_EXEC(ret == SUCCESS, device_count++);
return SUCCESS;
} while (0);

return ret;


+ 0
- 2
ge/graph/load/model_manager/model_manager.h View File

@@ -247,8 +247,6 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ModelManager {

ge::Status GetModelAttr(uint32_t model_id, std::vector<string> &dynamic_output_shape_info);

ge::Status SetDevice(int32_t deviceId) const;

ge::Status SetDynamicSize(uint32_t model_id, const std::vector<uint64_t> &batch_num, int32_t dynamic_type);

///


+ 5
- 11
ge/graph/manager/graph_manager.cc View File

@@ -2622,14 +2622,9 @@ Status GraphManager::IncreBuild(const GraphNodePtr &graph_node, GeModelPtr &ge_m
return FAILED;
}

void GraphManager::ConstructGeInput(std::vector<ge::GeTensor> &ge_inputs, PreRunArgs &args) {
for (auto const &input : args.input_tensor) {
std::vector<int64_t> input_dims;
std::transform(input.dims.begin(), input.dims.end(), std::back_inserter(input_dims),
[](int64_t x) -> int64_t { return x; });
GeShape input_shape(input_dims);
GeTensorDesc input_tensor_desc;
input_tensor_desc.SetShape(input_shape);
void GraphManager::ConstructGeInput(const vector<InputTensorInfo> &inputs, vector<GeTensor> &ge_inputs) {
for (auto const &input : inputs) {
GeTensorDesc input_tensor_desc(GeShape(input.dims));
input_tensor_desc.SetDataType(static_cast<ge::DataType>(input.data_type));
ge_inputs.emplace_back(input_tensor_desc);
}
@@ -2653,9 +2648,6 @@ void GraphManager::PreRunThread(GraphManager *graph_manager) {
GetThreadLocalContext() = args.context;
graph_manager->UpdateLocalOmgContext(args.graph_id);

std::vector<ge::GeTensor> ge_inputs;
ConstructGeInput(ge_inputs, args);

// find graph
GraphNodePtr graph_node = nullptr;
Status ret = graph_manager->GetGraphNode(args.graph_id, graph_node);
@@ -2709,6 +2701,8 @@ void GraphManager::PreRunThread(GraphManager *graph_manager) {
// check need incre build.
GeModelPtr ge_model = nullptr;
if (graph_manager->IncreBuild(graph_node, ge_model) != SUCCESS) {
std::vector<GeTensor> ge_inputs;
ConstructGeInput(args.input_tensor, ge_inputs);
ret = graph_manager->PreRun(graph_node, ge_inputs, ge_root_model, args.session_id);
// release rts generate context
RtContextUtil::GetInstance().DestroyRtContexts(args.session_id, graph_node->GetGraphId());


+ 1
- 1
ge/graph/manager/graph_manager.h View File

@@ -336,7 +336,7 @@ class GraphManager {
void RemoveModelCacheHelper(const GraphId &graph_id);
ModelCacheHelperPtr FindModelCacheHelper(GraphId graph_id);

static void ConstructGeInput(std::vector<ge::GeTensor> &ge_inputs, PreRunArgs &args);
static void ConstructGeInput(const std::vector<InputTensorInfo> &inputs, std::vector<GeTensor> &ge_inputs);
static void PreRunThread(GraphManager *graph_manager);
static void RunThread(GraphManager *graph_manager);
static void StopQueue(GraphManager *graph_manager);


+ 15
- 15
tests/ut/common/graph/testcase/ge_graph/ge_format_refiner_unittest.cc View File

@@ -58,7 +58,7 @@ namespace {
/// relu1
/// |
/// conv1
/// / \
/// / \.
/// var1 var2
///
ut::GraphBuilder BuildGraph1() {
@@ -95,9 +95,9 @@ ut::GraphBuilder BuildGraph1() {
/// relu1
/// |
/// bn1 -----------------
/// | \ \ \ \
/// | \ \ \ \.
/// conv1 var3 var4 var5 var6
/// | \
/// | \.
/// var1 var2
///
ut::GraphBuilder BuildGraph2() {
@@ -142,11 +142,11 @@ ut::GraphBuilder BuildGraph2() {
/// netoutput1
/// |
/// conv2
/// | \
/// | \.
/// relu1 var3
/// |
/// conv1
/// / \
/// / \.
/// var1 var2
///
ut::GraphBuilder BuildGraph3() {
@@ -197,13 +197,13 @@ ut::GraphBuilder BuildGraph3() {
/// netoutput1
/// |
/// conv2
/// | \
/// | \.
/// relu1 var3
/// |
/// bn1
/// |
/// conv1
/// / \
/// / \.
/// var1 var2
///
ut::GraphBuilder BuildGraph4() {
@@ -256,10 +256,10 @@ ut::GraphBuilder BuildGraph4() {
/// netoutput1
/// |
/// apply1
/// / \
/// relug1 --> bng1 \
/// \ / | \ \
/// relu1 | | \
/// / \.
/// relug1 --> bng1 \.
/// \ / | \ \.
/// relu1 | | \.
/// \| | |
/// | | |
/// bn1 | |
@@ -313,9 +313,9 @@ ut::GraphBuilder BuilderGraph5() {
/// netoutput1
/// |
/// AddN
/// / \ \
/// / \ \.
/// L2Loss GatherV2 Constant
/// / \
/// / \.
/// Data1 Data2
///
ut::GraphBuilder BuildGraph6() {
@@ -362,9 +362,9 @@ ut::GraphBuilder BuildGraph6() {
/// netoutput1
/// |
/// AddN
/// / \ \
/// / \ \.
/// L2Loss GatherV2 Constant
/// / \
/// / \.
/// Data1 Data2
///
ut::GraphBuilder BuildGraph7() {


+ 9
- 9
tests/ut/common/graph/testcase/ge_graph/ge_graph_anchor_unittest.cc View File

@@ -30,7 +30,7 @@
using namespace ge;
using namespace std;

class UtestGeAnchor : public testing::Test {
class UtestGeAnchor : public testing::Test {
protected:
void SetUp() {}

@@ -294,7 +294,7 @@ TEST_F(UtestGeAnchor, data_anchor_replace_peer) {
EXPECT_EQ(node1->GetOutDataAnchor(1)->LinkTo(node2->GetInDataAnchor(1)), GRAPH_SUCCESS);
EXPECT_EQ(node1->GetOutDataAnchor(1)->LinkTo(node2->GetInDataAnchor(2)), GRAPH_SUCCESS);

int out_idx = 0;
size_t out_idx = 0;
for (; out_idx < out_data_anchor->peer_anchors_.size(); out_idx++) {
if (out_data_anchor->peer_anchors_[out_idx].lock() == in_data_anchor) {
break;
@@ -302,7 +302,7 @@ TEST_F(UtestGeAnchor, data_anchor_replace_peer) {
}
EXPECT_EQ(out_idx, 1);

int in_idx = 0;
size_t in_idx = 0;
for (; in_idx < in_data_anchor->peer_anchors_.size(); in_idx++) {
if (in_data_anchor->peer_anchors_[in_idx].lock() == out_data_anchor) {
break;
@@ -312,7 +312,7 @@ TEST_F(UtestGeAnchor, data_anchor_replace_peer) {

out_data_anchor->ReplacePeer(in_data_anchor, node3->GetInDataAnchor(1), node3->GetOutDataAnchor(1));

int out_idx1 = 0;
size_t out_idx1 = 0;
for (; out_idx1 < out_data_anchor->peer_anchors_.size(); out_idx1++) {
if (out_data_anchor->peer_anchors_[out_idx1].lock() == node3->GetInDataAnchor(1)) {
break;
@@ -320,7 +320,7 @@ TEST_F(UtestGeAnchor, data_anchor_replace_peer) {
}
EXPECT_EQ(out_idx1, out_idx);

int in_idx1 = 0;
size_t in_idx1 = 0;
for (; in_idx1 < in_data_anchor->peer_anchors_.size(); in_idx1++) {
if (in_data_anchor->peer_anchors_[in_idx1].lock() == node3->GetOutDataAnchor(1)) {
break;
@@ -350,7 +350,7 @@ TEST_F(UtestGeAnchor, graph_utils_insert_node) {
EXPECT_EQ(node1->GetOutDataAnchor(1)->LinkTo(node2->GetInDataAnchor(1)), GRAPH_SUCCESS);
EXPECT_EQ(node1->GetOutDataAnchor(1)->LinkTo(node2->GetInDataAnchor(2)), GRAPH_SUCCESS);

int out_idx = 0;
size_t out_idx = 0;
for (; out_idx < out_data_anchor->peer_anchors_.size(); out_idx++) {
if (out_data_anchor->peer_anchors_[out_idx].lock() == in_data_anchor) {
break;
@@ -358,7 +358,7 @@ TEST_F(UtestGeAnchor, graph_utils_insert_node) {
}
EXPECT_EQ(out_idx, 1);

int in_idx = 0;
size_t in_idx = 0;
for (; in_idx < in_data_anchor->peer_anchors_.size(); in_idx++) {
if (in_data_anchor->peer_anchors_[in_idx].lock() == out_data_anchor) {
break;
@@ -368,7 +368,7 @@ TEST_F(UtestGeAnchor, graph_utils_insert_node) {

GraphUtils::InsertNodeBetweenDataAnchors(out_data_anchor, in_data_anchor, node3);

int out_idx1 = 0;
size_t out_idx1 = 0;
for (; out_idx1 < out_data_anchor->peer_anchors_.size(); out_idx1++) {
if (out_data_anchor->peer_anchors_[out_idx1].lock() == node3->GetInDataAnchor(0)) {
break;
@@ -376,7 +376,7 @@ TEST_F(UtestGeAnchor, graph_utils_insert_node) {
}
EXPECT_EQ(out_idx1, out_idx);

int in_idx1 = 0;
size_t in_idx1 = 0;
for (; in_idx1 < in_data_anchor->peer_anchors_.size(); in_idx1++) {
if (in_data_anchor->peer_anchors_[in_idx1].lock() == node3->GetOutDataAnchor(0)) {
break;


+ 5
- 2
tests/ut/common/graph/testcase/ge_graph/ge_model_serialize_unittest.cc View File

@@ -59,7 +59,7 @@ NodePtr CreateNode(OpDescPtr op, ComputeGraphPtr owner_graph) { return owner_gra
void CompareShape(const vector<int64_t> &shape1, const vector<int64_t> &shape2) {
EXPECT_EQ(shape1.size(), shape2.size());
if (shape1.size() == shape2.size()) {
for (int i = 0; i < shape1.size(); i++) {
for (size_t i = 0; i < shape1.size(); i++) {
EXPECT_EQ(shape1[i], shape2[i]);
}
}
@@ -69,7 +69,7 @@ template <typename T>
void CompareList(const vector<T> &val1, const vector<T> &val2) {
EXPECT_EQ(val1.size(), val2.size());
if (val1.size() == val2.size()) {
for (int i = 0; i < val1.size(); i++) {
for (size_t i = 0; i < val1.size(); i++) {
EXPECT_EQ(val1[i], val2[i]);
}
}
@@ -129,6 +129,9 @@ static bool NamedAttrsSimpleCmp(const GeAttrValue &left, const GeAttrValue &righ
return false;
}
}
default: {
return true;
}
}
}
return true;


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

@@ -625,7 +625,7 @@ set(DISTINCT_GRAPH_LOAD_TEST_FILES
"graph/load/data_dumper_unittest.cc"
#"graph/load/new_model_manager_data_inputer_unittest.cc"
#"graph/load/new_model_manager_davinci_model_unittest.cc"
"graph/load/new_model_manager_model_manager_unittest.cc"
"graph/load/model_manager_unittest.cc"
#"graph/load/new_model_manager_task_build_unittest.cc"
"graph/load/new_model_manager_model_manager_aicpu_unittest.cc"
"graph/load/end_graph_task_unittest.cc"


+ 63
- 62
tests/ut/ge/graph/load/davinci_model_unittest.cc View File

@@ -38,7 +38,6 @@ int32_t MsprofReport(uint32_t moduleId, uint32_t type, void *data, uint32_t len)
return 0;
}

/*
TEST_F(UtestDavinciModel, init_success) {
DavinciModel model(0, nullptr);
ComputeGraphPtr graph = make_shared<ComputeGraph>("default");
@@ -46,7 +45,7 @@ TEST_F(UtestDavinciModel, init_success) {

GeModelPtr ge_model = make_shared<GeModel>();
ge_model->SetGraph(GraphUtils::CreateGraphFromComputeGraph(graph));
AttrUtils::SetInt(ge_model, ATTR_MODEL_MEMORY_SIZE, 5120000);
AttrUtils::SetInt(ge_model, ATTR_MODEL_MEMORY_SIZE, 10240);
AttrUtils::SetInt(ge_model, ATTR_MODEL_STREAM_NUM, 1);

shared_ptr<domi::ModelTaskDef> model_task_def = make_shared<domi::ModelTaskDef>();
@@ -54,60 +53,66 @@ TEST_F(UtestDavinciModel, init_success) {

GeTensorDesc tensor(GeShape(), FORMAT_NCHW, DT_FLOAT);
TensorUtils::SetSize(tensor, 512);
{
OpDescPtr op_desc = CreateOpDesc("data", DATA);
op_desc->AddInputDesc(tensor);
op_desc->AddOutputDesc(tensor);
op_desc->SetInputOffset({1024});
op_desc->SetOutputOffset({1024});
NodePtr node = graph->AddNode(op_desc); // op_index = 0
}

OpDescPtr op_input = CreateOpDesc("data", DATA);
op_input->AddInputDesc(tensor);
op_input->AddOutputDesc(tensor);
op_input->SetInputOffset({1024});
op_input->SetOutputOffset({1024});
NodePtr node_input = graph->AddNode(op_input); // op_index = 0

OpDescPtr op_kernel = CreateOpDesc("square", "Square");
op_kernel->AddInputDesc(tensor);
op_kernel->AddOutputDesc(tensor);
op_kernel->SetInputOffset({1024});
op_kernel->SetOutputOffset({1024});
NodePtr node_kernel = graph->AddNode(op_kernel); // op_index = 1

OpDescPtr op_memcpy = CreateOpDesc("memcpy", MEMCPYASYNC);
op_memcpy->AddInputDesc(tensor);
op_memcpy->AddOutputDesc(tensor);
op_memcpy->SetInputOffset({1024});
op_memcpy->SetOutputOffset({5120});
NodePtr node_memcpy = graph->AddNode(op_memcpy); // op_index = 2

OpDescPtr op_output = CreateOpDesc("output", NETOUTPUT);
op_output->AddInputDesc(tensor);
op_output->SetInputOffset({5120});
op_output->SetSrcName( { "memcpy" } );
op_output->SetSrcIndex( { 0 } );
NodePtr node_output = graph->AddNode(op_output); // op_index = 3
{
OpDescPtr op_desc = CreateOpDesc("square", "Square");
op_desc->AddInputDesc(tensor);
op_desc->AddOutputDesc(tensor);
op_desc->SetInputOffset({1024});
op_desc->SetOutputOffset({1024});
NodePtr node = graph->AddNode(op_desc); // op_index = 1

domi::TaskDef *task_def = model_task_def->add_task();
task_def->set_stream_id(0);
task_def->set_type(RT_MODEL_TASK_KERNEL);
domi::KernelDef *kernel_def = task_def->mutable_kernel();
kernel_def->set_stub_func("stub_func");
kernel_def->set_args_size(64);
string args(64, '1');
kernel_def->set_args(args.data(), 64);
domi::KernelContext *context = kernel_def->mutable_context();
context->set_op_index(op_desc->GetId());
context->set_kernel_type(2); // ccKernelType::TE
uint16_t args_offset[9] = {0};
context->set_args_offset(args_offset, 9 * sizeof(uint16_t));
}

domi::TaskDef *task_def1 = model_task_def->add_task();
task_def1->set_stream_id(0);
task_def1->set_type(RT_MODEL_TASK_KERNEL);
domi::KernelDef *kernel_def = task_def1->mutable_kernel();
kernel_def->set_stub_func("stub_func");
kernel_def->set_args_size(64);
string args(64, '1');
kernel_def->set_args(args.data(), 64);
domi::KernelContext *context = kernel_def->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("memcpy", MEMCPYASYNC);
op_desc->AddInputDesc(tensor);
op_desc->AddOutputDesc(tensor);
op_desc->SetInputOffset({1024});
op_desc->SetOutputOffset({5120});
NodePtr node = graph->AddNode(op_desc); // op_index = 2

domi::TaskDef *task_def = model_task_def->add_task();
task_def->set_stream_id(0);
task_def->set_type(RT_MODEL_TASK_MEMCPY_ASYNC);
domi::MemcpyAsyncDef *memcpy_async = task_def->mutable_memcpy_async();
memcpy_async->set_src(1024);
memcpy_async->set_dst(5120);
memcpy_async->set_dst_max(512);
memcpy_async->set_count(1);
memcpy_async->set_kind(RT_MEMCPY_DEVICE_TO_DEVICE);
memcpy_async->set_op_index(op_desc->GetId());
}

domi::TaskDef *task_def2 = model_task_def->add_task();
task_def2->set_stream_id(0);
task_def2->set_type(RT_MODEL_TASK_MEMCPY_ASYNC);
domi::MemcpyAsyncDef *memcpy_async = task_def2->mutable_memcpy_async();
memcpy_async->set_src(1024);
memcpy_async->set_dst(5120);
memcpy_async->set_dst_max(512);
memcpy_async->set_count(1);
memcpy_async->set_kind(RT_MEMCPY_DEVICE_TO_DEVICE);
memcpy_async->set_op_index(2);
{
OpDescPtr op_desc = CreateOpDesc("output", NETOUTPUT);
op_desc->AddInputDesc(tensor);
op_desc->SetInputOffset({5120});
op_desc->SetSrcName( { "memcpy" } );
op_desc->SetSrcIndex( { 0 } );
NodePtr node = graph->AddNode(op_desc); // op_index = 3
}

EXPECT_EQ(model.Assign(ge_model), SUCCESS);
EXPECT_EQ(model.Init(), SUCCESS);
@@ -124,7 +129,6 @@ TEST_F(UtestDavinciModel, init_success) {

ProfilingManager::Instance().is_load_profiling_ = false;
}
*/

TEST_F(UtestDavinciModel, init_data_op) {
DavinciModel model(0, nullptr);
@@ -752,7 +756,6 @@ TEST_F(UtestDavinciModel, init_data_aipp_input_dims_normal) {
EXPECT_EQ(model.op_list_.size(), 1);
}

/*
// test label_set_task Init
TEST_F(UtestDavinciModel, label_task_success) {
DavinciModel model(0, nullptr);
@@ -760,7 +763,7 @@ TEST_F(UtestDavinciModel, label_task_success) {

GeModelPtr ge_model = make_shared<GeModel>();
ge_model->SetGraph(GraphUtils::CreateGraphFromComputeGraph(graph));
AttrUtils::SetInt(ge_model, ATTR_MODEL_MEMORY_SIZE, 5120000);
AttrUtils::SetInt(ge_model, ATTR_MODEL_MEMORY_SIZE, 10240);
AttrUtils::SetInt(ge_model, ATTR_MODEL_STREAM_NUM, 1);

shared_ptr<domi::ModelTaskDef> model_task_def = make_shared<domi::ModelTaskDef>();
@@ -769,7 +772,6 @@ TEST_F(UtestDavinciModel, label_task_success) {
GeTensorDesc tensor(GeShape(), FORMAT_ND, DT_INT32);
TensorUtils::SetSize(tensor, 64);

uint32_t op_index = 0;
{
OpDescPtr op_desc = CreateOpDesc("label_switch", LABELSWITCHBYINDEX);
op_desc->AddInputDesc(tensor);
@@ -781,7 +783,7 @@ TEST_F(UtestDavinciModel, label_task_success) {
task_def1->set_stream_id(0);
task_def1->set_type(RT_MODEL_TASK_STREAM_LABEL_SWITCH_BY_INDEX);
domi::LabelSwitchByIndexDef *label_task_def = task_def1->mutable_label_switch_by_index();
label_task_def->set_op_index(op_index++);
label_task_def->set_op_index(op_desc->GetId());
label_task_def->set_label_max(2);
}

@@ -794,7 +796,7 @@ TEST_F(UtestDavinciModel, label_task_success) {
task_def1->set_stream_id(0);
task_def1->set_type(RT_MODEL_TASK_LABEL_SET);
domi::LabelSetDef *label_task_def = task_def1->mutable_label_set();
label_task_def->set_op_index(op_index++);
label_task_def->set_op_index(op_desc->GetId());
}

{
@@ -806,7 +808,7 @@ TEST_F(UtestDavinciModel, label_task_success) {
task_def2->set_stream_id(0);
task_def2->set_type(RT_MODEL_TASK_STREAM_LABEL_GOTO);
domi::LabelGotoExDef *label_task_def = task_def2->mutable_label_goto_ex();
label_task_def->set_op_index(op_index++);
label_task_def->set_op_index(op_desc->GetId());
}

{
@@ -818,7 +820,7 @@ TEST_F(UtestDavinciModel, label_task_success) {
task_def1->set_stream_id(0);
task_def1->set_type(RT_MODEL_TASK_LABEL_SET);
domi::LabelSetDef *label_task_def = task_def1->mutable_label_set();
label_task_def->set_op_index(op_index++);
label_task_def->set_op_index(op_desc->GetId());
}

{
@@ -830,7 +832,7 @@ TEST_F(UtestDavinciModel, label_task_success) {
task_def1->set_stream_id(0);
task_def1->set_type(RT_MODEL_TASK_LABEL_SET);
domi::LabelSetDef *label_task_def = task_def1->mutable_label_set();
label_task_def->set_op_index(op_index++);
label_task_def->set_op_index(op_desc->GetId());
}

EXPECT_TRUE(AttrUtils::SetInt(ge_model, ATTR_MODEL_LABEL_NUM, 3));
@@ -840,7 +842,6 @@ TEST_F(UtestDavinciModel, label_task_success) {
EXPECT_EQ(model.output_addrs_list_.size(), 0);
EXPECT_EQ(model.task_list_.size(), 5);
}
*/

TEST_F(UtestDavinciModel, LoadWithQueue_fail_with_diff_args) {
DavinciModel model(0, nullptr);


tests/ut/ge/graph/load/new_model_manager_model_manager_unittest.cc → tests/ut/ge/graph/load/model_manager_unittest.cc View File

@@ -15,20 +15,17 @@
*/

#include <gtest/gtest.h>
#include <map>
#include "common/debug/log.h"
#include "common/types.h"
#include "graph/utils/graph_utils.h"

#define private public
#define protected public
#include "graph/load/model_manager/model_manager.h"
#include "common/helper/om_file_helper.h"
#include "graph/utils/graph_utils.h"
#include "graph/debug/ge_attr_define.h"
#include "common/op/ge_op_utils.h"
#include "graph/load/graph_loader.h"
#include "graph/load/model_manager/davinci_model.h"
#include "graph/load/model_manager/davinci_model_parser.h"
#undef private
#undef protected

using namespace std;
using namespace testing;
@@ -39,20 +36,20 @@ const static std::string ENC_KEY = "0123456789abcdef0123456789abcdef0123456789ab

class UtestModelManagerModelManager : public testing::Test {
protected:
static Status LoadStub(const uint8_t *data, size_t len, ge::Model &model) {
static Status LoadStub(const uint8_t *data, size_t len, Model &model) {
InitModelDefault(model);
return ge::SUCCESS;
return SUCCESS;
}

static void InitModelDefault(ge::Model &model) {
ge::AttrUtils::SetInt(&model, ge::ATTR_MODEL_MEMORY_SIZE, 0);
ge::AttrUtils::SetInt(&model, ge::ATTR_MODEL_WEIGHT_SIZE, 0);
ge::AttrUtils::SetInt(&model, ge::ATTR_MODEL_STREAM_NUM, 0);
ge::AttrUtils::SetInt(&model, ge::ATTR_MODEL_EVENT_NUM, 0);
ge::AttrUtils::SetStr(&model, ge::ATTR_MODEL_TARGET_TYPE, "MINI"); // domi::MINI
static void InitModelDefault(Model &model) {
AttrUtils::SetInt(&model, ATTR_MODEL_MEMORY_SIZE, 0);
AttrUtils::SetInt(&model, ATTR_MODEL_WEIGHT_SIZE, 0);
AttrUtils::SetInt(&model, ATTR_MODEL_STREAM_NUM, 0);
AttrUtils::SetInt(&model, ATTR_MODEL_EVENT_NUM, 0);
AttrUtils::SetStr(&model, ATTR_MODEL_TARGET_TYPE, "MINI"); // domi::MINI

auto computeGraph = std::make_shared<ge::ComputeGraph>("graph");
auto graph = ge::GraphUtils::CreateGraphFromComputeGraph(computeGraph);
auto computeGraph = std::make_shared<ComputeGraph>("graph");
auto graph = GraphUtils::CreateGraphFromComputeGraph(computeGraph);
model.SetGraph(graph);
}

@@ -60,9 +57,8 @@ class UtestModelManagerModelManager : public testing::Test {

void TearDown() {}

void GenUnencryptModelData(ge::ModelData &data) {
void GenUnencryptModelData(ModelData &data) {
const int model_len = 10;
data.key;
data.model_len = sizeof(ModelFileHeader) + model_len;
data.model_data = new uint8_t[data.model_len];
memset((uint8_t *)data.model_data + sizeof(ModelFileHeader), 10, model_len);
@@ -75,7 +71,7 @@ class UtestModelManagerModelManager : public testing::Test {
header->is_checksum = ModelCheckType::CHECK;
}

void GenEncryptModelData(ge::ModelData &data) {
void GenEncryptModelData(ModelData &data) {
const int model_len = 10;
data.key = ENC_KEY;
data.model_data = new uint8_t[data.model_len];
@@ -88,10 +84,10 @@ class UtestModelManagerModelManager : public testing::Test {
header->length = 10; // encrypt_len;
}

void LoadStandardModelData(ge::ModelData &data) {
void LoadStandardModelData(ModelData &data) {
static const std::string STANDARD_MODEL_DATA_PATH =
"llt/framework/domi/ut/ome/test/data/standard_partition_model.txt";
ge::proto::ModelDef model_def;
proto::ModelDef model_def;
ReadProtoFromText(STANDARD_MODEL_DATA_PATH.c_str(), &model_def);

data.model_len = model_def.ByteSizeLong();
@@ -100,79 +96,79 @@ class UtestModelManagerModelManager : public testing::Test {
}
};

class DModelListener : public ge::ModelListener {
class DModelListener : public ModelListener {
public:
DModelListener(){};
uint32_t OnComputeDone(uint32_t model_id, uint32_t data_index, uint32_t resultCode) { return 0; }
};


/*TEST_F(UtestModelManagerModelManager, case_load_incorrect_param) {
TEST_F(UtestModelManagerModelManager, case_load_incorrect_param) {
ModelManager mm;
uint32_t model_id = 0;
ge::ModelData model;
EXPECT_EQ(ge::FAILED, mm.LoadModelOffline(model_id, model, nullptr, nullptr));
ge::ModelData data;
ModelData data;
// Load allow listener is null
EXPECT_EQ(ge::FAILED, mm.LoadModelOffline(model_id, data, nullptr, nullptr));
EXPECT_EQ(mm.LoadModelOffline(model_id, data, nullptr, nullptr), ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID);
}

TEST_F(UtestModelManagerModelManager, case_load_model_len_too_short) {
ModelManager mm;
ge::ModelData data;
ModelData data;
data.model_len = 10;
data.model_data = (void *)&data;
uint32_t model_id = 1;
EXPECT_EQ(ge::FAILED, mm.LoadModelOffline(model_id, data, UTEST_CALL_BACK_FUN, nullptr));
EXPECT_EQ(mm.LoadModelOffline(model_id, data, nullptr, nullptr), ACL_ERROR_GE_PARAM_INVALID);
data.model_data = nullptr;
}

TEST_F(UtestModelManagerModelManager, case_load_model_len_not_match) {
ModelManager mm;
ge::ModelData data;
ModelData data;
GenUnencryptModelData(data);
data.model_len = sizeof(ModelFileHeader) + 1;
uint32_t model_id = 1;
EXPECT_EQ(ge::FAILED, mm.LoadModelOffline(model_id, data, UTEST_CALL_BACK_FUN, nullptr));
EXPECT_EQ(mm.LoadModelOffline(model_id, data, nullptr, nullptr), ACL_ERROR_GE_PARAM_INVALID);
delete[](uint8_t *) data.model_data;
}

TEST_F(UtestModelManagerModelManager, case_load_model_encypt_not_match) {
ModelManager mm;
ge::ModelData data;
ModelData data;
GenUnencryptModelData(data);
data.key = ENC_KEY;
uint32_t model_id = 1;
EXPECT_EQ(ge::PARAM_INVALID, mm.LoadModelOffline(model_id, data, UTEST_CALL_BACK_FUN, nullptr));
EXPECT_EQ(mm.LoadModelOffline(model_id, data, nullptr, nullptr), ACL_ERROR_GE_PARAM_INVALID);
delete[](uint8_t *) data.model_data;
}

TEST_F(UtestModelManagerModelManager, case_load_model_encypt_type_unsupported) {
ModelManager mm;
ge::ModelData data;
ModelData data;
GenUnencryptModelData(data);
ModelFileHeader *header = (ModelFileHeader *)data.model_data;
header->is_encrypt = 255;
uint32_t model_id = 1;
EXPECT_EQ(ge::FAILED, mm.LoadModelOffline(model_id, data, UTEST_CALL_BACK_FUN, nullptr));
EXPECT_EQ(mm.LoadModelOffline(model_id, data, nullptr, nullptr), ACL_ERROR_GE_PARAM_INVALID);
delete[](uint8_t *) data.model_data;
}
/*
shared_ptr<ModelListener> LabelCallBack(new DModelListener());

// test HandleCommand
TEST_F(UtestModelManagerModelManager, command_success1) {
ModelManager manager;
ge::Command cmd;
Command cmd;

cmd.cmd_type = "INFERENCE";
EXPECT_EQ(ge::PARAM_INVALID, manager.HandleCommand(cmd));
EXPECT_EQ(PARAM_INVALID, manager.HandleCommand(cmd));

cmd.cmd_type = "NOT SUPPORT";
EXPECT_EQ(ge::PARAM_INVALID, manager.HandleCommand(cmd));
EXPECT_EQ(PARAM_INVALID, manager.HandleCommand(cmd));
}

TEST_F(UtestModelManagerModelManager, command_success2) {
ModelManager manager;
ge::Command cmd;
Command cmd;

cmd.cmd_type = "dump";
cmd.cmd_params.push_back("status");
@@ -184,101 +180,101 @@ TEST_F(UtestModelManagerModelManager, command_success2) {
cmd.cmd_params.push_back("layer");
cmd.cmd_params.push_back("layer1");

EXPECT_EQ(ge::SUCCESS, manager.HandleCommand(cmd));
EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
}

// test profile
TEST_F(UtestModelManagerModelManager, command_profile_success) {
ModelManager manager;
ge::Command cmd;
Command cmd;
cmd.cmd_type = "profile";

cmd.cmd_params.push_back("ome");
cmd.cmd_params.push_back("on");
EXPECT_EQ(ge::SUCCESS, manager.HandleCommand(cmd));
EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
bool ome_profile_on = PropertiesManager::Instance().GetPropertyValue(OME_PROFILE) == "1";
EXPECT_EQ(true, ome_profile_on);

cmd.cmd_params.clear();
cmd.cmd_params.push_back("ome");
cmd.cmd_params.push_back("off");
EXPECT_EQ(ge::SUCCESS, manager.HandleCommand(cmd));
EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
ome_profile_on = PropertiesManager::Instance().GetPropertyValue(OME_PROFILE) == "1";
EXPECT_FALSE(ome_profile_on);

cmd.cmd_params.clear();
cmd.cmd_params.push_back("cce");
cmd.cmd_params.push_back("on");
EXPECT_EQ(ge::SUCCESS, manager.HandleCommand(cmd));
EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
bool cce_profile_on = PropertiesManager::Instance().GetPropertyValue(CCE_PROFILE) == "1";
EXPECT_EQ(true, cce_profile_on);

cmd.cmd_params.clear();
cmd.cmd_params.push_back("cce");
cmd.cmd_params.push_back("off");
EXPECT_EQ(ge::SUCCESS, manager.HandleCommand(cmd));
EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
cce_profile_on = PropertiesManager::Instance().GetPropertyValue(CCE_PROFILE) == "1";
EXPECT_FALSE(cce_profile_on);

cmd.cmd_params.clear();
cmd.cmd_params.push_back("runtime");
cmd.cmd_params.push_back("on");
EXPECT_EQ(ge::SUCCESS, manager.HandleCommand(cmd));
EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
bool rts_profile_on = PropertiesManager::Instance().GetPropertyValue(RTS_PROFILE) == "1";
EXPECT_EQ(true, rts_profile_on);

cmd.cmd_params.clear();
cmd.cmd_params.push_back("runtime");
cmd.cmd_params.push_back("off");
EXPECT_EQ(ge::SUCCESS, manager.HandleCommand(cmd));
EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
rts_profile_on = PropertiesManager::Instance().GetPropertyValue(RTS_PROFILE) == "1";
EXPECT_FALSE(rts_profile_on);

cmd.cmd_params.clear();
cmd.cmd_params.push_back("profiler_jobctx");
cmd.cmd_params.push_back("jobctx");
EXPECT_EQ(ge::SUCCESS, manager.HandleCommand(cmd));
EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
EXPECT_EQ("jobctx", PropertiesManager::Instance().GetPropertyValue(PROFILER_JOBCTX));

cmd.cmd_params.clear();
cmd.cmd_params.push_back("profiler_target_path");
cmd.cmd_params.push_back("/test/target");
EXPECT_EQ(ge::SUCCESS, manager.HandleCommand(cmd));
EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
EXPECT_EQ("/test/target", PropertiesManager::Instance().GetPropertyValue(PROFILER_TARGET_PATH));

cmd.cmd_params.clear();
cmd.cmd_params.push_back("RTS_PATH");
cmd.cmd_params.push_back("/test/rts_path");
EXPECT_EQ(ge::SUCCESS, manager.HandleCommand(cmd));
EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
EXPECT_EQ("/test/rts_path", PropertiesManager::Instance().GetPropertyValue(RTS_PROFILE_PATH));
}

// test acl profiling
TEST_F(UtestModelManagerModelManager, command_profiling) {
ModelManager manager;
ge::Command cmd;
Command cmd;
cmd.cmd_type = "profiling";

cmd.cmd_params.push_back("config");
cmd.cmd_params.push_back("on");
EXPECT_EQ(ge::SUCCESS, manager.HandleCommand(cmd));
EXPECT_EQ(SUCCESS, manager.HandleCommand(cmd));
}

TEST_F(UtestModelManagerModelManager, command_profile_failed) {
ModelManager manager;
ge::Command cmd;
Command cmd;
cmd.cmd_type = "profile";

cmd.cmd_params.push_back("ome");

EXPECT_EQ(ge::PARAM_INVALID, manager.HandleCommand(cmd));
EXPECT_EQ(PARAM_INVALID, manager.HandleCommand(cmd));
}

// test Start
TEST_F(UtestModelManagerModelManager, start_fail) {
ModelManager manager;
manager.model_map_[2] = nullptr;
EXPECT_EQ(ge::PARAM_INVALID, manager.Start(2));
EXPECT_EQ(PARAM_INVALID, manager.Start(2));
}

// test GetMaxUsedMemory
@@ -286,7 +282,7 @@ TEST_F(UtestModelManagerModelManager, get_max_used_memory_fail) {
ModelManager manager;
uint64_t max_size = 0;
manager.model_map_[2] = nullptr;
EXPECT_EQ(ge::PARAM_INVALID, manager.GetMaxUsedMemory(2, max_size));
EXPECT_EQ(PARAM_INVALID, manager.GetMaxUsedMemory(2, max_size));
}

// test GetInputOutputDescInfo
@@ -295,7 +291,7 @@ TEST_F(UtestModelManagerModelManager, get_input_output_desc_info_fail) {
manager.model_map_[2] = nullptr;
vector<InputOutputDescInfo> input_shape;
vector<InputOutputDescInfo> output_shape;
EXPECT_EQ(ge::PARAM_INVALID, manager.GetInputOutputDescInfo(2, input_shape, output_shape));
EXPECT_EQ(PARAM_INVALID, manager.GetInputOutputDescInfo(2, input_shape, output_shape));
}


@@ -306,7 +302,7 @@ TEST_F(UtestModelManagerModelManager, get_input_output_desc_info_zero_copy_fail)
manager.model_map_[2] = nullptr;
vector<InputOutputDescInfo> input_shape;
vector<InputOutputDescInfo> output_shape;
EXPECT_EQ(ge::PARAM_INVALID, manager.GetInputOutputDescInfoForZeroCopy(2, input_shape, output_shape));
EXPECT_EQ(PARAM_INVALID, manager.GetInputOutputDescInfoForZeroCopy(2, input_shape, output_shape));
}
*//*

@@ -314,7 +310,7 @@ TEST_F(UtestModelManagerModelManager, get_input_output_desc_info_zero_copy_fail)
TEST_F(UtestModelManagerModelManager, stop_fail) {
ModelManager manager;
manager.model_map_[2] = nullptr;
EXPECT_EQ(ge::PARAM_INVALID, manager.Stop(2));
EXPECT_EQ(PARAM_INVALID, manager.Stop(2));
}

// build input_data
@@ -322,8 +318,8 @@ TEST_F(UtestModelManagerModelManager, check_data_len_success) {
shared_ptr<ModelListener> g_label_call_back(new DModelListener());
DavinciModel model(0, g_label_call_back);
ModelManager model_manager;
ge::InputData input_data;
ge::DataBuffer data_buffer;
InputData input_data;
DataBuffer data_buffer;
data_buffer.data = new char[51200];
data_buffer.length = 51200;
input_data.index = 0;
@@ -353,6 +349,6 @@ TEST_F(UtestModelManagerModelManager, test_data_input_tensor) {
vector<InputTensorInfo> inputs;
inputs.emplace_back(input_tensor);
auto ret = mm.DataInputTensor(model_id,inputs);
EXPECT_EQ(ge::UNSUPPORTED, ret);
EXPECT_EQ(UNSUPPORTED, ret);
}
} // namespace ge

Loading…
Cancel
Save