Applicable Products
Product
|
Supported (√/x)
|
Ascend 950PR/Ascend 950DT
|
√
|
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
|
√
|
Description
Sets the context of a thread.
Prototype
- C Prototype
| aclError aclrtSetCurrentContext(aclrtContext context)
|
- Python Function
| ret = acl.rt.set_context(context)
|
Parameters
Parameter
|
Description
|
context
|
Int, pointer address of the current context object in the thread.
|
Return Values
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.