libtorch 报错 PyTorch is not linked with support for cuda devices
what(): PyTorch is not linked with support for cuda devices
Exception raised from getDeviceGuardImpl at /data_1/code/Libtorch/pytorch_1.7.1/c10/core/impl/DeviceGuardImplInterface.h:216 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) + 0x69 (0x7f8ba5350fd9 in /data_2/project_2021/tensorrt_psenet/psenet_now/3rdparty/3rdparty_10.2/libtorch/lib/libc10.so)
frame #1: at::native::to(at::Tensor const&, c10::TensorOptions const&, bool, bool, c10::optional<c10::MemoryFormat>) + 0x20da (0x7f8ba094c68a in /data_2/project_2021/tensorrt_psenet/psenet_now/3rdparty/3rdparty_10.2/libtorch/lib/libtorch_cpu.so)
frame #2: <unknown function> + 0x11a0786 (0x7f8ba0eb2786 in /data_2/project_2021/tensorrt_psenet/psenet_now/3rdparty/3rdparty_10.2/libtorch/lib/libtorch_cpu.so)
frame #3: <unknown function> + 0x11fe953 (0x7f8ba0f10953 in /data_2/project_2021/tensorrt_psenet/psenet_now/3rdparty/3rdparty_10.2/libtorch/lib/libtorch_cpu.so)
frame #4: <unknown function> + 0x7431ef (0x7f8ba04551ef in /data_2/project_2021/tensorrt_psenet/psenet_now/3rdparty/3rdparty_10.2/libtorch/lib/libtorch_cpu.so)
frame #5: <unknown function> + 0xf435fa (0x7f8ba0c555fa in /data_2/project_2021/tensorrt_psenet/psenet_now/3rdparty/3rdparty_10.2/libtorch/lib/libtorch_cpu.so)
frame #6: at::Tensor::to(c10::TensorOptions const&, bool, bool, c10::optional<c10::MemoryFormat>) const + 0x315 (0x7f8ba0f931e5 in /data_2/project_2021/tensorrt_psenet/psenet_now/3rdparty/3rdparty_10.2/libtorch/lib/libtorch_cpu.so)
frame #7: at::Tensor::cuda() const + 0xc1 (0x7f8ba0f93901 in /data_2/project_2021/tensorrt_psenet/psenet_now/3rdparty/3rdparty_10.2/libtorch/lib/libtorch_cpu.so)
frame #8: general_process_pse_mingpai(cv::Mat&, int, int, nvinfer1::IExecutionContext&) + 0x793 (0x40fbf3 in /data_2/project_2021/tensorrt_psenet/psenet_now/cmake-build-debug/psenet)
frame #9: process_contour(cv::Mat&, int, nvinfer1::IExecutionContext&, int, int, bool) + 0xeb (0x410e5b in /data_2/project_2021/tensorrt_psenet/psenet_now/cmake-build-debug/psenet)
frame #10: main + 0x487 (0x40dcd7 in /data_2/project_2021/tensorrt_psenet/psenet_now/cmake-build-debug/psenet)
frame #11: __libc_start_main + 0xf0 (0x7f8b9f10f840 in /lib/x86_64-linux-gnu/libc.so.6)
frame #12: _start + 0x29 (0x40e4f9 in /data_2/project_2021/tensorrt_psenet/psenet_now/cmake-build-debug/psenet)
请确认在代码中加如下:
std::cout << "CUDA: " << torch::cuda::is_available() << std::endl;
std::cout << "CUDNN: " << torch::cuda::cudnn_is_available() << std::endl;
std::cout << "GPU(s): " << torch::cuda::device_count() << std::endl;
torch::Tensor aa = tensor_image.cuda();
while(1);
三个都打印出0,并且一执行tensor_image.cuda();就会奔溃。那么这种情况解决方案是:在cmakelist写
target_link_libraries(psenet c10 c10_cuda torch torch_cuda torch_cpu "-Wl,--no-as-needed -ltorch_cuda")
就可以解决
好记性不如烂键盘---点滴、积累、进步!