How to interchage a scalar varable between host and device?

If we want to transfer array between host and device, we can use

cutilSafeCall( cudaMemcpy(d_data, h_data, size_h_data, cudaMemcpyHostToDevice) );
cutilSafeCall( cudaMemcpy(h_data, d_data, size_h_data, cudaMemcpyDeviceToHost) );

where d_data and h_data are both pointer.

But how to transfer just only a scalar variable? Do we still need like we did for array?

Pass it as a kernel invocation argument:

kernel<<<numOfBlocks, numOfThreads>>>(scalar);

Regards,

MK

Yes, this method can transfer the scalar variable from host to device.

But in my opion, it can not still transfert the scalar variable from device to host.

If I am right, I want to know how to transfert the scalar variable from device to host in a simple way.

Thanks very much.

You could define a global variable ([font=“Courier New”]device type varId;[/font]), retrive its address within module and read it after kernel usage (see section B.2.1 in CUDA C Programming Guide).

Regards,

MK