Search code examples
cudacompatibilitycuda-driver

Do cuDevicePrimaryCtxReset() and cudaDeviceReset() do the same thing?


Reading the CUDA Runtime API and Driver API docs, it seems that the two functions:

CUresult cuDevicePrimaryCtxReset ( CUdevice dev );
__host__ ​cudaError_t cudaDeviceReset ( void );

do the same thing (upto having to cudaSetDevice(dev) before the runtime API call):

Destroy all allocations and reset all state on the primary context.

for the first and

Destroy all allocations and reset all state on the current device in the current process.

Do they, indeed, do the same? Or are there perhaps subtle differences that I'm missing or that aren't documented? e.g. something related to threads-vs-processes?


Solution

  • They're quite different.

    Examining the program @RobertCrovella linked to, it seems that:

    • cuDevicePrimaryCtxReset() only destroys/resets the primary context, not touching other contexts.
    • cudaDeviceReset() destroys all contexts for the specified device, removing them from the context stack.