
    9j&                         d dl Z dgZeZdZ ee j                  d      re j                  j                  ZdZ G d de      Zy)    NGreenContextF_CUDAGreenContextTc                        e Zd ZdZeddddddedz  dedz  dedz  dedz  def
d	       Zeddedz  defd
       Z	d fdZ
d fdZd fdZ xZS )r   zyWrapper around a CUDA green context.

    .. warning::
       This API is in beta and may change in future releases.
    Nnum_smsworkqueue_scopeworkqueue_concurrency_limit	device_idr   r   r	   r
   returnc                 V    t         st        d      t        j                  || ||      S )a+  Create a CUDA green context.

        At least one of ``num_sms`` or ``workqueue_scope`` must be specified.
        Both can be combined to partition SMs and configure workqueues in the
        same green context.

        Arguments:
            num_sms (int, optional): The number of SMs to use in the green
                context. When ``None``, SMs are not partitioned.
            workqueue_scope (str, optional): Workqueue sharing scope. One of
                ``"device_ctx"`` (shared across all contexts, default driver
                behaviour) or ``"balanced"`` (non-overlapping workqueues with
                other balanced green contexts). When ``None``, no workqueue
                configuration is applied.
            workqueue_concurrency_limit (int, optional): Maximum number of
                concurrent stream-ordered workloads for the workqueue. Requires
                ``workqueue_scope`` to be set.
            device_id (int, optional): The device index of green context.
                When ``None``, the current device is used.
        1PyTorch was not built with Green Context support!)r
   r   r   r	   )	SUPPORTEDRuntimeError_GreenContextcreater   s       Y/media/conek/DATA/Code/OCR/venv/lib/python3.12/site-packages/torch/cuda/green_contexts.pyr   zGreenContext.create   s7    8 RSS##+(C	 $ 
 	
    c                 P    t         st        d      t        j                  |       S )aw  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.

        Arguments:
            device_id (int, optional): The device index to query. When
                ``None``, the current device is used.
        r   r
   )r   r   r   max_workqueue_concurrencyr   s    r   r   z&GreenContext.max_workqueue_concurrency>   s'     RSS666KKr   c                      t         |          S )z+Make the green context the current context.)superset_contextself	__class__s    r   r   zGreenContext.set_contextP   s    w"$$r   c                      t         |          S )zAssuming the green context is the current context, pop it from the
        context stack and restore the previous context.
        )r   pop_contextr   s    r   r   zGreenContext.pop_contextT   s     w"$$r   c                      t         |          S )z1Return the CUDA Stream used by the green context.)r   Streamr   s    r   r    zGreenContext.StreamZ   s    w~r   )N)r   N)r   ztorch.cuda.Stream)__name__
__module____qualname____doc__staticmethodintstrr   r   r   r   r   r    __classcell__)r   s   @r   r   r      s      #&*26 $"
t"
 t"
 &)4Z	"

 :"
 
"
 "
H LS4Z L3 L L"%%   r   )	torch__all__objectr   r   hasattr_Cr   r    r   r   <module>r/      sQ      	
588()HH..MI
J = J r   