
    
Ng                        d dl mZ d dlmZmZmZmZmZmZm	Z	 d dl
Z
d dlZd dlmc mZ d dlmZmZmZ  G d d          Z G d d          Zd	ed
ee         dedede	eedf                  f
dZ G d d          Z G d d          ZdS )    )
namedtuple)AnyDictNewTypeOptionalSequenceTupleTypeN)
IR_VERSION
ModelProto	NodeProtoc                   l    e Zd ZU dZ ede          Z ed          Zeed<    ed          Z	eed<   dS )
DeviceTypezDescribes device type._Typer   CPU   CUDAN)
__name__
__module____qualname____doc__r   intr   r   __annotations__r        M/var/www/html/ai-engine/env/lib/python3.11/site-packages/onnx/backend/base.pyr   r      sY           GGS!!EqC%((D%r   r   c                   "    e Zd ZdZdeddfdZdS )DevicezyDescribes device type and device id
    syntax: device_type:device_id(optional)
    example: 'CPU', 'CUDA', 'CUDA:1'
    devicereturnNc                     |                     d          }t          t          |d                   | _        d| _        t          |          dk    rt          |d                   | _        d S d S )N:r   r   )splitgetattrr   type	device_idlenr   )selfr   optionss      r   __init__zDevice.__init__   s]    ,,s##J
33	w<<! __DNNN r   )r   r   r   r   strr*   r   r   r   r   r      s@         
-s -t - - - - - -r   r   typenamefield_namesargskwargsr    .c                     d t          |          D             |                    dd           t          | |g|R i |}dt          dt          dt          ffd}||_        |S )Nc                     i | ]\  }}||	S r   r   ).0ins      r   
<dictcomp>z"namedtupledict.<locals>.<dictcomp>)   s    ???1q!???r   renameTr(   keyr    c                     t          |t                    r|         }t          t          |           |                               |          S N)
isinstancer+   superr%   __getitem__)r(   r7   field_names_maps     r   getitemznamedtupledict.<locals>.getitem.   sC    c3 	'!#&CT$ZZ&&223777r   )	enumerate
setdefaultr   r   r<   )r,   r-   r.   r/   datar>   r=   s         @r   namedtupledictrB   &   s     @?	+(>(>???O
h%%%h=d===f==D8c 8 8 8 8 8 8 8 8
 DKr   c                   6    e Zd ZdZdededeedf         fdZdS )
BackendRepzBackendRep is the handle that a Backend returns after preparing to execute
    a model repeatedly. Users will then pass inputs to the run function of
    BackendRep to retrieve the corresponding results.
    inputsr/   r    .c                     dS )zAbstract function.r9   r   )r(   rE   r/   s      r   runzBackendRep.run=   s    wr   N)r   r   r   r   r   r	   rG   r   r   r   rD   rD   7   sO         
#  sCx      r   rD   c                   z   e Zd ZdZe	 ddedededefd            Z	e	 ddededede
e         fd            Ze	 dded	edededeed
f         f
d            Ze	 	 dded	edede
eeej        eed
f         f                           deeef         de
eed
f                  fd            Zededefd            ZdS )Backenda  Backend is the entity that will take an ONNX model with inputs,
    perform a computation, and then return the output.

    For one-off execution, users can use run_node and run_model to obtain results quickly.

    For repeated execution, users should use prepare, in which the Backend
    does all of the preparation work for executing the model repeatedly
    (e.g., loading initializers), and returns a BackendRep handle.
    r   modelr   r/   r    c                     dS )NTr   clsrJ   r   r/   s       r   is_compatiblezBackend.is_compatibleM   	    
 tr   c                 D    t           j                            |           d S r9   )onnxcheckercheck_modelrL   s       r   preparezBackend.prepareT   s    
 	  '''tr   rE   .c                 R     | j         ||fi |}|J |                    |          S r9   )rT   rG   )rM   rJ   rE   r   r/   backends         r   	run_modelzBackend.run_model\   s=     #+eV66v66"""{{6"""r   Nnodeoutputs_infoc                     d|v rOt          j                    }t          |_        d|d         i|_        t
          j                            ||           nt
          j                            |           dS )a6  Simple run one operator and return the results.

        Args:
            node: The node proto.
            inputs: Inputs to the node.
            device: The device to run on.
            outputs_info: a list of tuples, which contains the element type and
                shape of each output. First element of the tuple is the dtype, and
                the second element is the shape. More use case can be found in
                https://github.com/onnx/onnx/blob/main/onnx/backend/test/runner/__init__.py
            kwargs: Other keyword arguments.
        opset_version N)	c_checkerCheckerContextr   
ir_versionopset_importsrQ   rR   
check_node)rM   rX   rE   r   rY   r/   special_contexts          r   run_nodezBackend.run_noded   sm    , f$$'688O)3O&-/1H,IO)L##D/::::L##D)))tr   c                     dS )zChecks whether the backend is compiled with particular device support.
        In particular it's used in the testing suite.
        Tr   )rM   r   s     r   supports_devicezBackend.supports_device   rO   r   )r   )r   N)r   r   r   r   classmethodr   r+   r   boolrN   r   rD   rT   r	   rW   r   r   numpydtyper   r   rc   re   r   r   r   rI   rI   B   s         .3 (+?B	   [ .3 (+?B	*	   [ ;@# ##(+#58#LO#	sCx# # # [# 
 PT   	
 xek5c?.J(KLM sCx. 
%S/	"   [> S T    [  r   rI   )collectionsr   typingr   r   r   r   r   r	   r
   rh   onnx.checkerrQ   onnx.onnx_cpp2py_export.checkeronnx_cpp2py_exportrR   r]   r   r   r   r   r   r+   rB   rD   rI   r   r   r   <module>ro      s   # " " " " " F F F F F F F F F F F F F F F F F F      3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2       - - - - - - - - (69EH	%S/   "       G G G G G G G G G Gr   