o
    h                     @   s   d dl Z d dlZd dlZd dlZd dlmZ ddlmZ ddlm	Z	 G dd de j
d	ZG d
d deZG dd deZG dd deZG dd deZG dd deZG dd dZdd ZeeZdS )    N)Path   )_build   )get_cache_managerc                   @   s*   e Zd ZdZdZedd Zd	ddZdS )

DriverBaser   r   c                   C   s    t jt jt jtddS )Nz..third_party)ospathjoindirnameabspath__file__ r   r   K/var/www/html/ai/venv/lib/python3.10/site-packages/triton/runtime/driver.pythird_party_dir   s    zDriverBase.third_party_dirreturnNc                 C   s   d S Nr   selfr   r   r   __init__   s   zDriverBase.__init__)r   N)__name__
__module____qualname__CUDAHIPstaticmethodr   r   r   r   r   r   r      s    
r   )	metaclassc                       $   e Zd Z fddZdd Z  ZS )	CudaUtilsc                    "   t | dstt| | | _| jS Ninstance)hasattrsuperr   __new__r"   cls	__class__r   r   r%         
zCudaUtils.__new__c              	   C   T  t jt jt}tt j|dd }t	|
d }t|}d}||}|d u rt N}t j|d}t|d}	|	| W d    n1 sPw   Y  td||}
t|
d}	|j|	 |d	d
}W d    n1 suw   Y  W d    n1 sw   Y  dd l}|jd|}|j|}|j| |j| _|j| _d S )Nbackendszcuda.cutf-8zcuda_utils.somain.cw
cuda_utilsrbTbinaryr   r	   r
   r   realpathr   r   r   	read_texthashlibmd5encode	hexdigestr   get_filetempfileTemporaryDirectoryopenwriter   putreadimportlib.utilutilspec_from_file_locationmodule_from_specloaderexec_moduleload_binaryget_device_propertiesr   r   srckeycachefname
cache_pathtmpdirsrc_pathfso	importlibspecmodr   r   r   r   "   0   

zCudaUtils.__init__r   r   r   r%   r   __classcell__r   r   r(   r   r          r   c                       r   )
CudaDriverc                    r    r!   )r#   r$   r[   r%   r"   r&   r(   r   r   r%   ;   r*   zCudaDriver.__new__c                 C      t  | _| j| _d S r   )r   utilsr   backendr   r   r   r   r   @      zCudaDriver.__init__rX   r   r   r(   r   r[   9   rZ   r[   c                       r   )HIPUtilsc                    r    r!   )r#   r$   r`   r%   r"   r&   r(   r   r   r%   J   r*   zHIPUtils.__new__c              	   C   r+   )Nr,   zhip.cr-   zhip_utils.sor.   r/   	hip_utilsr1   Tr2   r   r4   rJ   r   r   r   r   O   rW   zHIPUtils.__init__rX   r   r   r(   r   r`   I   s    r`   c                       r   )	HIPDriverc                    r    r!   )r#   r$   rb   r%   r"   r&   r(   r   r   r%   h   r*   zHIPDriver.__new__c                 C   r\   r   )r`   r]   r   r^   r   r   r   r   r   m   r_   zHIPDriver.__init__rX   r   r   r(   r   rb   f   rZ   rb   c                       r   )UnsupportedDriverc                    r    r!   )r#   r$   rc   r%   r"   r&   r(   r   r   r%   t   r*   zUnsupportedDriver.__new__c                 C   s   d | _ d | _d S r   )r]   r^   r   r   r   r   r   y      
zUnsupportedDriver.__init__rX   r   r   r(   r   rc   r   rZ   rc   c                       sL   e Zd Zdd Zdd Zdd Z fddZd	d
 Zdd Zdd Z	  Z
S )	LazyProxyc                 C   s   || _ d | _d S r   _init_fn_obj)r   init_fnr   r   r   r      rd   zLazyProxy.__init__c                 C   s   | j d u r|  | _ d S d S r   )rh   rg   r   r   r   r   _initialize_obj   s   
zLazyProxy._initialize_objc                 C   s   |    t| j|S r   )rj   getattrrh   r   namer   r   r   __getattr__   r_   zLazyProxy.__getattr__c                    s4   |dv rt  || d S |   t| j|| d S )Nrf   )r$   __setattr__rj   setattrrh   )r   rm   valuer(   r   r   ro      s   zLazyProxy.__setattr__c                 C   s   |    t| j| d S r   )rj   delattrrh   rl   r   r   r   __delattr__   s   zLazyProxy.__delattr__c                 C   s,   | j d u rd| jj d| j dS t| j S )N<z for z not yet initialized>)rh   r)   r   rg   reprr   r   r   r   __repr__   s   

zLazyProxy.__repr__c                 C   s   |    t| jS r   )rj   strrh   r   r   r   r   __str__   s   
zLazyProxy.__str__)r   r   r   r   rj   rn   ro   rs   rv   rx   rY   r   r   r(   r   re      s    re   c                  C   s0   dd l } | jjd urt S | j rt S t S )Nr   )torchversionhiprb   cudais_availabler[   rc   )ry   r   r   r   initialize_driver   s   
r~   )abcr7   r	   r<   pathlibr   common.buildr   rM   r   ABCMetar   objectr   r[   r`   rb   rc   re   r~   driverr   r   r   r   <module>   s     "
