o
    Ơi	                     @   s   d dl Z d dlmZ e jdkrd dlmZ nd dlmZ d dlZd dlmZ zd dl	m
Z
 W n ey<   ed Y nw G dd	 d	eZdS )
    N)Any)      )Self)Device)_CzrUnable to import torchscript frontend core and torch-tensorrt runtime. Some dependent features may be unavailable.c                       sP   e Zd ZdZdedef fddZdejfddZe	d	e
defd
dZ  ZS )TorchScriptDevicea  
    Defines a device that can be used to specify target devices for engines

    Attributes:
        device_type (torch_tensorrt.DeviceType): Target device type (GPU or DLA). Set implicitly based on if dla_core is specified.
        gpu_id (int): Device ID for target GPU
        dla_core (int): Core ID for target DLA core
        allow_gpu_fallback (bool): Whether falling back to GPU if DLA cannot support an op should be allowed
    argskwargsc                    s   t  j|i | dS )a  __init__ Method for torch_tensorrt.Device

        Device accepts one of a few construction patterns

        Args:
            spec (str): String with device spec e.g. "dla:0" for dla, core_id 0

        Keyword Arguments:
            gpu_id (int): ID of target GPU (will get overridden if dla_core is specified to the GPU managing DLA). If specified, no positional arguments should be provided
            dla_core (int): ID of target DLA core. If specified, no positional arguments should be provided.
            allow_gpu_fallback (bool): Allow TensorRT to schedule operations on GPU if they are not supported on DLA (ignored if device type is not DLA)

        Examples:
            - Device("gpu:1")
            - Device("cuda:1")
            - Device("dla:0", allow_gpu_fallback=True)
            - Device(gpu_id=0, dla_core=0, allow_gpu_fallback=True)
            - Device(dla_core=0, allow_gpu_fallback=True)
            - Device(gpu_id=1)
        N)super__init__)selfr	   r
   	__class__ M/home/ubuntu/.local/lib/python3.10/site-packages/torch_tensorrt/ts/_Device.pyr       s   zTorchScriptDevice.__init__returnc                 C   s4   t  }| jt j|_| j|_| j|_| j|_|S )N)r   r   device_typeto
DeviceTypegpu_iddla_coreallow_gpu_fallback)r   internal_devr   r   r   _to_internal7   s   zTorchScriptDevice._to_internaldc                 C   s   | |j |j|jdS )Nr   r   r   r   )clsr   r   r   r   _from?   s
   zTorchScriptDevice._from)__name__
__module____qualname____doc__r   r   r   r   r   classmethodobjectr   r   __classcell__r   r   r   r   r      s    
r   )systypingr   version_infor   typing_extensionswarningstorch_tensorrt._Devicer   torch_tensorrtr   ImportErrorwarnr   r   r   r   r   <module>   s    
