Function: set_device
Applicability
|
Product |
Supported (√/x) |
|---|---|
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
Function Usage
Sets the compute device in the calling thread. The call implicitly creates the default context.
For the
For the
For the
For the
For the
Prototype
- C Prototype
1aclError aclrtSetDevice(int32_t deviceId)
- Python Function
1ret = acl.rt.set_device(device_id)
Parameter Description
|
Parameter |
Description |
|---|---|
|
device_id |
Int, device ID. After acl.rt.get_device_count is called to obtain the number of available devices, the value range of device ID is [0, Number of available devices – 1]. |
Return Value Description
|
Return Value |
Description |
|---|---|
|
ret |
Int, error code: 0 on success; else, failure. |
Restrictions
If acl.rt.set_device is called for multiple times in a process, acl.rt.reset_device does not need to be called to reset the device resources, because the device resources will be reset when the process exits. It is recommended that the acl.rt.set_device and acl.rt.reset_device APIs be used in pairs. When resources on the device are not used, you can call acl.rt.reset_device to free the device resources used by the current process in a timely manner.
acl.rt.set_device can be called to specify the same device for computation in different processes or threads. In a multithreaded process, if acl.rt.set_device is called to specify the same compute device, they use the same default context.