Skip to content

Commit 8a1d12e

Browse files
author
Robert Muchsel
authored
Improve warning and error messages for in_sequences (#142)
* Disable processor number check when concatenating channels with a non-zero write_gap * Enable warning message to compare offsets for input sequences
1 parent 8317d41 commit 8a1d12e

File tree

3 files changed

+67
-63
lines changed

3 files changed

+67
-63
lines changed

assets/rtlsim-verify-output/verify-output.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
# corresponding file in 'data-output'. Open that file and make sure that the information matches.
4949
for _, _, fnames in sorted(os.walk('data-expected')): # type: ignore
5050
for fname in sorted(fnames):
51+
if not fname.startswith('DRAM_'):
52+
continue
5153
outname = fname.replace('DRAM_', 'DRAM_out_')
5254
if not os.path.isfile(os.path.join('data-output', outname)):
5355
log.error('data-output/%s does not exist!', outname)

izer/backend/max7800x.py

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -492,23 +492,24 @@ def create_net(self) -> str: # pylint: disable=too-many-locals,too-many-branche
492492

493493
if in_sequences[ll] is not None:
494494
if operands[ll] == 1: # cat
495-
min_proc = -1
496-
max_proc = -1
497-
for _, lt in enumerate(in_sequences[ll]):
498-
first_proc = ffs(output_processor_map[lt])
499-
last_proc = fls(output_processor_map[lt])
500-
if first_proc <= min_proc:
501-
eprint(f'Layer {ll}: In `in_sequences` {in_sequences[ll]}, '
502-
'an earlier layer in the sequence uses a higher first '
503-
f'processor ({min_proc}) than layer {lt} which uses '
504-
f'processor {first_proc}.')
505-
if last_proc <= max_proc:
506-
eprint(f'Layer {ll}: In `in_sequences` {in_sequences[ll]}, '
507-
'an earlier layer in the sequence uses a higher last '
508-
f'processor ({max_proc}) than layer {lt} which uses '
509-
f'processor {last_proc}.')
510-
min_proc = first_proc
511-
max_proc = last_proc
495+
if write_gap[ll] == 0:
496+
min_proc = -1
497+
max_proc = -1
498+
for _, lt in enumerate(in_sequences[ll]):
499+
first_proc = ffs(output_processor_map[lt])
500+
last_proc = fls(output_processor_map[lt])
501+
if first_proc <= min_proc:
502+
eprint(f'Layer {ll}: In `in_sequences` {in_sequences[ll]}, '
503+
'an earlier layer in the sequence uses a higher first '
504+
f'processor ({min_proc}) than layer {lt} which uses '
505+
f'processor {first_proc}.')
506+
if last_proc <= max_proc:
507+
eprint(f'Layer {ll}: In `in_sequences` {in_sequences[ll]}, '
508+
'an earlier layer in the sequence uses a higher last '
509+
f'processor ({max_proc}) than layer {lt} which uses '
510+
f'processor {last_proc}.')
511+
min_proc = first_proc
512+
max_proc = last_proc
512513
else: # eltwise
513514
eltwise_proc_map = 0
514515
for _, lt in enumerate(in_sequences[ll]):
@@ -569,7 +570,7 @@ def create_net(self) -> str: # pylint: disable=too-many-locals,too-many-branche
569570
if not block_mode and (embedded_code or compact_data):
570571
sampledata_header = \
571572
open(os.path.join(base_directory, test_name, state.sample_filename), mode='w')
572-
if state.generate_kat and state.result_filename.lower() != 'none':
573+
if embedded_code and state.generate_kat and state.result_filename.lower() != 'none':
573574
sampleoutput_header = \
574575
open(os.path.join(base_directory, test_name, state.result_filename), mode='w')
575576
else:
@@ -1211,43 +1212,47 @@ def create_net(self) -> str: # pylint: disable=too-many-locals,too-many-branche
12111212
for _, group in enumerate(groups_used):
12121213
apb.output(f' // Layer {r * layers + ll} group {group}\n', embedded_code)
12131214

1214-
if hasattr(tc.dev, 'LREG_NXTLYR'):
1215-
val = 0
1216-
if link_layer:
1217-
if ll != final_layer:
1218-
val = 1 << 7 | (ll + 1)
1219-
else:
1220-
val = 1 << 8 # Stop
1215+
val = 0
1216+
if link_layer:
1217+
if ll != final_layer:
1218+
val = 1 << 7 | (ll + 1)
12211219
else:
1222-
lt = next_sequence[ll]
1223-
if lt == -1:
1224-
if ll != layers - 1: # Don't set stop bit unless required
1225-
val = 1 << 8
1226-
elif lt != ll + 1:
1227-
val = 1 << 7 | lt
1228-
elif snoop_sequence[ll] is not None:
1229-
lt = snoop_sequence[ll]
1230-
assert lt >= 0
1231-
val = 1 << 7 | lt
1232-
if lt != -1:
1233-
if in_sequences[lt] is not None and ll in in_sequences[lt] \
1234-
and operands[lt] == 1:
1235-
if in_offset[lt] != out_offset[ll]:
1236-
wprint(f'Layer {ll}: The input offset of the next '
1237-
f'sequence (layer {lt}, 0x{in_offset[lt]:04x}) '
1238-
"does not match the current layer's output "
1239-
f'offset (0x{out_offset[ll]:04x}).')
1240-
if input_chan[lt] != output_chan[ll] \
1241-
* len(in_sequences[lt]) \
1242-
or input_dim[lt] != output_dim[ll]:
1243-
wprint(f'Layer {ll}: The input dimensions of the next '
1244-
f'sequence (layer {lt}, '
1245-
f'{len(in_sequences[lt])} inputs, '
1246-
f'{input_chan[lt]}x{input_dim_str[lt]}) do '
1247-
"not match the current layer's output "
1248-
"dimensions "
1249-
f'({output_chan[ll]}x{output_dim_str[ll]}).')
1220+
val = 1 << 8 # Stop
1221+
else:
1222+
lt = next_sequence[ll]
1223+
if lt == -1:
1224+
if ll != layers - 1: # Don't set stop bit unless required
1225+
val = 1 << 8
1226+
elif lt != ll + 1:
1227+
val = 1 << 7 | lt
1228+
elif snoop_sequence[ll] is not None:
1229+
lt = snoop_sequence[ll]
1230+
assert lt >= 0
1231+
val = 1 << 7 | lt
1232+
if lt != -1:
1233+
if in_sequences[lt] is not None and ll in in_sequences[lt] \
1234+
and operands[lt] == 1:
1235+
ll_index = in_sequences[lt].index(ll)
1236+
ll_offset = out_offset[ll] - ll_index * write_gap[ll] * 4
1237+
if in_offset[lt] != ll_offset:
1238+
wprint(f'Layer {ll}: The input offset of the next '
1239+
f'sequence (layer {lt}, 0x{in_offset[lt]:04x}) '
1240+
"does not match the current layer's output "
1241+
f'(offset 0x{out_offset[ll]:04x} - write gap '
1242+
f'{write_gap[ll]} * sequence position '
1243+
f'{ll_index} * 4 = 0x{ll_offset:04x}).')
1244+
if input_chan[lt] != output_chan[ll] \
1245+
* len(in_sequences[lt]) \
1246+
or input_dim[lt] != output_dim[ll]:
1247+
wprint(f'Layer {ll}: The input dimensions of the next '
1248+
f'sequence (layer {lt}, '
1249+
f'{len(in_sequences[lt])} inputs, '
1250+
f'{input_chan[lt]}x{input_dim_str[lt]}) do '
1251+
"not match the current layer's output "
1252+
"dimensions "
1253+
f'({output_chan[ll]}x{output_dim_str[ll]}).')
12501254

1255+
if hasattr(tc.dev, 'LREG_NXTLYR'):
12511256
apb.write_lreg(group, r * layers + ll, tc.dev.LREG_NXTLYR, val,
12521257
comment=' // Next Layer')
12531258

@@ -2751,6 +2756,7 @@ def run_eltwise(
27512756
test_name,
27522757
timeout,
27532758
riscv=riscv,
2759+
groups_used=groups_used,
27542760
)
27552761
assets.copy('assets', 'rtlsim-ai' + str(device), base_directory, test_name)
27562762
if riscv_cache:

izer/rtlsim.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
RTL simulation support routines
99
"""
1010
import os
11+
from typing import List, Optional
1112

1213
from . import state
1314
from . import tornadocnn as tc
@@ -19,6 +20,7 @@ def create_runtest_sv(
1920
test_name: str,
2021
timeout: int,
2122
riscv: bool = False,
23+
groups_used: Optional[List[int]] = None,
2224
):
2325
"""
2426
For for test `test_name`, create the runtest.sv file named `runtest_filename`, in the
@@ -131,12 +133,8 @@ def create_runtest_sv(
131133
' if (!start_ena) begin\n'
132134
)
133135
if state.rtl_preload:
134-
runfile.write(
135-
' load_cnn_mems_0;\n'
136-
' load_cnn_mems_1;\n'
137-
' load_cnn_mems_2;\n'
138-
' load_cnn_mems_3;\n'
139-
)
136+
for _, i in enumerate(groups_used):
137+
runfile.write(f' load_cnn_mems_{i};\n')
140138
runfile.write(
141139
' start_time = $realtime;\n'
142140
' start_ena = 1;\n'
@@ -150,11 +148,9 @@ def create_runtest_sv(
150148
' clkena1 = 1;\n'
151149
)
152150
if result_output:
151+
for _, i in enumerate(groups_used):
152+
runfile.write(f' dump_cnn_mems_{i};\n')
153153
runfile.write(
154-
' dump_cnn_mems_0;\n'
155-
' dump_cnn_mems_1;\n'
156-
' dump_cnn_mems_2;\n'
157-
' dump_cnn_mems_3;\n'
158154
' close_files;\n'
159155
' chk_stat = $system({`TARGET_DIR,"/verify-output.py ",`TARGET_DIR});\n'
160156
' if (chk_stat != 0)\n'

0 commit comments

Comments
 (0)