Define Which Device Code Runs on

Is there a way, using the runtime api? If so, can you point me to an example.

Thank you

cudaSetDevice ?

cudaSetDevice() function may be what you are looking for.

Thanks. Is memory shared across device; i.e. what happens if I do

cudaSetDevice(0);

cudaMalloc(d_a, 1024*sizeof(int));

cudaSetDevice(1);

kernel<<<gridDim,blockDim>>>(d_a);

thanks

CUDA will probably generate an error. Once the device is set for a context, you cannot change it.