How to Use

Recommended

  1. Preferentially using explicit contexts: For multi-threaded or complex applications, explicitly create contexts to make the code's intent clearer.
  2. 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.
  3. Destroying resources in a timely manner: Destroy a context in a timely manner when it is no longer used to avoid resource leakage.
  4. Using aclrtResetDeviceForce: Use aclrtResetDeviceForce to release all resources on the device in a single operation once the device is no longer needed.
  5. Specifying the context switching time: In multi-context scenarios, explicitly call aclrtSetCurrentContext to switch the context, improving code readability.

Not recommended

  1. Destroying the default context: The default context is managed by Runtime and cannot be destroyed by calling aclrtDestroyContext.
  2. Causing unpredictable context status: When multiple threads share a context, avoid relying on implicit context status switching.
  3. Operating the same stream across threads: If the context must be shared among multiple threads, each thread should use an independent stream.
  4. Using a context on a reset device: After a device is reset, the related context becomes unavailable.