Skip to content

Commit 370f5e4

Browse files
author
Robert Muchsel
authored
Improve --one-shot code generation on MAX78002 (#148)
* Block --one-shot on unsupported devices * Allow --one-shot in combination with --no-wfi
1 parent 0263a76 commit 370f5e4

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

izer/backend/max7800x.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ def create_net(self) -> str: # pylint: disable=too-many-locals,too-many-branche
206206
if snoop is not None and not tc.dev.SUPPORT_SNOOP:
207207
eprint("`snoop` is not supported on this device.")
208208

209+
if oneshot and not tc.dev.SUPPORT_ONESHOT:
210+
eprint("`--one-shot` is not supported on this device.")
211+
209212
if state.pipeline is None:
210213
state.pipeline = tc.dev.SUPPORT_PIPELINE
211214
pipeline = state.pipeline # Cache

izer/toplevel.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -656,27 +656,33 @@ def main(
656656
memfile.write(' cnn_start(); // Run inference\n')
657657
if fifo:
658658
memfile.write(' load_input(); // Load data input via FIFO\n')
659-
if not riscv:
660-
memfile.write(' SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; // SLEEPDEEP=0\n')
661-
memfile.write(' while (cnn_time == 0)\n')
662-
if not riscv:
663-
memfile.write(' __WFI(); // Wait for CNN\n')
659+
if state.wfi:
660+
if not riscv:
661+
memfile.write(' SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; // SLEEPDEEP=0\n')
662+
memfile.write(' while (cnn_time == 0)\n')
663+
if not riscv:
664+
memfile.write(' __WFI(); // Wait for CNN\n')
665+
else:
666+
memfile.write(' asm volatile("wfi"); // Wait for CNN\n')
664667
else:
665-
memfile.write(' asm volatile("wfi"); // Wait for CNN\n')
668+
memfile.write(' while (cnn_time == 0); // Spin wait\n')
666669
memfile.write(' }\n'
667670
' CNN_COMPLETE;\n\n')
668671

669672
if oneshot > 0:
670673
memfile.write(f' for (i = 0; i < {oneshot}; i++) {{\n')
671674
memfile.write(' cnn_continue();\n')
672675
if embedded_code or tc.dev.MODERN_SIM:
673-
if not riscv:
674-
memfile.write(' SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; // SLEEPDEEP=0\n')
675-
memfile.write(' while (cnn_time == 0)\n')
676-
if not riscv:
677-
memfile.write(' __WFI(); // Wait for CNN\n')
676+
if state.wfi:
677+
if not riscv:
678+
memfile.write(' SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; // SLEEPDEEP=0\n')
679+
memfile.write(' while (cnn_time == 0)\n')
680+
if not riscv:
681+
memfile.write(' __WFI(); // Wait for CNN\n')
682+
else:
683+
memfile.write(' asm volatile("wfi"); // Wait for CNN\n')
678684
else:
679-
memfile.write(' asm volatile("wfi"); // Wait for CNN\n')
685+
memfile.write(' while (cnn_time == 0); // Spin wait\n')
680686
else:
681687
memfile.write(' cnn_wait();\n')
682688
memfile.write(' }\n\n')

izer/tornadocnn.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Dev:
3838
SUPPORT_FIFO_GO = False
3939
SUPPORT_SNOOP = False
4040
SUPPORT_STREAM_NONPAD_FINAL = False
41+
SUPPORT_ONESHOT = False
4142
REQUIRE_REG_CLEAR = False
4243
REQUIRE_SEMA_LPWKEN = False
4344
REQUIRE_ONESHOT_CLEAR = True
@@ -459,6 +460,7 @@ class DevAI87(Dev):
459460
SUPPORT_FIFO_GO = True
460461
SUPPORT_SNOOP = True
461462
SUPPORT_STREAM_NONPAD_FINAL = True
463+
SUPPORT_ONESHOT = True
462464
SUPPORTED_X2D_PADS = [0, 1, 2]
463465
SUPPORTED_X2D_OUTPUT_PADS = [1]
464466
REQUIRE_REG_CLEAR = True

0 commit comments

Comments
 (0)