pub unsafe extern "C" fn cudaSetDevice(device: c_int) -> cudaError_tExpand description
Set device to be used for GPU executions.
Sets 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 device. Any host memory allocated from this host thread using cudaMallocHost or cudaHostAlloc or cudaHostRegister will have its lifetime associated with device. Any streams or events created from this host thread will be associated with device. Any kernels launched from this host thread using the <<<>>> operator or cudaLaunchKernel will be executed on 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 device immediately. This function will return an error if the device is in cudaComputeMode::cudaComputeModeExclusiveProcess and is occupied by another process or if the device is in cudaComputeMode::cudaComputeModeProhibited.
It is not required to call cudaInitDevice before using this function.
Note that this function may also return error codes from previous, asynchronous launches.
Note that this function may also return cudaError_t::CUDA_ERROR_NOT_INITIALIZED, cudaErrorInsufficientDriver or cudaError_t::CUDA_ERROR_NO_DEVICE if this call tries to initialize internal CUDA RT state.
Note that as specified by cudaStreamAddCallback no CUDA function may be called from callback. cudaError_t::CUDA_ERROR_NOT_PERMITTED may, but is not guaranteed to, be returned as a diagnostic in such case.
§Parameters
device: Device on which the active host thread should execute the device code.
§Return value
See also: cudaGetDeviceCount, cudaGetDevice, cudaGetDeviceProperties, cudaChooseDevice, cudaInitDevice, cuCtxSetCurrent.