aclrtResetDeviceForce

Applicable Products

Product

Supported

Ascend 950PR / Ascend 950DT

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

Function

Resets the current compute 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 tasks in the default context or default stream have not yet completed, the system will wait for the tasks to finish before releasing the resources.

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

1
aclError aclrtResetDeviceForce(int32_t deviceId)

Parameters

Parameter

Input/Output

Description

deviceId

Input

Device ID.

Returns

0 on success; otherwise, 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 below. 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 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)

API Call Example

For the API call example, see Initialization.