o
    ^i                  	   @  s   d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
mZmZmZmZ d dlmZ e
dZdd	g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 )     )annotations)	ASTSource)Language)JITFunctionconstexpr_function)TypeVarOptionalCallableIterableUnion)irTr   jitc                      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/RAG/RAG_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|}| }	||}
|
|}|	d|	| |	d|
|j |	d|
|j |	d|
|j |jdk}|r[|jd ur[|	d	|
|j || j| |||||	d
}	|	S )Nr   )make_backend)ast_to_ttirz
ttg.targetzttg.num-warpszttg.num-ctaszttg.threads-per-warpcudazttg.maxnreg)contextoptionscodegen_fns
module_mapmodule)triton.compiler.compilerr!   triton.compiler.code_generatorr"   r   buildercreate_moduleget_target_nameset_attrget_string_attrget_int32_attr	num_warpsnum_ctas	warp_sizebackend_namemaxnregr   )r   targetr%   r&   r'   r$   r!   r"   r+   r(   backendis_cudar   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_gluon4   s   zGluonJITFunction.is_gluon)r:   r;   r<   r@   rB   r=   r   r   r   r    r>   -   s    r>   N)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    	decoratorU   s   zjit.<locals>.decoratorN)r   r   r   rO   r   )	r   rC   rD   rE   rF   rG   rH   rI   rR   r   rQ   r    r   8   s   r?   )r   rJ   rD   rK   rE   rK   rF   rL   rG   rL   rH   rM   rI   rM   r   rN   )
__future__r   r)   r   triton.backends.compilerr   triton.runtime.jitr   r   typingr   r   r	   r
   r   triton._C.libtritonr   r   __all__r   r>   r   r   r   r   r    <module>   s(     