a
    khC                     @  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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d fddZdd Z  ZS )	GluonASTSourceNNone)returnc                   s$   t  |||| tj| _d| _d S )NZttgir)super__init__r   ZGLUONlanguageext)selffn	signatureZ
constexprsattrs	__class__ P/var/www/auris/lib/python3.9/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r|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driver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)__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   r0   *   s   r0   )versionreprlaunch_metadatado_not_specializedo_not_specialize_on_alignmentdebugnoinlinezOptional[T]zOptional[Callable]zOptional[Iterable[int | str]]zOptional[bool]z9Union[GluonJITFunction[T], Callable[[T], JITFunction[T]]])r   r5   r6   r7   r8   r9   r:   r   c          	        s8   ddd fdd}| dur0|| S |S d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   zJITFunction[T])r   r   c              
     s$   t | sJ t|  dS )N)r4   r7   r8   r9   r:   r5   r6   )callabler0   )r   r9   r7   r8   r6   r:   r5   r4   r   r   	decoratorR   s    zjit.<locals>.decoratorNr   )	r   r4   r5   r6   r7   r8   r9   r:   r=   r   r<   r   jit5   s     r>   )N)
__future__r   r'   r$   r   Ztriton.backends.compilerr   Ztriton.runtime.jitr   typingr   r   r   r	   r
   Ztriton._C.libtritonr   r   r   r0   r>   r   r   r   r   <module>   s&    