U
    ‹Ñhå  ã                   @   sF   d dl m Z  d dl mZ dd„ ZG dd„ dƒZG dd„ dƒZeƒ Zd	S )
é   )Úbackends)Ú
DriverBasec                  C   s@   dd„ t  ¡ D ƒ} t| ƒdkr6tt| ƒ› d| › d�ƒ‚| d ƒ S )Nc                 S   s   g | ]}|j  ¡ r|j ‘qS © )ÚdriverZ	is_active)Ú.0Úxr   r   úC/tmp/user/2202/pip-unpacked-wheel-sn6cy74c/triton/runtime/driver.pyÚ
<listcomp>   s     
 z"_create_driver.<locals>.<listcomp>é   z active drivers (z). There should only be one.é    )r   ÚvaluesÚlenÚRuntimeError)Zactivesr   r   r   Ú_create_driver   s    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 ©N©Ú_init_fnÚ_obj)ÚselfZinit_fnr   r   r   Ú__init__   s    zLazyProxy.__init__c                 C   s   | j d kr|  ¡ | _ d S r   )r   r   ©r   r   r   r   Ú_initialize_obj   s    
zLazyProxy._initialize_objc                 C   s   |   ¡  t| j|ƒS r   )r   Úgetattrr   ©r   Únamer   r   r   Ú__getattr__   s    zLazyProxy.__getattr__c                    s2   |dkrt ƒ  ||¡ n|  ¡  t| j||ƒ d S )Nr   )ÚsuperÚ__setattr__r   Úsetattrr   )r   r   Úvalue©Ú	__class__r   r   r      s    zLazyProxy.__setattr__c                 C   s   |   ¡  t| j|ƒ d S r   )r   Údelattrr   r   r   r   r   Ú__delattr__!   s    zLazyProxy.__delattr__c                 C   s,   | j d kr"d| jj› d| j› d�S t| j ƒS )Nú<z for z not yet initialized>)r   r"   Ú__name__r   Úreprr   r   r   r   Ú__repr__%   s    
zLazyProxy.__repr__c                 C   s   |   ¡  t| jƒS r   )r   Ústrr   r   r   r   r   Ú__str__*   s    zLazyProxy.__str__)r&   Ú
__module__Ú__qualname__r   r   r   r   r$   r(   r*   Ú__classcell__r   r   r!   r   r      s   r   c                   @   s*   e Zd Zdd„ Zedœdd„Zdd„ ZdS )	ÚDriverConfigc                 C   s   t tƒ| _| j| _d S r   )r   r   ÚdefaultÚactiver   r   r   r   r   1   s    
zDriverConfig.__init__)r   c                 C   s
   || _ d S r   )r0   )r   r   r   r   r   Ú
set_active5   s    zDriverConfig.set_activec                 C   s   | j | _d S r   )r/   r0   r   r   r   r   Úreset_active8   s    zDriverConfig.reset_activeN)r&   r+   r,   r   r   r1   r2   r   r   r   r   r.   /   s   r.   N)r   r   r   r   r.   r   r   r   r   r   Ú<module>   s
   #