Delete repeated rtSetDevice

pull/1116/head
zhangxiaokun 4 years ago
parent 09977bb41f
commit aaf496e02a

@ -270,18 +270,6 @@ ModelManager::~ModelManager() {
GE_IF_BOOL_EXEC(device_count > 0, GE_CHK_RT(rtDeviceReset(0))); 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, ge::Status ModelManager::SetDynamicSize(uint32_t model_id, const std::vector<uint64_t> &batch_num,
int32_t dynamic_type) { int32_t dynamic_type) {
std::shared_ptr<DavinciModel> davinci_model = GetModel(model_id); 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); 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(); mmTimespec timespec = mmGetTickCount();
std::shared_ptr<DavinciModel> davinci_model = MakeShared<DavinciModel>(0, listener); std::shared_ptr<DavinciModel> davinci_model = MakeShared<DavinciModel>(0, listener);
if (davinci_model == nullptr) { 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); GELOGI("Parse model %u success.", model_id);
} while (0); } while (0);
GE_CHK_RT(rtDeviceReset(static_cast<int32_t>(GetContext().DeviceId())));
return ret; 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)); ACL_ERROR_GE_PARAM_INVALID, "input key file path %s is invalid, %s", model.key.c_str(), strerror(errno));
GenModelId(&model_id); GenModelId(&model_id);
shared_ptr<DavinciModel> davinci_model = nullptr;
mmTimespec timespec = mmGetTickCount(); mmTimespec timespec = mmGetTickCount();
ModelHelper model_helper; ModelHelper model_helper;
Status ret = model_helper.LoadRootModel(model); Status ret = model_helper.LoadRootModel(model);
if (ret != SUCCESS) {
GELOGE(ret, "load model failed.");
return ret;
}
if (model_helper.GetModelType()) { if (model_helper.GetModelType()) {
bool is_shape_unknown = false; bool is_shape_unknown = false;
GE_CHK_STATUS_RET(model_helper.GetGeRootModel()->CheckIsUnknownShape(is_shape_unknown), 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); return DoLoadHybridModelOnline(model_id, model_helper.GetGeRootModel(), listener);
} }
} }
if (ret != SUCCESS) {
GELOGE(ret, "load model failed.");
return ret;
}
do { do {
GeModelPtr ge_model = model_helper.GetGeModel(); GeModelPtr ge_model = model_helper.GetGeModel();
try { shared_ptr<DavinciModel> davinci_model = MakeShared<DavinciModel>(model.priority, listener);
davinci_model = std::make_shared<DavinciModel>(model.priority, listener); if (davinci_model == nullptr) {
} catch (std::bad_alloc &) {
GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Make shared failed"); GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Make shared failed");
return ACL_ERROR_GE_MEMORY_ALLOCATION; 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 + davinci_model->SetProfileTime(MODEL_LOAD_START, (timespec.tv_sec * kTimeSpecNano +
timespec.tv_nsec)); // 1000 ^ 3 converts second to nanosecond 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); InsertModel(model_id, davinci_model);
GELOGI("Parse model %u success.", model_id); GELOGI("Parse model %u success.", model_id);
GE_IF_BOOL_EXEC(ret == SUCCESS, device_count++); GE_IF_BOOL_EXEC(ret == SUCCESS, device_count++);
return SUCCESS;
} while (0); } while (0);
return ret; return ret;

@ -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 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); ge::Status SetDynamicSize(uint32_t model_id, const std::vector<uint64_t> &batch_num, int32_t dynamic_type);
/// ///

