
    ^j                         d dl mc mc mc mZ d dl mZ d dlmZm	Z	m
Z
mZmZmZmZ g dZedd       Zd	dZed	d       Zy)
    N)builtin)async_copy_global_to_sharedasync_copy_shared_to_global
store_waittensor_descriptortensor_descriptor_typemake_tensor_descriptor_emit_alignment_check)async_gatherasync_scatterr   r   r   r   r   r	   c                 b   |j                   j                  j                  rt        | |fdd|       |j	                  |      }|j	                  |      }|j                   j                  | j                  |j                  |j                  |j                  |j                  |j                         y)a,  
    Asynchronously gather elements from global memory to shared memory using TMA.

    Args:
        tensor_desc (tensor_descriptor): The tensor descriptor.
        x_offsets (tensor): 1D tensor of X offsets.
        y_offset (int): Scalar Y offset.
        barrier (shared_memory_descriptor): Barrier that will be signaled when the operation is complete.
        result (tensor_memory_descriptor): Result shared memory, must have NVMMASharedLayout.
        pred (bool): Scalar predicate. Operation is skipped if predicate is False. Defaults to True.
    r   y_offset	_semanticN)builderoptionsenable_iisanr
   	to_tensorcreate_async_tma_gatherhandle)tensor_desc	x_offsetsr   barrierresultpredr   s          /var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/triton/experimental/gluon/language/nvidia/blackwell/tma.pyr   r      s       --kH<_hit$D""8,H--k.@.@)BRBRT\TcTceleses.4mmT[[J    c                    t        j                  ||      }t        j                  d|      }|j                  ||      }t        j                  |d|       | j                  ||      }t        j                  |d|       y )Nr   r   z)async_scatter y_offset cannot be negativez9async_scatter x_offsets cannot have any negative elements)ttglr   __ge__device_assert)r   r   r   zerois_nonnegatives        r   _emit_scatter_nonnegative_checkr$   /   sq    ~~h)<H>>!y1D__TY_?N~'R^gh%%di%@N~'bnwxr   c                 0   |j                   j                  j                  rt        | |fdd|       t	        |||       |j                  |      }|j                   j                  | j                  |j                  |j                  |j                         y)aW  
    Asynchronously scatter elements from shared memory to global memory using TMA.

    Args:
        tensor_desc (tensor_descriptor): The tensor descriptor.
        x_offsets (tensor): 1D tensor of X offsets.
        y_offset (int): Scalar Y offset.
        src (tensor_memory_descriptor): The source data, must be in NVMMASharedLayout.
    r   r   r   N)r   r   r   r
   r$   r   create_async_tma_scatterr   )r   r   r   srcr   s        r   r   r   :   s|       --kH<*`ij'	8yQ""8,H..{/A/A9CSCSU]UdUdfifpfpqr   )TN)N)(triton.experimental.gluon.language._coreexperimentalgluonlanguage_corer   r   4triton.experimental.gluon.language.nvidia.hopper.tmar   r   r   r   r   r	   r
   __all__r   r$   r    r   r   <module>r0      sV    7 7 <  	 	J 	J*y 	r 	rr   