GreenContext#
- class torch.cuda.green_contexts.GreenContext(*, num_sms=None, workqueue_scope=None, workqueue_concurrency_limit=None, device_id=None)[source]#
Wrapper around a CUDA green context.
Warning
This API is in beta and may change in future releases.
CUDA work should be placed on streams created from the green context:
ctx = GreenContext(...) stream = ctx.Stream() with torch.cuda.stream(stream): # torch operations here are using resources from `ctx` pass
Green-context streams are custom CUDA streams. Synchronization with other streams is the user’s responsibility and should be handled with CUDA events, as with any other custom stream.
- Stream()[source]#
Return a CUDA stream associated with this green context.
Use the returned stream with
torch.cuda.stream()to run work on the green context. Synchronization with other streams is not automatic; use CUDA events as with any other custom stream.- Return type:
- static create(*, num_sms=None, workqueue_scope=None, workqueue_concurrency_limit=None, device_id=None)[source]#
Create a CUDA green context.
Kept for compatibility, see GreenContext constructor.
- Return type:
- static max_workqueue_concurrency(device_id=None)[source]#
Return the maximum workqueue concurrency limit for the device.
This queries the device for the default number of concurrent stream-ordered workloads supported by workqueue configuration resources.
- pop_context()[source]#
Assuming the green context is the current context, pop it from the context stack and restore the previous context.
Deprecated. Create streams with
Stream()and usetorch.cuda.stream()instead.
- set_context()[source]#
Make the green context the current context.
Deprecated. Create streams with
Stream()and usetorch.cuda.stream()instead.