o
    iG
                     @   s   d dl m  m  m  mZ d dlmZ d dl mZm	Z	 g dZ
G dd deZedddZedd	d
ZedddddZdS )    N)SwizzledSharedLayout)builtin_unwrap_if_constexpr)MBarrierLayoutinitwaitarrivec                       s"   e Zd ZdZd fdd	Z  ZS )r   z
    Layout for mbarrier synchronization.

    Args:
        cga_layout (List[List[int]]): CTA layout bases. Defaults to [].
    Nc                    s    t  jddddg|pg d d S )N   r   )vec	per_phase	max_phaseorder
cga_layout)super__init__)selfr   	__class__ j/home/kuhnn/.local/lib/python3.10/site-packages/triton/experimental/gluon/language/amd/gfx1250/mbarrier.pyr      s    zMBarrierLayout.__init__N)__name__
__module____qualname____doc__r   __classcell__r   r   r   r   r      s    r   c                 C   s   t |}|j| j| dS )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	_semanticr   r   r   r      s   
r   c                 C   s    | |}|j| j|j dS )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!   r   r   r   r   "   s   
r   r	   )r    r!   c                C   s&   t |}|j| j|}t|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 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   r   r   r   r   2   s   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   r   r   <module>   s    