@ -2622,14 +2622,9 @@ Status GraphManager::IncreBuild(const GraphNodePtr &graph_node, GeModelPtr &ge_m
return FAILED; return FAILED;
} }
void GraphManager::ConstructGeInput(std::vector<ge::GeTensor> &ge_inputs, PreRunArgs &args) { void GraphManager::ConstructGeInput(const vector<InputTensorInfo> &inputs, vector<GeTensor> &ge_inputs) {
for (auto const &input : args.input_tensor) { for (auto const &input : inputs) {
std::vector<int64_t> input_dims; GeTensorDesc input_tensor_desc(GeShape(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);
input_tensor_desc.SetDataType(static_cast<ge::DataType>(input.data_type)); input_tensor_desc.SetDataType(static_cast<ge::DataType>(input.data_type));
ge_inputs.emplace_back(input_tensor_desc); ge_inputs.emplace_back(input_tensor_desc);
} }
@ -2653,9 +2648,6 @@ void GraphManager::PreRunThread(GraphManager *graph_manager) {
GetThreadLocalContext() = args.context; GetThreadLocalContext() = args.context;
graph_manager->UpdateLocalOmgContext(args.graph_id); graph_manager->UpdateLocalOmgContext(args.graph_id);
std::vector<ge::GeTensor> ge_inputs;
ConstructGeInput(ge_inputs, args);
// find graph // find graph
GraphNodePtr graph_node = nullptr; GraphNodePtr graph_node = nullptr;
Status ret = graph_manager->GetGraphNode(args.graph_id, graph_node); Status ret = graph_manager->GetGraphNode(args.graph_id, graph_node);
@ -2709,6 +2701,8 @@ void GraphManager::PreRunThread(GraphManager *graph_manager) {
// check need incre build. // check need incre build.
GeModelPtr ge_model = nullptr; GeModelPtr ge_model = nullptr;
if (graph_manager->IncreBuild(graph_node, ge_model) != SUCCESS) { 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); ret = graph_manager->PreRun(graph_node, ge_inputs, ge_root_model, args.session_id);
// release rts generate context // release rts generate context
RtContextUtil::GetInstance().DestroyRtContexts(args.session_id, graph_node->GetGraphId()); RtContextUtil::GetInstance().DestroyRtContexts(args.session_id, graph_node->GetGraphId());

@ -336,7 +336,7 @@ class GraphManager {
void RemoveModelCacheHelper(const GraphId &graph_id); void RemoveModelCacheHelper(const GraphId &graph_id);
ModelCacheHelperPtr FindModelCacheHelper(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 PreRunThread(GraphManager *graph_manager);
static void RunThread(GraphManager *graph_manager); static void RunThread(GraphManager *graph_manager);
static void StopQueue(GraphManager *graph_manager); static void StopQueue(GraphManager *graph_manager);

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

@ -30,7 +30,7 @@
using namespace ge; using namespace ge;
using namespace std; using namespace std;
class UtestGeAnchor : public testing::Test { class UtestGeAnchor : public testing::Test {
protected: protected:
void SetUp() {} 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(1)), GRAPH_SUCCESS);
EXPECT_EQ(node1->GetOutDataAnchor(1)->LinkTo(node2->GetInDataAnchor(2)), 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++) { for (; out_idx < out_data_anchor->peer_anchors_.size(); out_idx++) {
if (out_data_anchor->peer_anchors_[out_idx].lock() == in_data_anchor) { if (out_data_anchor->peer_anchors_[out_idx].lock() == in_data_anchor) {
break; break;
@ -302,7 +302,7 @@ TEST_F(UtestGeAnchor, data_anchor_replace_peer) {
} }
EXPECT_EQ(out_idx, 1); 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++) { for (; in_idx < in_data_anchor->peer_anchors_.size(); in_idx++) {
if (in_data_anchor->peer_anchors_[in_idx].lock() == out_data_anchor) { if (in_data_anchor->peer_anchors_[in_idx].lock() == out_data_anchor) {
break; 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)); 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++) { for (; out_idx1 < out_data_anchor->peer_anchors_.size(); out_idx1++) {
if (out_data_anchor->peer_anchors_[out_idx1].lock() == node3->GetInDataAnchor(1)) { if (out_data_anchor->peer_anchors_[out_idx1].lock() == node3->GetInDataAnchor(1)) {
break; break;
@ -320,7 +320,7 @@ TEST_F(UtestGeAnchor, data_anchor_replace_peer) {
} }
EXPECT_EQ(out_idx1, out_idx); 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++) { for (; in_idx1 < in_data_anchor->peer_anchors_.size(); in_idx1++) {
if (in_data_anchor->peer_anchors_[in_idx1].lock() == node3->GetOutDataAnchor(1)) { if (in_data_anchor->peer_anchors_[in_idx1].lock() == node3->GetOutDataAnchor(1)) {
break; 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(1)), GRAPH_SUCCESS);
EXPECT_EQ(node1->GetOutDataAnchor(1)->LinkTo(node2->GetInDataAnchor(2)), 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++) { for (; out_idx < out_data_anchor->peer_anchors_.size(); out_idx++) {
if (out_data_anchor->peer_anchors_[out_idx].lock() == in_data_anchor) { if (out_data_anchor->peer_anchors_[out_idx].lock() == in_data_anchor) {
break; break;
@ -358,7 +358,7 @@ TEST_F(UtestGeAnchor, graph_utils_insert_node) {
} }
EXPECT_EQ(out_idx, 1); 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++) { for (; in_idx < in_data_anchor->peer_anchors_.size(); in_idx++) {
if (in_data_anchor->peer_anchors_[in_idx].lock() == out_data_anchor) { if (in_data_anchor->peer_anchors_[in_idx].lock() == out_data_anchor) {
break; break;
@ -368,7 +368,7 @@ TEST_F(UtestGeAnchor, graph_utils_insert_node) {
GraphUtils::InsertNodeBetweenDataAnchors(out_data_anchor, in_data_anchor, node3); 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++) { for (; out_idx1 < out_data_anchor->peer_anchors_.size(); out_idx1++) {
if (out_data_anchor->peer_anchors_[out_idx1].lock() == node3->GetInDataAnchor(0)) { if (out_data_anchor->peer_anchors_[out_idx1].lock() == node3->GetInDataAnchor(0)) {
break; break;
@ -376,7 +376,7 @@ TEST_F(UtestGeAnchor, graph_utils_insert_node) {
} }
EXPECT_EQ(out_idx1, out_idx); 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++) { for (; in_idx1 < in_data_anchor->peer_anchors_.size(); in_idx1++) {
if (in_data_anchor->peer_anchors_[in_idx1].lock() == node3->GetOutDataAnchor(0)) { if (in_data_anchor->peer_anchors_[in_idx1].lock() == node3->GetOutDataAnchor(0)) {
break; break;

@ -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) { void CompareShape(const vector<int64_t> &shape1, const vector<int64_t> &shape2) {
EXPECT_EQ(shape1.size(), shape2.size()); EXPECT_EQ(shape1.size(), shape2.size());
if (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]); EXPECT_EQ(shape1[i], shape2[i]);
} }
} }
@ -69,7 +69,7 @@ template <typename T>
void CompareList(const vector<T> &val1, const vector<T> &val2) { void CompareList(const vector<T> &val1, const vector<T> &val2) {
EXPECT_EQ(val1.size(), val2.size()); EXPECT_EQ(val1.size(), val2.size());
if (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]); EXPECT_EQ(val1[i], val2[i]);
} }
} }
@ -129,6 +129,9 @@ static bool NamedAttrsSimpleCmp(const GeAttrValue &left, const GeAttrValue &righ
return false; return false;
} }
} }
default: {
return true;
}
} }
} }
return true; return true;

@ -625,7 +625,7 @@ set(DISTINCT_GRAPH_LOAD_TEST_FILES
"graph/load/data_dumper_unittest.cc" "graph/load/data_dumper_unittest.cc"
#"graph/load/new_model_manager_data_inputer_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_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_task_build_unittest.cc"
"graph/load/new_model_manager_model_manager_aicpu_unittest.cc" "graph/load/new_model_manager_model_manager_aicpu_unittest.cc"
"graph/load/end_graph_task_unittest.cc" "graph/load/end_graph_task_unittest.cc"

@ -38,7 +38,6 @@ int32_t MsprofReport(uint32_t moduleId, uint32_t type, void *data, uint32_t len)
return 0; return 0;
} }
/*
TEST_F(UtestDavinciModel, init_success) { TEST_F(UtestDavinciModel, init_success) {
DavinciModel model(0, nullptr); DavinciModel model(0, nullptr);
ComputeGraphPtr graph = make_shared<ComputeGraph>("default"); ComputeGraphPtr graph = make_shared<ComputeGraph>("default");
@ -46,7 +45,7 @@ TEST_F(UtestDavinciModel, init_success) {
GeModelPtr ge_model = make_shared<GeModel>(); GeModelPtr ge_model = make_shared<GeModel>();
ge_model->SetGraph(GraphUtils::CreateGraphFromComputeGraph(graph)); 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); AttrUtils::SetInt(ge_model, ATTR_MODEL_STREAM_NUM, 1);
shared_ptr<domi::ModelTaskDef> model_task_def = make_shared<domi::ModelTaskDef>(); 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); GeTensorDesc tensor(GeShape(), FORMAT_NCHW, DT_FLOAT);
TensorUtils::SetSize(tensor, 512); 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); OpDescPtr op_desc = CreateOpDesc("square", "Square");
op_input->AddOutputDesc(tensor); op_desc->AddInputDesc(tensor);
op_input->SetInputOffset({1024}); op_desc->AddOutputDesc(tensor);
op_input->SetOutputOffset({1024}); op_desc->SetInputOffset({1024});
NodePtr node_input = graph->AddNode(op_input); // op_index = 0 op_desc->SetOutputOffset({1024});
NodePtr node = graph->AddNode(op_desc); // op_index = 1
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
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); OpDescPtr op_desc = CreateOpDesc("memcpy", MEMCPYASYNC);
task_def1->set_type(RT_MODEL_TASK_KERNEL); op_desc->AddInputDesc(tensor);
domi::KernelDef *kernel_def = task_def1->mutable_kernel(); op_desc->AddOutputDesc(tensor);
kernel_def->set_stub_func("stub_func"); op_desc->SetInputOffset({1024});
kernel_def->set_args_size(64); op_desc->SetOutputOffset({5120});
string args(64, '1'); NodePtr node = graph->AddNode(op_desc); // op_index = 2
kernel_def->set_args(args.data(), 64);
domi::KernelContext *context = kernel_def->mutable_context(); domi::TaskDef *task_def = model_task_def->add_task();
context->set_op_index(1); task_def->set_stream_id(0);
context->set_kernel_type(2); // ccKernelType::TE task_def->set_type(RT_MODEL_TASK_MEMCPY_ASYNC);
uint16_t args_offset[9] = {0}; domi::MemcpyAsyncDef *memcpy_async = task_def->mutable_memcpy_async();
context->set_args_offset(args_offset, 9 * sizeof(uint16_t)); 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); OpDescPtr op_desc = CreateOpDesc("output", NETOUTPUT);
task_def2->set_type(RT_MODEL_TASK_MEMCPY_ASYNC); op_desc->AddInputDesc(tensor);
domi::MemcpyAsyncDef *memcpy_async = task_def2->mutable_memcpy_async(); op_desc->SetInputOffset({5120});
memcpy_async->set_src(1024); op_desc->SetSrcName( { "memcpy" } );
memcpy_async->set_dst(5120); op_desc->SetSrcIndex( { 0 } );
memcpy_async->set_dst_max(512); NodePtr node = graph->AddNode(op_desc); // op_index = 3
memcpy_async->set_count(1); }
memcpy_async->set_kind(RT_MEMCPY_DEVICE_TO_DEVICE);
memcpy_async->set_op_index(2);
EXPECT_EQ(model.Assign(ge_model), SUCCESS); EXPECT_EQ(model.Assign(ge_model), SUCCESS);
EXPECT_EQ(model.Init(), SUCCESS); EXPECT_EQ(model.Init(), SUCCESS);
@ -124,7 +129,6 @@ TEST_F(UtestDavinciModel, init_success) {
ProfilingManager::Instance().is_load_profiling_ = false; ProfilingManager::Instance().is_load_profiling_ = false;
} }
*/
TEST_F(UtestDavinciModel, init_data_op) { TEST_F(UtestDavinciModel, init_data_op) {
DavinciModel model(0, nullptr); DavinciModel model(0, nullptr);
@ -752,7 +756,6 @@ TEST_F(UtestDavinciModel, init_data_aipp_input_dims_normal) {
EXPECT_EQ(model.op_list_.size(), 1); EXPECT_EQ(model.op_list_.size(), 1);
} }
/*
// test label_set_task Init // test label_set_task Init
TEST_F(UtestDavinciModel, label_task_success) { TEST_F(UtestDavinciModel, label_task_success) {
DavinciModel model(0, nullptr); DavinciModel model(0, nullptr);
@ -760,7 +763,7 @@ TEST_F(UtestDavinciModel, label_task_success) {
GeModelPtr ge_model = make_shared<GeModel>(); GeModelPtr ge_model = make_shared<GeModel>();
ge_model->SetGraph(GraphUtils::CreateGraphFromComputeGraph(graph)); 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); AttrUtils::SetInt(ge_model, ATTR_MODEL_STREAM_NUM, 1);
shared_ptr<domi::ModelTaskDef> model_task_def = make_shared<domi::ModelTaskDef>(); 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); GeTensorDesc tensor(GeShape(), FORMAT_ND, DT_INT32);
TensorUtils::SetSize(tensor, 64); TensorUtils::SetSize(tensor, 64);
uint32_t op_index = 0;
{ {
OpDescPtr op_desc = CreateOpDesc("label_switch", LABELSWITCHBYINDEX); OpDescPtr op_desc = CreateOpDesc("label_switch", LABELSWITCHBYINDEX);
op_desc->AddInputDesc(tensor); op_desc->AddInputDesc(tensor);
@ -781,7 +783,7 @@ TEST_F(UtestDavinciModel, label_task_success) {
task_def1->set_stream_id(0); task_def1->set_stream_id(0);
task_def1->set_type(RT_MODEL_TASK_STREAM_LABEL_SWITCH_BY_INDEX); task_def1->set_type(RT_MODEL_TASK_STREAM_LABEL_SWITCH_BY_INDEX);
domi::LabelSwitchByIndexDef *label_task_def = task_def1->mutable_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); 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_stream_id(0);
task_def1->set_type(RT_MODEL_TASK_LABEL_SET); task_def1->set_type(RT_MODEL_TASK_LABEL_SET);
domi::LabelSetDef *label_task_def = task_def1->mutable_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_stream_id(0);
task_def2->set_type(RT_MODEL_TASK_STREAM_LABEL_GOTO); task_def2->set_type(RT_MODEL_TASK_STREAM_LABEL_GOTO);
domi::LabelGotoExDef *label_task_def = task_def2->mutable_label_goto_ex(); 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_stream_id(0);
task_def1->set_type(RT_MODEL_TASK_LABEL_SET); task_def1->set_type(RT_MODEL_TASK_LABEL_SET);
domi::LabelSetDef *label_task_def = task_def1->mutable_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_stream_id(0);
task_def1->set_type(RT_MODEL_TASK_LABEL_SET); task_def1->set_type(RT_MODEL_TASK_LABEL_SET);
domi::LabelSetDef *label_task_def = task_def1->mutable_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)); 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.output_addrs_list_.size(), 0);
EXPECT_EQ(model.task_list_.size(), 5); EXPECT_EQ(model.task_list_.size(), 5);
} }
*/
TEST_F(UtestDavinciModel, LoadWithQueue_fail_with_diff_args) { TEST_F(UtestDavinciModel, LoadWithQueue_fail_with_diff_args) {
DavinciModel model(0, nullptr); DavinciModel model(0, nullptr);

Loading…
Cancel
Save