CUDA same function for CPU and GPU

c, c++, cuda, gpgpu

Solution

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;
}

Problem

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?

Original source

Related problems