o
    i                     @   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..Zthird_party)ospathjoindirnameabspath__file__ r   r   d/var/www/html/eduruby.in/lip-sync/lip-sync-env/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wZ
cuda_utilsrbTbinaryr   r   r	   r   realpathr   r   r
   	read_texthashlibmd5encode	hexdigestr   Zget_filetempfileTemporaryDirectoryopenwriter   putreadimportlib.utilutilspec_from_file_locationmodule_from_specloaderexec_moduleZload_binaryZget_device_propertiesr   r   srckeycachefname
cache_pathZtmpdirZ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#   rT   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__rQ   r   r   r'   r   rT   9   rS   rT   c                       r   )HIPUtilsc                    r   r    )r"   r#   rY   r$   r!   r%   r'   r   r   r$   J   r)   zHIPUtils.__new__c              	   C   r*   )Nr+   zhip.cr,   zhip_utils.sor-   r.   Z	hip_utilsr/   Tr0   r   r2   rE   r   r   r   r   O   rP   zHIPUtils.__init__rQ   r   r   r'   r   rY   I   s    rY   c                       r   )	HIPDriverc                    r   r    )r"   r#   rZ   r$   r!   r%   r'   r   r   r$   h   r)   zHIPDriver.__new__c                 C   rU   r   )rY   rV   r   rW   r   r   r   r   r   m   rX   zHIPDriver.__init__rQ   r   r   r'   r   rZ   f   rS   rZ   c                       r   )UnsupportedDriverc                    r   r    )r"   r#   r[   r$   r!   r%   r'   r   r   r$   t   r)   zUnsupportedDriver.__new__c                 C   s   d | _ d | _d S r   )rV   rW   r   r   r   r   r   y      
zUnsupportedDriver.__init__rQ   r   r   r'   r   r[   r   rS   r[   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   Zinit_fnr   r   r   r      r\   zLazyProxy.__init__c                 C   s   | j d u r|  | _ d S d S r   )r`   r_   r   r   r   r   _initialize_obj   s   
zLazyProxy._initialize_objc                 C   s   |    t| j|S r   )ra   getattrr`   r   namer   r   r   __getattr__   rX   zLazyProxy.__getattr__c                    s4   |dv rt  || d S |   t| j|| d S )Nr^   )r#   __setattr__ra   setattrr`   )r   rd   valuer'   r   r   rf      s   zLazyProxy.__setattr__c                 C   s   |    t| j| d S r   )ra   delattrr`   rc   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>)r`   r(   r   r_   reprr   r   r   r   __repr__   s   

zLazyProxy.__repr__c                 C   s   |    t| jS r   )ra   strr`   r   r   r   r   __str__   s   
zLazyProxy.__str__)r   r   r   r   ra   re   rf   rj   rm   ro   rR   r   r   r'   r   r]      s    r]   c                  C   s0   dd l } | jjd urt S | j rt S t S )Nr   )torchversionZhiprZ   cudaZis_availablerT   r[   )rp   r   r   r   initialize_driver   s   
rs   )abcr5   r   r9   pathlibr   Zcommon.buildr   rH   r   ABCMetar   objectr   rT   rY   rZ   r[   r]   rs   Zdriverr   r   r   r   <module>   s     "
