
      i                     l    d dl mZ d dlZd dlmZ d dlmZ d dlmZ  G d de      Z	dee
ef   d	e
fd
Zy)    )UnionN)override)Accelerator)_AcceleratorRegistryc                   J   e Zd ZdZedej                  ddfd       Zedd       Ze	ede
eef   defd              Ze	ede
eef   deej                     fd	              Ze	edefd
              Ze	edefd              Ze	edefd              Zeededdfd              Zy)CPUAcceleratorzAccelerator for CPU devices.devicereturnNc                 @    |j                   dk7  rt        d| d      y)zd
        Raises:
            ValueError:
                If the selected device is not CPU.
        cpuzDevice should be CPU, got z	 instead.N)type
ValueError)selfr	   s     v/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/lightning/fabric/accelerators/cpu.pysetup_devicezCPUAccelerator.setup_device   s*     ;;%9&KLL      c                      y )N )r   s    r   teardownzCPUAccelerator.teardown$   s    r   devicesc                     t        |       S )z!Accelerator device parsing logic.)_parse_cpu_coresr   s    r   parse_deviceszCPUAccelerator.parse_devices(   s      ((r   c                 J    t        |       } t        j                  d      g| z  S )z*Gets parallel devices for the Accelerator.r   )r   torchr	   r   s    r   get_parallel_devicesz#CPUAccelerator.get_parallel_devices.   s%     #7+U#$w..r   c                       y)z!Get the devices when set to auto.   r   r   r   r   auto_device_countz CPUAccelerator.auto_device_count5   s     r   c                       y)z&CPU is always available for execution.Tr   r   r   r   is_availablezCPUAccelerator.is_available;   s     r   c                       y)Nr   r   r   r   r   namezCPUAccelerator.nameA   s     r   accelerator_registryc                 \    |j                  | j                         | | j                         y )N)description)registerr$   __name__)clsr%   s     r   register_acceleratorsz$CPUAccelerator.register_acceleratorsF   s*     	%%HHJ 	& 	
r   )r
   N)r)   
__module____qualname____doc__r   r   r	   r   r   staticmethodr   intstrr   listr   r    boolr"   r$   classmethodr   r+   r   r   r   r   r      sC   &M5<< MD M M   )uS#X )3 )  ) /eCHo /$u||:L /  /
 s    $    #    
9M 
RV 
  
r   r   	cpu_coresr
   c                     t        | t              r)| j                         j                         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:`~lightning.pytorch.trainer.trainer.Trainer`.

    Args:
        cpu_cores: An int > 0 or a string that can be converted to 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.)
isinstancer1   stripisdigitr0   	TypeError)r5   s    r   r   r   P   sK     )S!ioo&7&?&?&A	N	i%aXYYr   )typingr   r   typing_extensionsr   )lightning.fabric.accelerators.acceleratorr   &lightning.fabric.accelerators.registryr   r   r0   r1   r   r   r   r   <module>r?      s>      & A G6
[ 6
rc3h C r   