aclrtSetCurrentContext

Description

Sets the context of a thread.

Restrictions

  • The following use cases are supported:
    • If you explicitly create a context (for example, ctx1) by using the aclrtCreateContext call in a thread (for example, thread1), you do not need to call aclrtSetCurrentContext to specify the context bound to the calling thread. ctx1 is bound to thread1 by default.
    • If aclrtCreateContext is not called to explicitly create a context, the default context is bound to the calling thread. In this case, the default context cannot be destroyed by using the aclrtDestroyContext call.
    • If aclrtSetCurrentContext is repeatedly called to bind a context to the calling thread, the most recent setting applies.
  • If the device of the context to be bound has been reset, the context cannot be bound to the calling thread. Otherwise, exceptions may occur.
  • It is recommended that the context created in a thread be used in the thread. If thread A calls aclrtCreateContext to create a context and thread B uses this context, ensure the tasks execution sequence of the two threads that are in the same stream of the same context.

Prototype

aclError aclrtSetCurrentContext(aclrtContext context)

Parameters

Parameter

Input/Output

Description

context

Input

Current context of a thread.

Returns

The value 0 indicates success, and other values indicate failure. For details, see aclError.