aclrtSetCurrentContext

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

Sets the context of a thread.

Prototype

1
aclError aclrtSetCurrentContext(aclrtContext context)

Parameters

Parameter

Input/Output

Description

context

Input

Current context of the specified thread. For details about the type definition, see aclrtContext.

Returns

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

Restrictions

  • The following use cases are supported:
    • If you explicitly create a context (for example, ctx1) by calling the aclrtCreateContext API in a thread (for example, thread1), you do not need to call aclrtSetCurrentContext to bind the context to the thread. ctx1 is bound to thread1 by default.
    • If aclrtCreateContext is not called to explicitly create a context for a thread, the default context is bound to the thread. In this case, the context cannot be destroyed by calling the aclrtDestroyContext API.
    • If aclrtSetCurrentContext is repeatedly called to bind a context to a thread, the last call takes effect.
  • If the device of the context to be bound to a thread has been reset, the context cannot be bound to the thread. Otherwise, exceptions may occur.
  • It is recommended that a context created in a thread be used in that thread. If a context is created by calling the aclrtCreateContext API in thread A and used in thread B, you need to ensure the execution order of tasks within the same stream under the same context across the two threads.
  • If the new context and the current context belong to different devices, calling aclrtSetCurrentContext to switch the context also switches the device.