
    i                         S r SSKrSSKJrJr  SSKJr  SSKJr  SSK	J
r
  SSKJrJr  SSKJr  SS	KJr  \R$                  " \5      r\ " S
 S\5      5       rg)zDAhead-of-time Arm Ethos-U backend built on the shared TOSA pipeline.    N)finalList)vela_compile)EthosUCompileSpec)TOSABackend)BackendDetailsPreprocessResult)CompileSpec)ExportedProgramc                   ^    \ rS rSrSr\S\S\S\4S j5       r\S\	S\
\   S\4S	 j5       rS
rg)EthosUBackend   zBackendDetails subclass for delegation to Ethos-U.

Deduce the TOSA lowering from the compile spec list by filtering out the
compile spec values that are of interest for the TOSABackend.

tosa_flatbuffercompile_specreturnc                    UR                   n[        U5      S:X  a  [        S5      eSn[        U 5      nXC:  a  [        SU SU S35      e[        U U[        R                  5       [        R                  :*  UR                  5       S9nU$ )aV  Compile a TOSA flatbuffer into a target-specific binary stream.

Args:
    tosa_flatbuffer (bytes): Serialized TOSA graph produced by
        ``TOSABackend``.
    compile_spec (EthosUCompileSpec): Compile specification providing
        Vela flags and intermediate paths.

Returns:
    bytes: Target-specific binary stream produced by Vela.

r   zDcompile_flags are required in the CompileSpec list for EthosUBackendl        z'TOSA flatbuffer is too large for Vela (z	 bytes > z bytes limit).)verboseintermediate_path)	compiler_flagslenRuntimeErrorr   loggergetEffectiveLevelloggingINFOget_intermediate_path)r   r   compile_flagsmax_flatbuffer_sizeflatbuffer_sizebinarys         e/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/executorch/backends/arm/ethosu/backend.py_compile_tosa_flatbuffer&EthosUBackend._compile_tosa_flatbuffer&   s      %33}" V 
 5o.0#$I.A-B.R  ,,.',,>*@@B	
     edge_programcompile_specsc                 $   [         R                  [        R                   S35        [        R
                  " U5      n[        R                  " U5      n[        R                  " X5      n[        R                  UR                  U5      n[        US9$ )aC  Lower the exported program and compile it for an Ethos-U target.

Args:
    edge_program (ExportedProgram): Program to lower to Ethos-U.
    compile_specs (List[CompileSpec]): Serialized Ethos-U compile specs
        supplied by the frontend.

Returns:
    PreprocessResult: Result containing the compiled Ethos-U binary.

z preprocess)processed_bytes)r   infor   __name__r   	from_listr   filter_tosa_compile_specs_preprocessr"   r(   r	   )r%   r&   r   tosa_compile_spectosa_preprocessr    s         r!   
preprocessEthosUBackend.preprocessQ   s{      	}--.k:;(22=A (AA,O &11,R77++\
  77r$    N)r*   
__module____qualname____firstlineno____doc__staticmethodbytesr   r"   r   r   r
   r	   r0   __static_attributes__r2   r$   r!   r   r      sg     ((.?(	( (T !8%!8K(!8 
!8 !8r$   r   )r6   r   typingr   r    executorch.backends.arm.arm_velar   +executorch.backends.arm.ethosu.compile_specr   $executorch.backends.arm.tosa.backendr   'executorch.exir.backend.backend_detailsr   r	   +executorch.exir.backend.compile_spec_schemar
   torch.export.exported_programr   	getLoggerr*   r   r   r2   r$   r!   <module>rB      sS    K   9 I < T C 9 
		8	$ U8N U8 U8r$   