Product |
Supported (√/x) |
|---|---|
√ |
|
√ |
|
√ |
|
√ |
|
√ |
|
√ |
Resets the current device and releases the resources on the device. The resources to be released 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 together with the acl.rt.set_device API. 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 together with the acl.rt.set_device API. acl.rt.set_device(1) -> acl.rt.set_device(1) -> acl.rt.reset_device_force(1)
1 | aclError aclrtResetDeviceForce(int32_t deviceId) |
1 | ret=acl.rt.reset_device_force(device_id) |
Parameter |
Description |
|---|---|
device_id |
Int, device ID. |
Return Value |
Description |
|---|---|
ret |
Int, error code. 0 on success; else, failure. |
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)
# 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)