| 448 | #if LITE_WITH_CUDA |
| 449 | namespace { |
| 450 | bool 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 | |
| 504 | REGIST_EXAMPLE("load_from_path_run_cuda", load_from_path_run_cuda); |
nothing calls this directly
no test coverage detected