CUDA function called by device or host

I have a reuse function in CUDA code that needs to be called from both the device and the host. Is there an appropriate qualifier for this?

eg. what is the correct definition for func1 in this case:

int func1 (int a, int b) { return a+b; } __global__ devicecode (float *A) { int i = blockDim.x * blockIdx.x + threadIdx.x; A[i] = func1(i,i); } void main() { // Normal cuda memory set-up // Call func1 from inside main: int j = func1(2,4) // Normal cuda memory copy / program run / retrieve data } 

So far, I can only get this to work with the function twice: once for the device and once for the host. Is there a better way?

+8
c ++ function scope cuda
source share
1 answer

In the CUDA Programming Guide:

The __device__ and __host__ can be used together, in which case the function is compiled for both the host and the device.

+16
source share

Source: https://habr.com/ru/post/651211/


All Articles