sharing function between Host and Device

I have some problem writing cuda application…
So I need help!
I have some utility function made by me on a .h and .c file and I want to make visible to Host and Device.
How can I do this?
I must use the global keyword before any function? :wacko:
Any help will be very appreciated.
Thanks you

you can declare functions as device host function(…) which will make them compile for both the host cpu and the gpu.

I don’t know if this is what you’re after but:

__device__ __host__ float myFunction(int idx, float data[])


	//your computations

	//write in C, the subset supported by both CPU and GPU

	//so no device only stuff like threadIdx

	//and no host only stuff like printf

	return someFloat; //example


void CPUcompute(float host_data[], int size)


	for(int i=0, i<size, ++i)

		myFunction(i, host_data);


__global__ GPUcompute(float device_data[], int size)


	int tid = threadIdx.x + blockIdx.x * blockDim.x;

	if(tid < size)

		myFunction(i, device_data);


You can’t have the kernel compiled as a host function but you can use utility functions compiled to both host and device if you precede the definition by device host

ok I understand finally!
many thanks!!! :)