o
    h=                  	   @   sB   d dl mZ d dlZd dlmZ 	ddedededefd	d
ZdS )    )AnyN)_get_device_indexFdeviceoptional	allow_cpureturnc                 C   s   t | tr| S t | trt| } t | tjr2|r&| jdvr%td|  n| jdkr2td|  tj sAt | tj	jrA| j
S t| ||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 CUDA device. Note that for a CUDA device without a specified index,
    i.e., ``torch.device('cuda')``, this will return the current default CUDA
    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 CUDA
    device if :attr:`optional` is ``True``.
    )cudacpuz(Expected a cuda or cpu device, but got: r   z!Expected a cuda device, but got: )
isinstanceintstrtorchr   type
ValueErrorjitis_scriptingr   idx_torch_get_device_index)r   r   r    r   e/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/torch/cuda/_utils.pyr   	   s   





r   )FF)typingr   r   torch._utilsr   r   boolr   r   r   r   r   <module>   s    