4040
4141def _make_sess_from_op (
4242 temp_dir ,
43- model ,
44- zephyr_board ,
43+ board ,
4544 op_name ,
4645 sched ,
4746 arg_bufs ,
@@ -50,23 +49,23 @@ def _make_sess_from_op(
5049 serial_number ,
5150):
5251 runtime = Runtime ("crt" , {"system-lib" : True })
53- target = tvm .target . target . micro ( model )
52+ target = tvm .micro . testing . get_target ( "zephyr" , board )
5453 target = tvm .target .Target (target = target , host = target )
5554 with tvm .transform .PassContext (opt_level = 3 , config = {"tir.disable_vectorize" : True }):
5655 mod = tvm .build (sched , arg_bufs , target = target , runtime = runtime , name = op_name )
5756
58- return _make_session (temp_dir , zephyr_board , mod , build_config , use_fvp , serial_number )
57+ return _make_session (temp_dir , board , mod , build_config , use_fvp , serial_number )
5958
6059
61- def _make_session (temp_dir , zephyr_board , mod , build_config , use_fvp , serial_number ):
60+ def _make_session (temp_dir , board , mod , build_config , use_fvp , serial_number ):
6261 config_main_stack_size = None
63- if utils .qemu_boards ( zephyr_board ) :
62+ if utils .ZEPHYR_BOARDS [ board ][ "is_qemu" ] :
6463 config_main_stack_size = 1536
6564
6665 project_options = {
6766 "project_type" : "host_driven" ,
6867 "verbose" : bool (build_config .get ("debug" )),
69- "board" : zephyr_board ,
68+ "board" : board ,
7069 "arm_fvp_path" : "/opt/arm/FVP_Corstone_SSE-300/models/Linux64_GCC-6.4/FVP_Corstone_SSE-300_Ethos-U55" ,
7170 "use_fvp" : bool (use_fvp ),
7271 "serial_number" : serial_number ,
@@ -85,17 +84,14 @@ def _make_session(temp_dir, zephyr_board, mod, build_config, use_fvp, serial_num
8584 return tvm .micro .Session (project .transport ())
8685
8786
88- def _make_add_sess (
89- temp_dir , model , zephyr_board , build_config , use_fvp , serial_number , dtype = "int8"
90- ):
87+ def _make_add_sess (temp_dir , board , build_config , use_fvp , serial_number , dtype = "int8" ):
9188 A = tvm .te .placeholder ((2 ,), dtype = dtype )
9289 B = tvm .te .placeholder ((1 ,), dtype = dtype )
9390 C = tvm .te .compute (A .shape , lambda i : A [i ] + B [0 ], name = "C" )
9491 sched = tvm .te .create_schedule (C .op )
9592 return _make_sess_from_op (
9693 temp_dir ,
97- model ,
98- zephyr_board ,
94+ board ,
9995 "add" ,
10096 sched ,
10197 [A , B , C ],
@@ -111,8 +107,6 @@ def _make_add_sess(
111107@pytest .mark .xfail_on_fvp ()
112108def test_add_uint (workspace_dir , board , microtvm_debug , use_fvp , serial_number ):
113109 """Test compiling the on-device runtime."""
114-
115- model = utils .ZEPHYR_BOARDS [board ]
116110 build_config = {"debug" : microtvm_debug }
117111
118112 # NOTE: run test in a nested function so cPython will delete arrays before closing the session.
@@ -128,7 +122,7 @@ def test_basic_add(sess):
128122 system_lib .get_function ("add" )(A_data , B_data , C_data )
129123 assert (C_data .numpy () == np .array ([6 , 7 ])).all ()
130124
131- with _make_add_sess (workspace_dir , model , board , build_config , use_fvp , serial_number ) as sess :
125+ with _make_add_sess (workspace_dir , board , build_config , use_fvp , serial_number ) as sess :
132126 test_basic_add (sess )
133127
134128
@@ -138,8 +132,7 @@ def test_basic_add(sess):
138132@pytest .mark .xfail_on_fvp ()
139133def test_add_float (workspace_dir , board , microtvm_debug , use_fvp , serial_number ):
140134 """Test compiling the on-device runtime."""
141- model = utils .ZEPHYR_BOARDS [board ]
142- if not utils .has_fpu (board ):
135+ if not utils .ZEPHYR_BOARDS [board ]["fpu" ]:
143136 pytest .skip (f"FPU not enabled for { board } " )
144137
145138 build_config = {"debug" : microtvm_debug }
@@ -159,7 +152,6 @@ def test_basic_add(sess):
159152
160153 with _make_add_sess (
161154 workspace_dir ,
162- model ,
163155 board ,
164156 build_config ,
165157 use_fvp ,
@@ -174,8 +166,6 @@ def test_basic_add(sess):
174166@pytest .mark .xfail_on_fvp ()
175167def test_platform_timer (workspace_dir , board , microtvm_debug , use_fvp , serial_number ):
176168 """Test compiling the on-device runtime."""
177-
178- model = utils .ZEPHYR_BOARDS [board ]
179169 build_config = {"debug" : microtvm_debug }
180170
181171 # NOTE: run test in a nested function so cPython will delete arrays before closing the session.
@@ -196,7 +186,7 @@ def test_basic_add(sess):
196186 assert result .mean > 0
197187 assert len (result .results ) == 3
198188
199- with _make_add_sess (workspace_dir , model , board , build_config , use_fvp , serial_number ) as sess :
189+ with _make_add_sess (workspace_dir , board , build_config , use_fvp , serial_number ) as sess :
200190 test_basic_add (sess )
201191
202192
@@ -205,7 +195,6 @@ def test_basic_add(sess):
205195@pytest .mark .xfail_on_fvp ()
206196def test_relay (workspace_dir , board , microtvm_debug , use_fvp , serial_number ):
207197 """Testing a simple relay graph"""
208- model = utils .ZEPHYR_BOARDS [board ]
209198 build_config = {"debug" : microtvm_debug }
210199 shape = (10 ,)
211200 dtype = "int8"
@@ -218,7 +207,7 @@ def test_relay(workspace_dir, board, microtvm_debug, use_fvp, serial_number):
218207 ir_mod = tvm .IRModule .from_expr (func )
219208
220209 runtime = Runtime ("crt" , {"system-lib" : True })
221- target = tvm .target . target . micro ( model )
210+ target = tvm .micro . testing . get_target ( "zephyr" , board )
222211 with tvm .transform .PassContext (opt_level = 3 , config = {"tir.disable_vectorize" : True }):
223212 mod = tvm .relay .build (ir_mod , target = target , runtime = runtime )
224213
@@ -239,7 +228,6 @@ def test_relay(workspace_dir, board, microtvm_debug, use_fvp, serial_number):
239228@pytest .mark .xfail_on_fvp ()
240229def test_onnx (workspace_dir , board , microtvm_debug , use_fvp , serial_number ):
241230 """Testing a simple ONNX model."""
242- model = utils .ZEPHYR_BOARDS [board ]
243231 build_config = {"debug" : microtvm_debug }
244232
245233 this_dir = pathlib .Path (os .path .dirname (__file__ ))
@@ -262,7 +250,7 @@ def test_onnx(workspace_dir, board, microtvm_debug, use_fvp, serial_number):
262250 # There is currently a bug preventing the host_driven environment from receiving
263251 # the model weights when set using graph_mod.set_input().
264252 # See: https://github.com/apache/tvm/issues/7567
265- target = tvm .target . target . micro ( model )
253+ target = tvm .micro . testing . get_target ( "zephyr" , board )
266254 with tvm .transform .PassContext (opt_level = 3 , config = {"tir.disable_vectorize" : True }):
267255 executor = Executor ("graph" , {"link-params" : True })
268256 runtime = Runtime ("crt" , {"system-lib" : True })
@@ -292,8 +280,7 @@ def test_onnx(workspace_dir, board, microtvm_debug, use_fvp, serial_number):
292280def check_result (
293281 temp_dir ,
294282 relay_mod ,
295- model ,
296- zephyr_board ,
283+ board ,
297284 map_inputs ,
298285 out_shape ,
299286 result ,
@@ -304,13 +291,11 @@ def check_result(
304291 """Helper function to verify results"""
305292 TOL = 1e-5
306293 runtime = Runtime ("crt" , {"system-lib" : True })
307- target = tvm .target . target . micro ( model )
294+ target = tvm .micro . testing . get_target ( "zephyr" , board )
308295 with tvm .transform .PassContext (opt_level = 3 , config = {"tir.disable_vectorize" : True }):
309296 mod = tvm .relay .build (relay_mod , target = target , runtime = runtime )
310297
311- with _make_session (
312- temp_dir , zephyr_board , mod , build_config , use_fvp , serial_number
313- ) as session :
298+ with _make_session (temp_dir , board , mod , build_config , use_fvp , serial_number ) as session :
314299 rt_mod = tvm .micro .create_local_graph_executor (
315300 mod .get_graph_json (), session .get_system_lib (), session .device
316301 )
@@ -334,7 +319,6 @@ def check_result(
334319@pytest .mark .xfail_on_fvp ()
335320def test_byoc_microtvm (workspace_dir , board , microtvm_debug , use_fvp , serial_number ):
336321 """This is a simple test case to check BYOC capabilities of microTVM"""
337- model = utils .ZEPHYR_BOARDS [board ]
338322 build_config = {"debug" : microtvm_debug }
339323 x = relay .var ("x" , shape = (10 , 10 ))
340324 w0 = relay .var ("w0" , shape = (10 , 10 ))
@@ -387,22 +371,19 @@ def test_byoc_microtvm(workspace_dir, board, microtvm_debug, use_fvp, serial_num
387371 ),
388372 axis = 0 ,
389373 ),
390- model = model ,
391- zephyr_board = board ,
374+ board = board ,
392375 build_config = build_config ,
393376 use_fvp = use_fvp ,
394377 serial_number = serial_number ,
395378 )
396379
397380
398- def _make_add_sess_with_shape (
399- temp_dir , model , zephyr_board , shape , build_config , use_fvp , serial_number
400- ):
381+ def _make_add_sess_with_shape (temp_dir , board , shape , build_config , use_fvp , serial_number ):
401382 A = tvm .te .placeholder (shape , dtype = "int8" )
402383 C = tvm .te .compute (A .shape , lambda i : A [i ] + A [i ], name = "C" )
403384 sched = tvm .te .create_schedule (C .op )
404385 return _make_sess_from_op (
405- temp_dir , model , zephyr_board , "add" , sched , [A , C ], build_config , use_fvp , serial_number
386+ temp_dir , board , "add" , sched , [A , C ], build_config , use_fvp , serial_number
406387 )
407388
408389
@@ -419,7 +400,6 @@ def _make_add_sess_with_shape(
419400@pytest .mark .xfail_on_fvp ()
420401def test_rpc_large_array (workspace_dir , board , microtvm_debug , shape , use_fvp , serial_number ):
421402 """Test large RPC array transfer."""
422- model = utils .ZEPHYR_BOARDS [board ]
423403 build_config = {"debug" : microtvm_debug }
424404
425405 # NOTE: run test in a nested function so cPython will delete arrays before closing the session.
@@ -432,7 +412,7 @@ def test_tensors(sess):
432412 assert (C_data .numpy () == np .zeros (shape )).all ()
433413
434414 with _make_add_sess_with_shape (
435- workspace_dir , model , board , shape , build_config , use_fvp , serial_number
415+ workspace_dir , board , shape , build_config , use_fvp , serial_number
436416 ) as sess :
437417 test_tensors (sess )
438418
@@ -445,7 +425,6 @@ def test_autotune_conv2d(workspace_dir, board, microtvm_debug, use_fvp, serial_n
445425 pytest .xfail (f"Autotune fails on { board } ." )
446426
447427 runtime = Runtime ("crt" , {"system-lib" : True })
448- model = utils .ZEPHYR_BOARDS [board ]
449428 build_config = {"debug" : microtvm_debug }
450429
451430 # Create a Relay model
@@ -473,14 +452,14 @@ def test_autotune_conv2d(workspace_dir, board, microtvm_debug, use_fvp, serial_n
473452 ).astype ("float32" )
474453 params = {mod ["main" ].params [1 ].name_hint : weight_sample }
475454
476- target = tvm .target . target . micro ( model )
455+ target = tvm .micro . testing . get_target ( "zephyr" , board )
477456 pass_context = tvm .transform .PassContext (opt_level = 3 , config = {"tir.disable_vectorize" : True })
478457 with pass_context :
479458 tasks = tvm .autotvm .task .extract_from_program (mod ["main" ], {}, target )
480459 assert len (tasks ) > 0
481460
482461 config_main_stack_size = None
483- if utils .qemu_boards ( board ) :
462+ if utils .ZEPHYR_BOARDS [ board ][ "is_qemu" ] :
484463 config_main_stack_size = 1536
485464
486465 project_options = {
@@ -572,9 +551,10 @@ def test_schedule_build_with_cmsis_dependency(workspace_dir, board, microtvm_deb
572551 """Test Relay schedule with CMSIS dependency. This test shows if microTVM Auto tuning
573552 with Zephyr breaks if CMSIS dependency was required for a schedule.
574553 """
575- model = utils .ZEPHYR_BOARDS [board ]
576554 build_config = {"debug" : microtvm_debug }
577- target = tvm .target .target .micro (model , options = ["-keys=arm_cpu,cpu" ])
555+ target = tvm .target .target .micro (
556+ utils .ZEPHYR_BOARDS [board ]["model" ], options = ["-keys=arm_cpu,cpu" ]
557+ )
578558
579559 if not target .features .has_dsp :
580560 pytest .skip (f"ISA does not support DSP. target: { target } " )
0 commit comments