MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / test_input_no_copy

Function test_input_no_copy

lite/test/test_network.cpp:637–677  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

635}
636
637void test_input_no_copy(int record) {
638 Config config;
639 config.options.force_output_use_user_specified_memory = true;
640 config.options.comp_node_seq_record_level = record;
641 std::string model_path = "./shufflenet.mge";
642 std::string input_name = "data";
643
644 Layout layout_in{{1, 3, 224, 224}, 4};
645 std::vector<std::shared_ptr<Tensor>> inputs;
646 std::vector<std::shared_ptr<Tensor>> outputs;
647 for (int i = 0; i < 3; i++) {
648 auto tmp_in = std::make_shared<Tensor>(LiteDeviceType::LITE_CPU, layout_in);
649
650 auto ptr = static_cast<float*>(tmp_in->get_memory_ptr());
651 for (size_t id = 0; id < 2 * 224 * 224; id++) {
652 ptr[id] = i + 1;
653 }
654 inputs.push_back(tmp_in);
655 outputs.push_back(mgb_lar(model_path, config, input_name, tmp_in));
656 }
657
658 std::shared_ptr<Network> network = std::make_shared<Network>(config);
659
660 network->load_model(model_path);
661 std::shared_ptr<Tensor> input_tensor = network->get_io_tensor(input_name);
662 std::shared_ptr<Tensor> output_tensor = network->get_output_tensor(0);
663
664 for (int i = 0; i < 3; i++) {
665 auto ptr = inputs[i]->get_memory_ptr();
666 input_tensor->reset(ptr, layout_in);
667
668 auto tmp_out = std::make_shared<Tensor>(
669 LiteDeviceType::LITE_CPU,
670 Layout{{1, 1000}, 2, LiteDataType::LITE_FLOAT});
671 output_tensor->reset(tmp_out->get_memory_ptr(), output_tensor->get_layout());
672
673 network->forward();
674 network->wait();
675 compare_lite_tensor<float>(output_tensor, outputs[i]);
676 }
677}
678
679void test_io_no_copy_ax(std::string model_name, int record = 1) {
680 std::string model_path = model_name;

Callers 1

TESTFunction · 0.85

Calls 10

mgb_larFunction · 0.85
get_memory_ptrMethod · 0.45
push_backMethod · 0.45
load_modelMethod · 0.45
get_io_tensorMethod · 0.45
get_output_tensorMethod · 0.45
resetMethod · 0.45
get_layoutMethod · 0.45
forwardMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected