Friday 2 June 2017

How to define a kernel which is called from another kernel?


                            Kernels which are called from another kernel, are prefixed with __device__ during their definition.

e.g. 

 __device__ void func2()
  {
    //code to be executed on GPU
  }

 __global__ void func1(int *a,int *b)
  {
     func2(); 
  }

void main()
  {
    func1<<<1,2>>>(d,e);
  }


Note: Here func1() is called from CPU function i.e. main(). That's why, it is prefixed with __global__ in its definition.

On the other hand, func2() is called from kernel func1(); that's why, it is prefixed with __kernel__ in its definition.

No comments:

Post a Comment