libtorch c++ call (5)

A summary of the problems that may be encountered when calling libtorch c++.

1. Computing power mismatch problem

import torch
import torchvision
print(torch.cuda.is_available())

The above command only detects whether CUDA is installed correctly and can be detected by Pytorch, but does not indicate whether it can be used normally. If you want to see if Pytorch can call cuda acceleration, you need a simple test:

a = torch.Tensor(5,3)
a=a.cuda()
print(a)

Generally speaking, the output is mainly the 48th error, which is the problem of CUDA. This problem is due to the support of the hardware. For the graphics card of Hashrate 3.0, this problem will occur if CUDA 9.0 is installed. The way is to return to CUDA8.0, or change to a more high-end graphics card, or compile directly from the source code, and set the corresponding settings in the source code (modify the TORCH_CUDA_ARCH_LIST in the setup.py file, and change this value to the corresponding computing power of the GPU you are currently using !) For the last method, I haven’t tried it yet, but Pytorch is doing a good job, and it’s considered very thoughtful~

The reason for recording these notes is because I encountered that the torchscript model transferred on NVIDIA GForce RTX2070 crashed on NVIDIA GForce GTX1080Ti, and an error was reported:

THCudaCheck FAIL file=D:/documents/vs2015/Project/pytorch1.5.1/pytorch/aten/src\THC/generic/THCTensorMathReduce.cu line=73 error=48 : no kernel image is available for execution on the device

The problem is the mismatch of computing power. The computing power of 2070 is 7.5 and that of 1080Ti is 6.1. In the final analysis, it is a hardware problem.

The problem is not the generated model, because the model can also be used normally on the cpu. The problem is that I compile the libtorch-gpu version myself, because there is no problem with the libtorch-gpu on the official website. You need to check the precautions when compiling libtorch.

 

 

Reference: pytorch to view the CUDA support situation, only three lines of code are required, and Cuda runtime error (48): no kernel image is available for execution is attached.

Guess you like

Origin blog.csdn.net/juluwangriyue/article/details/108670882