o
    m9:j|                  	   @   s6   d dl mZ d dlZ	d
dedededefdd	ZdS )    )AnyNFdeviceoptional	allow_cpureturnc                 C   s   | du r|rt j S t| tr| S t j s!t| t jjr!| j	S t| t
r+t | } d}t| t jrW|sA| jdkrAtd|  | jdvrMtd|  | jdkrTdn| j}|du rk|rdt j }|S td|  |S )a  Get the device index from :attr:`device`, which can be a torch.device object, a Python integer, or ``None``.

    If :attr:`device` is a torch.device object, returns the device index if it
    is a MTIA device. Note that for a MTIA device without a specified index,
    i.e., ``torch.device('mtia')``, this will return the current default MTIA
    device if :attr:`optional` is ``True``. If :attr:`allow_cpu` is ``True``,
    CPU devices will be accepted and ``-1`` will be returned in this case.

    If :attr:`device` is a Python integer, it is returned as is.

    If :attr:`device` is ``None``, this will return the current default MTIA
    device if :attr:`optional` is ``True``.
    Ncpuz$Expected a non cpu device, but got: )mtiar   z(Expected a mtia or cpu device, but got: zGExpected a torch.device with a specified index or an integer, but got: )torch_C_mtia_getDevice
isinstanceintjitis_scriptingr   r   idxstrtype
ValueErrorindex)r   r   r   
device_idx r   X/home/nk/hobo-godmode/plappi-mvp/.venv/lib/python3.10/site-packages/torch/mtia/_utils.py_get_device_index   s0   






r   )FF)typingr   r
   boolr   r   r   r   r   r   <module>   s    