Function: set_context

C Prototype

aclError aclrtSetCurrentContext(aclrtContext context)

Python Function

ret = acl.rt.set_context(context)

Function Usage

Sets the context of a thread.

Input Description

context: int, pointer address of the current context object in the thread.

Return Value

ret: int, error code.

Restrictions

  • The following scenarios are supported:
    • If you explicitly create a context (for example, ctx1) by using the acl.rt.create_context call in a thread (for example, thread1), you do not need to call acl.rt.set_context to specify the context bound to the calling thread. ctx1 is bound to thread1 by default.
    • If acl.rt.create_context 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 acl.rt.destroy_context call.
    • If acl.rt.set_context is called for multiple times to set the context of the thread, the last setting applies.
  • If the device corresponding to the context set for the thread has been reset, the context cannot be set as the thread context. Otherwise, exceptions may occur.
  • It is recommended that the context created in a thread be used in the thread. If thread A calls acl.rt.create_context to create a context and thread B uses this context, you need to ensure the tasks execution sequence of the two threads that are in the same stream of the same context.

Reference

For details about the API call sequence, see Multi-device Switchover.