How do I get my older GPU that supports CUDA to work with PyTorch 1.4?

I’m using anaconda for python 3.7, and have CUDA 10.1 installed. My GPU is a GTX 760, with 3.0 CUDA capability. I’m getting true values for torch.cuda.is_available , but I keep getting this error whenever I try to use CUDA for anything.

Here’s the error:
RuntimeError: CUDA error: no kernel image is available for execution on the device

I was wondering how I could use my GPU with PyTorch, and if it would work for newer versions. I’ve heard that other people had to build their pytorch from source, but I am new and the instructions weren’t completely clear to me.

Any assistance would be greatly appreciated, and thank you in advance!

The binaries are built for devices with compute capability >= 3.7, which is why you are seeing this error.
To build from source, you could follow these instructions.
Let us know, if you get stuck and we can most likely help you out. :slight_smile:

Thanks for responding!

While trying to build from source, I was given this issue, and I am unsure as to how I can work around this! Any input would be greatly appreciated!

Traceback (most recent call last):
  File "setup.py", line 737, in <module>
    build_deps()
  File "setup.py", line 316, in build_deps
    cmake=cmake)
  File "C:\Users\user\pytorch\tools\build_pytorch_libs.py", line 62, in build_caffe2
    cmake.build(my_env)
  File "C:\Users\user\pytorch\tools\setup_helpers\cmake.py", line 341, in build
    self.run(build_args, my_env)
  File "C:\Users\user\pytorch\tools\setup_helpers\cmake.py", line 141, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "D:\Users\user\Anaconda3\lib\subprocess.py", line 347, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '-j', '8']' returned non-zero exit status 1.

Could you post the complete stack trace as it seems the actual error message is missing? :slight_smile:

I’m not fully familiar with what a stack trace is, and it is hard for me to find where the error began. Here is the closest approximation that I could find. If you would like the entire output, I can try to obtain that as well. My apologies if this is not what you asked for. Thank you for your continued assistance!


