Project System Interface
README.md
Use this reference while implementing Tasks A–C. It defines network geometry, storage layouts, integer arithmetic and the memory-mapped I/O (MMIO) interface used to read and write controller registers. Hardware and software share stage descriptors: records of each stage's operation, tensor dimensions, memory addresses and execution parameters.
Network and arithmetic
Each stage groups a convolution (conv) or fully connected (fc) layer with its following rectified linear unit (ReLU) activation and max pooling, where present. The following table describes Lab1Cifar10Model.inferenceProfile, used by the supplied model data and complete-system run. Shapes use height–width–channel (HWC) order; fully connected layers list feature counts.
| Stage | Operations | Input HWC/features | Result HWC/features |
|---|---|---|---|
| 0 | conv1 + ReLU + 2x2 max pool | 21x21x3 | 8x8x5 |
| 1 | conv2 + ReLU + 2x2 max pool | 8x8x5 | 4x4x7 |
| 2 | conv3 + ReLU | 4x4x7 | 4x4x9 |
| 3 | conv4 + ReLU | 4x4x9 | 4x4x9 |
| 4 | conv5 + ReLU + 2x2 max pool | 4x4x9 | 2x2x5 |
| 5 | fc1 + ReLU | 20 | 32 |
| 6 | fc2 + ReLU | 32 | 16 |
| 7 | fc3 | 16 | 10 signed INT32 outputs |
The controller tests also use Lab1Cifar10Model.validationProfile, which has the same stage order and its own tensor dimensions and buffer sizes. Use the fields of the profile selected by useInferenceProfile.
The inference profile has 3,703 weights and requires 157,063 multiply-accumulate operations (MACs) per input. The first convolution uses a 5x5 kernel without padding; the remaining convolutions use 3x3 kernels with padding 1. Convolution stride is 1. Pooling uses a 2x2 window with stride 2.
Operands and intermediate activations are signed INT8. Accumulation and final outputs are signed INT32. Gemmini executes all convolution and fully connected multiplications, ReLU and max pooling. Multiplication uses full accumulator results (full_C=true), with activation and scaling disabled for that step. Software performs integer requantization before Gemmini applies ReLU/pooling.
Gemmini ReLU and max pooling
For each non-final stage, use the supplied requantize helper to convert the INT32 multiplication result to INT8. Load these values into Gemmini's accumulator using gemmini_extended2_config_ld with shrunk=true and gemmini_extended_mvin. Use gemmini_extended_config_st or gemmini_extended2_config_st with RELU and ACC_SCALE_IDENTITY, then gemmini_extended_mvout, to produce the stage output.
For stages 0, 1 and 4, configure the Gemmini store path for 2x2 max pooling with stride 2 and padding 0. Supply the convolution and pooled tensor dimensions from the current descriptor; pooling stores use rows=0 in gemmini_extended_mvout. For stages 2, 3, 5 and 6, use ordinary ReLU stores with pooling disabled. Stage 7 writes raw INT32 multiplication results.
The instruction interfaces are defined in the supplied gemmini.h. Respect the generated DIM and ACC_ROWS limits when loading and storing tiles, and finish the Gemmini operations before reporting stage completion.
Data layout and storage
| Data | Storage order |
|---|---|
| Input and intermediate activations | HWC |
| Convolution weights | Kernel-row, kernel-column, input-channel, output-channel (KH,KW,C_in,C_out) |
| Linear weights | Input-feature, output-feature, row major |
| Final output | Ten little-endian signed INT32 values |
For convolution as matrix multiplication, K = KH * KW * C_in and N = C_out; the weight array is a row-major K x N matrix. For a fully connected layer, K and N are the input and output feature counts.
The final 2x2x5 convolution result is flattened in HWC order into 20 FC1 input features. The supplied FC1 weights already use that order.
For the inference profile, intermediate activations use two adjacent 320-byte buffers. This combined 640-byte region is the activation arena. The final output uses a separate 40-byte buffer. All weight offsets are byte offsets, with one byte per weight.
The files below are supplied under tests/cases/model/. make model-data verifies their checksums and prepares copies in build/model/.
| File | Contents |
|---|---|
model_int8.json | Model manifest: layer shapes, byte offsets, requantization shifts and MAC counts |
model_int8.bin | 3,703 signed INT8 weights in the order specified by model_int8.json |
lab1_test_input_nhwc_int8.bin | One 21x21x3 signed INT8 HWC input |
lab1_cifar10_quant.h | Per-layer integer requantization parameters |
lab1_cifar10_profile.h | Input size, weight count and activation-buffer size |
stage_0.bin through stage_6.bin | Signed INT8 intermediate results in HWC order |
stage_7.bin | Ten little-endian signed INT32 final outputs |
lab1_test_expected_logits_accumulator.bin | Final INT32 outputs used by the entry-program checker |
SHA256SUMS | Checksums of the supplied files |
Quantization
Requantization converts an INT32 accumulator to an INT8 activation. Use the supplied per-layer right-shift amounts and a zero point of zero. In the formula below, acc is the INT32 accumulator, shift is the supplied nonnegative shift, q is the INT8 result and clip clamps to the stated range. For each non-final stage, round to nearest with ties away from zero, then saturate to [-128,127]:
magnitude = (abs(acc) + 2^(shift-1)) >> shift # shift > 0
magnitude = abs(acc) # shift == 0
q = clip(sign(acc) * magnitude, -128, 127)
Use a 64-bit temporary when taking an INT32 absolute value. ReLU and pooling follow requantization. The provided requantize helper implements this numeric contract. The final linear stage stores its ten raw INT32 accumulator values without requantization. Results are checked exactly against the supplied data.
MMIO interface
The controller's MMIO registers occupy addresses 0x2000 through 0x2fff. Offsets below are relative to 0x2000; R and W mean read and write. Sticky done/error bits retain events until reset or an accepted start clears them. Busy indicates an active inference; descriptor valid indicates that software can read the current stage descriptor.
| Offset | Access | Meaning |
|---|---|---|
| 0x00 | W | Write 1 to start |
| 0x04 | R | Status: bit 0 busy, bit 1 sticky done, bit 2 descriptor valid, bit 3 sticky error |
| 0x08 | W | Write 1 to complete the current stage |
| 0x10 | RW | 64-bit input base |
| 0x18 | RW | 64-bit weights base |
| 0x20 | RW | 64-bit activation-arena base |
| 0x28 | RW | 64-bit final-output base |
| 0x40 | R | Stage index |
| 0x44 | R | Operation in bits 1:0; ReLU in bit 2 |
| 0x48 | R | 64-bit current input address |
| 0x50 | R | 64-bit current output address |
| 0x58 | R | 64-bit current weights address |
| 0x60 | R | 64-bit input geometry |
| 0x68 | R | 64-bit convolution-output geometry |
| 0x70 | R | 64-bit result geometry |
| 0x78 | R | 64-bit kernel/pooling geometry |
| 0x80 | R | 32-bit weight element count |
| 0x88 | R | 64-bit MAC count |
| 0x90 | R | Stage count, 8 |
| 0x94 | R | Selected activation-buffer size |
Each 64-bit read-only field occupies two consecutive 32-bit registers, with the low word at the listed offset. Geometry uses 16-bit lanes: channels in bits 15:0, rows in 31:16 and columns in 47:32. Kernel, stride, padding, pool size, pool stride and pool padding use successive 8-bit lanes from the least significant byte. Operation 0 is convolution; operation 1 is linear.
Command and completion protocol
- A start is accepted only while idle. It latches all four base addresses and clears previous sticky done/error status.
- While busy, the controller presents the current descriptor and keeps it stable until an accepted completion.
- Software finishes Gemmini computation and result writes, then executes a Gemmini fence to wait for outstanding Gemmini operations to finish, before writing stage completion.
- Completion is accepted only while busy. It advances the stage or finishes the network after stage 7.
- Illegal requests set sticky error. An illegal simultaneous request still sets error even when another request is accepted.
- The final sequencer done pulse is retained as sticky done status.
Stage 0 reads the input buffer. For stage index i, the output goes to activation buffer i % 2, except that stage 7 writes the separate final-output buffer. Each later stage reads the preceding stage's result. Base-register writes after start must not change the active inference.