cubecl_hip_sys

Function hipSetDevice

Source
pub unsafe extern "C" fn hipSetDevice(deviceId: c_int) -> hipError_t
Expand description

@brief Set default device to be used for subsequent hip API calls from this thread.

@param[in] deviceId Valid device in range 0…hipGetDeviceCount().

Sets @p device as the default device for the calling host thread. Valid device id’s are 0… (hipGetDeviceCount()-1).

Many HIP APIs implicitly use the “default device” :

  • Any device memory subsequently allocated from this host thread (using hipMalloc) will be allocated on device.
  • Any streams or events created from this host thread will be associated with device.
  • Any kernels launched from this host thread (using hipLaunchKernel) will be executed on device (unless a specific stream is specified, in which case the device associated with that stream will be used).

This function may be called from any host thread. Multiple host threads may use the same device. This function does no synchronization with the previous or new device, and has very little runtime overhead. Applications can use hipSetDevice to quickly switch the default device before making a HIP runtime call which uses the default device.

The default device is stored in thread-local-storage for each thread. Thread-pool implementations may inherit the default device of the previous thread. A good practice is to always call hipSetDevice at the start of HIP coding sequency to establish a known standard device.

@returns #hipSuccess, #hipErrorInvalidDevice, #hipErrorNoDevice

@see #hipGetDevice, #hipGetDeviceCount