a
    yd{                     @  sL   d dl mZ d dlZdd Zdd ZG dd dZG d	d
 d
Zdd ZdS )    )annotationsNc                 C  s   | | d | S )N    )xyr   r   U/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/triton/utils.pycdiv   s    r   c                 C  sP   | d8 } | | d? O } | | d? O } | | d? O } | | d? O } | | d? O } | d7 } | S )z9Return the smallest power of 2 greater than or equal to nr               r   )nr   r   r   next_power_of_2
   s    r   c                   @  s0   e Zd ZdZedd Zdd Zedd ZdS )	
MockTensorzr
    Can be used in place of real tensors when calling:
        kernel.warmup(MockTensor(torch.float32), ...)
    c                 C  s   t | tjrt| S | S N)
isinstancetorchdtyper   )argr   r   r   
wrap_dtype   s    zMockTensor.wrap_dtypec                 C  s
   || _ d S r   )r   )selfr   r   r   r   __init__!   s    zMockTensor.__init__c                   C  s   dS )Nr   r   r   r   r   r   data_ptr$   s    zMockTensor.data_ptrN)__name__
__module____qualname____doc__staticmethodr   r   r   r   r   r   r   r      s   
r   c                   @  s*   e Zd Zdd Zdd ZddddZd	S )
TensorWrapperc                 C  s    || _ || _|j| _|j| _d S r   )r   baseZis_cudaZdevice)r   r   r   r   r   r   r   *   s    zTensorWrapper.__init__c                 C  s
   | j  S r   )r   r   r   r   r   r   r   0   s    zTensorWrapper.data_ptrstr)returnc                 C  s   d| j  d| j dS )NzTensorWrapper[z]())r   r   r    r   r   r   __str__3   s    zTensorWrapper.__str__N)r   r   r   r   r   r$   r   r   r   r   r   )   s   r   c                 C  sX   t | tr*|| jjkr| jS t| j|S n*t | tjr@t| |S tdt|  dd S )NzCannot reinterpret a .)r   r   r   r   r   ZTensor	TypeErrortype)Ztensorr   r   r   r   reinterpret7   s    

r(   )
__future__r   r   r   r   r   r   r(   r   r   r   r   <module>   s   