Skip to content

Commit 7374038

Browse files
authored
[microTVM]Refactor test and add skip to current failing tests/boards (#13858)
This PR refactors some of the Zephyr tests and adds skip for each test/board that is currently failing.
1 parent 5e652c1 commit 7374038

File tree

8 files changed

+55
-99
lines changed

8 files changed

+55
-99
lines changed

tests/micro/common/test_autotune.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131

3232
@pytest.mark.requires_hardware
3333
@tvm.testing.requires_micro
34+
@pytest.mark.skip_boards(
35+
["nucleo_l4r5zi", "", "nucleo_f746zg", "stm32f746g_disco", "nrf5340dk_nrf5340_cpuapp"]
36+
)
3437
def test_kws_autotune_workflow(platform, board, tmp_path):
3538
mod, params = fetch_model_from_url(
3639
url="https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/micro_speech/micro_speech.tflite",

tests/micro/common/test_tvmc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ def test_tvmc_model_build_only(platform, board, output_dir):
128128
"output_dir,",
129129
[pathlib.Path("./tvmc_relative_path_test"), pathlib.Path(tempfile.mkdtemp())],
130130
)
131+
@pytest.mark.skip_boards(
132+
["nucleo_l4r5zi", "", "nucleo_f746zg", "stm32f746g_disco", "nrf5340dk_nrf5340_cpuapp"]
133+
)
131134
def test_tvmc_model_run(platform, board, output_dir):
132135
target = tvm.micro.testing.get_target(platform, board)
133136

tests/micro/zephyr/test_ms_tuning.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import tvm
2424
from tvm import relay
25+
import tvm.micro.testing
2526
from tvm.relay.backend import Executor
2627
from tvm.contrib import graph_executor, utils
2728
from tvm import meta_schedule as ms
@@ -61,7 +62,7 @@ def create_relay_module():
6162

6263

6364
@tvm.testing.requires_micro
64-
@pytest.mark.skip_boards(["mps2_an521", "mps3_an547"])
65+
@pytest.mark.skip_boards(["mps2_an521", "mps3_an547", "nucleo_f746zg", "stm32f746g_disco"])
6566
def test_ms_tuning_conv2d(workspace_dir, board, microtvm_debug, use_fvp, serial_number):
6667
"""Test meta-schedule tuning for microTVM Zephyr"""
6768

@@ -92,7 +93,7 @@ def test_ms_tuning_conv2d(workspace_dir, board, microtvm_debug, use_fvp, serial_
9293
boards_file = pathlib.Path(tvm.micro.get_microtvm_template_projects("zephyr")) / "boards.json"
9394
with open(boards_file) as f:
9495
boards = json.load(f)
95-
target = tvm.target.target.micro(model=boards[project_options["board"]]["model"])
96+
target = tvm.micro.testing.get_target("zephyr", board)
9697

9798
runtime = relay.backend.Runtime("crt", {"system-lib": True})
9899
executor = Executor("aot", {"link-params": True})
@@ -158,7 +159,7 @@ def test_ms_tuning_conv2d(workspace_dir, board, microtvm_debug, use_fvp, serial_
158159

159160
# Build reference model (without tuning)
160161
dev = tvm.cpu()
161-
target = tvm.target.target.micro(model="host")
162+
target = tvm.micro.testing.get_target("crt")
162163
with tvm.transform.PassContext(
163164
opt_level=3, config={"tir.disable_vectorize": True}, disabled_pass=["AlterOpLayout"]
164165
):

tests/micro/zephyr/test_zephyr.py

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040

4141
def _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()
112108
def 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()
139133
def 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()
175167
def 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()
206196
def 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()
240229
def 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):
292280
def 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()
335320
def 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()
420401
def 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}")

tests/micro/zephyr/test_zephyr_aot_exec.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
1919

2020
import tvm
2121
import tvm.testing
22+
import tvm.micro.testing
2223
import tvm.relay as relay
2324
from tvm.relay.backend import Executor, Runtime
2425
from tvm.contrib import utils
2526

2627
from . import utils
2728

2829

29-
def _make_session(workspace_dir, zephyr_board, mod, build_config, use_fvp, serial_number):
30+
def _make_session(workspace_dir, board, mod, build_config, use_fvp, serial_number):
3031
config_main_stack_size = None
31-
if utils.qemu_boards(zephyr_board):
32+
if utils.ZEPHYR_BOARDS[board]["is_qemu"]:
3233
# fyi: qemu_riscv64 seems to be the greediest stack user
3334
config_main_stack_size = 4096
3435
else:
@@ -38,7 +39,7 @@ def _make_session(workspace_dir, zephyr_board, mod, build_config, use_fvp, seria
3839
project_options = {
3940
"project_type": "host_driven",
4041
"verbose": bool(build_config.get("debug")),
41-
"board": zephyr_board,
42+
"board": board,
4243
"arm_fvp_path": "/opt/arm/FVP_Corstone_SSE-300/models/Linux64_GCC-6.4/FVP_Corstone_SSE-300_Ethos-U55",
4344
"use_fvp": bool(use_fvp),
4445
"serial_number": serial_number,
@@ -63,7 +64,6 @@ def _make_session(workspace_dir, zephyr_board, mod, build_config, use_fvp, seria
6364
def test_relay(workspace_dir, board, microtvm_debug, use_fvp, serial_number):
6465
"""Testing a simple relay graph"""
6566

66-
model = utils.ZEPHYR_BOARDS[board]
6767
build_config = {"debug": microtvm_debug}
6868
shape = (10,)
6969
dtype = "int8"
@@ -77,7 +77,7 @@ def test_relay(workspace_dir, board, microtvm_debug, use_fvp, serial_number):
7777

7878
runtime = Runtime("crt", {"system-lib": True})
7979
executor = Executor("aot")
80-
target = tvm.target.target.micro(model)
80+
target = tvm.micro.testing.get_target("zephyr", board)
8181
with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}):
8282
mod = tvm.relay.build(ir_mod, target=target, runtime=runtime, executor=executor)
8383

@@ -98,7 +98,6 @@ def test_relay(workspace_dir, board, microtvm_debug, use_fvp, serial_number):
9898
def test_aot_executor(workspace_dir, board, microtvm_debug, use_fvp, serial_number):
9999
"""Test use of the AOT executor with microTVM."""
100100

101-
model = utils.ZEPHYR_BOARDS[board]
102101
build_config = {"debug": microtvm_debug}
103102
shape = (10,)
104103
dtype = "int8"
@@ -117,7 +116,7 @@ def @main(%a : Tensor[(1, 2), uint8], %b : Tensor[(1, 2), uint8]) {
117116

118117
runtime = Runtime("crt", {"system-lib": True})
119118
executor = Executor("aot")
120-
target = tvm.target.target.micro(model)
119+
target = tvm.micro.testing.get_target("zephyr", board)
121120
with tvm.transform.PassContext(opt_level=3, config={"tir.disable_vectorize": True}):
122121
mod = tvm.relay.build(relay_mod, target=target, runtime=runtime, executor=executor)
123122

0 commit comments

Comments
 (0)