@@ -177,6 +177,7 @@ def __init__(
177177 self .qp_input : list [QuantizationParams ] = None
178178 self .qp_output : QuantizationParams = None
179179 self .timeout = 120
180+ self .target_board : str = None
180181
181182 self ._has_init_run = False
182183
@@ -185,11 +186,17 @@ def init_run(
185186 exported_program : ExportedProgram ,
186187 edge_program : ExportedProgram ,
187188 is_quantized : bool ,
189+ target_board : str ,
188190 ):
191+
192+ if target_board not in ["corstone-300" , "corstone-320" ]:
193+ raise RuntimeError (f"Unknown target board: { target_board } " )
194+
189195 self .input_names = _get_input_names (edge_program )
190196 self .output_node = _get_output_node (exported_program )
191197 self .output_name = self .output_node .name
192198 self .is_quantized = is_quantized
199+ self .target_board = target_board
193200
194201 if is_quantized :
195202 self .qp_input = _get_input_quantization_params (exported_program )
@@ -205,7 +212,7 @@ def init_run(
205212 def set_timeout (self , timeout : int ):
206213 self .timeout = timeout
207214
208- def run_corstone300 (
215+ def run_corstone (
209216 self ,
210217 inputs : Tuple [torch .Tensor ],
211218 ) -> list [torch .Tensor ]:
@@ -231,7 +238,7 @@ def run_corstone300(
231238 )
232239 elf_path = os .path .join (
233240 "cmake-out" ,
234- "arm_semihosting_executor_runner_corstone-300 " ,
241+ f"arm_semihosting_executor_runner_ { self . target_board } " ,
235242 "arm_executor_runner" ,
236243 )
237244 assert os .path .exists (
@@ -242,32 +249,66 @@ def run_corstone300(
242249 for input_path in input_paths :
243250 cmd_line += f" -i { input_path } "
244251
245- command_args = [
246- "FVP_Corstone_SSE-300_Ethos-U55" ,
247- "-C" ,
248- "ethosu.num_macs=128" ,
249- "-C" ,
250- "mps3_board.visualisation.disable-visualisation=1" ,
251- "-C" ,
252- "mps3_board.telnetterminal0.start_telnet=0" ,
253- "-C" ,
254- "mps3_board.uart0.out_file='-'" ,
255- "-C" ,
256- "cpu0.CFGITCMSZ=11" ,
257- "-C" ,
258- "cpu0.semihosting-enable=1" ,
259- "-C" ,
260- "cpu0.semihosting-stack_base=0" ,
261- "-C" ,
262- "cpu0.semihosting-heap_limit=0" ,
263- "-C" ,
264- f"cpu0.semihosting-cmd_line='{ cmd_line } '" ,
265- "-a" ,
266- elf_path ,
267- "--timelimit" ,
268- f"{ self .timeout } " ,
269- ]
270- result = _run_cmd (command_args , check = False )
252+ command_args = {
253+ "corstone-300" : [
254+ "FVP_Corstone_SSE-300_Ethos-U55" ,
255+ "-C" ,
256+ "ethosu.num_macs=128" ,
257+ "-C" ,
258+ "mps3_board.visualisation.disable-visualisation=1" ,
259+ "-C" ,
260+ "mps3_board.telnetterminal0.start_telnet=0" ,
261+ "-C" ,
262+ "mps3_board.uart0.out_file='-'" ,
263+ "-C" ,
264+ "cpu0.CFGITCMSZ=11" ,
265+ "-C" ,
266+ "cpu0.semihosting-enable=1" ,
267+ "-C" ,
268+ "cpu0.semihosting-stack_base=0" ,
269+ "-C" ,
270+ "cpu0.semihosting-heap_limit=0" ,
271+ "-C" ,
272+ f"cpu0.semihosting-cmd_line='{ cmd_line } '" ,
273+ "-a" ,
274+ elf_path ,
275+ "--timelimit" ,
276+ f"{ self .timeout } " ,
277+ ],
278+ "corstone-320" : [
279+ "FVP_Corstone_SSE-320" ,
280+ "-C" ,
281+ "mps4_board.subsystem.ethosu.num_macs=128" ,
282+ "-C" ,
283+ "mps4_board.visualisation.disable-visualisation=1" ,
284+ "-C" ,
285+ "mps4_board.telnetterminal0.start_telnet=0" ,
286+ "-C" ,
287+ "mps4_board.uart0.out_file='-'" ,
288+ "-C" ,
289+ "mps4_board.uart0.unbuffered_output=1" ,
290+ "-C" ,
291+ "mps4_board.uart0.shutdown_on_eot=1" ,
292+ "-C" ,
293+ "mps4_board.subsystem.cpu0.semihosting-enable=1" ,
294+ "-C" ,
295+ "mps4_board.subsystem.cpu0.semihosting-stack_base=0" ,
296+ "-C" ,
297+ "mps4_board.subsystem.cpu0.semihosting-heap_limit=0" ,
298+ "-C" ,
299+ f"mps4_board.subsystem.cpu0.semihosting-cmd_line='{ cmd_line } '" ,
300+ "-a" ,
301+ elf_path ,
302+ "--timelimit" ,
303+ f"{ self .timeout } " ,
304+ ],
305+ }
306+
307+ result = _run_cmd (command_args [self .target_board ], check = False )
308+ if result .returncode != 0 :
309+ raise RuntimeError (
310+ f"Failed to run { command_args [self .target_board ]} \n Error: { result .stderr .decode ()} "
311+ )
271312 result_stdout = result .stdout .decode ()
272313
273314 error_regex = r"(^[EF][: ].*$)|(^.*Hard fault.*$)|(^.*Assertion.*$)"
@@ -276,10 +317,8 @@ def run_corstone300(
276317 # regex to check for error or fault messages in stdout from FVP
277318 if re .compile (error_regex , re .MULTILINE ).search (result_stdout ):
278319 raise RuntimeError (
279- f"Corstone simulation failed, log: \n { result_stdout } \n { result .stderr .decode ()} "
320+ f"Corstone simulation failed: \n cmd: { command_args [ self . target_board ] } \n , log: \n { result_stdout } \n { result .stderr .decode ()} "
280321 )
281- elif "E [" in result_stdout :
282- logger .error (result_stdout )
283322
284323 tosa_ref_output = np .fromfile (out_path_with_suffix , dtype = np .float32 )
285324 output_shape = self .output_node .args [0 ][0 ].meta ["val" ].shape
0 commit comments