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

Function load_from_path_run_cuda

lite/example/cpp_example/mge/basic.cpp:450–501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

448#if LITE_WITH_CUDA
449namespace {
450bool load_from_path_run_cuda(const Args& args) {
451 std::string network_path = args.model_path;
452 std::string input_path = args.input_path;
453 set_log_level(LiteLogLevel::DEBUG);
454 //! config the network running in CUDA device
455 lite::Config config{false, -1, LiteDeviceType::LITE_CUDA};
456 //! set NetworkIO
457 NetworkIO network_io;
458 std::string input_name = "img0_comp_fullface";
459 bool is_host = false;
460 IO device_input{input_name, is_host};
461 network_io.inputs.push_back(device_input);
462 //! create and load the network
463 std::shared_ptr<Network> network = std::make_shared<Network>(config, network_io);
464 network->load_model(network_path);
465
466 std::shared_ptr<Tensor> input_tensor = network->get_input_tensor(0);
467 Layout input_layout = input_tensor->get_layout();
468
469 //! read data from numpy data file
470 auto src_tensor = parse_npy(input_path);
471
472 //! malloc the device memory
473 auto tensor_device = Tensor(LiteDeviceType::LITE_CUDA, input_layout);
474
475 //! copy to the device memory
476 tensor_device.copy_from(*src_tensor);
477
478 //! Now the device memory if filled with user input data, set it to the
479 //! input tensor
480 input_tensor->reset(tensor_device.get_memory_ptr(), input_layout);
481
482 //! forward
483 {
484 lite_example_helper::Timer ltimer("warmup");
485 network->forward();
486 network->wait();
487 ltimer.print_used_time(0);
488 }
489 lite_example_helper::Timer ltimer("forward_iter");
490 for (int i = 0; i < 10; i++) {
491 ltimer.reset_start();
492 network->forward();
493 network->wait();
494 ltimer.print_used_time(i);
495 }
496 //! get the output data or read tensor set in network_in
497 size_t output_size = network->get_all_output_name().size();
498 output_info(network, output_size);
499 output_data_info(network, output_size);
500 return true;
501}
502} // namespace
503
504REGIST_EXAMPLE("load_from_path_run_cuda", load_from_path_run_cuda);

Callers

nothing calls this directly

Calls 15

output_infoFunction · 0.85
output_data_infoFunction · 0.85
set_log_levelFunction · 0.50
TensorClass · 0.50
push_backMethod · 0.45
load_modelMethod · 0.45
get_input_tensorMethod · 0.45
get_layoutMethod · 0.45
copy_fromMethod · 0.45
resetMethod · 0.45
get_memory_ptrMethod · 0.45
forwardMethod · 0.45

Tested by

no test coverage detected