o
    hC                  	   @  s   d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
mZmZmZmZ d dlmZ e
dZG d	d
 d
eZG dd dee Z	ddddddddddddZdS )    )annotationsN)	ASTSource)Language)JITFunction)TypeVarOptionalCallableIterableUnion)irTc                      s(   e Zd Zdd	 fddZdd Z  ZS )
GluonASTSourceNreturnNonec                   s$   t  |||| tj| _d| _d S )Nttgir)super__init__r   GLUONlanguageext)selffn	signature
constexprsattrs	__class__ ]/var/www/html/scripts/venv/lib/python3.10/site-packages/triton/experimental/gluon/_runtime.pyr      s   
zGluonASTSource.__init__c              	   C  s   ddl m} ddlm} t|}| }tjj	j
 }	||	}
|
|}	|d||	 |d||j |d||j |d|d |jd urZ|d	||j || j| |||||d
}|S )Nr   )make_backend)ast_to_ttirz
ttg.targetzttg.num-warpszttg.num-ctaszttg.threads-per-warp    zttg.maxnreg)contextoptionscodegen_fns
module_mapmodule)triton.compiler.compilerr   triton.compiler.code_generatorr    r   buildercreate_moduletritonruntimedriveractiveget_current_targetget_target_nameset_attrget_string_attrget_int32_attr	num_warpsnum_ctasmaxnregr   )r   r#   r$   r%   r"   r   r    r)   r&   targetbackendr   r   r   make_ir   s"   


zGluonASTSource.make_ir)NN)r   r   )__name__
__module____qualname__r   r9   __classcell__r   r   r   r   r      s    r   c                      s$   e Zd Z fddZdd Z  ZS )GluonJITFunctionc                   s   t   }t| _|S N)r   create_binderr   r   )r   resultr   r   r   r@   ,   s   
zGluonJITFunction.create_binderc                 C  s   dS )NTr   )r   r   r   r   is_gluon1   s   zGluonJITFunction.is_gluon)r:   r;   r<   r@   rB   r=   r   r   r   r   r>   *   s    r>   )versionreprlaunch_metadatado_not_specializedo_not_specialize_on_alignmentdebugnoinliner   Optional[T]rD   Optional[Callable]rE   rF   Optional[Iterable[int | str]]rG   rH   Optional[bool]rI   r   9Union[GluonJITFunction[T], Callable[[T], JITFunction[T]]]c          	        s.   d fdd}| dur|| S |S )	a<  
    Decorator for JIT-compiling a function using the Triton compiler.

    :note: When a jit'd function is called, arguments are
        implicitly converted to pointers if they have a :code:`.data_ptr()` method
        and a `.dtype` attribute.

    :note: This function will be compiled and run on the GPU. It will only have access to:

           * python primitives,
           * builtins within the triton package,
           * arguments to this function,
           * other jit'd functions

    :param fn: the function to be jit-compiled
    :type fn: Callable
    r   r   r   JITFunction[T]c              
     s$   t | sJ t|  dS )N)rC   rF   rG   rH   rI   rD   rE   )callabler>   )r   rH   rF   rG   rE   rI   rD   rC   r   r   	decoratorR   s   zjit.<locals>.decoratorN)r   r   r   rO   r   )	r   rC   rD   rE   rF   rG   rH   rI   rR   r   rQ   r   jit5   s   rS   r?   )r   rJ   rD   rK   rE   rK   rF   rL   rG   rL   rH   rM   rI   rM   r   rN   )
__future__r   r+   r'   r   triton.backends.compilerr   triton.runtime.jitr   typingr   r   r   r	   r
   triton._C.libtritonr   r   r   r>   rS   r   r   r   r   <module>   s(    