aclrtSetCurrentContext
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
√ |
|
√ |
|
√ |
Function
Sets the context of a thread.
Prototype
1 | aclError aclrtSetCurrentContext(aclrtContext context) |
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
context |
Input |
Current context of a thread. For the type definition, see aclrtContext. |
Returns
0 on success; otherwise, failure. For details, see aclError.
Restrictions
- The following scenarios are supported:
- If you explicitly create a context (for example, ctx1) by calling aclrtCreateContext 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 calling aclrtDestroyContext.
- If aclrtSetCurrentContext is called for multiple times to set the context of the thread, the most recent 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 aclrtCreateContext to create a context and thread B uses this context, ensure the task execution sequence of the two threads that are in the same stream of the same context.
- If the new context and the current context belong to different devices, calling aclrtSetCurrentContext to switch the context also switches the device.
Parent topic: Context Management