Setting and unsetting a device - cudaSetDevice()

Hi everyone,

At the start of my application make a call to CUDA_DEVICE_INIT() that sets a device using cudaSetDevice(). How do I unset it when I’m done with my cuda computations?

When this is called again with the same device ID, it throws an error, and my app crashes.

-Oj

Basically you don’t have to initialize your device by using CUDA_DEVICE_INIT().

When you only have one nvidia board supporting CUDA. Its automatically use your device 0 to be the computing device.

You don’t. It automatically happens after your host thread (or process) exits.

This is expected behavior. The programming guide states that calling cudaSetDevice() after the context is initialized (i.e. by a cudaMalloc()) results in an error.