Skip to content

Commit 450865b

Browse files
author
Robert Muchsel
authored
Allow overriding automatically selected bias memories (#106)
* AI87: reshape kernels for calcx4 mode; RTL sims * Properly follow the bias group map when specified; --ignore-bias-groups
1 parent 2ad7ad6 commit 450865b

17 files changed

+230
-5
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MAX78000 Model Training and Synthesis
22

3-
_February 6, 2021_
3+
_February 10, 2021_
44

55
The Maxim Integrated AI project is comprised of four repositories:
66

@@ -650,6 +650,10 @@ The following example shows the weight memory layout for two layers. The first l
650650

651651
![Layers and Weight Memory](docs/KernelMemoryLayers.png)
652652

653+
#### Bias Memories
654+
655+
Bias values are stored in separate bias memories. There are four bias memory instances available, and a layer can access any bias memory instance where at least one processor is enabled. By default, bias memories are automatically allocated using a modified Fit-First Descending (FFD) algorithm. Before considering the required resource sizes in descending order, and placing values in the bias memory with most available resources, the algorithm places those bias values that require a single specified bias memory. The bias memory allocation can optionally be controlled using the [`bias_group`](#`bias_group` (Optional)) configuration option.
656+
653657

654658
### Weight Storage Example
655659

@@ -1192,6 +1196,7 @@ The following table describes the most important command line arguments for `ai8
11921196
| `--debug-computation` | Debug computation (SLOW) | |
11931197
| `--stop-after` | Stop after layer | `--stop-after 2` |
11941198
| `--one-shot` | Use layer-by-layer one-shot mechanism | |
1199+
| `--ignore-bias-groups` | Do not force `bias_group` to only available x16 groups | |
11951200
| *Streaming tweaks* | | |
11961201
| `--overlap-data` | Allow output to overwrite input | |
11971202
| `--override-start` | Override auto-computed streaming start value (x8 hex) | |
@@ -1549,6 +1554,17 @@ Set `write_gap` to `1` to produce output for a subsequent two-input element-wise
15491554
Example:
15501555
`write_gap: 1`
15511556

1557+
##### `bias_group` (Optional)
1558+
1559+
For layers that use a bias, this key can specify one or more bias memories that should be used. By default, the software uses a “Fit First Descending (FFD)” allocation algorithm that considers largest bias lengths first, and then the layer number, and places each bias in the available group with the most available space, descending to the smallest bias length.
1560+
1561+
“Available groups” is layer specific and is a list of the groups that have enabled processors for the respective layer. `bias_group` must reference one or more of the available groups. This check can be overridden using the command line option `--ignore-bias-groups` that allows any group or list of groups for any layer.
1562+
1563+
`bias_group` can be a list of integers or a single integer.
1564+
1565+
Example:
1566+
`bias_group: 0`
1567+
15521568
#### Example
15531569

15541570
The following shows an example for a single “Fire” operation, the MAX78000/MAX78002 hardware layer numbers and its YAML description.

README.pdf

7.32 KB
Binary file not shown.

izer/commandline.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ def get_parser():
196196
help="set ext_rdy bit (default: false)")
197197
group.add_argument('--weight-start', type=int, metavar='N', default=0,
198198
help="specify start offset for weights (debug, default: 0)")
199+
group.add_argument('--ignore-bias-groups', action='store_true', default=False,
200+
help="do not force `bias_group` to use an active group (default: false)")
199201

200202
# RTL sim
201203
group = parser.add_argument_group('RTL simulation')

izer/izer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ def main():
593593
input_pix_clk=args.input_pix_clk,
594594
fifo_go=args.fifo_go,
595595
pretend_zero_sram=args.pretend_zero_sram,
596+
ignore_bias_groups=args.ignore_bias_groups,
596597
)
597598
if not args.embedded_code and args.autogen.lower() != 'none':
598599
rtlsim.append_regression(

izer/kbias.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def bias_sort(e):
179179
bias_map = sorted(bias_map, key=bias_sort)
180180

181181
for _, (ll, gmap, blen) in enumerate(bias_map):
182-
group = group_map[ll][argmin(group_bias_max[t] for t in gmap)]
182+
group = gmap[argmin(group_bias_max[t] for t in gmap)]
183183
if group_bias_max[group] + blen > tc.dev.BIAS_SIZE:
184184
eprint(f'Layer {ll}: bias memory capacity exceeded - available groups: '
185185
f'{gmap}, used so far: {group_bias_max}, needed: {blen}, '

izer/kernels.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ def load( # pylint: disable=too-many-branches,too-many-statements
132132

133133
in_exp = 1
134134
in_chan = in_expand_thresh[ll]
135+
elif calcx4[ll]:
136+
kernel_reshaped = kernel[ll].reshape(
137+
output_chan[ll],
138+
in_expand[ll],
139+
-1,
140+
).swapaxes(0, 1).reshape(
141+
kernel[ll].shape,
142+
)
143+
in_exp = in_expand[ll]
144+
in_chan = input_chan[ll]
135145
else:
136146
kernel_reshaped = kernel[ll]
137147
in_exp = in_expand[ll]

izer/max7800x.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def create_net( # pylint: disable=too-many-arguments,too-many-locals,too-many-b
159159
input_pix_clk=9,
160160
fifo_go=False,
161161
pretend_zero_sram=False,
162+
ignore_bias_groups=False,
162163
):
163164
"""
164165
Chain multiple CNN layers, create and save input and output
@@ -550,10 +551,11 @@ def create_net( # pylint: disable=too-many-arguments,too-many-locals,too-many-b
550551
group_map[ll] = this_map
551552

552553
if bias_group_map[ll] is not None:
553-
for _, e in bias_group_map[ll]:
554+
for _, e in enumerate(bias_group_map[ll]):
554555
if e not in group_map[ll]:
555-
eprint(f'Layer {ll}: `bias_group` references an unused group. Used groups for '
556-
f'this layer are: {group_map[ll]}.')
556+
eprint(f'Layer {ll}: `bias_group` references the unused group {e}. '
557+
f'Used groups for this layer are: {group_map[ll]}.',
558+
error=not ignore_bias_groups)
557559

558560
# Ensure input and output map are the same for passthrough layers
559561
if operator[ll] == op.NONE:

rtldev/gen-rtlsims-preregression.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@
1010
./ai8xize.py --rtl"$PRELOAD" --verbose --autogen $TARGET --log --test-dir $TARGET --prefix $PREFIX-mppool-256 --config-file tests/test-mppool-256.yaml --device "$DEVICE" "$@"
1111

1212
./ai8xize.py --rtl"$PRELOAD" --verbose --autogen $TARGET --log --test-dir $TARGET --prefix $PREFIX-flatten-bias --config-file tests/test-flatten-bias.yaml --device "$DEVICE" "$@"
13+
./ai8xize.py --rtl"$PRELOAD" --verbose --autogen $TARGET --log --test-dir $TARGET --prefix $PREFIX-tfrock-bias --config-file tests/test-tfrock-bias.yaml --ignore-bias-groups --device "$DEVICE" "$@"
14+
15+
./ai8xize.py --rtl"$PRELOAD" --verbose --autogen $TARGET --log --test-dir $TARGET --prefix $PREFIX-riscv-csv-qfastfifostream-x4-likecifar --config-file tests/test-ffsx4-likecifar10-hwc.yaml --fast-fifo-quad --riscv --device "$DEVICE" "$@"
1316

1417
./ai8xize.py --rtl"$PRELOAD" --verbose --autogen $TARGET --log --test-dir $TARGET --prefix $PREFIX-qfastfifostream-readahead-multipass --config-file tests/test-ffsreadahead-multipass.yaml --fast-fifo-quad --riscv --device "$DEVICE" "$@"
1518
./ai8xize.py --rtl"$PRELOAD" --verbose --autogen $TARGET --log --test-dir $TARGET --prefix $PREFIX-fastfifostream-readahead-multipass --config-file tests/test-ffsreadahead-multipass.yaml --fast-fifo --riscv --device "$DEVICE" "$@"
1619
./ai8xize.py --rtl"$PRELOAD" --verbose --autogen $TARGET --log --test-dir $TARGET --prefix $PREFIX-qfastfifostream-x4-readahead-multipass --config-file tests/test-ffsx4readahead-multipass.yaml --fast-fifo-quad --riscv --device "$DEVICE" "$@"
1720
./ai8xize.py --rtl"$PRELOAD" --verbose --autogen $TARGET --log --test-dir $TARGET --prefix $PREFIX-fastfifostream-x4-readahead-multipass --config-file tests/test-ffsx4readahead-multipass.yaml --fast-fifo --riscv --device "$DEVICE" "$@"
21+
22+
./ai8xize.py --rtl"$PRELOAD" --verbose --autogen $TARGET --log --test-dir $TARGET --prefix $PREFIX-qfastfifostream-readahead-multipass-bias --config-file tests/test-ffsreadahead-multipass-bias.yaml --fast-fifo-quad --riscv --device "$DEVICE" "$@"
23+
./ai8xize.py --rtl"$PRELOAD" --verbose --autogen $TARGET --log --test-dir $TARGET --prefix $PREFIX-fastfifostream-readahead-multipass-bias --config-file tests/test-ffsreadahead-multipass-bias.yaml --fast-fifo --riscv --device "$DEVICE" "$@"
24+
./ai8xize.py --rtl"$PRELOAD" --verbose --autogen $TARGET --log --test-dir $TARGET --prefix $PREFIX-qfastfifostream-x4-readahead-multipass-bias --config-file tests/test-ffsx4readahead-multipass-bias.yaml --fast-fifo-quad --riscv --device "$DEVICE" "$@"
25+
./ai8xize.py --rtl"$PRELOAD" --verbose --autogen $TARGET --log --test-dir $TARGET --prefix $PREFIX-fastfifostream-x4-readahead-multipass-bias --config-file tests/test-ffsx4readahead-multipass-bias.yaml --fast-fifo --riscv --device "$DEVICE" "$@"

tests/bias_ffs-multipass.npy

3.78 KB
Binary file not shown.

tests/bias_tfrock-bias.npy

2.42 KB
Binary file not shown.

0 commit comments

Comments
 (0)