Function: reset_device_force
Description
Resets the current device and releases the resources on the device. The resources it releases include the default context, default stream, and all streams created in the default context. If a task in the default context or stream is not complete, the system releases the context or stream after the task is complete.
The acl.rt.reset_device_force API can be used with the acl.rt.set_device API or not with the aclrtSetDevice API. If they are not used in pairs, this API needs to be called only once after the acl.rt.set_device API is called for one or more times for the same device in a process to release resources on the device.
# This API is used in pair with acl.rt.set_device. acl.rt.set_device(1) -> acl.rt.reset_device_force(1) -> acl.rt.set_device(1) -> acl.rt.reset_device_force(1) # This API is not used in pair with acl.rt.set_device: acl.rt.set_device(1) -> acl.rt.set_device(1) -> acl.rt.reset_device_force(1)
Prototype
- C Prototype
1aclError aclrtResetDeviceForce(int32_t deviceId)
- Python Function
1ret=acl.rt.reset_device_force(device_id)
Parameters
Parameter |
Description |
|---|---|
device_id |
Int, device ID. |
Return Value
Return Value |
Description |
|---|---|
ret |
Int, error code. 0 on success; else, failure. |
Restrictions
- In multi-thread scenarios, if acl.rt.set_device and acl.rt.reset_device_force are called in each thread for the same device, acl.rt.reset_device_force in thread 2 returns an error as shown in the following. The reason is that acl.rt.reset_device_force in thread 1 has released the resources of device 1.
Timeline ------------------------------------------------------------------------------> Thread 1: acl.rt.set_device(1) acl.rt.reset_device_force(1) Thread 2: acl.rt.set_device(1) acl.rt.reset_device_force(1)
In multi-thread scenarios, call acl.rt.reset_device_force to release device resources at the end of the thread execution, as shown in the following:
Timeline ------------------------------------------------------------------------------> Thread 1: acl.rt.set_device(1) Thread 2: acl.rt.set_device(1) acl.rt.reset_device_force(1)
- The acl.rt.reset_device API and acl.rt.reset_device_force API can be used together. However, when they are used together, if the number of times and call sequence of the two Reset APIs are incorrect, an error will be returned.
# Positive example: # The two reset APIs are used with the set APIs in pairs, and acl.rt.reset_device_force is called after acl.rt.reset_device. acl.rt.set_device(1) -> acl.rt.reset_device(1) -> acl.rt.set_device(1) -> acl.rt.reset_device_force(1) acl.rt.set_device(1) -> acl.rt.set_device(1) -> acl.rt.reset_device(1) -> acl.rt.reset_device_force(1) # Negative example: # The acl.rt.reset_device API implements reference counting. Each time the acl.rt.reset_device API is called, the reference count is decreased by 1. # When the reference count decreases to 0, the resources on the device are released. If the acl.rt.reset_device or acl.rt.reset_device_force API is called again, an error is reported. acl.rt.set_device(1) -> acl.rt.set_device(1) -> acl.rt.reset_device(1) -> acl.rt.reset_device(1) -> acl.rt.reset_device_force(1) acl.rt.set_device(1) -> acl.rt.set_device(1) -> acl.rt.reset_device(1) -> acl.rt.reset_device_force(1) -> acl.rt.reset_device_force(1) # The acl.rt.reset_device_force API must be called after the acl.rt.reset_device API. Otherwise, an error is reported. acl.rt.set_device(1) -> acl.rt.set_device(1) -> acl.rt.reset_device_force(1) -> acl.rt.reset_device(1)