@@ -25,21 +25,37 @@ def __init__(self):
2525 self .output_format = None
2626 self .path_for_intermediates = None
2727 self .tosa_spec = None
28- self .input_order = None
28+
29+ def vgf_compile_spec (
30+ self ,
31+ compiler_flags : Optional [str ] = "" ,
32+ ) -> "ArmCompileSpecBuilder" :
33+ """
34+ Generate compile spec for VGF compatible targets
35+
36+ Args:
37+ compiler_flags: Extra compiler flags for converter_backend
38+ """
39+ self .output_format = "vgf"
40+ self .compiler_flags = [
41+ compiler_flags ,
42+ ]
43+ self .tosa_spec = TosaSpecification .create_from_string ("TOSA-0.80+MI" )
44+ return self
2945
3046 def ethosu_compile_spec (
3147 self ,
32- config : str ,
33- system_config : str ,
34- memory_mode : str ,
48+ target : str ,
49+ system_config : Optional [ str ] = None ,
50+ memory_mode : Optional [ str ] = None ,
3551 extra_flags : Optional [str ] = None ,
3652 config_ini : Optional [str ] = "Arm/vela.ini" ,
3753 ) -> "ArmCompileSpecBuilder" :
3854 """
3955 Generate compile spec for Ethos-U NPU
4056
4157 Args:
42- config : Ethos-U accelerator configuration, e.g. ethos-u55-128
58+ target : Ethos-U accelerator configuration, e.g. ethos-u55-128
4359 system_config: System configuration to select from the Vel
4460 configuration file
4561 memory_mode: Memory mode to select from the Vela configuration file
@@ -52,18 +68,38 @@ def ethosu_compile_spec(
5268 ), f"Output format already set to f{ self .output_format } "
5369 self .output_format = "vela"
5470 self .compiler_flags = [
55- f"--accelerator-config={ config } " ,
71+ f"--accelerator-config={ target } " ,
5672 f"--config={ config_ini } " ,
5773 ]
74+
75+ # default system config and memory mode
76+ if "ethos-u55" in target :
77+ if system_config is None :
78+ system_config = "Ethos_U55_High_End_Embedded"
79+ if memory_mode is None :
80+ memory_mode = "Shared_Sram"
81+ elif "ethos-u85" in target :
82+ if system_config is None :
83+ system_config = "Ethos_U85_SYS_DRAM_Mid"
84+ if memory_mode is None :
85+ memory_mode = "Sram_Only"
86+ else :
87+ raise RuntimeError (f"Unknown ethos target: { target } " )
88+
5889 if system_config is not None :
5990 self .compiler_flags .append (f"--system-config={ system_config } " )
6091 if memory_mode is not None :
6192 self .compiler_flags .append (f"--memory-mode={ memory_mode } " )
6293 if extra_flags is not None :
6394 self .compiler_flags .append (extra_flags )
6495
96+ # We require raw output and regor, so add these flags if absent. This
97+ # overrides any other output setting.
98+ self .compiler_flags .append ("--output-format=raw" )
99+ self .compiler_flags .append ("--debug-force-regor" )
100+
65101 base_tosa_version = "TOSA-0.80+BI"
66- if "u55" in config :
102+ if "u55" in target :
67103 # Add the Ethos-U55 extension marker
68104 base_tosa_version += "+u55"
69105 self .tosa_spec = TosaSpecification .create_from_string (base_tosa_version )
@@ -106,26 +142,22 @@ def build(self) -> List[CompileSpec]:
106142 # Always supply a TOSA version
107143 self .compile_spec = [CompileSpec ("tosa_spec" , str (self .tosa_spec ).encode ())]
108144
109- if self .output_format == "vela" :
110- self .compile_spec += [
111- CompileSpec ("output_format" , "vela" .encode ()),
112- CompileSpec ("compile_flags" , " " .join (self .compiler_flags ).encode ()),
113- ]
114- elif self .output_format == "tosa" :
115- self .compile_spec .append (CompileSpec ("output_format" , "tosa" .encode ()))
145+ # Add compile flags, these are backend specific, refer to the backend
146+ # documentation.
147+ self .compile_spec += [
148+ CompileSpec ("compile_flags" , " " .join (self .compiler_flags ).encode ()),
149+ ]
150+
151+ # encode output format
152+ self .compile_spec .append (
153+ CompileSpec ("output_format" , self .output_format .encode ())
154+ )
116155
117156 if self .path_for_intermediates is not None :
118157 self .compile_spec .append (
119158 CompileSpec ("debug_artifact_path" , self .path_for_intermediates .encode ())
120159 )
121160
122- if self .input_order :
123- self .compile_spec .append (
124- CompileSpec (
125- "input_order" , " " .join (map (str , self .input_order )).encode ()
126- )
127- )
128-
129161 return self .compile_spec
130162
131163
@@ -148,6 +180,13 @@ def is_ethosu(compile_spec: List[CompileSpec]) -> bool:
148180 return False
149181
150182
183+ def is_vgf (compile_spec : List [CompileSpec ]) -> bool :
184+ for spec in compile_spec :
185+ if spec .key == "output_format" :
186+ return spec .value .decode () == "vgf"
187+ return False
188+
189+
151190def get_tosa_spec (compile_spec : List [CompileSpec ]) -> TosaSpecification :
152191 for spec in compile_spec :
153192 if spec .key == "tosa_spec" :
0 commit comments