Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CUDA same function for CPU and GPU [duplicate]

Tags:

c++

c

cuda

gpgpu

In order to call the same function from host code and GPU kernel, Do I have to keep the two copies of the same function as below:

int sum(int a, int b){
return a+b;
}

__device int sumGPU(int a, int b){
return a+b;
}

Or is there any technique to keep/manage a single copy of the function?

like image 929
Imran Avatar asked Dec 02 '22 17:12

Imran


1 Answers

You just have to add the __host__ keyword to be able to call call a function from host or device.

__host__ __device__ int sum(int a, int b){
  return a+b;
}
like image 189
hubs Avatar answered Dec 11 '22 09:12

hubs