[1539/2035] Building NVCC (Device) object caffe2/CMakeFiles/torch_cuda.dir/operators/torch_cuda_generated_piecewise_linear_transform_op.cu.obj
FAILED: caffe2/CMakeFiles/torch_cuda.dir/operators/torch_cuda_generated_piecewise_linear_transform_op.cu.obj
cmd.exe /C "cd /D C:\Users\user\pytorch\build\caffe2\CMakeFiles\torch_cuda.dir\operators && D:\Users\user\Anaconda3\Library\bin\cmake.exe -E make_directory C:/Users/user/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/operators/. && D:\Users\user\Anaconda3\Library\bin\cmake.exe -D verbose:BOOL=OFF -D build_configuration:STRING=Release -D generated_file:STRING=C:/Users/user/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/operators/./torch_cuda_generated_piecewise_linear_transform_op.cu.obj -D generated_cubin_file:STRING=C:/Users/user/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/operators/./torch_cuda_generated_piecewise_linear_transform_op.cu.obj.cubin.txt -P C:/Users/user/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/operators/torch_cuda_generated_piecewise_linear_transform_op.cu.obj.Release.cmake"
piecewise_linear_transform_op.cu
piecewise_linear_transform_op.cu
D:/CUDA/CUDA 10.1/Development/include\thrust/system/cuda/detail/scan_by_key.h(204): error C2993: 'KeysInputIt': illegal type for non-type template parameter '__formal'
D:/CUDA/CUDA 10.1/Development/include\thrust/system/cuda/detail/scan_by_key.h(233): note: see reference to class template instantiation 'thrust::cuda_cub::__scan_by_key::ScanByKeyAgent<KeysInputIt,ValuesInputIt,ValuesOutputIt,EqualityOp,ScanOp,Size,T,Inclusive>::PtxPlan<Arch>' being compiled
D:/CUDA/CUDA 10.1/Development/include\thrust/system/cuda/detail/scan_by_key.h(567): note: see reference to class template instantiation 'thrust::cuda_cub::__scan_by_key::ScanByKeyAgent<KeysInputIt,ValuesInputIt,ValuesOutputIt,EqualityOp,ScanOp,Size,T,Inclusive>' being compiled
D:/CUDA/CUDA 10.1/Development/include\thrust/system/cuda/detail/scan_by_key.h(204): error C2993: 'KeysInputIt': illegal type for non-type template parameter '__formal'
D:/CUDA/CUDA 10.1/Development/include\thrust/system/cuda/detail/scan_by_key.h(210): error C2993: 'KeysInputIt': illegal type for non-type template parameter '__formal'
D:/CUDA/CUDA 10.1/Development/include\thrust/system/cuda/detail/scan_by_key.h(210): error C2993: 'KeysInputIt': illegal type for non-type template parameter '__formal'
D:/CUDA/CUDA 10.1/Development/include\thrust/system/cuda/detail/scan_by_key.h(217): error C2993: 'KeysInputIt': illegal type for non-type template parameter '__formal'
D:/CUDA/CUDA 10.1/Development/include\thrust/system/cuda/detail/scan_by_key.h(217): error C2993: 'KeysInputIt': illegal type for non-type template parameter '__formal'
D:/CUDA/CUDA 10.1/Development/include\thrust/system/cuda/detail/scan_by_key.h(223): error C2993: 'KeysInputIt': illegal type for non-type template parameter '__formal'
D:/CUDA/CUDA 10.1/Development/include\thrust/system/cuda/detail/scan_by_key.h(232): note: see reference to class template instantiation 'thrust::cuda_cub::__scan_by_key::ScanByKeyAgent<KeysInputIt,ValuesInputIt,ValuesOutputIt,EqualityOp,ScanOp,Size,T,Inclusive>::PtxPlan<Arch>::TempStorage' being compiled
D:/CUDA/CUDA 10.1/Development/include\thrust/system/cuda/detail/scan_by_key.h(223): error C2993: 'KeysInputIt': illegal type for non-type template parameter '__formal'
D:/CUDA/CUDA 10.1/Development/include\thrust/system/cuda/detail/scan_by_key.h(224): error C2993: 'KeysInputIt': illegal type for non-type template parameter '__formal'
D:/CUDA/CUDA 10.1/Development/include\thrust/system/cuda/detail/scan_by_key.h(224): error C2993: 'KeysInputIt': illegal type for non-type template parameter '__formal'
D:/CUDA/CUDA 10.1/Development/include\thrust/system/cuda/detail/scan_by_key.h(225): error C2993: 'KeysInputIt': illegal type for non-type template parameter '__formal'
D:/CUDA/CUDA 10.1/Development/include\thrust/system/cuda/detail/scan_by_key.h(225): error C2993: 'KeysInputIt': illegal type for non-type template parameter '__formal'
CMake Error at torch_cuda_generated_piecewise_linear_transform_op.cu.obj.Release.cmake:281 (message):
  Error generating file
  C:/Users/user/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/operators/./torch_cuda_generated_piecewise_linear_transform_op.cu.obj


[1540/2035] Building NVCC (Device) object caffe2/CMakeFiles/torch_cuda.dir/operators/torch_cuda_generated_normalize_ops.cu.obj
normalize_ops.cu
normalize_ops.cu
[1541/2035] Building NVCC (Device) object caffe2/CMakeFiles/torch_cuda.dir/operators/torch_cuda_generated_prelu_op.cu.obj
prelu_op.cu
prelu_op.cu
[1542/2035] Building NVCC (Device) object caffe2/CMakeFiles/torch_cuda.dir/operators/torch_cuda_generated_pool_op.cu.obj
pool_op.cu
pool_op.cu
[1543/2035] Building NVCC (Device) object caffe2/CMakeFiles/torch_cuda.dir/operators/torch_cuda_generated_perplexity_op.cu.obj
perplexity_op.cu
perplexity_op.cu
[1544/2035] Building NVCC (Device) object caffe2/CMakeFiles/torch_cuda.dir/operators/torch_cuda_generated_pow_op.cu.obj
pow_op.cu
pow_op.cu
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "setup.py", line 737, in <module>
    build_deps()
  File "setup.py", line 316, in build_deps
    cmake=cmake)
  File "C:\Users\user\pytorch\tools\build_pytorch_libs.py", line 62, in build_caffe2
    cmake.build(my_env)
  File "C:\Users\user\pytorch\tools\setup_helpers\cmake.py", line 341, in build
    self.run(build_args, my_env)
  File "C:\Users\user\pytorch\tools\setup_helpers\cmake.py", line 141, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "D:\Users\user\Anaconda3\lib\subprocess.py", line 347, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '-j', '8']' returned non-zero exit status 1.

