Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

4x4 INT8 Matrix Multiplication Accelerator with AXI4-Lite Interface

A synthesizable, hardware-accelerated 4x4 Matrix-Matrix Multiplier (MMM) implemented in Verilog for the AMD Artix-7 FPGA (Basys 3). The core features a signed INT8 processing datapath with an INT32 accumulator, fully wrapped in an AXI4-Lite slave interface for memory-mapped integration with host processors or DMA engines.


1. System Architecture

The accelerator consists of three primary layers:

  • AXI4-Lite Bus Interface (axi_MMM.v): Memory-mapped slave handling independent 5-channel AXI transactions, register decoding, and data packing/unpacking.
  • Matrix Controller (matrix_ctrl.v): Finite State Machine (FSM) managing address generation for operand fetching, accumulation clearing, and memory writeback.
  • Processing Element (Base_PE.v): Pipelined multiply-accumulate (MAC) arithmetic unit with a 16-bit intermediate product register and a 32-bit output accumulator.
       ┌─────────────────────────────────────────────────────────────┐
       │                          axi_MMM                            │
       │                                                             │
       │  ┌──────────────────┐               ┌────────────────────┐  │
AXI    │  │ Address Decoder  │─── mem_a[15:0]│                    │  │
Bus ───┼─►│ & Latch Buffers  │─── mem_b[15:0]│   Matrix Engine    │  │
       │  │ (aw_done/w_done) │               │                    │  │
       │  └────────┬─────────┘               │  ┌──────────────┐  │  │
       │           │ ctrl_start              │  │ matrix_ctrl  │  │  │
       │           │                         │  └──────┬───────┘  │  │
       │           ▼                         │         │          │  │
       │  ┌──────────────────┐  core_done    │  ┌──────▼───────┐  │  │
       │  │ Sticky Status    │◄──────────────┼──┤   Base_PE    │  │  │
       │  │ Register (0x04)  │               │  └──────┬───────┘  │  │
       │  └────────┬─────────┘               │         │          │  │
       │           │ status_done             │  ┌──────▼───────┐  │  │
       │           ▼                         │  │ mem_c[15:0]  │  │  │
       │       AXI Read MUX ◄────────────────┼──┤ (Writeback)  │  │  │
       │                                     │  └──────────────┘  │  │
       └─────────────────────────────────────┴────────────────────┘──┘

2. Memory Map Specification

The module is addressed over an 8-bit local address space (0x00 – 0x7C). Each 32-bit register is word-aligned (4-byte increments).

Offset Address Register Name Access Bit Field Description
0x00 CTRL_REG W [0] Start Strobe: Write 1 to begin computation (self-clearing).
0x04 STATUS_REG R [0] Done Flag: Sticky status bit (1 = complete, 0 = busy/idle).
0x10 MAT_A_ROW0 W [31:0] Matrix A Row 0: {A[0][3], A[0][2], A[0][1], A[0][0]}
0x14 MAT_A_ROW1 W [31:0] Matrix A Row 1: {A[1][3], A[1][2], A[1][1], A[1][0]}
0x18 MAT_A_ROW2 W [31:0] Matrix A Row 2: {A[2][3], A[2][2], A[2][1], A[2][0]}
0x1C MAT_A_ROW3 W [31:0] Matrix A Row 3: {A[3][3], A[3][2], A[3][1], A[3][0]}
0x20 MAT_B_ROW0 W [31:0] Matrix B Row 0: {B[0][3], B[0][2], B[0][1], B[0][0]}
0x24 MAT_B_ROW1 W [31:0] Matrix B Row 1: {B[1][3], B[1][2], B[1][1], B[1][0]}
0x28 MAT_B_ROW2 W [31:0] Matrix B Row 2: {B[2][3], B[2][2], B[2][1], B[2][0]}
0x2C MAT_B_ROW3 W [31:0] Matrix B Row 3: {B[3][3], B[3][2], B[3][1], B[3][0]}
0x40 – 0x7C MAT_C[0..15] R [31:0] Matrix C Output: 16 individual signed 32-bit accumulated results.

3. Protocol Implementation & Engineering Challenges

Asynchronous Write Channel Decoupling

The AMBA AXI4-Lite standard defines the Write Address (AW) and Write Data (W) channels as completely independent. A master may issue the address and payload simultaneously, or separated across arbitrary clock cycles.

  • Tracking Handshakes: Independent tracking registers (aw_done, w_done) latch incoming transactions, ensuring the address is held safely if data arrives late.
  • Bypass Multiplexer: To prevent a 1-cycle latency skew when address and data arrive in the exact same cycle, a combinational multiplexer (active_waddr) selects the incoming bus pins directly rather than reading the un-latched register.
  • Response Safety: The s_axi_bvalid response handshake ensures the slave blocks subsequent transactions until the master confirms receipt of the previous write.

Sticky Status Flag vs. Polling Starvation

The internal FSM produces a single-cycle impulse (step == 66) to denote computation completion. Because an AXI read sequence requires a multi-cycle handshake, software polling routines frequently miss single-cycle pulses:

  • A dedicated flip-flop latches high on core_done to maintain status_done = 1.
  • The flag is automatically cleared upon issuing a subsequent write to CTRL_REG (0x00), preventing polling lockups without requiring manual interrupt clearing.

4. Hardware Utilization (AMD Artix-7 XC7A35T)

Synthesized in Vivado targeting the Basys 3 FPGA:

Resource Used Available Utilization (%)
Slice LUTs 421 20,800 2.02%
└─ LUT as Logic 397 20,800 1.91%
└─ LUT as Distributed RAM 24 9,600 0.25%
Slice Registers (FFs) 363 41,600 0.87%
Block RAM Tiles 0 50 0.00%
DSP48E1 Slices 0 90 0.00%

Synthesis Optimization Note:

  1. Input matrices A and B were mapped directly into 24 Distributed RAM (SLICEM LUTRAM) cells rather than dedicated BRAM tiles due to their small depth (16 bytes each).
  2. Vivado mapped the 8x8 signed multiplication into LUT logic rather than consuming a full DSP48E1 slice. A DSP slice can be explicitly forced using the (* use_dsp = "yes" *) synthesis attribute if LUT reduction is desired.

5. Verification & Testbench

The bus-functional testbench (tb_axi_MMM.v) models an AXI4-Lite master CPU:

  1. Writes packed test matrices into memory map offsets 0x10–0x2C.
  2. Asserts CTRL_REG[0] = 1 to begin hardware execution.
  3. Actively polls STATUS_REG[0] until completion (~66 execution cycles, 660 ns at 100 MHz).
  4. Reads back all 16 results across 0x40–0x7C and prints signed matrix values to the terminal.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages