U
    ‹Ñh 
  ã                   @   st   d dl Z d dlZd dlZd dlmZmZmZ d dlmZ d dl	m
Z
 edd�G dd„ deƒƒZG d	d
„ d
ed�ZdS )é    N)ÚABCMetaÚabstractmethodÚabstractclassmethod)Ú	dataclass)ÚUnionT)Úfrozenc                   @   s.   e Zd ZU eed< eeef ed< eed< dS )Ú	GPUTargetÚbackendÚarchZ	warp_sizeN)Ú__name__Ú
__module__Ú__qualname__ÚstrÚ__annotations__r   Úint© r   r   úF/tmp/user/2202/pip-unpacked-wheel-sn6cy74c/triton/backends/compiler.pyr   
   s   
r   c                   @   sˆ   e Zd Zeddœdd„Zeedœdd„ƒZeedœd	d
„ƒZ	e
edœdd„ƒZe
eedœdd„ƒZe
eeddœdd„ƒZe
dd„ ƒZdS )ÚBaseBackendN)ÚtargetÚreturnc                 C   s   || _ |  |¡st‚d S ©N)r   Úsupports_targetÚAssertionError)Úselfr   r   r   r   Ú__init__   s    zBaseBackend.__init__)Úbinaryc                 C   sÖ   t j t j t¡t j¡}t j d|  ¡ › d�d¡t j |ddd| ¡g}|D ]x}| 	d¡d }t j 
|¡rJt j |¡rJtj|d	gtjd
�}|d k	rJtjd| d¡tjd�}|d k	rJ|| d¡f  S qJtd| › �ƒ‚d S )NZTRITON_Z_PATHÚ Zthird_partyZcudaÚbinú r   z	--version)Ústderrz.*release (\d+\.\d+).*zutf-8)Úflagsé   zCannot find )ÚosÚpathÚjoinÚdirnameÚ__file__ÚpardirÚenvironÚgetÚupperÚsplitÚexistsÚisfileÚ
subprocessÚcheck_outputÚSTDOUTÚreÚsearchÚdecodeÚ	MULTILINEÚgroupÚRuntimeError)r   Úbase_dirÚpathsÚpr   ÚresultÚversionr   r   r   Ú_path_to_binary   s    þzBaseBackend._path_to_binary©r   c                 C   s   t ‚d S r   ©ÚNotImplementedErrorr=   r   r   r   r   *   s    zBaseBackend.supports_target)r   c                 C   s   t ‚dS )z,Returns a unique identifier for this backendNr>   )r   r   r   r   Úhash.   s    zBaseBackend.hash)Úoptionsr   c                 C   s   t ‚dS )zÇ
        Converts an `options` dictionary into an arbitrary object and returns it.
        This function may contain target-specific heuristics and check the legality of the provided options
        Nr>   )r   rA   r   r   r   Úparse_options3   s    zBaseBackend.parse_options)ÚstagesrA   r   c                 C   s   t ‚dS )a×  
        Populates `stages` dictionary with entries of the form:
        ir_name [str] => Function[(src: str, metadata: dict) -> str|bytes]
        The value of each entry may populate a `metadata` dictionary.
        Stages will be run sequentially (in inseriton order) and can communicate using `metadata`.
        All stages are expected to return a `str` object, except for the last stage which returns
        a `bytes` object for execution by the launcher.
        Nr>   )r   rC   rA   r   r   r   Ú
add_stages;   s    
zBaseBackend.add_stagesc                 C   s   t ‚dS )zK
        Load additional MLIR dialects into the provided `context`
        Nr>   )r   Úcontextr   r   r   Úload_dialectsG   s    zBaseBackend.load_dialects)r   r   r   r   r   Ústaticmethodr   r<   r   r   r   r@   ÚdictÚobjectrB   rD   rF   r   r   r   r   r      s   r   )Ú	metaclass)r"   r1   r.   Úabcr   r   r   Zdataclassesr   Útypingr   rI   r   r   r   r   r   r   Ú<module>   s   