AI Computing Systems (EE219)

School of Science and Technology (SIST), ShanghaiTech University

Shanghai Institute of Semiconductor Innovation (SISI)

Project

Project · README.md · System interface

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.

StageOperationsInput HWC/featuresResult HWC/features
0conv1 + ReLU + 2x2 max pool21x21x38x8x5
1conv2 + ReLU + 2x2 max pool8x8x54x4x7
2conv3 + ReLU4x4x74x4x9
3conv4 + ReLU4x4x94x4x9
4conv5 + ReLU + 2x2 max pool4x4x92x2x5
5fc1 + ReLU2032
6fc2 + ReLU3216
7fc31610 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

DataStorage order
Input and intermediate activationsHWC
Convolution weightsKernel-row, kernel-column, input-channel, output-channel (KH,KW,C_in,C_out)
Linear weightsInput-feature, output-feature, row major
Final outputTen 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/.

FileContents
model_int8.jsonModel manifest: layer shapes, byte offsets, requantization shifts and MAC counts
model_int8.bin3,703 signed INT8 weights in the order specified by model_int8.json
lab1_test_input_nhwc_int8.binOne 21x21x3 signed INT8 HWC input
lab1_cifar10_quant.hPer-layer integer requantization parameters
lab1_cifar10_profile.hInput size, weight count and activation-buffer size
stage_0.bin through stage_6.binSigned INT8 intermediate results in HWC order
stage_7.binTen little-endian signed INT32 final outputs
lab1_test_expected_logits_accumulator.binFinal INT32 outputs used by the entry-program checker
SHA256SUMSChecksums 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.

OffsetAccessMeaning
0x00WWrite 1 to start
0x04RStatus: bit 0 busy, bit 1 sticky done, bit 2 descriptor valid, bit 3 sticky error
0x08WWrite 1 to complete the current stage
0x10RW64-bit input base
0x18RW64-bit weights base
0x20RW64-bit activation-arena base
0x28RW64-bit final-output base
0x40RStage index
0x44ROperation in bits 1:0; ReLU in bit 2
0x48R64-bit current input address
0x50R64-bit current output address
0x58R64-bit current weights address
0x60R64-bit input geometry
0x68R64-bit convolution-output geometry
0x70R64-bit result geometry
0x78R64-bit kernel/pooling geometry
0x80R32-bit weight element count
0x88R64-bit MAC count
0x90RStage count, 8
0x94RSelected 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

  1. A start is accepted only while idle. It latches all four base addresses and clears previous sticky done/error status.
  2. While busy, the controller presents the current descriptor and keeps it stable until an accepted completion.
  3. Software finishes Gemmini computation and result writes, then executes a Gemmini fence to wait for outstanding Gemmini operations to finish, before writing stage completion.
  4. Completion is accepted only while busy. It advances the stage or finishes the network after stage 7.
  5. Illegal requests set sticky error. An illegal simultaneous request still sets error even when another request is accepted.
  6. 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.