o
    ۷i                     @   sX   d dl Z d dlm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dS )    N)ABCc                   @   s   e Zd ZU eed< eed< eed< eed< eed< edd Zedd	 Zed
d Zedd Z	edd Z
edd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zed d! Zd"S )#BasePlatformdevice_typedevice_control_env_vardispatch_keydist_backendfull_dist_backendc                  O      t NNotImplementedErrorargskwargs r   R/home/ubuntu/vllm_env/lib/python3.10/site-packages/cache_dit/platforms/platform.pyempty_cache      zBasePlatform.empty_cachec                  O   r	   r
   r   r   r   r   r   ipc_collect   r   zBasePlatform.ipc_collectc                   C   r	   r
   r   r   r   r   r   get_device_name   r   zBasePlatform.get_device_namec                  O   r	   r
   r   r   r   r   r   
device_ctx   r   zBasePlatform.device_ctxc                  O   r	   r
   r   r   r   r   r   default_device   r   zBasePlatform.default_devicec                  O   r	   r
   r   r   r   r   r   synchronize!   r   zBasePlatform.synchronizec                  O   r	   r
   r   r   r   r   r   device_count%   r   zBasePlatform.device_countc                  O   r	   r
   r   r   r   r   r   is_accelerator_available)   r   z%BasePlatform.is_accelerator_availablec                  O   r	   r
   r   r   r   r   r   current_device-   r   zBasePlatform.current_devicec                  O   r	   r
   r   r   r   r   r   reset_peak_memory_stats1   r   z$BasePlatform.reset_peak_memory_statsc                  O   r	   r
   r   r   r   r   r   max_memory_allocated5   r   z!BasePlatform.max_memory_allocatedc                  O   r	   r
   r   r   r   r   r   get_device_properties9   r   z"BasePlatform.get_device_propertiesc                  O   r	   r
   r   r   r   r   r   
set_device=   r   zBasePlatform.set_devicec                  O   r	   r
   r   r   r   r   r   get_device_capabilityA   r   z"BasePlatform.get_device_capabilityN)__name__
__module____qualname__str__annotations__staticmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r   r   r   r      sD   
 












r   c                   @   sf   e Zd ZU dZeed< dZeed< dZdZeed< dZ	eed	< e
d
d Ze
dd Ze
dd ZdS )CpuPlatformcpur   CPUr   CPU_VISIBLE_MEMORY_NODESgloor   zcpu:gloor   c                   C   
   t dS )Nr(   torchdevicer   r   r   r   r   M      
zCpuPlatform.default_devicec                   C      dS )Nr)   r   r   r   r   r   r   Q   r   zCpuPlatform.get_device_namec                   C   r1   )NFr   r   r   r   r   r   U   r   z$CpuPlatform.is_accelerator_availableN)r!   r"   r#   r   r$   r%   r   r   r   r   r&   r   r   r   r   r   r   r   r'   F   s   
 

r'   c                   @   s   e Zd ZU dZeed< dZeed< dZeed< dZeed< d	Z	eed
< e
dd Ze
dd Ze
dd Ze
dd Ze
dd Ze
d(ddZe
dd Ze
dd Ze
dd Ze
d(ddZe
d(d d!Ze
d(d"d#Ze
d$d% Ze
d(d&d'ZdS ))CudaPlatformcudar   CUDA_VISIBLE_DEVICESr   CUDAr   ncclr   z	cuda:ncclr   c                   C      t j  d S r
   )r.   r3   r   r   r   r   r   r   a      zCudaPlatform.empty_cachec                   C   r7   r
   )r.   r3   r   r   r   r   r   r   e   r8   zCudaPlatform.ipc_collectc                   C   
   t j S r
   )r.   r3   r   r   r   r   r   r   i   r0   zCudaPlatform.get_device_namec                 C      t j| S r
   )r.   r3   r/   r/   r   r   r   r   m      zCudaPlatform.device_ctxc                   C   r,   )Nr3   r-   r   r   r   r   r   q   r0   zCudaPlatform.default_deviceNc                 C      t j|  d S r
   )r.   r3   r   r;   r   r   r   r   u      zCudaPlatform.synchronizec                   C   r9   r
   )r.   r3   r   r   r   r   r   r   y   r0   zCudaPlatform.device_countc                   C   r9   r
   )r.   r3   is_availabler   r   r   r   r   }   r0   z%CudaPlatform.is_accelerator_availablec                   C   r9   r
   )r.   r3   r   r   r   r   r   r      r0   zCudaPlatform.current_devicec                 C   r:   r
   )r.   r3   r   r;   r   r   r   r      r<   z$CudaPlatform.reset_peak_memory_statsc                 C   r:   r
   )r.   r3   r   r;   r   r   r   r      r<   z!CudaPlatform.max_memory_allocatedc                 C   r:   r
   )r.   r3   r   r;   r   r   r   r      r<   z"CudaPlatform.get_device_propertiesc                 C   r:   r
   )r.   r3   r   r;   r   r   r   r      r<   zCudaPlatform.set_devicec                 C   r:   r
   )r.   r3   r    r;   r   r   r   r       r<   z"CudaPlatform.get_device_capabilityr
   )r!   r"   r#   r   r$   r%   r   r   r   r   r&   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r   r   r   r2   Z   sD   
 








r2   c                   @   s   e Zd ZU dZeed< dZeed< dZeed< dZeed< d	Z	eed
< e
dd Ze
dd Ze
dd Ze
dd Ze
dd Ze
d&ddZe
dd Ze
dd Ze
dd Ze
d&ddZe
d&d d!Ze
d&d"d#Ze
d$d% ZdS )'NPUPlatformnpur   ASCEND_RT_VISIBLE_DEVICESr   PrivateUse1r   hcclr   znpu:hcclr   c                   C   r7   r
   )r.   rA   r   r   r   r   r   r      r8   zNPUPlatform.empty_cachec                   C   r1   )zA
        torch.npu.ipc_collect() is not implemented yet.
        Nr   r   r   r   r   r      s   zNPUPlatform.ipc_collectc                   C   r9   r
   )r.   rA   r   r   r   r   r   r      r0   zNPUPlatform.get_device_namec                 C   r:   r
   )r.   rA   r/   r;   r   r   r   r      r<   zNPUPlatform.device_ctxc                   C   r,   )NrA   r-   r   r   r   r   r      r0   zNPUPlatform.default_deviceNc                 C   r=   r
   )r.   rA   r   r;   r   r   r   r      r>   zNPUPlatform.synchronizec                   C   r9   r
   )r.   rA   r   r   r   r   r   r      r0   zNPUPlatform.device_countc                   C   r9   r
   )r.   rA   r?   r   r   r   r   r      r0   z$NPUPlatform.is_accelerator_availablec                   C   r9   r
   )r.   rA   r   r   r   r   r   r      r0   zNPUPlatform.current_devicec                 C   r:   r
   )r.   rA   r   r;   r   r   r   r      r<   z#NPUPlatform.reset_peak_memory_statsc                 C   r:   r
   )r.   rA   r   r;   r   r   r   r      r<   z NPUPlatform.max_memory_allocatedc                 C   r:   r
   )r.   rA   r   r;   r   r   r   r      r<   z!NPUPlatform.get_device_propertiesc                 C   r:   r
   )r.   rA   r   r;   r   r   r   r      r<   zNPUPlatform.set_devicer
   )r!   r"   r#   r   r$   r%   r   r   r   r   r&   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r@      s@   
 







r@   )r.   abcr   r   r'   r2   r@   r   r   r   r   <module>   s   @@