Skip to content

Commit 2f2f589

Browse files
author
Robert Muchsel
authored
Ensure bias values for flatten layers are allocated first (#152)
* Ensure bias values for flatten layers are allocated first * Do not include sampleoutput.h in RTL sims
1 parent 3d03a66 commit 2f2f589

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

izer/backend/max7800x.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ def create_net(self) -> str: # pylint: disable=too-many-locals,too-many-branche
875875
output_processor_map,
876876
out_expand,
877877
list(set().union(groups_used)),
878+
flatten,
878879
)
879880

880881
apb.function_header(function='init')
@@ -1069,6 +1070,7 @@ def create_net(self) -> str: # pylint: disable=too-many-locals,too-many-branche
10691070
output_processor_map,
10701071
out_expand,
10711072
list(set().union(groups_used)),
1073+
flatten,
10721074
)
10731075

10741076
if verbose:

izer/kbias.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def load(
3232
output_processor_map,
3333
out_expand,
3434
groups_used,
35+
flatten,
3536
):
3637
"""
3738
Write `bias` values for the network to C code.
@@ -78,7 +79,7 @@ def load(
7879
bias_len[ll] += 1 # Work around a problem on AI85
7980

8081
bias_map += [(ll, groups_used if bias_group_map[ll] is None else bias_group_map[ll],
81-
bias_len[ll])]
82+
bias_len[ll], flatten[ll])]
8283
continue
8384

8485
# For depth-wise convolutions, and qupac, each group needs to have 'its own' bias values
@@ -175,7 +176,10 @@ def rearrange_processor(p, bc_mode):
175176
# Reverse-sort the data structure for a Fit-First Descending (FFD) algorithm
176177
def bias_sort(e):
177178
"""Order bias tuples"""
178-
# Highest priority: If only one group is allowed
179+
# Highest priority: flatten
180+
if tc.dev.REQUIRE_FLATTEN_BIAS_FIRST and e[3]: # flatten
181+
return -1
182+
# Next highest priority: If only one group is allowed
179183
if len(e[1]) == 1:
180184
return 0
181185
# For all other cases, reverse sort by size; sorted() will keep the original order
@@ -187,7 +191,7 @@ def bias_sort(e):
187191

188192
bias_map = sorted(bias_map, key=bias_sort)
189193

190-
for _, (ll, gmap, blen) in enumerate(bias_map):
194+
for _, (ll, gmap, blen, _) in enumerate(bias_map):
191195
if not calcx4[ll]:
192196
group = gmap[argmin(group_bias_max[t] for t in gmap)]
193197
else:

izer/toplevel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ def header(
118118
memfile.write(f'#include "{state.weight_filename}"\n')
119119
if not lib and (embedded_code or state.compact_data):
120120
memfile.write(f'#include "{state.sample_filename}"\n')
121-
if not cmsis_nn and state.generate_kat and state.result_filename.lower() != 'none':
121+
if not cmsis_nn and embedded_code and state.generate_kat \
122+
and state.result_filename.lower() != 'none':
122123
memfile.write(f'#include "{state.result_filename}"\n')
123124
memfile.write('\n')
124125

izer/tornadocnn.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Dev:
4444
REQUIRE_ONESHOT_CLEAR = True
4545
REQUIRE_NEW_STREAMING = False
4646
REQUIRE_FIFO_CPL = True
47+
REQUIRE_FLATTEN_BIAS_FIRST = False
4748
EMULATE_ELTWISE_MP = False
4849
EMULATE_1X1_STREAMING = True
4950
USE_PROCESSORS = True
@@ -262,6 +263,7 @@ class DevAI85(Dev):
262263
FAST_FIFO_DR = 4 # Data register
263264
FAST_FIFO_DMA = 5 # DMA register (reserved function, not yet supported)
264265

266+
REQUIRE_FLATTEN_BIAS_FIRST = True
265267
EMULATE_ELTWISE_MP = True
266268
SUPPORTED_X2D_PADS = [0, 1, 2]
267269
SUPPORTED_X2D_OUTPUT_PADS = [1]
@@ -483,7 +485,7 @@ class DevAI87(Dev):
483485
C_PAD = 2
484486

485487
# PLL Speed in MHz
486-
PLL_SPEED = 240
488+
PLL_SPEED = 200
487489

488490
def __str__(self):
489491
return self.__class__.__name__

0 commit comments

Comments
 (0)