3 different kinds of functions in a CUDA program
 

  • There are 3 different kinds of functions in a CUDA program:

      1. __host__ specified function (this is the default)       

      2. __global__ specified function

      3. __device__ specified function

 

If you do not provide any specification, the CUDA compiler will assume:   __host__ speficied

__host__ specified functions
 

  • __host__ specified functions:

      • The __host__ execution space specifier declares a function that is:

          • Executed on the host (= CPU)       
          • Callable from the host only.

      • The __host__ specifier is the default:

          • If a function has no execution space specifier, it is assumed to be __host__

    A __host__ specified functions is an "ordinary" C function !!!

__global__ specified functions
 

  • The __global__ execution space specifier declares a function that is:

      • Executed on the device (= GPU),
      • Callable from the host.
      • Callable from the device (with compute capacability ≥ 3.2).

  • Usage of __global__ specified functions:

      • The __global__ specified functions are called (launched) by C function(s) in the main program to perform a task using the GPU

__device__ specified functions
 

  • The __device__ execution space specifier declares a function that is:

      • Executed on the device (= GPU),
      • Callable from the device (GPU) only !!!

  • Usage of __device__ specified functions:

      • The __device__ specified functions are GPU help functions used by __global__ speficied function