o
    zib                     @   sp   d dl mZm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Z
deeeee f d	efd
dZdS )    )ListUnionN)override)Accelerator)_AcceleratorRegistryc                   @   s   e Zd ZdZedejddfddZedddZe	ed	e
eeee f defd
dZe	ed	e
eeee f deej fddZe	edefddZe	edefddZeededdfddZdS )CPUAcceleratorzAccelerator for CPU devices.devicereturnNc                 C   s   |j dkrtd| ddS )zd
        Raises:
            ValueError:
                If the selected device is not CPU.
        cpuzDevice should be CPU, got z	 instead.N)type
ValueError)selfr    r   U/home/ubuntu/.local/lib/python3.10/site-packages/lightning_fabric/accelerators/cpu.pysetup_device   s   
zCPUAccelerator.setup_devicec                 C   s   d S )Nr   )r   r   r   r   teardown$   s   zCPUAccelerator.teardowndevicesc                 C   s   t | S )z!Accelerator device parsing logic.)_parse_cpu_cores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_devices.   s   z#CPUAccelerator.get_parallel_devicesc                   C      dS )z!Get the devices when set to auto.   r   r   r   r   r   auto_device_count5      z CPUAccelerator.auto_device_countc                   C   r   )z&CPU is always available for execution.Tr   r   r   r   r   is_available;   r   zCPUAccelerator.is_availableaccelerator_registryc                 C   s   |j d| | jd d S )Nr
   )description)register__name__)clsr   r   r   r   register_acceleratorsA   s
   
z$CPUAccelerator.register_accelerators)r	   N)r    
__module____qualname____doc__r   r   r   r   r   staticmethodr   intstrr   r   r   r   boolr   classmethodr   r"   r   r   r   r   r      s*    	$*r   	cpu_coresr	   c                 C   s<   t | tr|   rt| } t | tr| dkrtd| S )a]  Parses the cpu_cores given in the format as accepted by the ``devices`` argument in the
    :class:`~pytorch_lightning.trainer.trainer.Trainer`.

    Args:
        cpu_cores: An int > 0.

    Returns:
        An int representing the number of processes

    Raises:
        MisconfigurationException:
            If cpu_cores is not an int > 0

    r   z>`devices` selected with `CPUAccelerator` should be an int > 0.)
isinstancer(   stripisdigitr'   	TypeError)r+   r   r   r   r   K   s
   r   )typingr   r   r   typing_extensionsr   )lightning_fabric.accelerators.acceleratorr   &lightning_fabric.accelerators.registryr   r   r'   r(   r   r   r   r   r   <module>   s   $4