CUDA Programming Quick Start Tutorial

Prepare

If you are using CUDA for the first time, you can use the following command under Linux to check whether the CUDA compiler is installed correctly:

$ which nvcc

Typically, the command output is:

/usr/local/cuda/bin/nvcc

In addition, you may also need to check the GPU model on your machine, you can use the following command to query:

$ ls  -l /dev/nv*

Possible outputs are:

crw-rw-rw- 1 root root 195, 0 Jul 3 13:44 /dev/nvidia0

crw-rw-rw- 1 root root 195, 1 Jul 3 13:44 /dev/nvidia1

crw-rw-rw- 1 root root 195, 255 Jul 3 13:44 /dev/nvidiactl

crw-rw---- 1 root root 10, 144 Jul 3 13:39 /dev/nvram

The above output shows that there are two GPU graphics cards installed on the machine.

The basic process of writing a CUDA program is:

  • Create a source file, suffixed with ".cu".
  • Compile the program with nvcc.
  • run from the command line.

Then there is what we call the kernel function (i.e. CUDA code)

__global__ void helloFromGpu(void){

                printf(“hello world form GPU!\\n”);

}

The qualifier __global__ tells the compiler that this function will be called by the CPU to execute on the GPU, and its call is of the form:

helloFromGPU<<

Guess you like

Origin blog.csdn.net/weixin_43838785/article/details/123085959