已合并
feat(rt2): V2执行器增加用户输入buffer大小校验 #4557
wuzheng创建于 8月25日
feat(rt2): V2执行器增加用户输入buffer大小校验 #4557
已合并
共 17 个文件变更+342-28
| @@ -207,6 +207,7 @@ Status TransposeWithShapeCheck(const uint8_t *const src, const std::vector<int64 | |||
| 207 | ", invalid dst shape" + FmtToStr(ShapeToString(dst_shape)) + ", expect" + | 207 | ", invalid dst shape" + FmtToStr(ShapeToString(dst_shape)) + ", expect" + |
| 208 | FmtToStr(ShapeToString(expected_shape)); | 208 | FmtToStr(ShapeToString(expected_shape)); |
| 209 | GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_SHAPE_INVALID, error.c_str()); | 209 | GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_SHAPE_INVALID, error.c_str()); |
| 210 | + return ACL_ERROR_GE_SHAPE_INVALID; | ||
| 210 | } | 211 | } |
| 211 | 212 | ||
| 212 | return Transpose(src, src_shape, src_data_type, perm_arg, result); | 213 | return Transpose(src, src_shape, src_data_type, perm_arg, result); |
| @@ -207,6 +207,7 @@ Status TransposeWithShapeCheck(const uint8_t *const src, const std::vector<int64 | |||
| 207 | ", invalid dst shape" + FmtToStr(ShapeToString(dst_shape)) + ", expect" + | 207 | ", invalid dst shape" + FmtToStr(ShapeToString(dst_shape)) + ", expect" + |
| 208 | FmtToStr(ShapeToString(expected_shape)); | 208 | FmtToStr(ShapeToString(expected_shape)); |
| 209 | GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_SHAPE_INVALID, error.c_str()); | 209 | GE_ERRORLOG_AND_ERRORMSG(ACL_ERROR_GE_SHAPE_INVALID, error.c_str()); |
| 210 | + return ACL_ERROR_GE_SHAPE_INVALID; | ||
| 210 | } | 211 | } |
| 211 | 212 | ||
| 212 | return Transpose(src, src_shape, src_data_type, perm_arg, result); | 213 | return Transpose(src, src_shape, src_data_type, perm_arg, result); |
| @@ -11,6 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | + | ||
| 14 | 15 | ||
| 15 | 16 | ||
| 16 | 17 | ||
| @@ -30,6 +31,7 @@ | |||
| 30 | 31 | ||
| 31 | 32 | ||
| 32 | 33 | ||
| 34 | + | ||
| 33 | 35 | ||
| 34 | 36 | ||
| 35 | 37 | ||
| @@ -53,6 +55,51 @@ ge::graphStatus CheckTensors(Tensor **const tensors, const size_t num, const cha | |||
| 53 | return ge::GRAPH_SUCCESS; | 55 | return ge::GRAPH_SUCCESS; |
| 54 | } | 56 | } |
| 55 | 57 | ||
| 58 | +constexpr int64_t kDataMemAlignSizeCompare = 64; | ||
| 59 | +constexpr int64_t kOverflowUserSize = INT64_MAX - kDataMemAlignSizeCompare; | ||
| 60 | + | ||
| 61 | +ge::graphStatus CheckUserInputSize(const Tensor *const *const inputs, const size_t input_num, | ||
| 62 | + const ModelDesc &model_desc) { | ||
| 63 | + for (size_t i = 0U; i < input_num; ++i) { | ||
| 64 | + const auto *desc = model_desc.GetInputDesc(i); | ||
| 65 | + const int64_t expected_size = desc->GetSize(); | ||
| 66 | + if (expected_size == 0) { | ||
| 67 | + GELOGW("Input[%zu] expected_size is 0 (dynamic shape), skip validation", i); | ||
| 68 | + continue; | ||
| 69 | + } | ||
| 70 | + const size_t raw_user_size = inputs[i]->GetSize(); | ||
| 71 | + if (raw_user_size > static_cast<size_t>(INT64_MAX)) { | ||
| 72 | + GELOGW("Input[%zu] user_size [%zu] exceeds INT64_MAX, skip validation", i, raw_user_size); | ||
| 73 | + continue; | ||
| 74 | + } | ||
| 75 | + const int64_t user_size = static_cast<int64_t>(raw_user_size); | ||
| 76 | + if (user_size > expected_size) { | ||
| 77 | + GELOGW("User input[%zu] size(bytes) [%" PRId64 "] is bigger than model size [%" PRId64 | ||
| 78 | + "], may cause inference problem, please check model input", | ||
| 79 | + i, user_size, expected_size); | ||
| 80 | + continue; | ||
| 81 | + } | ||
| 82 | + if (user_size > kOverflowUserSize) { | ||
| 83 | + GELOGW("Input[%zu] user_size [%" PRId64 "] is near INT64_MAX, skip validation to avoid overflow", i, user_size); | ||
| 84 | + continue; | ||
| 85 | + } | ||
| 86 | + if (user_size + kDataMemAlignSizeCompare < expected_size) { | ||
| 87 | + const std::string reason = "The input memory size set by the user is invalid. The provided " + | ||
| 88 | + std::to_string(user_size) + " bytes of buffer size plus the aligned " + | ||
| 89 | + std::to_string(kDataMemAlignSizeCompare) + " bytes is less than the tensor size " + | ||
| 90 | + std::to_string(expected_size) + " bytes required by the model"; | ||
| 91 | + REPORT_PREDEFINED_ERR_MSG("E13025", std::vector<const char *>({"reason"}), | ||
| 92 | + std::vector<const char *>({reason.c_str()})); | ||
| 93 | + GELOGE(ge::PARAM_INVALID, | ||
| 94 | + "[Check][Param] Input[%zu] size(bytes) [%" PRId64 "] from user add align [%" PRId64 | ||
| 95 | + "] is less than model size [%" PRId64 "]", | ||
| 96 | + i, user_size, kDataMemAlignSizeCompare, expected_size); | ||
| 97 | + return ge::PARAM_INVALID; | ||
| 98 | + } | ||
夏 | |||
| 99 | + } | ||
| 100 | + return ge::GRAPH_SUCCESS; | ||
| 101 | +} | ||
| 102 | + | ||
| 56 | inline ge::graphStatus CheckModelOutputsNum(const void *void_ed, size_t num) { | 103 | inline ge::graphStatus CheckModelOutputsNum(const void *void_ed, size_t num) { |
| 57 | auto ed = static_cast<const SequentialExecutionData *>(void_ed); | 104 | auto ed = static_cast<const SequentialExecutionData *>(void_ed); |
| 58 | if (ed->output_num != num) { | 105 | if (ed->output_num != num) { |
| @@ -268,6 +315,7 @@ ge::graphStatus ModelV2Executor::Execute(const ModelExecuteArg &arg, Tensor **in | |||
| 268 | auto &graph_executor = graphs_[kMainExeGraph]; | 315 | auto &graph_executor = graphs_[kMainExeGraph]; |
| 269 | GE_RETURN_IF_ERROR(CheckModelInputsNum(graph_executor.GetExecutionData(), input_num, kArgCount)); | 316 | GE_RETURN_IF_ERROR(CheckModelInputsNum(graph_executor.GetExecutionData(), input_num, kArgCount)); |
| 270 | GE_RETURN_IF_ERROR(CheckTensors(inputs, input_num, "inputs")); | 317 | GE_RETURN_IF_ERROR(CheckTensors(inputs, input_num, "inputs")); |
| 318 | + GE_RETURN_IF_ERROR(CheckUserInputSize(inputs, input_num, GetModelDesc())); | ||
| 271 | GE_RETURN_IF_ERROR(graph_executor.SpecifyInputs(reinterpret_cast<void *const *>(inputs), 0U, input_num)); | 319 | GE_RETURN_IF_ERROR(graph_executor.SpecifyInputs(reinterpret_cast<void *const *>(inputs), 0U, input_num)); |
| 272 | GE_RETURN_IF_ERROR(SpecifyArgsInputs(arg, input_num, graph_executor)); | 320 | GE_RETURN_IF_ERROR(SpecifyArgsInputs(arg, input_num, graph_executor)); |
| 273 | 321 | ||
| @@ -85,6 +85,8 @@ class TensorFaker { | |||
| 85 | 85 | ||
| 86 | TensorFaker &Placement(TensorPlacement placement); | 86 | TensorFaker &Placement(TensorPlacement placement); |
| 87 | 87 | ||
| 88 | + TensorFaker &Size(size_t size); | ||
| 89 | + | ||
| 88 | template <typename T> | 90 | template <typename T> |
| 89 | TensorFaker &Value(const std::vector<T> &value) { | 91 | TensorFaker &Value(const std::vector<T> &value) { |
| 90 | tensor_value_.resize(sizeof(T) * value.size()); | 92 | tensor_value_.resize(sizeof(T) * value.size()); |
| @@ -106,6 +108,8 @@ class TensorFaker { | |||
| 106 | nullptr // address | 108 | nullptr // address |
| 107 | }; | 109 | }; |
| 108 | bool alloc_tensor_data_ = true; | 110 | bool alloc_tensor_data_ = true; |
| 111 | + bool has_custom_size_ = false; | ||
| 112 | + size_t custom_size_ = 0; | ||
| 109 | }; | 113 | }; |
| 110 | 114 | ||
| 111 | struct FakeTensors { | 115 | struct FakeTensors { |
| @@ -144,6 +144,11 @@ TensorFaker &TensorFaker::Placement(TensorPlacement placement) { | |||
| 144 | tensor_.SetPlacement(placement); | 144 | tensor_.SetPlacement(placement); |
| 145 | return *this; | 145 | return *this; |
| 146 | } | 146 | } |
| 147 | +TensorFaker &TensorFaker::Size(size_t size) { | ||
| 148 | + has_custom_size_ = true; | ||
| 149 | + custom_size_ = size; | ||
| 150 | + return *this; | ||
| 151 | +} | ||
| 147 | TensorHolder TensorFaker::Build() const { | 152 | TensorHolder TensorFaker::Build() const { |
| 148 | TensorHolder th; | 153 | TensorHolder th; |
| 149 | if (tensor_.GetPlacement() == kFollowing) { | 154 | if (tensor_.GetPlacement() == kFollowing) { |
| @@ -155,10 +160,18 @@ TensorHolder TensorFaker::Build() const { | |||
| 155 | Tensor::CreateFollowing(tensor_.GetStorageShape().GetShapeSize(), tensor_.GetDataType(), total_size)); | 160 | Tensor::CreateFollowing(tensor_.GetStorageShape().GetShapeSize(), tensor_.GetDataType(), total_size)); |
| 156 | } else { | 161 | } else { |
| 157 | th.SetTensor(std::unique_ptr<Tensor>(new Tensor)); | 162 | th.SetTensor(std::unique_ptr<Tensor>(new Tensor)); |
| 158 | - auto tensor_size = ge::GetSizeInBytes(tensor_.GetStorageShape().GetShapeSize(), tensor_.GetDataType()); | 163 | + size_t tensor_size; |
| 159 | - tensor_size = ge::RoundUp(tensor_size, 32) + 32; | 164 | + size_t alloc_size; |
| 165 | + if (has_custom_size_) { | ||
| 166 | + tensor_size = custom_size_; | ||
| 167 | + alloc_size = 64; | ||
| 168 | + } else { | ||
| 169 | + tensor_size = ge::GetSizeInBytes(tensor_.GetStorageShape().GetShapeSize(), tensor_.GetDataType()); | ||
| 170 | + tensor_size = ge::RoundUp(tensor_size, 32) + 32; | ||
| 171 | + alloc_size = tensor_size; | ||
| 172 | + } | ||
| 160 | if (alloc_tensor_data_) { | 173 | if (alloc_tensor_data_) { |
| 161 | - auto block = StubHostTensorHead::Create(tensor_size); | 174 | + auto block = StubHostTensorHead::Create(alloc_size); |
| 162 | th.SetBlock(block); | 175 | th.SetBlock(block); |
| 163 | TensorData td; | 176 | TensorData td; |
| 164 | td.SetAddr(block, HostTensorManager); | 177 | td.SetAddr(block, HostTensorManager); |
| @@ -173,7 +186,7 @@ TensorHolder TensorFaker::Build() const { | |||
| 173 | th.GetTensor()->SetDataType(tensor_.GetDataType()); | 186 | th.GetTensor()->SetDataType(tensor_.GetDataType()); |
| 174 | th.GetTensor()->SetPlacement(tensor_.GetPlacement()); | 187 | th.GetTensor()->SetPlacement(tensor_.GetPlacement()); |
| 175 | 188 | ||
| 176 | - if (alloc_tensor_data_) { | 189 | + if (alloc_tensor_data_ && !has_custom_size_) { |
| 177 | if (tensor_.GetPlacement() == kFollowing || tensor_.GetPlacement() == kOnHost) { | 190 | if (tensor_.GetPlacement() == kFollowing || tensor_.GetPlacement() == kOnHost) { |
| 178 | if (tensor_value_.empty()) { | 191 | if (tensor_value_.empty()) { |
| 179 | auto shape_size = th.GetTensor()->GetStorageShape().GetShapeSize(); | 192 | auto shape_size = th.GetTensor()->GetStorageShape().GetShapeSize(); |
| @@ -253,6 +253,9 @@ void RunIfGraphWithDataDump(TensorHolder &pred_tensor, bool expect_branch) { | |||
| 253 | auto compute_graph = ShareGraph::IfGraph2(); | 253 | auto compute_graph = ShareGraph::IfGraph2(); |
| 254 | ASSERT_NE(compute_graph, nullptr); | 254 | ASSERT_NE(compute_graph, nullptr); |
| 255 | compute_graph->TopologicalSorting(); | 255 | compute_graph->TopologicalSorting(); |
| 256 | + auto pred_data_desc = compute_graph->FindNode("pred")->GetOpDesc()->MutableOutputDesc(0); | ||
| 257 | + pred_data_desc->SetShape(ge::GeShape()); | ||
| 258 | + pred_data_desc->SetOriginShape(ge::GeShape()); | ||
| 256 | GeModelBuilder builder(compute_graph); | 259 | GeModelBuilder builder(compute_graph); |
| 257 | auto ge_root_model = builder.BuildGeRootModel(); | 260 | auto ge_root_model = builder.BuildGeRootModel(); |
| 258 | 261 | ||
| @@ -52,6 +52,12 @@ REG_OP(If) | |||
| 52 | auto compute_graph = ShareGraph::IfGraphShapeChangedOneBranch(); | 52 | auto compute_graph = ShareGraph::IfGraphShapeChangedOneBranch(); |
| 53 | ASSERT_NE(compute_graph, nullptr); | 53 | ASSERT_NE(compute_graph, nullptr); |
| 54 | compute_graph->TopologicalSorting(); | 54 | compute_graph->TopologicalSorting(); |
| 55 | + auto pred_data_desc = compute_graph->FindNode("pred")->GetOpDesc()->MutableOutputDesc(0); | ||
| 56 | + pred_data_desc->SetShape(ge::GeShape()); | ||
| 57 | + pred_data_desc->SetOriginShape(ge::GeShape()); | ||
| 58 | + auto input_data_desc = compute_graph->FindNode("input")->GetOpDesc()->MutableOutputDesc(0); | ||
| 59 | + input_data_desc->SetShape(ge::GeShape({8, 3, 16, 16})); | ||
| 60 | + input_data_desc->SetOriginShape(ge::GeShape({8, 3, 16, 16})); | ||
| 55 | ge::GraphUtils::DumpGEGraphToOnnx(*compute_graph, "ComputeGraphChainConflict"); | 61 | ge::GraphUtils::DumpGEGraphToOnnx(*compute_graph, "ComputeGraphChainConflict"); |
| 56 | GeModelBuilder builder(compute_graph); | 62 | GeModelBuilder builder(compute_graph); |
| 57 | auto ge_root_model = builder.BuildGeRootModel(); | 63 | auto ge_root_model = builder.BuildGeRootModel(); |
| @@ -96,6 +102,9 @@ REG_OP(If) | |||
| 96 | auto compute_graph = ShareGraph::IfGraph2(); | 102 | auto compute_graph = ShareGraph::IfGraph2(); |
| 97 | ASSERT_NE(compute_graph, nullptr); | 103 | ASSERT_NE(compute_graph, nullptr); |
| 98 | compute_graph->TopologicalSorting(); | 104 | compute_graph->TopologicalSorting(); |
| 105 | + auto pred_data_desc = compute_graph->FindNode("pred")->GetOpDesc()->MutableOutputDesc(0); | ||
| 106 | + pred_data_desc->SetShape(ge::GeShape()); | ||
| 107 | + pred_data_desc->SetOriginShape(ge::GeShape()); | ||
| 99 | GeModelBuilder builder(compute_graph); | 108 | GeModelBuilder builder(compute_graph); |
| 100 | auto ge_root_model = builder.BuildGeRootModel(); | 109 | auto ge_root_model = builder.BuildGeRootModel(); |
| 101 | 110 | ||
| @@ -152,6 +161,9 @@ REG_OP(If) | |||
| 152 | auto compute_graph = ShareGraph::IfGraph3(); | 161 | auto compute_graph = ShareGraph::IfGraph3(); |
| 153 | ASSERT_NE(compute_graph, nullptr); | 162 | ASSERT_NE(compute_graph, nullptr); |
| 154 | compute_graph->TopologicalSorting(); | 163 | compute_graph->TopologicalSorting(); |
| 164 | + auto pred_data_desc = compute_graph->FindNode("pred")->GetOpDesc()->MutableOutputDesc(0); | ||
| 165 | + pred_data_desc->SetShape(ge::GeShape()); | ||
| 166 | + pred_data_desc->SetOriginShape(ge::GeShape()); | ||
| 155 | auto ge_root_model = GeModelBuilder(compute_graph) | 167 | auto ge_root_model = GeModelBuilder(compute_graph) |
| 156 | .AddTaskDef("Add", AiCoreTaskDefFaker("AddStubBin").WithHandle()) | 168 | .AddTaskDef("Add", AiCoreTaskDefFaker("AddStubBin").WithHandle()) |
| 157 | .BuildGeRootModel(); | 169 | .BuildGeRootModel(); |
| @@ -200,6 +212,9 @@ REG_OP(If) | |||
| 200 | auto compute_graph = ShareGraph::CaseGraph(); | 212 | auto compute_graph = ShareGraph::CaseGraph(); |
| 201 | ASSERT_NE(compute_graph, nullptr); | 213 | ASSERT_NE(compute_graph, nullptr); |
| 202 | compute_graph->TopologicalSorting(); | 214 | compute_graph->TopologicalSorting(); |
| 215 | + auto index_data_desc = compute_graph->FindNode("index")->GetOpDesc()->MutableOutputDesc(0); | ||
| 216 | + index_data_desc->SetShape(ge::GeShape()); | ||
| 217 | + index_data_desc->SetOriginShape(ge::GeShape()); | ||
| 203 | GeModelBuilder builder(compute_graph); | 218 | GeModelBuilder builder(compute_graph); |
| 204 | auto ge_root_model = builder.BuildGeRootModel(); | 219 | auto ge_root_model = builder.BuildGeRootModel(); |
| 205 | 220 | ||
| @@ -337,16 +352,15 @@ REG_OP(If) | |||
| 337 | auto model_executor = ModelV2Executor::Create(exe_graph, ge_root_model); | 352 | auto model_executor = ModelV2Executor::Create(exe_graph, ge_root_model); |
| 338 | ASSERT_NE(model_executor, nullptr); | 353 | ASSERT_NE(model_executor, nullptr); |
| 339 | 354 | ||
| 340 | - int32_t output = 0; | ||
| 341 | ASSERT_EQ(model_executor->Load(), ge::GRAPH_SUCCESS); | 355 | ASSERT_EQ(model_executor->Load(), ge::GRAPH_SUCCESS); |
| 342 | - auto outputs = FakeTensors({}, 1, &output); | 356 | + auto outputs = FakeTensors({1, 1, 224, 224}, 1); |
| 343 | 357 | ||
| 344 | rtStream_t stream; | 358 | rtStream_t stream; |
| 345 | ASSERT_EQ(aclrtCreateStreamWithConfig(&stream, static_cast<uint32_t>(RT_STREAM_PRIORITY_DEFAULT), 0), | 359 | ASSERT_EQ(aclrtCreateStreamWithConfig(&stream, static_cast<uint32_t>(RT_STREAM_PRIORITY_DEFAULT), 0), |
| 346 | RT_ERROR_NONE); | 360 | RT_ERROR_NONE); |
| 347 | auto i1 = FakeValue<uint64_t>(reinterpret_cast<uint64_t>(stream)); | 361 | auto i1 = FakeValue<uint64_t>(reinterpret_cast<uint64_t>(stream)); |
| 348 | 362 | ||
| 349 | - auto inputs = FakeTensors({}, 1); | 363 | + auto inputs = FakeTensors({1, 1, 224, 224}, 1); |
| 350 | *static_cast<int32_t *>(inputs.data()[0].GetAddr()) = 0; | 364 | *static_cast<int32_t *>(inputs.data()[0].GetAddr()) = 0; |
| 351 | 365 | ||
| 352 | ASSERT_EQ(model_executor->Execute({i1.value}, inputs.GetTensorList(), inputs.size(), outputs.GetTensorList(), | 366 | ASSERT_EQ(model_executor->Execute({i1.value}, inputs.GetTensorList(), inputs.size(), outputs.GetTensorList(), |
| @@ -393,8 +407,8 @@ REG_OP(If) | |||
| 393 | 407 | ||
| 394 | std::vector<TensorHolder> input_holders; | 408 | std::vector<TensorHolder> input_holders; |
| 395 | std::vector<Tensor *> inputs; | 409 | std::vector<Tensor *> inputs; |
| 396 | - input_holders.push_back(TensorFaker().Build()); | 410 | + input_holders.push_back(TensorFaker().Shape({1, 1, 224, 224}).Build()); |
| 397 | - input_holders.push_back(TensorFaker().Build()); | 411 | + input_holders.push_back(TensorFaker().Shape({1, 1, 224, 224}).Build()); |
| 398 | inputs.push_back(input_holders[0].GetTensor()); | 412 | inputs.push_back(input_holders[0].GetTensor()); |
| 399 | inputs.push_back(input_holders[1].GetTensor()); | 413 | inputs.push_back(input_holders[1].GetTensor()); |
| 400 | 414 | ||
| @@ -403,8 +417,8 @@ REG_OP(If) | |||
| 403 | 417 | ||
| 404 | std::vector<TensorHolder> output_holders; | 418 | std::vector<TensorHolder> output_holders; |
| 405 | std::vector<Tensor *> outputs; | 419 | std::vector<Tensor *> outputs; |
| 406 | - output_holders.push_back(TensorFaker().Build()); | 420 | + output_holders.push_back(TensorFaker().Shape({1, 1, 224, 224}).Build()); |
| 407 | - output_holders.push_back(TensorFaker().Build()); | 421 | + output_holders.push_back(TensorFaker().Shape({1, 1, 224, 224}).Build()); |
| 408 | outputs.push_back(output_holders[0].GetTensor()); | 422 | outputs.push_back(output_holders[0].GetTensor()); |
| 409 | outputs.push_back(output_holders[1].GetTensor()); | 423 | outputs.push_back(output_holders[1].GetTensor()); |
| 410 | ASSERT_EQ(model_executor->Load(), ge::GRAPH_SUCCESS); | 424 | ASSERT_EQ(model_executor->Load(), ge::GRAPH_SUCCESS); |
| @@ -475,8 +489,8 @@ REG_OP(If) | |||
| 475 | 489 | ||
| 476 | std::vector<TensorHolder> input_holders; | 490 | std::vector<TensorHolder> input_holders; |
| 477 | std::vector<Tensor *> inputs; | 491 | std::vector<Tensor *> inputs; |
| 478 | - input_holders.push_back(TensorFaker().Build()); | 492 | + input_holders.push_back(TensorFaker().Shape({1, 1, 224, 224}).Build()); |
| 479 | - input_holders.push_back(TensorFaker().Build()); | 493 | + input_holders.push_back(TensorFaker().Shape({1, 1, 224, 224}).Build()); |
| 480 | inputs.push_back(input_holders[0].GetTensor()); | 494 | inputs.push_back(input_holders[0].GetTensor()); |
| 481 | inputs.push_back(input_holders[1].GetTensor()); | 495 | inputs.push_back(input_holders[1].GetTensor()); |
| 482 | 496 | ||
| @@ -485,8 +499,8 @@ REG_OP(If) | |||
| 485 | 499 | ||
| 486 | std::vector<TensorHolder> output_holders; | 500 | std::vector<TensorHolder> output_holders; |
| 487 | std::vector<Tensor *> outputs; | 501 | std::vector<Tensor *> outputs; |
| 488 | - output_holders.push_back(TensorFaker().Build()); | 502 | + output_holders.push_back(TensorFaker().Shape({1, 1, 224, 224}).Build()); |
| 489 | - output_holders.push_back(TensorFaker().Build()); | 503 | + output_holders.push_back(TensorFaker().Shape({1, 1, 224, 224}).Build()); |
| 490 | outputs.push_back(output_holders[0].GetTensor()); | 504 | outputs.push_back(output_holders[0].GetTensor()); |
| 491 | outputs.push_back(output_holders[1].GetTensor()); | 505 | outputs.push_back(output_holders[1].GetTensor()); |
| 492 | ASSERT_EQ(model_executor->Load(), ge::GRAPH_SUCCESS); | 506 | ASSERT_EQ(model_executor->Load(), ge::GRAPH_SUCCESS); |
| @@ -663,6 +663,13 @@ TEST_F(GraphExecutorWithKernelUnitTest, ExecuteModel_HostInput) { | |||
| 663 | TEST_F(GraphExecutorWithKernelUnitTest, ExecuteModel_BinaryKernel) { | 663 | TEST_F(GraphExecutorWithKernelUnitTest, ExecuteModel_BinaryKernel) { |
| 664 | auto graph = ShareGraph::BinaryKernelTypicalGraph(); | 664 | auto graph = ShareGraph::BinaryKernelTypicalGraph(); |
| 665 | for (auto &node : graph->GetAllNodes()) { | 665 | for (auto &node : graph->GetAllNodes()) { |
| 666 | + if (node->GetType() == "Data") { | ||
| 667 | + auto data_desc = node->GetOpDesc()->MutableOutputDesc(0); | ||
| 668 | + data_desc->SetShape(ge::GeShape()); | ||
| 669 | + data_desc->SetOriginShape(ge::GeShape()); | ||
| 670 | + data_desc->SetDataType(ge::DT_FLOAT16); | ||
| 671 | + data_desc->SetOriginDataType(ge::DT_FLOAT16); | ||
| 672 | + } | ||
| 666 | if (node->GetType() == "Foo" || node->GetType() == "Bar") { | 673 | if (node->GetType() == "Foo" || node->GetType() == "Bar") { |
| 667 | MockLessImportantNodeKernel(node); | 674 | MockLessImportantNodeKernel(node); |
| 668 | } else if (node->GetType() == "ConditionCalc") { | 675 | } else if (node->GetType() == "ConditionCalc") { |
| @@ -723,6 +730,15 @@ TEST_F(GraphExecutorWithKernelUnitTest, ExecuteModel_BinaryKernel) { | |||
| 723 | TEST_F(GraphExecutorWithKernelUnitTest, Lowering_Execute_Model_On_UB_fusion_node) { | 730 | TEST_F(GraphExecutorWithKernelUnitTest, Lowering_Execute_Model_On_UB_fusion_node) { |
| 724 | auto graph = ShareGraph::BuildGraphWithUBFusionNode(); | 731 | auto graph = ShareGraph::BuildGraphWithUBFusionNode(); |
| 725 | graph->TopologicalSorting(); | 732 | graph->TopologicalSorting(); |
| 733 | + const std::vector<const char_t *> data_names = {"data1", "data2", "data3"}; | ||
| 734 | + const std::vector<std::vector<int64_t>> input_shapes = {{2}, {2}, {3}}; | ||
| 735 | + for (size_t i = 0U; i < data_names.size(); ++i) { | ||
| 736 | + auto data_desc = graph->FindNode(data_names[i])->GetOpDesc()->MutableOutputDesc(0); | ||
| 737 | + data_desc->SetShape(ge::GeShape(input_shapes[i])); | ||
| 738 | + data_desc->SetOriginShape(ge::GeShape(input_shapes[i])); | ||
| 739 | + data_desc->SetDataType(ge::DT_FLOAT16); | ||
| 740 | + data_desc->SetOriginDataType(ge::DT_FLOAT16); | ||
| 741 | + } | ||
| 726 | 742 | ||
| 727 | GeModelBuilder builder(graph); | 743 | GeModelBuilder builder(graph); |
| 728 | auto ge_root_model = builder.AddTaskDef("Add", AiCoreTaskDefFaker(AddStubName).WithHandle()) | 744 | auto ge_root_model = builder.AddTaskDef("Add", AiCoreTaskDefFaker(AddStubName).WithHandle()) |
| @@ -1500,6 +1516,9 @@ TEST_F(GraphExecutorWithKernelUnitTest, Cmo_ExecuteSuccess) { | |||
| 1500 | dlog_setlevel(GE_MODULE_NAME, DLOG_INFO, 0); | 1516 | dlog_setlevel(GE_MODULE_NAME, DLOG_INFO, 0); |
| 1501 | auto graph = ShareGraph::AicoreWithCmoGraph(); | 1517 | auto graph = ShareGraph::AicoreWithCmoGraph(); |
| 1502 | graph->TopologicalSorting(); | 1518 | graph->TopologicalSorting(); |
| 1519 | + auto data1_desc = graph->FindNode("data1")->GetOpDesc()->MutableOutputDesc(0); | ||
| 1520 | + data1_desc->SetDataType(ge::DT_FLOAT16); | ||
| 1521 | + data1_desc->SetOriginDataType(ge::DT_FLOAT16); | ||
| 1503 | GeModelBuilder builder(graph); | 1522 | GeModelBuilder builder(graph); |
| 1504 | auto ge_root_model = | 1523 | auto ge_root_model = |
| 1505 | builder.AddTaskDef("ReduceSum", AiCoreTaskDefFaker("ReduceSumStubBin").WithHandle()).BuildGeRootModel(); | 1524 | builder.AddTaskDef("ReduceSum", AiCoreTaskDefFaker("ReduceSumStubBin").WithHandle()).BuildGeRootModel(); |
| @@ -1707,6 +1726,12 @@ graphStatus LaunchKernelFailedByLaunchFlagFake(gert::KernelContext *context) { | |||
| 1707 | TEST_F(GraphExecutorWithKernelUnitTest, TopologicalExecuteFailThenSuccess) { | 1726 | TEST_F(GraphExecutorWithKernelUnitTest, TopologicalExecuteFailThenSuccess) { |
| 1708 | auto graph = ShareGraph::IfCondByShapeGraph(); | 1727 | auto graph = ShareGraph::IfCondByShapeGraph(); |
| 1709 | graph->TopologicalSorting(); | 1728 | graph->TopologicalSorting(); |
| 1729 | + auto pred_data_desc = graph->FindNode("pred")->GetOpDesc()->MutableOutputDesc(0); | ||
| 1730 | + pred_data_desc->SetShape(ge::GeShape()); | ||
| 1731 | + pred_data_desc->SetOriginShape(ge::GeShape()); | ||
| 1732 | + auto input_data_desc = graph->FindNode("input")->GetOpDesc()->MutableOutputDesc(0); | ||
| 1733 | + input_data_desc->SetShape(ge::GeShape({2, 3, 4, 6})); | ||
| 1734 | + input_data_desc->SetOriginShape(ge::GeShape({2, 3, 4, 6})); | ||
| 1710 | const char *const Cast = "Cast"; | 1735 | const char *const Cast = "Cast"; |
| 1711 | auto ge_root_model = GeModelBuilder(graph) | 1736 | auto ge_root_model = GeModelBuilder(graph) |
| 1712 | .AddTaskDef("Add", AiCoreTaskDefFaker("AddStubBin").WithHandle()) | 1737 | .AddTaskDef("Add", AiCoreTaskDefFaker("AddStubBin").WithHandle()) |
| @@ -1774,6 +1799,9 @@ TEST_F(GraphExecutorWithKernelUnitTest, PriorityTopologicalExecuteFailThenSucces | |||
| 1774 | auto compute_graph = ShareGraph::IfGraph4(); | 1799 | auto compute_graph = ShareGraph::IfGraph4(); |
| 1775 | ASSERT_NE(compute_graph, nullptr); | 1800 | ASSERT_NE(compute_graph, nullptr); |
| 1776 | compute_graph->TopologicalSorting(); | 1801 | compute_graph->TopologicalSorting(); |
| 1802 | + auto pred_data_desc = compute_graph->FindNode("pred")->GetOpDesc()->MutableOutputDesc(0); | ||
| 1803 | + pred_data_desc->SetShape(ge::GeShape()); | ||
| 1804 | + pred_data_desc->SetOriginShape(ge::GeShape()); | ||
| 1777 | GE_DUMP(compute_graph, "computegraph_IfGraph4"); | 1805 | GE_DUMP(compute_graph, "computegraph_IfGraph4"); |
| 1778 | 1806 | ||
| 1779 | auto ge_root_model = | 1807 | auto ge_root_model = |
| @@ -55,6 +55,11 @@ class KnownShapeGraphUnitTest : public bg::BgTest { | |||
| 55 | 55 | ||
| 56 | TEST_F(KnownShapeGraphUnitTest, ControlFlowNodeWithKnownShapeSubgraph) { | 56 | TEST_F(KnownShapeGraphUnitTest, ControlFlowNodeWithKnownShapeSubgraph) { |
| 57 | auto graph = ShareGraph::IfWithKnownShapeSubGraph("main"); | 57 | auto graph = ShareGraph::IfWithKnownShapeSubGraph("main"); |
| 58 | + auto cond_data_desc = graph->FindNode("main/data_0")->GetOpDesc()->MutableOutputDesc(0); | ||
| 59 | + cond_data_desc->SetShape(ge::GeShape()); | ||
| 60 | + cond_data_desc->SetOriginShape(ge::GeShape()); | ||
| 61 | + cond_data_desc->SetDataType(ge::DT_INT32); | ||
| 62 | + cond_data_desc->SetOriginDataType(ge::DT_INT32); | ||
| 58 | auto root_model = GeModelBuilder(graph).BuildGeRootModel(); | 63 | auto root_model = GeModelBuilder(graph).BuildGeRootModel(); |
| 59 | auto faker = GlobalDataFaker(root_model); | 64 | auto faker = GlobalDataFaker(root_model); |
| 60 | auto global_data = faker.FakeWithHandleAiCore("StaticFoo", false).Build(); | 65 | auto global_data = faker.FakeWithHandleAiCore("StaticFoo", false).Build(); |
| @@ -147,6 +147,9 @@ void RunIfGraph(TensorHolder &pred_tensor, bool expect_branch, const TaskProduce | |||
| 147 | auto compute_graph = ShareGraph::IfGraph2(); | 147 | auto compute_graph = ShareGraph::IfGraph2(); |
| 148 | ASSERT_NE(compute_graph, nullptr); | 148 | ASSERT_NE(compute_graph, nullptr); |
| 149 | compute_graph->TopologicalSorting(); | 149 | compute_graph->TopologicalSorting(); |
| 150 | + auto pred_data_desc = compute_graph->FindNode("pred")->GetOpDesc()->MutableOutputDesc(0); | ||
| 151 | + pred_data_desc->SetShape(ge::GeShape()); | ||
| 152 | + pred_data_desc->SetOriginShape(ge::GeShape()); | ||
| 150 | GeModelBuilder builder(compute_graph); | 153 | GeModelBuilder builder(compute_graph); |
| 151 | auto ge_root_model = builder.BuildGeRootModel(); | 154 | auto ge_root_model = builder.BuildGeRootModel(); |
| 152 | 155 | ||
| @@ -229,16 +232,15 @@ void RunWhileGraph(const TaskProducerType &producer_type) { | |||
| 229 | auto model_executor = ModelV2Executor::Create(exe_graph, option, ge_root_model); | 232 | auto model_executor = ModelV2Executor::Create(exe_graph, option, ge_root_model); |
| 230 | ASSERT_NE(model_executor, nullptr); | 233 | ASSERT_NE(model_executor, nullptr); |
| 231 | 234 | ||
| 232 | - int32_t output = 0; | ||
| 233 | ASSERT_EQ(model_executor->Load(), ge::GRAPH_SUCCESS); | 235 | ASSERT_EQ(model_executor->Load(), ge::GRAPH_SUCCESS); |
| 234 | - auto outputs = FakeTensors({}, 1, &output); | 236 | + auto outputs = FakeTensors({1, 1, 224, 224}, 1); |
| 235 | 237 | ||
| 236 | rtStream_t stream; | 238 | rtStream_t stream; |
| 237 | ASSERT_EQ(aclrtCreateStreamWithConfig(&stream, static_cast<uint32_t>(RT_STREAM_PRIORITY_DEFAULT), 0), | 239 | ASSERT_EQ(aclrtCreateStreamWithConfig(&stream, static_cast<uint32_t>(RT_STREAM_PRIORITY_DEFAULT), 0), |
| 238 | RT_ERROR_NONE); | 240 | RT_ERROR_NONE); |
| 239 | auto i1 = FakeValue<uint64_t>(reinterpret_cast<uint64_t>(stream)); | 241 | auto i1 = FakeValue<uint64_t>(reinterpret_cast<uint64_t>(stream)); |
| 240 | 242 | ||
| 241 | - auto inputs = FakeTensors({}, 1); | 243 | + auto inputs = FakeTensors({1, 1, 224, 224}, 1); |
| 242 | *static_cast<int32_t *>(inputs.data()[0].GetAddr()) = 0; | 244 | *static_cast<int32_t *>(inputs.data()[0].GetAddr()) = 0; |
| 243 | 245 | ||
| 244 | ASSERT_EQ(model_executor->Execute({i1.value}, inputs.GetTensorList(), inputs.size(), outputs.GetTensorList(), | 246 | ASSERT_EQ(model_executor->Execute({i1.value}, inputs.GetTensorList(), inputs.size(), outputs.GetTensorList(), |
| @@ -262,6 +264,9 @@ void RunCaseGraph(TensorHolder &index_tensor, const TaskProducerType &producer_t | |||
| 262 | auto compute_graph = ShareGraph::CaseGraph(); | 264 | auto compute_graph = ShareGraph::CaseGraph(); |
| 263 | ASSERT_NE(compute_graph, nullptr); | 265 | ASSERT_NE(compute_graph, nullptr); |
| 264 | compute_graph->TopologicalSorting(); | 266 | compute_graph->TopologicalSorting(); |
| 267 | + auto index_data_desc = compute_graph->FindNode("index")->GetOpDesc()->MutableOutputDesc(0); | ||
| 268 | + index_data_desc->SetShape(ge::GeShape()); | ||
| 269 | + index_data_desc->SetOriginShape(ge::GeShape()); | ||
| 265 | GeModelBuilder builder(compute_graph); | 270 | GeModelBuilder builder(compute_graph); |
| 266 | auto ge_root_model = builder.BuildGeRootModel(); | 271 | auto ge_root_model = builder.BuildGeRootModel(); |
| 267 | 272 | ||
| @@ -299,6 +304,12 @@ void RunCaseGraph(TensorHolder &index_tensor, const TaskProducerType &producer_t | |||
| 299 | void RunGraphFailThenSuccess(const TaskProducerType &producer_type) { | 304 | void RunGraphFailThenSuccess(const TaskProducerType &producer_type) { |
| 300 | auto graph = ShareGraph::IfCondByShapeGraph(); | 305 | auto graph = ShareGraph::IfCondByShapeGraph(); |
| 301 | graph->TopologicalSorting(); | 306 | graph->TopologicalSorting(); |
| 307 | + auto pred_data_desc = graph->FindNode("pred")->GetOpDesc()->MutableOutputDesc(0); | ||
| 308 | + pred_data_desc->SetShape(ge::GeShape()); | ||
| 309 | + pred_data_desc->SetOriginShape(ge::GeShape()); | ||
| 310 | + auto input_data_desc = graph->FindNode("input")->GetOpDesc()->MutableOutputDesc(0); | ||
| 311 | + input_data_desc->SetShape(ge::GeShape({2, 3, 4, 6})); | ||
| 312 | + input_data_desc->SetOriginShape(ge::GeShape({2, 3, 4, 6})); | ||
| 302 | const char *const Cast = "Cast"; | 313 | const char *const Cast = "Cast"; |
| 303 | auto ge_root_model = GeModelBuilder(graph) | 314 | auto ge_root_model = GeModelBuilder(graph) |
| 304 | .AddTaskDef("Add", AiCoreTaskDefFaker("AddStubBin").WithHandle()) | 315 | .AddTaskDef("Add", AiCoreTaskDefFaker("AddStubBin").WithHandle()) |
| @@ -143,8 +143,10 @@ class RuleMaker { | |||
| 143 | 143 | ||
| 144 | RuleMaker &Input(const Json::array_t &input, std::initializer_list<int64_t> dims) { | 144 | RuleMaker &Input(const Json::array_t &input, std::initializer_list<int64_t> dims) { |
| 145 | json["shape"]["inputs"].push_back(input); | 145 | json["shape"]["inputs"].push_back(input); |
| 146 | - inputs.emplace_back(FakeTensors(dims, 1)); | 146 | + constexpr size_t kDslDefaultDataDescSize = 1 * 1 * 224 * 224 * sizeof(float); |
| 147 | - input_ptrs.push_back(&inputs.back().at(0)); | 147 | + input_holders.emplace_back( |
| 148 | + TensorFaker().Shape(dims).DataType(ge::DT_FLOAT).Placement(kOnDeviceHbm).Size(kDslDefaultDataDescSize).Build()); | ||
| 149 | + input_ptrs.push_back(input_holders.back().GetTensor()); | ||
| 148 | return *this; | 150 | return *this; |
| 149 | } | 151 | } |
| 150 | 152 | ||
| @@ -176,7 +178,7 @@ class RuleMaker { | |||
| 176 | 178 | ||
| 177 | Json json; | 179 | Json json; |
| 178 | 180 | ||
| 179 | - std::vector<FakeTensors> inputs; | 181 | + std::vector<TensorHolder> input_holders; |
| 180 | std::vector<FakeTensors> outputs; | 182 | std::vector<FakeTensors> outputs; |
| 181 | std::vector<std::shared_ptr<std::vector<int32_t>>> output_holders; | 183 | std::vector<std::shared_ptr<std::vector<int32_t>>> output_holders; |
| 182 | 184 | ||
| @@ -149,6 +149,9 @@ TEST_F(TilingCacheSt, PriorityTopologicalExecute_Ok_EnableTilingCache) { | |||
| 149 | auto compute_graph = ShareGraph::IfGraph4(); | 149 | auto compute_graph = ShareGraph::IfGraph4(); |
| 150 | ASSERT_NE(compute_graph, nullptr); | 150 | ASSERT_NE(compute_graph, nullptr); |
| 151 | compute_graph->TopologicalSorting(); | 151 | compute_graph->TopologicalSorting(); |
| 152 | + auto pred_data_desc = compute_graph->FindNode("pred")->GetOpDesc()->MutableOutputDesc(0); | ||
| 153 | + pred_data_desc->SetShape(ge::GeShape()); | ||
| 154 | + pred_data_desc->SetOriginShape(ge::GeShape()); | ||
| 152 | GE_DUMP(compute_graph, "computegraph_IfGraph4"); | 155 | GE_DUMP(compute_graph, "computegraph_IfGraph4"); |
| 153 | 156 | ||
| 154 | auto ge_root_model = | 157 | auto ge_root_model = |
| @@ -201,6 +204,9 @@ TEST_F(TilingCacheSt, PriorityTopologicalExecute_Ok_SameStorageShapeMissCache) { | |||
| 201 | auto compute_graph = ShareGraph::IfGraph4(); | 204 | auto compute_graph = ShareGraph::IfGraph4(); |
| 202 | ASSERT_NE(compute_graph, nullptr); | 205 | ASSERT_NE(compute_graph, nullptr); |
| 203 | compute_graph->TopologicalSorting(); | 206 | compute_graph->TopologicalSorting(); |
| 207 | + auto pred_data_desc = compute_graph->FindNode("pred")->GetOpDesc()->MutableOutputDesc(0); | ||
| 208 | + pred_data_desc->SetShape(ge::GeShape()); | ||
| 209 | + pred_data_desc->SetOriginShape(ge::GeShape()); | ||
| 204 | GE_DUMP(compute_graph, "computegraph_IfGraph4"); | 210 | GE_DUMP(compute_graph, "computegraph_IfGraph4"); |
| 205 | 211 | ||
| 206 | auto ge_root_model = | 212 | auto ge_root_model = |
| @@ -1107,6 +1107,7 @@ TEST_F(InferAndFoldingTest, test_If_InferShape_change_rank_in_branch) { | |||
| 1107 | TensorDesc input_tensor_desc(Shape({2, 3, 1, 3}), FORMAT_ND, DT_FLOAT); | 1107 | TensorDesc input_tensor_desc(Shape({2, 3, 1, 3}), FORMAT_ND, DT_FLOAT); |
| 1108 | input_tensor_desc.SetPlacement(kPlacementDevice); | 1108 | input_tensor_desc.SetPlacement(kPlacementDevice); |
| 1109 | Tensor input(input_tensor_desc); | 1109 | Tensor input(input_tensor_desc); |
| 1110 | + input.SetData(std::vector<uint8_t>(72U, 0U)); | ||
| 1110 | std::vector<int64_t> scaler_shape = {}; | 1111 | std::vector<int64_t> scaler_shape = {}; |
| 1111 | Tensor pred{TensorDesc(Shape(scaler_shape), FORMAT_ND, DT_INT32)}; | 1112 | Tensor pred{TensorDesc(Shape(scaler_shape), FORMAT_ND, DT_INT32)}; |
| 1112 | Tensor output(input_tensor_desc); | 1113 | Tensor output(input_tensor_desc); |
| @@ -4985,7 +4985,7 @@ TEST_F(UtestFormatTranspose, transpose_with_shape_check_mismatch) { | |||
| 4985 | uint16_t data[6] = {1, 2, 3, 4, 5, 6}; | 4985 | uint16_t data[6] = {1, 2, 3, 4, 5, 6}; |
| 4986 | TransResult result; | 4986 | TransResult result; |
| 4987 | auto ret = TransposeWithShapeCheck(reinterpret_cast<uint8_t *>(data), {2, 3}, {2, 3}, DT_FLOAT16, {1, 0}, result); | 4987 | auto ret = TransposeWithShapeCheck(reinterpret_cast<uint8_t *>(data), {2, 3}, {2, 3}, DT_FLOAT16, {1, 0}, result); |
| 4988 | - EXPECT_TRUE((ret == SUCCESS) || (ret == ACL_ERROR_GE_SHAPE_INVALID)); | 4988 | + EXPECT_EQ(ret, ACL_ERROR_GE_SHAPE_INVALID); |
| 4989 | } | 4989 | } |
| 4990 | 4990 | ||
| 4991 | TEST_F(UtestFormatTranspose, get_perm_by_format_not_support_src) { | 4991 | TEST_F(UtestFormatTranspose, get_perm_by_format_not_support_src) { |
| @@ -295,6 +295,182 @@ TEST_F(ExecutorUnitTest, CheckParam_Failed_WhenNullIoTensor) { | |||
| 295 | output_tensors.data(), outputs.size()), | 295 | output_tensors.data(), outputs.size()), |
| 296 | ge::GRAPH_SUCCESS); | 296 | ge::GRAPH_SUCCESS); |
| 297 | } | 297 | } |
| 298 | +TEST_F(ExecutorUnitTest, CheckUserInputSize_Failed_WhenUserBufferTooSmall) { | ||
| 299 | + auto exe_graph = BuildExeGraphFromSingleNodeWithShapeAndRange( | ||
| 300 | + {{256}, {256}, {256}, {256}}, {{256}, {256}, {256}, {256}}, {{256}, {256}, {256}, {256}}); | ||
| 301 | + ASSERT_NE(exe_graph, nullptr); | ||
| 302 | + | ||
| 303 | + GertRuntimeStub stub; | ||
| 304 | + stub.GetKernelStub().AllKernelRegisteredAndSuccess(); | ||
| 305 | + | ||
| 306 | + auto compute_graph = std::make_shared<ge::ComputeGraph>("tests"); | ||
| 307 | + auto root_model = GeModelBuilder(compute_graph).BuildGeRootModel(); | ||
| 308 | + auto model_executor = ModelV2Executor::Create(exe_graph, root_model); | ||
| 309 | + ASSERT_NE(model_executor, nullptr); | ||
| 310 | + ASSERT_EQ(model_executor->Load(), ge::GRAPH_SUCCESS); | ||
| 311 | + | ||
| 312 | + const auto *input_desc = model_executor->GetModelDesc().GetInputDesc(0); | ||
| 313 | + ASSERT_NE(input_desc, nullptr); | ||
| 314 | + const int64_t expected_size = input_desc->GetSize(); | ||
| 315 | + ASSERT_GT(expected_size, 0); | ||
| 316 | + | ||
| 317 | + auto outputs = FakeTensors({256}, 1); | ||
| 318 | + auto small_input = | ||
| 319 | + FakeValue<Tensor>(Tensor{{{256}, {4}}, {ge::FORMAT_ND, ge::FORMAT_ND, {}}, kOnDeviceHbm, ge::DT_FLOAT, 0}); | ||
| 320 | + auto normal_input = | ||
| 321 | + FakeValue<Tensor>(Tensor{{{256}, {256}}, {ge::FORMAT_ND, ge::FORMAT_ND, {}}, kOnDeviceHbm, ge::DT_FLOAT, 0}); | ||
| 322 | + Tensor *inputs[] = {small_input.holder.get(), normal_input.holder.get()}; | ||
| 323 | + ASSERT_EQ(model_executor->Execute({nullptr}, inputs, 2U, reinterpret_cast<Tensor **>(outputs.GetAddrList()), | ||
| 324 | + outputs.size()), | ||
| 325 | + ge::PARAM_INVALID); | ||
| 326 | + EXPECT_EQ(model_executor->UnLoad(), ge::GRAPH_SUCCESS); | ||
| 327 | +} | ||
| 328 | + | ||
| 329 | +TEST_F(ExecutorUnitTest, CheckUserInputSize_Success_WhenDynamicShape) { | ||
| 330 | + GertRuntimeStub stub; | ||
| 331 | + stub.GetKernelStub().AllKernelRegisteredAndSuccess(); | ||
| 332 | + | ||
| 333 | + auto model_executor = BuildExecutorFromSingleNode().executor; | ||
| 334 | + ASSERT_NE(model_executor, nullptr); | ||
| 335 | + ASSERT_EQ(model_executor->Load(), ge::GRAPH_SUCCESS); | ||
| 336 | + | ||
| 337 | + const auto *input_desc = model_executor->GetModelDesc().GetInputDesc(0); | ||
| 338 | + ASSERT_NE(input_desc, nullptr); | ||
| 339 | + EXPECT_EQ(input_desc->GetSize(), 0); | ||
| 340 | + | ||
| 341 | + auto outputs = FakeTensors({2}, 1); | ||
| 342 | + auto input0 = | ||
| 343 | + FakeValue<Tensor>(Tensor{{{256}, {256}}, {ge::FORMAT_ND, ge::FORMAT_ND, {}}, kOnDeviceHbm, ge::DT_FLOAT16, 0}); | ||
| 344 | + auto input1 = | ||
| 345 | + FakeValue<Tensor>(Tensor{{{256}, {256}}, {ge::FORMAT_ND, ge::FORMAT_ND, {}}, kOnDeviceHbm, ge::DT_FLOAT16, 0}); | ||
| 346 | + Tensor *inputs[] = {input0.holder.get(), input1.holder.get()}; | ||
| 347 | + ASSERT_EQ(model_executor->Execute({nullptr}, inputs, 2U, reinterpret_cast<Tensor **>(outputs.GetAddrList()), | ||
| 348 | + outputs.size()), | ||
| 349 | + ge::GRAPH_SUCCESS); | ||
| 350 | + EXPECT_EQ(model_executor->UnLoad(), ge::GRAPH_SUCCESS); | ||
| 351 | +} | ||
| 352 | + | ||
| 353 | +TEST_F(ExecutorUnitTest, CheckUserInputSize_Warning_WhenUserBufferLarger) { | ||
| 354 | + auto exe_graph = BuildExeGraphFromSingleNodeWithShapeAndRange( | ||
| 355 | + {{256}, {256}, {256}, {256}}, {{256}, {256}, {256}, {256}}, {{256}, {256}, {256}, {256}}); | ||
| 356 | + ASSERT_NE(exe_graph, nullptr); | ||
| 357 | + | ||
| 358 | + GertRuntimeStub stub; | ||
| 359 | + stub.GetKernelStub().AllKernelRegisteredAndSuccess(); | ||
| 360 | + | ||
| 361 | + auto compute_graph = std::make_shared<ge::ComputeGraph>("tests"); | ||
| 362 | + auto root_model = GeModelBuilder(compute_graph).BuildGeRootModel(); | ||
| 363 | + auto model_executor = ModelV2Executor::Create(exe_graph, root_model); | ||
| 364 | + ASSERT_NE(model_executor, nullptr); | ||
| 365 | + ASSERT_EQ(model_executor->Load(), ge::GRAPH_SUCCESS); | ||
| 366 | + | ||
| 367 | + auto outputs = FakeTensors({256}, 1); | ||
| 368 | + auto large_input = | ||
| 369 | + FakeValue<Tensor>(Tensor{{{512}, {512}}, {ge::FORMAT_ND, ge::FORMAT_ND, {}}, kOnDeviceHbm, ge::DT_FLOAT, 0}); | ||
| 370 | + auto normal_input = | ||
| 371 | + FakeValue<Tensor>(Tensor{{{256}, {256}}, {ge::FORMAT_ND, ge::FORMAT_ND, {}}, kOnDeviceHbm, ge::DT_FLOAT, 0}); | ||
| 372 | + Tensor *inputs[] = {large_input.holder.get(), normal_input.holder.get()}; | ||
| 373 | + ASSERT_EQ(model_executor->Execute({nullptr}, inputs, 2U, reinterpret_cast<Tensor **>(outputs.GetAddrList()), | ||
| 374 | + outputs.size()), | ||
| 375 | + ge::GRAPH_SUCCESS); | ||
| 376 | + EXPECT_EQ(model_executor->UnLoad(), ge::GRAPH_SUCCESS); | ||
| 377 | +} | ||
| 378 | + | ||
| 379 | +TEST_F(ExecutorUnitTest, CheckUserInputSize_Success_WhenUserSizeMatchesExactly) { | ||
| 380 | + auto exe_graph = BuildExeGraphFromSingleNodeWithShapeAndRange( | ||
| 381 | + {{256}, {256}, {256}, {256}}, {{256}, {256}, {256}, {256}}, {{256}, {256}, {256}, {256}}); | ||
| 382 | + ASSERT_NE(exe_graph, nullptr); | ||
| 383 | + | ||
| 384 | + GertRuntimeStub stub; | ||
| 385 | + stub.GetKernelStub().AllKernelRegisteredAndSuccess(); | ||
| 386 | + | ||
| 387 | + auto compute_graph = std::make_shared<ge::ComputeGraph>("tests"); | ||
| 388 | + auto root_model = GeModelBuilder(compute_graph).BuildGeRootModel(); | ||
| 389 | + auto model_executor = ModelV2Executor::Create(exe_graph, root_model); | ||
| 390 | + ASSERT_NE(model_executor, nullptr); | ||
| 391 | + ASSERT_EQ(model_executor->Load(), ge::GRAPH_SUCCESS); | ||
| 392 | + | ||
| 393 | + const auto *input_desc = model_executor->GetModelDesc().GetInputDesc(0); | ||
| 394 | + ASSERT_NE(input_desc, nullptr); | ||
| 395 | + const int64_t expected_size = input_desc->GetSize(); | ||
| 396 | + ASSERT_GT(expected_size, 0); | ||
| 397 | + | ||
| 398 | + auto outputs = FakeTensors({256}, 1); | ||
| 399 | + auto exact_input = | ||
| 400 | + FakeValue<Tensor>(Tensor{{{256}, {256}}, {ge::FORMAT_ND, ge::FORMAT_ND, {}}, kOnDeviceHbm, ge::DT_FLOAT, 0}); | ||
| 401 | + auto normal_input = | ||
| 402 | + FakeValue<Tensor>(Tensor{{{256}, {256}}, {ge::FORMAT_ND, ge::FORMAT_ND, {}}, kOnDeviceHbm, ge::DT_FLOAT, 0}); | ||
| 403 | + Tensor *inputs[] = {exact_input.holder.get(), normal_input.holder.get()}; | ||
| 404 | + ASSERT_EQ(model_executor->Execute({nullptr}, inputs, 2U, reinterpret_cast<Tensor **>(outputs.GetAddrList()), | ||
| 405 | + outputs.size()), | ||
| 406 | + ge::GRAPH_SUCCESS); | ||
| 407 | + EXPECT_EQ(model_executor->UnLoad(), ge::GRAPH_SUCCESS); | ||
| 408 | +} | ||
| 409 | + | ||
| 410 | +TEST_F(ExecutorUnitTest, CheckUserInputSize_Success_WhenWithinAlignTolerance) { | ||
| 411 | + auto exe_graph = BuildExeGraphFromSingleNodeWithShapeAndRange( | ||
| 412 | + {{256}, {256}, {256}, {256}}, {{256}, {256}, {256}, {256}}, {{256}, {256}, {256}, {256}}); | ||
| 413 | + ASSERT_NE(exe_graph, nullptr); | ||
| 414 | + | ||
| 415 | + GertRuntimeStub stub; | ||
| 416 | + stub.GetKernelStub().AllKernelRegisteredAndSuccess(); | ||
| 417 | + | ||
| 418 | + auto compute_graph = std::make_shared<ge::ComputeGraph>("tests"); | ||
| 419 | + auto root_model = GeModelBuilder(compute_graph).BuildGeRootModel(); | ||
| 420 | + auto model_executor = ModelV2Executor::Create(exe_graph, root_model); | ||
| 421 | + ASSERT_NE(model_executor, nullptr); | ||
| 422 | + ASSERT_EQ(model_executor->Load(), ge::GRAPH_SUCCESS); | ||
| 423 | + | ||
| 424 | + const auto *input_desc = model_executor->GetModelDesc().GetInputDesc(0); | ||
| 425 | + ASSERT_NE(input_desc, nullptr); | ||
| 426 | + const int64_t expected_size = input_desc->GetSize(); | ||
| 427 | + ASSERT_GT(expected_size, 0); | ||
| 428 | + | ||
| 429 | + auto outputs = FakeTensors({256}, 1); | ||
| 430 | + auto slightly_small_input = | ||
| 431 | + FakeValue<Tensor>(Tensor{{{256}, {240}}, {ge::FORMAT_ND, ge::FORMAT_ND, {}}, kOnDeviceHbm, ge::DT_FLOAT, 0}); | ||
| 432 | + auto normal_input = | ||
| 433 | + FakeValue<Tensor>(Tensor{{{256}, {256}}, {ge::FORMAT_ND, ge::FORMAT_ND, {}}, kOnDeviceHbm, ge::DT_FLOAT, 0}); | ||
| 434 | + Tensor *inputs[] = {slightly_small_input.holder.get(), normal_input.holder.get()}; | ||
| 435 | + ASSERT_EQ(model_executor->Execute({nullptr}, inputs, 2U, reinterpret_cast<Tensor **>(outputs.GetAddrList()), | ||
| 436 | + outputs.size()), | ||
| 437 | + ge::GRAPH_SUCCESS); | ||
| 438 | + EXPECT_EQ(model_executor->UnLoad(), ge::GRAPH_SUCCESS); | ||
| 439 | +} | ||
| 440 | + | ||
| 441 | +TEST_F(ExecutorUnitTest, CheckUserInputSize_Success_WhenUserSizeNearOverflow) { | ||
| 442 | + auto exe_graph = BuildExeGraphFromSingleNodeWithShapeAndRange( | ||
| 443 | + {{256}, {256}, {256}, {256}}, {{256}, {256}, {256}, {256}}, {{256}, {256}, {256}, {256}}); | ||
| 444 | + ASSERT_NE(exe_graph, nullptr); | ||
| 445 | + | ||
| 446 | + GertRuntimeStub stub; | ||
| 447 | + stub.GetKernelStub().AllKernelRegisteredAndSuccess(); | ||
| 448 | + | ||
| 449 | + auto compute_graph = std::make_shared<ge::ComputeGraph>("tests"); | ||
| 450 | + auto root_model = GeModelBuilder(compute_graph).BuildGeRootModel(); | ||
| 451 | + auto model_executor = ModelV2Executor::Create(exe_graph, root_model); | ||
| 452 | + ASSERT_NE(model_executor, nullptr); | ||
| 453 | + ASSERT_EQ(model_executor->Load(), ge::GRAPH_SUCCESS); | ||
| 454 | + | ||
| 455 | + auto &model_desc = const_cast<ModelDesc &>(model_executor->GetModelDesc()); | ||
| 456 | + auto *input_desc = model_desc.MutableInputDesc(0); | ||
| 457 | + ASSERT_NE(input_desc, nullptr); | ||
| 458 | + input_desc->MutableStorageShape() = {INT64_MAX / 4}; | ||
| 459 | + const int64_t expected_size = model_executor->GetModelDesc().GetInputDesc(0)->GetSize(); | ||
| 460 | + ASSERT_GT(expected_size, 0); | ||
| 461 | + | ||
| 462 | + auto outputs = FakeTensors({256}, 1); | ||
| 463 | + auto very_large_holder = | ||
| 464 | + TensorFaker().Shape({256}).DataType(ge::DT_FLOAT).Size(static_cast<size_t>(INT64_MAX - 10)).Build(); | ||
| 465 | + auto normal_input = | ||
| 466 | + FakeValue<Tensor>(Tensor{{{256}, {256}}, {ge::FORMAT_ND, ge::FORMAT_ND, {}}, kOnDeviceHbm, ge::DT_FLOAT, 0}); | ||
| 467 | + Tensor *inputs[] = {very_large_holder.GetTensor(), normal_input.holder.get()}; | ||
| 468 | + ASSERT_EQ(model_executor->Execute({nullptr}, inputs, 2U, reinterpret_cast<Tensor **>(outputs.GetAddrList()), | ||
| 469 | + outputs.size()), | ||
| 470 | + ge::GRAPH_SUCCESS); | ||
| 471 | + EXPECT_EQ(model_executor->UnLoad(), ge::GRAPH_SUCCESS); | ||
| 472 | +} | ||
| 473 | + | ||
| 298 | TEST_F(ExecutorUnitTest, test_graph_executor_for_add_graph_run_success) { | 474 | TEST_F(ExecutorUnitTest, test_graph_executor_for_add_graph_run_success) { |
| 299 | GertRuntimeStub stub; | 475 | GertRuntimeStub stub; |
| 300 | stub.GetKernelStub().AllKernelRegisteredAndSuccess(); | 476 | stub.GetKernelStub().AllKernelRegisteredAndSuccess(); |
Mtests/ge/ut/ge/runtime/fast_v2/core/multi_thread_executor/schedule/kernel_task_producer_unittest.cc+2-3
| @@ -186,16 +186,15 @@ TEST_F(KernelTaskProducerUnitTest, kernel_while_graph_success) { | |||
| 186 | auto model_executor = ModelV2Executor::Create(exe_graph, option, ge_root_model); | 186 | auto model_executor = ModelV2Executor::Create(exe_graph, option, ge_root_model); |
| 187 | ASSERT_NE(model_executor, nullptr); | 187 | ASSERT_NE(model_executor, nullptr); |
| 188 | 188 | ||
| 189 | - int32_t output = 0; | ||
| 190 | ASSERT_EQ(model_executor->Load(), ge::GRAPH_SUCCESS); | 189 | ASSERT_EQ(model_executor->Load(), ge::GRAPH_SUCCESS); |
| 191 | - auto outputs = FakeTensors({}, 1, &output); | 190 | + auto outputs = FakeTensors({1, 1, 224, 224}, 1); |
| 192 | 191 | ||
| 193 | rtStream_t stream; | 192 | rtStream_t stream; |
| 194 | ASSERT_EQ(aclrtCreateStreamWithConfig(&stream, static_cast<uint32_t>(RT_STREAM_PRIORITY_DEFAULT), 0U), | 193 | ASSERT_EQ(aclrtCreateStreamWithConfig(&stream, static_cast<uint32_t>(RT_STREAM_PRIORITY_DEFAULT), 0U), |
| 195 | RT_ERROR_NONE); | 194 | RT_ERROR_NONE); |
| 196 | auto i1 = FakeValue<uint64_t>(reinterpret_cast<uint64_t>(stream)); | 195 | auto i1 = FakeValue<uint64_t>(reinterpret_cast<uint64_t>(stream)); |
| 197 | 196 | ||
| 198 | - auto inputs = FakeTensors({}, 1); | 197 | + auto inputs = FakeTensors({1, 1, 224, 224}, 1); |
| 199 | *static_cast<int32_t *>(inputs.data()[0].GetAddr()) = 0; | 198 | *static_cast<int32_t *>(inputs.data()[0].GetAddr()) = 0; |
| 200 | 199 | ||
| 201 | ASSERT_EQ(model_executor->Execute({i1.value}, inputs.GetTensorList(), inputs.size(), outputs.GetTensorList(), | 200 | ASSERT_EQ(model_executor->Execute({i1.value}, inputs.GetTensorList(), inputs.size(), outputs.GetTensorList(), |
| @@ -132,8 +132,10 @@ class RuleMaker { | |||
| 132 | 132 | ||
| 133 | RuleMaker &Input(const Json::array_t &input, std::initializer_list<int64_t> dims) { | 133 | RuleMaker &Input(const Json::array_t &input, std::initializer_list<int64_t> dims) { |
| 134 | json["shape"]["inputs"].push_back(input); | 134 | json["shape"]["inputs"].push_back(input); |
| 135 | - inputs.emplace_back(FakeTensors(dims, 1)); | 135 | + constexpr size_t kDslDefaultDataDescSize = 1 * 1 * 224 * 224 * sizeof(float); |
| 136 | - input_ptrs.push_back(&inputs.back().at(0)); | 136 | + input_holders.emplace_back( |
| 137 | + TensorFaker().Shape(dims).DataType(ge::DT_FLOAT).Placement(kOnDeviceHbm).Size(kDslDefaultDataDescSize).Build()); | ||
| 138 | + input_ptrs.push_back(input_holders.back().GetTensor()); | ||
| 137 | return *this; | 139 | return *this; |
| 138 | } | 140 | } |
| 139 | 141 | ||
| @@ -165,7 +167,7 @@ class RuleMaker { | |||
| 165 | 167 | ||
| 166 | Json json; | 168 | Json json; |
| 167 | 169 | ||
| 168 | - std::vector<FakeTensors> inputs; | 170 | + std::vector<TensorHolder> input_holders; |
| 169 | std::vector<FakeTensors> outputs; | 171 | std::vector<FakeTensors> outputs; |
| 170 | std::vector<std::shared_ptr<std::vector<int32_t>>> output_holders; | 172 | std::vector<std::shared_ptr<std::vector<int32_t>>> output_holders; |
| 171 | 173 | ||
[高] 当 user_size + kDataMemAlignSizeCompare < expected_size 时,这里只打印告警并继续返回 GRAPH_SUCCESS,Execute() 随后仍会调用 SpecifyInputs 并执行模型。PR 描述要求该场景返回 PARAM_INVALID,否则用户 buffer 小于模型所需大小时仍可能继续执行并导致越界访问或推理异常。建议在此分支返回 ge::PARAM_INVALID,按照描述上报E13025错误码,并同步修正对应 UT 的期望值。
参考:编码红线