Function: set_device
|
C Prototype |
aclError aclrtSetDevice(int32_t deviceId) |
|---|---|
|
Python Function |
ret = acl.rt.set_device(device_id) |
|
Function Usage |
Sets the compute device in the calling thread. The call implicitly creates the default context. For the Atlas 200/300/500 Inference Product, the default context contains two streams: one default stream and one stream for internal synchronization. For the Atlas Training Series Product, the default context contains one default stream. |
|
Input 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 |
ret: int, error code.
|
|
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 acl.rt.set_device and acl.rt.reset_device be used in pairs to reset the device resources that are no longer needed 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. |
|
Reference |
For details about the API call sequence and example, see Runtime Resource Allocation and Deallocation and Synchronous Wait. |