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?
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With