aclrtResetDeviceForce

Applicability

Product

Supported

Atlas A3 training products/Atlas A3 inference products

Atlas A2 training products/Atlas A2 inference products

Atlas 200I/500 A2 inference products

Atlas inference products

Atlas training products

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.

aclrtResetDeviceForce can either be used with aclrtSetDevice or not. If aclrtResetDeviceForce is not used with aclrtSetDevice, after aclrtSetDevice is called once or multiple times for the same device in a process, you only need to call aclrtResetDeviceForce once to release the resources on the device.

# Using this API with aclrtSetDevice:
aclrtSetDevice(1) -> aclrtResetDeviceForce(1) -> aclrtSetDevice(1) -> aclrtResetDeviceForce(1)
 
# Using this API without using aclrtSetDevice:
aclrtSetDevice(1) -> aclrtSetDevice(1) -> aclrtResetDeviceForce(1)

Prototype

aclError aclrtResetDeviceForce(int32_t deviceId)

Parameters

Parameter

Input/Output

Description

deviceId

Input

Device ID.

Returns

0 on success; else, failure. For details, see aclError.

Restrictions

  • In multi-thread scenarios, if aclrtSetDevice and aclrtResetDeviceForce are called in each thread for the same device, aclrtResetDeviceForce in thread 2 returns an error as shown in the following. The reason is that aclrtResetDeviceForce in thread 1 has released the resources of device 1.
    Timeline ----------------------------------------------------------------------------->
    Thread 1: aclrtSetDevice(1)           aclrtResetDeviceForce(1)
    Thread 2: aclrtSetDevice(1)                                   aclrtResetDeviceForce(1)

    In multi-thread scenarios, call aclrtResetDeviceForce to release device resources at the end of the thread execution, as shown in the following:

    Timeline ----------------------------------------------------------------------------->
    Thread 1: aclrtSetDevice (1)
    Thread 2: aclrtSetDevice(1)                                   aclrtResetDeviceForce(1)
  • aclrtResetDevice and aclrtResetDeviceForce can be used together. However, if the number of times and calling sequence of the two Reset APIs are incorrect, an error is reported.
    # Positive example:
    # The two reset APIs are used with the set APIs in pairs, and aclrtResetDeviceForce is called after aclrtResetDevice.
    aclrtSetDevice(1) -> aclrtResetDevice(1) -> aclrtSetDevice(1) -> aclrtResetDeviceForce(1)
    aclrtSetDevice(1) -> aclrtSetDevice(1) -> aclrtResetDevice(1) -> aclrtResetDeviceForce(1)
    
    # Negative example:
    # aclrtResetDevice involves the implementation of reference counting. Each time aclrtResetDevice is called, the reference count decreases by 1. When the reference count decreases to 0, the resources on the device are released. In this case, an error is reported when aclrtResetDevice or aclrtResetDeviceForce is called.
    aclrtSetDevice(1) -> aclrtSetDevice(1) -> aclrtResetDevice(1)-->aclrtResetDevice(1)-->aclrtResetDeviceForce(1)
    aclrtSetDevice(1) -> aclrtSetDevice(1) -> aclrtResetDevice(1)-->aclrtResetDeviceForce(1)-->aclrtResetDeviceForce(1)
    # aclrtResetDeviceForce is called after aclrtResetDevice. Otherwise, an error is returned.
    aclrtSetDevice(1) -> aclrtSetDevice(1) -> aclrtResetDeviceForce(1)-->aclrtResetDevice(1)