How to verify CUDA installation in 16.04?

Is this ok?

Yes, everything is as expected.

Why is nvcc pointing to other directory?

nvcc lives on the typical folder for executables whereas the others are CUDA "drivers". It's mostly a Nvidia decision but it makes sense.


Compile and run a CUDA hello world

The best answer to "is something installed properly" questions tends to be: "try to use it for whatever you want to use it, and see if blows up and if it is as fast as you would expect".

If the "blows up" part fails, you might then want to try and make a hello world work:

main.cu

#include <cassert>

#define N 3

__global__ void inc(int *a) {
    int i = blockIdx.x;
    if (i<N) {
        a[i]++;
    }
}

int main() {
    int ha[N], *da;
    cudaMalloc((void **)&da, N*sizeof(int));
    for (int i = 0; i<N; ++i) {
        ha[i] = i;
    }
    cudaMemcpy(da, ha, N*sizeof(int), cudaMemcpyHostToDevice);
    inc<<<N, 1>>>(da);
    cudaMemcpy(ha, da, N*sizeof(int), cudaMemcpyDeviceToHost);
    for (int i = 0; i < N; ++i) {
        assert(ha[i] == i + 1);
    }
    cudaFree(da);
    return 0;
}

GitHub upstream.

and compile and run with:

nvcc -o main.out main.cu
./main.out

and the assert does not fail on my properly working setup.

Then if that fails, go over how to install questions:

  • How do I Install CUDA on Ubuntu 18.04?
  • How can I install CUDA on Ubuntu 16.04?

Run some CPU vs GPU benchmarks

A more interesting performance check would be to take a well optimized program that does a single GPU-acceleratable algorithm either CPU or GPU, and run both to see if the GPU version is faster.

TODO propose and test one here, e.g. matrix multiplication with both MAGMA (GPU) and LAPACKE (CPU). They might expose the same C API, so it could be easy to compare results.

You could then also open nvidia-settings while that runs to see if the GPU is actually getting used only in the GPU version: How do I check if Ubuntu is using my NVIDIA graphics card?

Tags:

Cuda

Nvidia