aclrtSetDevice
Applicable Products
|
Product |
Supported |
|---|---|
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
Function
Sets the compute device in the current thread. aclrtSetDevice can be called to specify the same device for computation in different threads.
If there are multiple devices, aclrtSetDevice can be called in the process to switch to another device.
Calling this API implicitly creates a default context that contains a default stream. In multiple threads of the same process, if aclrtSetDevice is called and the same device is specified for computation, these threads share the same default context.
Prototype
1
|
aclError aclrtSetDevice(int32_t deviceId) |
Parameters
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
deviceId |
Input |
Device ID. The value must be in the range of [0, (Available device count – 1)]. Call aclrtGetDeviceCount to obtain the device count. |
Returns
0 on success; otherwise, failure. For details, see aclError.
Restrictions
- If aclrtResetDevice is called to release device resources:
aclrtResetDevice involves reference counting. You are advised to use aclrtResetDevice and aclrtSetDevice in pairs. Each time aclrtSetDevice is called, the reference count increases by 1. Each time aclrtResetDevice is called, the reference count decreases by 1. Resources on the device are released only when the reference count decreases to 0.
- If aclrtResetDeviceForce is called to release device resources:
aclrtResetDeviceForce can either be used with aclrtSetDevice or not. If aclrtResetDeviceForce is not used with aclrtSetDevice, after aclrtSetDevice is called once or multiple times for the same device in a process, you only need to call aclrtResetDeviceForce once to release the resources on the device.