How to Use
Recommended
- Preferentially using explicit contexts: For multi-threaded or complex applications, explicitly create contexts to make the code's intent clearer.
- Binding contexts to threads: It is recommended that a context be used in the thread where it is created to avoid the complexity caused by cross-thread usage.
- Destroying resources in a timely manner: Destroy a context in a timely manner when it is no longer used to avoid resource leakage.
- Using aclrtResetDeviceForce: Use aclrtResetDeviceForce to release all resources on the device in a single operation once the device is no longer needed.
- Specifying the context switching time: In multi-context scenarios, explicitly call aclrtSetCurrentContext to switch the context, improving code readability.
Not recommended
- Destroying the default context: The default context is managed by Runtime and cannot be destroyed by calling aclrtDestroyContext.
- Causing unpredictable context status: When multiple threads share a context, avoid relying on implicit context status switching.
- Operating the same stream across threads: If the context must be shared among multiple threads, each thread should use an independent stream.
- Using a context on a reset device: After a device is reset, the related context becomes unavailable.
Parent topic: Context Management