Function: reset_device_force

Applicability

Product

Supported (√/x)

Atlas A3 training products/Atlas A3 inference products

Atlas A2 training products/Atlas A2 inference products

Atlas training products

Atlas inference products

Atlas 200I/500 A2 inference products

Function Usage

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.

acl.rt.reset_device_force can either be used with acl.rt.set_device or not. If they are not used in pairs, after acl.rt.set_device is called once or multiple times for the same device in a process, you only need to call acl.rt.reset_device_force once to release the 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)

Prototype

  • C Prototype
    1
    aclError aclrtResetDeviceForce(int32_t deviceId)
    
  • Python Function
    1
    ret=acl.rt.reset_device_force(device_id)
    

Parameter Description

Parameter

Description

device_id

Int, device ID.

Return Value Description

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)
  • acl.rt.reset_device and acl.rt.reset_device_force can be used together. However, if the number of times and call 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 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)