Function: set_context

Description

Sets the context of a thread.

Prototype

  • C Prototype
    1
    aclError aclrtSetCurrentContext(aclrtContext context)
    
  • Python Function
    1
    ret = acl.rt.set_context(context)
    

Parameters

Parameter

Description

context

Int, pointer address of the current context object in the thread.

Return Value

Return Value

Description

ret

Int, error code. 0 on success; else, failure.

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.