Device Management
Function: set_device
C Prototype |
aclError aclrtSetDevice(int32_t deviceId) |
---|---|
Python Function |
ret = acl.rt.set_device(device_id) |
Function Usage |
Specifies the device used for computation, and implicitly creates the default context, which contains two streams, one default stream, and one stream for internal synchronization. It is a synchronous interface. 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. The following application scenarios are supported:
|
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 minus 1]. |
Return Value |
ret: int, error code.
|
Restrictions |
None |
Precautions |
None |
Function: reset_device
C Prototype |
aclError aclrtResetDevice(int32_t deviceId) |
---|---|
Python Function |
ret = acl.rt.reset_device(device_id) |
Function Usage |
Resets the computing device and releases the resources (including the default context and stream, and all streams created in the default context) on the device. It is a synchronous interface. If a task in the default context or stream is not complete, resources will be released after the task is complete. |
Input Description |
device_id: int, device ID. |
Return Value |
ret: int, error code.
|
Restrictions |
If there are explicitly created contexts, streams, or events on the device to be reset, you are advised to follow the following calling sequence before resetting. Otherwise, exceptions may occur. The interfaces calling sequence is as follows: call acl.rt.destroy_event to release the event or call acl.rt.destroy_stream to release the explicitly created stream --> call acl.rt.destroy_context to release the explicitly created context --> call acl.rt.reset_device. |
Precautions |
None |
Function: get_device
C Prototype |
aclError aclrtGetDevice(int32_t *deviceId) |
---|---|
Python Function |
device_id, ret = acl.rt.get_device() |
Function Usage |
Obtains the IDs of devices in use. It is a synchronous interface. |
Input Description |
None |
Return Value |
device_id: int ID of the device in use. ret: int, error code.
|
Restrictions |
If neither acl.rt.set_device nor acl.rt.create_context is called to specify a device, an error is returned when acl.rt.get_device is called. |
Precautions |
None |
Function: get_run_mode
C Prototype |
aclError aclrtGetRunMode(aclrtRunMode *runMode) |
---|---|
Python Function |
run_mode, ret = acl.rt.get_run_mode() |
Function Usage |
Obtains the running mode of the current Ascend AI software stack. It is a synchronous interface. |
Input Description |
None |
Return Value |
run_mode: int, running mode.
ret: int, error code.
|
Restrictions |
None |
Precautions |
None |
Function: set_ts_device
C Prototype |
aclError aclrtSetTsDevice(aclrtTsId tsId) |
---|---|
Python Function |
ret = acl.rt.set_ts_device(ts_id) |
Function Usage |
Sets the Task Schedule required for computation. It is a synchronous interface. |
Input Description |
ts_id: int, Task Schedule required for computation. If the Ascend AI software stack contains only the AICORE Task Schedule, this parameter is invalid and the AICORE Task Schedule is used by default.
|
Return Value |
ret: int, error code.
|
Restrictions |
None |
Precautions |
None |
Function: get_device_count
C Prototype |
aclError aclrtGetDeviceCount(uint32_t *count) |
---|---|
Python Function |
count, ret = acl.rt.get_device_count() |
Function Usage |
Obtains the number of available devices. It is a synchronous interface. |
Input Description |
None |
Output Description |
None |
Return Value |
count: int, number of devices. ret: int, error code.
|
Restrictions |
None |
Precautions |
None |