
    ^jf
                         d dl mc mc mc mZ d dlmZ d dl mZm	Z	 g dZ
 G d de      Zedd       Zedd       Zed	dd
d       Zy)    N)SwizzledSharedLayout)builtin_unwrap_if_constexpr)MBarrierLayoutinitwaitarrivec                   $     e Zd ZdZd fd	Z xZS )r   z
    Layout for mbarrier synchronization.

    Args:
        cga_layout (List[List[int]]): CGA layout bases. Defaults to [].
    c                 8    t         |   ddddg|xs g        y )N   r   )vec	per_phase	max_phaseorder
cga_layout)super__init__)selfr   	__class__s     /var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/triton/experimental/gluon/language/amd/gfx1250/mbarrier.pyr   zMBarrierLayout.__init__   s$    Q!qPZP`^`a    N)__name__
__module____qualname____doc__r   __classcell__)r   s   @r   r   r      s    b br   r   c                 f    t        |      }|j                  j                  | j                  |       y)a  
    Initialize an mbarrier with a specified count. An mbarrier consists of an init count, a pending count and a phase.
    At initialization, the init count and pending count are initialized with the given 'count' and the phase is initialized to 0.

    Args:
        mbarrier (shared_memory_descriptor): The barrier object to initialize.
        count (int): The initial count for the barrier. Must be a positive integer.
    N)r   buildercreate_lds_barrier_inithandle)mbarriercount	_semantics      r   r   r      s(     !'E--hoouEr   c                     |j                  |      }|j                  j                  | j                  |j                         y)al  
    Wait until the mbarrier's phase differs from the provided phase value.
    This means that the given 'phase' has completed.

    Args:
        mbarrier (shared_memory_descriptor): The barrier object to wait on.
        phase (int): The phase value to compare against. The wait completes when
        the barrier's phase becomes different from this value.
    N)	to_tensorr   create_lds_barrier_waitr!   )r"   phaser$   s      r   r   r   "   s2     &E--hoou||Lr   r   )r#   r$   c                    t        |      }|j                  j                  | j                  |      }t	        j
                  |t        j                        S )a  
    Arrive at an mbarrier with a specified count. The operation requires a `count` attribute
    of at least 1, and decreases the pending arrival count of the mbarrier by the specific count.
    If the pending count reaches zero, the phase changes (is decremented in a wraparound manner) and the
    pending count is reloaded with the init count value. Returns the mbarrier's phase parity (0 for even, 1 for odd) prior to the "arrive" operation.

    Args:
        mbarrier (shared_memory_descriptor): Barrier to be signalled.
        count (int): Count to arrive with. Defaults to 1.

    Returns:
        prior phase (int): phase of mbarrier, prior to "arrive" operation.
    )r   r   create_lds_barrier_arriver!   ttgltensorint32)r"   r#   r$   r!   s       r   r	   r	   2   s?     !'E88%PF;;vtzz**r   r   )(triton.experimental.gluon.language._coreexperimentalgluonlanguage_corer+   +triton.experimental.gluon.language._layoutsr   r   r   __all__r   r   r   r	    r   r   <module>r6      sj    7 7 L R
6	b) 	b 	
F 	
F 	M 	M 	4 + 	+r   