Function: set_context
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Function
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. If 0 is returned, the operation is successful. If other values are returned, the operation fails. |
Constraints
-
The following scenarios are supported:
- If you explicitly create a context (for example, ctx1) by calling acl.rt.create_context 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 calling acl.rt.destroy_context.
- If acl.rt.set_context is called for multiple times to set the context of the thread, the last setting applies.
-
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 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.