MATLAB: CUDA 10.1 not recognized (searching for CUDA 10.0 instead)

cudacuda 10.0cuda 10.1mexcuda

Hey Everyone,
I'm working on a fresh install of an Ubuntu 18.04 system. Everything was going well until I got MATLAB 2019a and was trying to compile GPU code.
Namely, when running
mexcuda mexGPUExample.cu
In MATLAB, it will tell me:
Warning: Version 10.0 of the CUDA toolkit could not be found. If installed, set MW_NVCC_PATH environment variable
to location of nvcc compiler.
> In mexcuda (line 166)
Error using mex
No supported compiler was found. For options, visit https://www.mathworks.com/support/compilers.
Error in mexcuda (line 166)
[varargout{1:nargout}] = mex(mexArguments{:});
So I found my CUDA 10.1 installation at the normal symbolic link place and updated the environment:
setenv('MW_NVCC_PATH','/usr/local/cuda/bin')
Then ran mexcuda again. Still the same error message. However, oddly enough, when I run d = gpuDevice() it works perfectly and shows:
>> d = gpuDevice
d =
CUDADevice with properties:
Name: 'GeForce GTX 1070'
Index: 1
ComputeCapability: '6.1'
SupportsDouble: 1
DriverVersion: 10.1000
ToolkitVersion: 10
MaxThreadsPerBlock: 1024
MaxShmemPerBlock: 49152
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
SIMDWidth: 32
TotalMemory: 8.5126e+09
AvailableMemory: 8.0890e+09
MultiprocessorCount: 15
ClockRateKHz: 1721000
ComputeMode: 'Default'
GPUOverlapsTransfers: 1
KernelExecutionTimeout: 1
CanMapHostMemory: 1
DeviceSupported: 1
DeviceSelected: 1
If I update my path variable and run nvcc –version it shows:
$ export PATH=/usr/local/cuda-10.1/bin
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Apr_24_19:10:27_PDT_2019
Cuda compilation tools, release 10.1, V10.1.168
Any ideas as to why CUDA is recognized, the GPU works, but MATLAB will not let CUDA 10.1 be CUDA 10.0?
Thanks!

Best Answer

Unfortunately, the situation here is admittedly somewhat confusing. There are two relevant pieces of software going on here, both related to CUDA, both potentially with different version numbers. These are:
  1. The CUDA driver. It is (nearly) always fine to simply install the latest CUDA driver on your system. NVIDIA guarantees backwards compatibility for the driver, and so older software can run without problems using a newer driver. gpuDevice shows you the CUDA version number of your driver in the DriverVersion property.
  2. The CUDA toolkit. This is needed only when building MEX files using mexcuda. In this case, it's important that the version of the toolkit that you use matches the version of the toolkit that was used to build MATLAB. gpuDevice shows you that version in the ToolkitVersion property.
So, the fact that you have a CUDA 10.1 toolkit and are trying to use it with a version of MATLAB built with the 10.0 toolkit is the problem - you should download and install the 10.0 toolkit from the NVIDIA website (it's fine to have multiple toolkit versions on your machine).