Function cudaSetDevice

Source
pub unsafe extern "C" fn cudaSetDevice(device: c_int) -> cudaError_t
Expand description

\brief Set device to be used for GPU executions

Sets \p device as the current device for the calling host thread. Valid device id’s are 0 to (::cudaGetDeviceCount() - 1).

Any device memory subsequently allocated from this host thread using ::cudaMalloc(), ::cudaMallocPitch() or ::cudaMallocArray() will be physically resident on \p device. Any host memory allocated from this host thread using ::cudaMallocHost() or ::cudaHostAlloc() or ::cudaHostRegister() will have its lifetime associated with \p device. Any streams or events created from this host thread will be associated with \p device. Any kernels launched from this host thread using the <<<>>> operator or ::cudaLaunchKernel() will be executed on \p device.

This call may be made from any host thread, to any device, and at any time. This function will do no synchronization with the previous or new device, and should only take significant time when it initializes the runtime’s context state. This call will bind the primary context of the specified device to the calling thread and all the subsequent memory allocations, stream and event creations, and kernel launches will be associated with the primary context. This function will also immediately initialize the runtime state on the primary context, and the context will be current on \p device immediately. This function will return an error if the device is in ::cudaComputeModeExclusiveProcess and is occupied by another process or if the device is in ::cudaComputeModeProhibited.

It is not required to call ::cudaInitDevice before using this function. \param device - Device on which the active host thread should execute the device code.

\return ::cudaSuccess, ::cudaErrorInvalidDevice, ::cudaErrorDeviceUnavailable, \notefnerr \note_init_rt \note_callback

\sa ::cudaGetDeviceCount, ::cudaGetDevice, ::cudaGetDeviceProperties, ::cudaChooseDevice, ::cudaInitDevice, ::cuCtxSetCurrent