| 593 | namespace { |
| 594 | |
| 595 | void test_output_no_copy(int record) { |
| 596 | Config config; |
| 597 | config.options.force_output_use_user_specified_memory = true; |
| 598 | config.options.comp_node_seq_record_level = record; |
| 599 | auto tensor = get_input_data("./input_data.npy"); |
| 600 | std::string model_path = "./shufflenet.mge"; |
| 601 | std::string input_name = "data"; |
| 602 | auto result_mgb = mgb_lar(model_path, config, input_name, tensor); |
| 603 | |
| 604 | std::shared_ptr<Network> network = std::make_shared<Network>(config); |
| 605 | |
| 606 | network->load_model(model_path); |
| 607 | std::shared_ptr<Tensor> input_tensor = network->get_io_tensor(input_name); |
| 608 | |
| 609 | auto src_ptr = tensor->get_memory_ptr(); |
| 610 | auto src_layout = tensor->get_layout(); |
| 611 | input_tensor->reset(src_ptr, src_layout); |
| 612 | |
| 613 | std::shared_ptr<Tensor> output_tensor = network->get_output_tensor(0); |
| 614 | size_t times = 5; |
| 615 | std::vector<std::shared_ptr<Tensor>> result_tensors; |
| 616 | for (size_t i = 0; i < times; i++) { |
| 617 | auto tmp = std::make_shared<Tensor>( |
| 618 | LiteDeviceType::LITE_CPU, |
| 619 | Layout{{1, 1000}, 2, LiteDataType::LITE_FLOAT}); |
| 620 | result_tensors.push_back(tmp); |
| 621 | } |
| 622 | |
| 623 | for (size_t i = 0; i < times; i++) { |
| 624 | void* out_data = result_tensors[i]->get_memory_ptr(); |
| 625 | output_tensor->reset(out_data, result_tensors[i]->get_layout()); |
| 626 | |
| 627 | network->forward(); |
| 628 | network->wait(); |
| 629 | ASSERT_EQ(output_tensor->get_memory_ptr(), out_data); |
| 630 | compare_lite_tensor<float>(output_tensor, result_mgb); |
| 631 | } |
| 632 | for (size_t i = 0; i < times; i++) { |
| 633 | compare_lite_tensor<float>(result_tensors[i], result_mgb); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | void test_input_no_copy(int record) { |
| 638 | Config config; |
no test coverage detected