
    ^j
                    $    d dl mZ  G d d      Zy)    )annotationsc                  0    e Zd ZdZdZdddd	dZd Zd Zy)
warp_pipeline_stageas  
    Marks a warp-pipeline stage inside a Gluon kernel.

	When used inside @gl.kernel, each with amd.warp_pipeline_stage(...) block
	semantically defines a distinct stage of a warp pipeline. All operations
	inside the block belong to the same pipeline cluster and are intended to
	execute as a unit relative to other stages.

	The optional string label (e.g., "load", "compute") names the pipeline
	stage for identification and diagnostics, without affecting program
	semantics.

	An optional integer priority may be specified to express the relative
	scheduling priority of the warp the stage belongs to. The priority applies
	to the entire cluster. Valid values range from 0 (lowest) to 3 (highest)
    as it's lowered to the operand of `s_setprio`. If unspecified, priority
    resets to zero when any other stage in the loop uses explicit priority;
    otherwise no priority instruction is emitted.
    N.B., This is a performance hint to the hardware scheduler, and its effect
	may vary depending on the dynamic interaction of instruction streams
	across different warps. It is optional and should be used judiciously,
	only when explicit scheduling guidance is beneficial.

    Example: (only to show how to use, this example is not supposed to
    represent the optimal way.)

    @gl.kernel
    ...

    for k in gl.range(0, K, one):

        # Stage 0: prefetch tiles
        with amd.warp_pipeline_stage("load", priority=3):
            a = gl.amd.buffer_load(a_ptr, offs_a)
            b = gl.amd.buffer_load(b_ptr, offs_b)

        # Stage 1: prepare MFMA operands
        with amd.warp_pipeline_stage("prep"):
            a_tile = a.load(layout=...)
            b_tile = b.load(layout=...)

        # Stage 2: compute
        with amd.warp_pipeline_stage("compute", priority=0):
            acc = gl.amd.mfma(a_tile, b_tile, acc)
            offs_a += strideA
            offs_b += strideB
    )labelpriority	_semanticN)r   c                   t        |dd       | _        ||dkD  r|dk  sJ d       || _        |j                  dd       | _        y )Nvalue   zpriority should be 0 to 3.r   )getattrr   r   getr   )selfr   r   	_internals       /var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/triton/experimental/gluon/language/amd/warp_pipeline.py__init__zwarp_pipeline_stage.__init__7   sJ    UGT2
b=X\O3OO1 "{D9    c                    | S N )r   s    r   	__enter__zwarp_pipeline_stage.__enter__>   s    r   c                    |y| j                   y| j                  | j                  nd}| j                  | j                  nd}| j                   j                  j	                  ||       y)NFclusterr   )r   r   r   buildercreate_warp_pipeline_border)r   exc_typeexctbmarkerprios         r   __exit__zwarp_pipeline_stage.__exit__A   s]    >>!#zz59 $ 9t}}r::64Hr   r   )r   z
int | None)__name__
__module____qualname____doc__	__slots__r   r   r!   r   r   r   r   r      s%    .` 3I:T :r   r   N)
__future__r   r   r   r   r   <module>r(      s    "E Er   