(base) C:\Users\user\pytorch>

Thanks for the error message.
Could you refer to this post, install the latest VS 2019, and try to rebuild it?

Please let us know, if you are continuously running into this error, as it seems to be hard to reproduce on the Windows CI.

1 Like

No need to install VS 2019. Just retry the build a few times. If that doesn’t work, then you may need to build from scratch.

2 Likes

I currently have the latest from the Visual Studio build tools 2019. Do I have to install the IDE as well? Or are there any changes that I need to make for in the build?

:: [Optional] If you want to build with VS 2019 generator, please change the value in the next line to `Visual Studio 16 2019`.
:: Note: This value is useless if Ninja is detected. However, you can force that by using `set USE_NINJA=OFF`.
set CMAKE_GENERATOR=Visual Studio 15 2017

I see this in the tutorial from building from source, but I did not include it. If I should add this, what changes would I need to make?

No, just retry the build. I suppose this line is useless since you are using Ninja.

1 Like

I have restarted the process 3 times, would you recommend continuing? If I need to build it from scratch, how is it different from building from source? I am unfamiliar with the process in general.

Would you please try out set MAX_JOBS=1 and then continue the build job?

1 Like

I will give it a try, although when I put in the command, it did not give me any messages indicating that it worked. I assumed that it went through, so I just entered in python setup.py install again.

That’s fine. Just post here when you meet a problem.

The installation worked, but I have yet to test if my cuda now works. I have run into a slight problem with torchvision not being found

ModuleNotFoundError: No module named 'torchvision'

Should I just try conda install torchvision, or would you recommend trying something else? Thank you again for your continued assistance!

Wait! You’ll need to compile torchvision from source too.

1 Like

I will try this. I may be mistaken in the reading of the log, but I think this might be downloading pytorch again.

(base) C:\Users\user\pytorch>pip install torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html
Looking in links: https://download.pytorch.org/whl/torch_stable.html
Collecting torchvision===0.5.0
  Downloading https://files.pythonhosted.org/packages/7d/3e/2b5ddf744226159dc90a52f0d044c0de7c5ca4f42d12a350a674ebb6fb2a/torchvision-0.5.0-cp37-cp37m-win_amd64.whl (1.2MB)
     |████████████████████████████████| 1.2MB 595kB/s
Requirement already satisfied: six in d:\users\user\anaconda3\lib\site-packages (from torchvision===0.5.0) (1.12.0)
Requirement already satisfied: numpy in d:\users\user\anaconda3\lib\site-packages (from torchvision===0.5.0) (1.16.5)
Requirement already satisfied: pillow>=4.1.1 in d:\users\user\anaconda3\lib\site-packages (from torchvision===0.5.0) (6.2.0)
Collecting torch==1.4.0 (from torchvision===0.5.0)
  Downloading https://download.pytorch.org/whl/cu92/torch-1.4.0%2Bcu92-cp37-cp37m-win_amd64.whl (641.8MB)
     |██████████████                  | 286.8MB 726kB/s eta 0:08:09

Sorry for suggesting the wrong thing. Please build torchvision from source too.

Will the command that I entered impact my source build of pytorch?

If that command finishes, then yes. You may need to uninstall them first. pip uninstall torch torchvision And then, reinstall pytorch. python setup.py install

Would you be able to provide any links for building torchvision from source?