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 )NZttgir)super__init__r   ZGLUONlanguageext)selffn	signatureZ
constexprsattrs	__class__ h/home/www/facesmatcher.com/frenv_anti/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   Ztriton.compiler.code_generatorr   r   buildercreate_moduletritonZruntimeZdriverZactiveZget_current_targetZget_target_nameZset_attrZget_string_attrZget_int32_attrZ	num_warpsZnum_ctasZ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   r*   __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   r1   ,   s   
zGluonJITFunction.create_binderc                 C  s   dS )NTr   )r   r   r   r   is_gluon1   s   zGluonJITFunction.is_gluon)r+   r,   r-   r1   r3   r.   r   r   r   r   r/   *   s    r/   )versionreprlaunch_metadatado_not_specializedo_not_specialize_on_alignmentdebugnoinliner   Optional[T]r5   Optional[Callable]r6   r7   Optional[Iterable[int | str]]r8   r9   Optional[bool]r:   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)r4   r7   r8   r9   r:   r5   r6   )callabler/   )r   r9   r7   r8   r6   r:   r5   r4   r   r   	decoratorR   s   zjit.<locals>.decoratorN)r   r   r   r@   r   )	r   r4   r5   r6   r7   r8   r9   r:   rC   r   rB   r   jit5   s   rD   r0   )r   r;   r5   r<   r6   r<   r7   r=   r8   r=   r9   r>   r:   r>   r   r?   )
__future__r   r'   r$   r   Ztriton.backends.compilerr   Ztriton.runtime.jitr   typingr   r   r   r	   r
   Ztriton._C.libtritonr   r   r   r/   rD   r   r   r   r   <module>   s(    