Install using runfile
$ wget https://developer.download.nvidia.com/compute/cuda/11.0.3/local_installers/cuda_11.0.3_450.51.06_linux.run $ sudo sh cuda_11.0.3_450.51.06_linux.run
Add to Global Environment Variables
Make your /etc/environment file look like the following and then restart the OS. This is only necessary if you would like to use CLion for CUDA development.
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/cuda-11.0/bin" LD_LIBRARY_PATH="/usr/local/cuda-11.0/lib"
Some Notes
For some GPU cards, for example, GTX970, it’s impossible to boot the system when connected to a 4K display. So you have to disable the default NVIDIA GPU driver and install the official one.
First CUDA Program!
#include <cstdio> #define SIZE 1024 __global__ void VectorAdd(int *a, int *b, int *c, int n) { int i = threadIdx.x; if(i < n) c[i] = a[i] + b[i]; } int main() { int *a, *b, *c; cudaMallocManaged(&a, SIZE * sizeof(int)); cudaMallocManaged(&b, SIZE * sizeof(int)); cudaMallocManaged(&c, SIZE * sizeof(int)); for(int i = 0; i < SIZE; ++i) { a[i] = i; b[i] = i; c[i] = 0; } VectorAdd <<<1, SIZE>>> (a, b, c, SIZE); cudaDeviceSynchronize(); for(int i = 0; i < 10; ++i) printf("c[%d] = %d\n", i, c[i]); cudaFree(a); cudaFree(b); cudaFree(c); return 0; }