@@ -25,21 +25,37 @@ def __init__(self):
25
25
self .output_format = None
26
26
self .path_for_intermediates = None
27
27
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
29
45
30
46
def ethosu_compile_spec (
31
47
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 ,
35
51
extra_flags : Optional [str ] = None ,
36
52
config_ini : Optional [str ] = "Arm/vela.ini" ,
37
53
) -> "ArmCompileSpecBuilder" :
38
54
"""
39
55
Generate compile spec for Ethos-U NPU
40
56
41
57
Args:
42
- config : Ethos-U accelerator configuration, e.g. ethos-u55-128
58
+ target : Ethos-U accelerator configuration, e.g. ethos-u55-128
43
59
system_config: System configuration to select from the Vel
44
60
configuration file
45
61
memory_mode: Memory mode to select from the Vela configuration file
@@ -52,18 +68,38 @@ def ethosu_compile_spec(
52
68
), f"Output format already set to f{ self .output_format } "
53
69
self .output_format = "vela"
54
70
self .compiler_flags = [
55
- f"--accelerator-config={ config } " ,
71
+ f"--accelerator-config={ target } " ,
56
72
f"--config={ config_ini } " ,
57
73
]
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
+
58
89
if system_config is not None :
59
90
self .compiler_flags .append (f"--system-config={ system_config } " )
60
91
if memory_mode is not None :
61
92
self .compiler_flags .append (f"--memory-mode={ memory_mode } " )
62
93
if extra_flags is not None :
63
94
self .compiler_flags .append (extra_flags )
64
95
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
+
65
101
base_tosa_version = "TOSA-0.80+BI"
66
- if "u55" in config :
102
+ if "u55" in target :
67
103
# Add the Ethos-U55 extension marker
68
104
base_tosa_version += "+u55"
69
105
self .tosa_spec = TosaSpecification .create_from_string (base_tosa_version )
@@ -106,26 +142,22 @@ def build(self) -> List[CompileSpec]:
106
142
# Always supply a TOSA version
107
143
self .compile_spec = [CompileSpec ("tosa_spec" , str (self .tosa_spec ).encode ())]
108
144
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
+ )
116
155
117
156
if self .path_for_intermediates is not None :
118
157
self .compile_spec .append (
119
158
CompileSpec ("debug_artifact_path" , self .path_for_intermediates .encode ())
120
159
)
121
160
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
-
129
161
return self .compile_spec
130
162
131
163
@@ -148,6 +180,13 @@ def is_ethosu(compile_spec: List[CompileSpec]) -> bool:
148
180
return False
149
181
150
182
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
+
151
190
def get_tosa_spec (compile_spec : List [CompileSpec ]) -> TosaSpecification :
152
191
for spec in compile_spec :
153
192
if spec .key == "tosa_spec" :
0 commit comments