a
    d                     @   s   d dl mZmZmZmZ d dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ G dd	 d	eZd
ZdZdZeeef dddZdS )    )AnyDictListUnionN_parse_cpu_cores)_DEVICE)Accelerator)MisconfigurationException)_PSUTIL_AVAILABLEc                   @   s   e Zd ZdZejddddZeee	e
f dddZddd	d
Zeeee	ee f edddZeeee	ee f eej dddZeedddZeedddZeeddddZdS )CPUAcceleratorzAccelerator for CPU devices.N)devicereturnc                 C   s   |j dkrtd| ddS )zs
        Raises:
            MisconfigurationException:
                If the selected device is not CPU.
        cpuzDevice should be CPU, got z	 instead.N)typer
   selfr    r   k/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/pytorch_lightning/accelerators/cpu.pysetup_device   s    
zCPUAccelerator.setup_devicec                 C   s   t  S )z&Get CPU stats from ``psutil`` package.)get_cpu_statsr   r   r   r   get_device_stats%   s    zCPUAccelerator.get_device_statsr   c                 C   s   d S )Nr   )r   r   r   r   teardown)   s    zCPUAccelerator.teardown)devicesr   c                 C   s   t | } | S )z!Accelerator device parsing logic.r   r   r   r   r   parse_devices,   s    zCPUAccelerator.parse_devicesc                 C   s   t | } tdg|  S )z*Gets parallel devices for the Accelerator.r   )r   torchr   r   r   r   r   get_parallel_devices2   s    z#CPUAccelerator.get_parallel_devicesc                   C   s   dS )z!Get the devices when set to auto.   r   r   r   r   r   auto_device_count8   s    z CPUAccelerator.auto_device_countc                   C   s   dS )z&CPU is always available for execution.Tr   r   r   r   r   is_available=   s    zCPUAccelerator.is_available)accelerator_registryr   c                 C   s   |j d| | jj d d S )Nr   )description)register	__class____name__)clsr"   r   r   r   register_acceleratorsB   s
    z$CPUAccelerator.register_accelerators)r&   
__module____qualname____doc__r   r   r   r   r   strr   r   r   staticmethodr   intr   r   r   r    boolr!   classmethodr(   r   r   r   r   r      s   	 &r   Zcpu_vm_percentcpu_percentZcpu_swap_percentr   c                  C   s4   t stddd l} t|  jt|  t| 	 jiS )NzkFetching CPU device stats requires `psutil` to be installed. Install it by running `pip install -U psutil`.r   )
r   ModuleNotFoundErrorpsutil_CPU_VM_PERCENTZvirtual_memorypercent_CPU_PERCENTr1   _CPU_SWAP_PERCENTZswap_memory)r3   r   r   r   r   Q   s    

r   )typingr   r   r   r   r   Z!lightning_fabric.accelerators.cpur   Z lightning_fabric.utilities.typesr   Z*pytorch_lightning.accelerators.acceleratorr	   Z&pytorch_lightning.utilities.exceptionsr
   Z#pytorch_lightning.utilities.importsr   r   r4   r6   r7   r,   floatr   r   r   r   r   <module>   s   3