Interactive engineering notebook

Follow the data.

Start with a dot product. Partition the work, carry the operands through a conceptual processor, and inspect the cost of moving them. Scroll to explore, or use the playback controls.

Educational model · no hardware execution or profiling

Configure the analytical model 256 × 256 × 256 · FP32 · 32 × 32 × 32
Problem dimensions

M, N, K and BM, BN, BK control the analytical problem and tile view. The separate numerical example offers 3×3, 6×6 and 8×8 matrices; it does not compute the large configured problem.

Tile dimensions

FP32 stores 4-byte elements; FP16/BF16 store 2-byte elements with FP32 accumulation. INT8 inputs use 1 byte, with INT32 accumulation and a 4-byte output. No requantization or floating-point rounding is simulated.

Illustrative machine parameters
Illustrative machine parameters

Defaults are illustrative, with decimal units. Supply compatible compute and bandwidth ceilings for the same representation and memory boundary. No measured utilization is inferred.

Scroll to this notebook to load the interactive view.

Scene 01 / 07Scroll-driven
A · Matrix AB · Matrix BC · Matrix C
From mathematics to computation — One output combines one row of A with one column of B. Color is reinforced by A, B and C labels. A · 8×8 B · 8×8 C · 8×8

Exact 8×8 worked example

C = AB · 8 × 8

One output combines one row of A with one column of B. Color is reinforced by A, B and C labels.

01 / The bilinear map

From mathematics to computation

A has M rows and K columns. B has K rows and N columns. The shared K dimension must agree; C has M rows and N columns.

Select any output below the diagram to inspect its actual products and partial sums. The default 8×8 example has 64 outputs and 512 products. Choose 3×3 to recover the reference C[0,0] = 1×9 + 2×6 + 3×3 = 30.

In the 3D view each interior point represents A[i,k] B[k,j]. The amber fiber contracts along k onto C. Try the row, column and outer-product views to see different groupings of the same arithmetic; Orbit changes the camera, and 2D matrices restores the flat view.

A∈RM×K,B∈RK×N,C=AB∈RM×NA\in\mathbb R^{M\times K},\quad B\in\mathbb R^{K\times N},\quad C=AB\in\mathbb R^{M\times N}
From mathematics to computation — One output combines one row of A with one column of B. Color is reinforced by A, B and C labels. A · 8×8 B · 8×8 C · 8×8

One output combines one row of A with one column of B. Color is reinforced by A, B and C labels.

02 / The scalar traversal

The first approach: naive GEMM

The i–j–k loop completes one output before advancing. In row-major storage A[i,k] is contiguous as k changes; B[k,j] has stride N. The scalar sum stays in a register in the simplified model.

The conventional count is 2MNK operations: one multiplication and one accumulation per MAC. Blocking keeps the same O(MNK) arithmetic order and changes reuse. This is not a claim that cubic multiplication is globally optimal.

Cij=∑k=0K−1AikBkj,F≈2MNKC_{ij}=\sum_{k=0}^{K-1}A_{ik}B_{kj},\qquad F\approx2MNK
for (int i = 0; i < M; i++) {
  for (int j = 0; j < N; j++) {
    float sum = 0.0f;
    for (int k = 0; k < K; k++) {
      sum += A[i*K+k] * B[k*N+j];
    }
    C[i*N+j] = sum;
  }
}
The first approach: naive GEMM — Repeated logical loads need not become repeated DRAM transfers: caches, layouts and compiler transformations affect actual traffic. A · 8×8 B · 8×8 C · 8×8

Repeated logical loads need not become repeated DRAM transfers: caches, layouts and compiler transformations affect actual traffic.

03 / Reuse within a tile

Introducing data reuse

BM and BN set an output tile's row and column extents. BK partitions the reduction dimension. A BM×BK panel and a BK×BN panel update a BM×BN output tile.

The animation follows the first output tile. Highlighted A/B panels physically travel toward the compute unit, and subsequent K panels update the same resident C tile. Boundary panels are clipped to the matrix dimensions; large grids are grouped. Selecting the naive traversal shows scalar panels instead.

CI,J+=AI,LBL,J,∣I∣≤BM, ∣J∣≤BN, ∣L∣≤BKC_{I,J}\mathrel{+}=A_{I,L}B_{L,J},\quad |I|\le BM,\ |J|\le BN,\ |L|\le BK
Introducing data reuse — A larger tile offers reuse but consumes storage. A 16, 32 or 64 preset is a starting point for analysis, not an architecture-independent optimum. A · 8×8 B · 8×8 C · 8×8

A larger tile offers reuse but consumes storage. A 16, 32 or 64 preset is a starting point for analysis, not an architecture-independent optimum.

04 / The execution path

Inside the computational engine

Follow a panel from main memory into on-chip cache or scratchpad storage, then into registers. The compute unit multiplies operand fragments and updates an accumulator before the output is stored.

This diagram is a conceptual data path. Caches and explicitly managed scratchpads have different behavior; no particular GPU, CPU or GAP8 memory hierarchy is asserted here.

c←c+a⋅bc\leftarrow c+a\cdot b
Inside the computational engine — The numeric MAC trace follows the selected numerical example. Transfers and stage spacing do not represent device timing. DRAMSRAMREG / MACACC / C

The numeric MAC trace follows the selected numerical example. Transfers and stage spacing do not represent device timing.

05 / The communication cost

Performance is also about moving data

For beta=0, compulsory traffic reads each input once and writes the final output once. With uniform s-byte storage this is s(MK+KN+MN). INT8-to-INT32 needs a different output size.

Our naive traversal model reloads both input scalars for every MAC. The blocked model reads each A/B panel once per output tile and retains C across all K panels. Neither includes cache-line transfers, packing or reuse across output tiles.

Bmin⁡=sAMK+sBKN+sCMN,Ftile=2BM BN BKB_{\min}=s_A MK+s_B KN+s_C MN,\qquad F_{\mathrm{tile}}=2BM\,BN\,BK
Performance is also about moving data — Packing can add traffic while enabling much more reuse later. Lower bounds, logical accesses and measured transfers are different quantities. DRAMSRAMREG / MACACC / C

Packing can add traffic while enabling much more reuse later. Lower bounds, logical accesses and measured transfers are different quantities.

06 / The analytical ceiling

Understanding performance

Arithmetic intensity divides useful conventional work by bytes at a specified memory boundary. The chart combines the selected traversal intensity with the illustrative compute and bandwidth inputs.

The sloped region is bandwidth-limited; the plateau is compute-limited. Their intersection is the ridge point. The marked ceiling is not achieved throughput, GPU occupancy or measured utilization.

I=F/B,P≤min⁡(Ppeak,BmemoryI)I=F/B,\qquad P\le\min(P_{\mathrm{peak}},B_{\mathrm{memory}}I)
Understanding performance — For INT8, the dashboard reports integer operations and MACs. FP32/FP16/BF16 use the conventional FLOP count. PI = F/BP_peak

For INT8, the dashboard reports integer operations and MACs. FP32/FP16/BF16 use the conventional FLOP count.

Analytical dashboard

Conventional work
33554432 FLOPs
Multiply–accumulate operations
16777216 MACs
Selected traversal bytes
4456448 B
Compulsory byte lower bound
786432 B
Traversal arithmetic intensity
7.53 op/B
Geometric tile-shape efficiency
100%
Roofline throughput ceiling
752.94 Gop/s
Roofline ceiling / peak
75.29%
First tile working set
12288 B
Last tile extents (M, N, K)
32 × 32 × 32

Memory-bound ceiling

Hardware utilization and occupancy: not measured

Roofline uses the selected logical traversal model at one memory boundary. These byte counts exclude packing passes, cache-line effects, write allocation and inter-tile cache reuse. They are not measured traffic or speedups.

Shape efficiency compares useful MNK with the configured nominal padded tiles, including when the scalar traversal is selected for comparison. The byte model clips edge tiles and does not charge padded loads. This geometric ratio is not measured occupancy or a prediction of runtime.

An intermediate tile-panel update reads and writes FP32/INT32 accumulators. The first panel can start from zero; the last panel may convert the output. These are different boundaries from the whole-operation compulsory bound.

07 / The complete computation

From an operation to an efficient computation

The selected output matrix is reconstructed from its row–column products. The complete numerical result is available in the tables below. The independent analytical problem changes how panels are organized and reused.

Efficient computation requires a data schedule as well as an arithmetic identity. Locality, storage capacity, numerical representation and the executing architecture determine whether the available reuse is realized.

C=AB,η=MNK(⌈M/BM⌉BM)(⌈N/BN⌉BN)(⌈K/BK⌉BK)C=AB,\qquad \eta=\frac{MNK}{(\lceil M/BM\rceil BM)(\lceil N/BN\rceil BN)(\lceil K/BK\rceil BK)}
From an operation to an efficient computation — This browser experience is an educational simulation. Actual latency, occupancy, bandwidth utilization and energy require a real implementation and profiling. A · 8×8 B · 8×8 C · 8×8

This browser experience is an educational simulation. Actual latency, occupancy, bandwidth utilization and energy require a real implementation and profiling.

Configured problem: final analytical summary

Problem dimensions (M, N, K)
256 × 256 × 256
Traversal
Blocked GEMM
Tile dimensions (BM, BN, BK)
32 × 32 × 32
Conventional work
33554432 FLOPs
Compulsory byte lower bound
786432 B
Traversal arithmetic intensity
7.53 op/B
Geometric tile-shape efficiency
100%
Worked example and full result
A · 8 × 8
18791351
99927242
85921991
76999678
83739887
84331226
87631766
17433334
B · 8 × 8
38335298
27325974
95711232
93815852
91451161
68221721
19936217
64355727
C · 8 × 8
20120020666136199150118
235253207117152176235181
211308224100153184179186
367322309169216279266236
299302251160177211221218
14517512583123143148151
212287201114170219192202
15215613374103155120105

8×8 · 64 outputs · 512 scalar multiplications

Four views of the same contraction

The volume contains T[i,j,k] = A[i,k] B[k,j]. Each output sums a depth fiber along k. A and C share the row axis i; B and C share the column axis j. A and B share the reduction axis k. Changing the decomposition changes which outputs are emphasized, while preserving the same product. The matrix-view controls apply to the mathematical chapters; memory, processor and Roofline chapters keep their own diagrams.

Dot products
C[i,j] = Σ_k A[i,k] B[k,j]

One row of A intersects one column of B. Their product fiber reduces along k into one selected C cell. Click a C cell or use the output selector to inspect another fiber.

Row products
C[i,:] = A[i,:] B

A row-vector–matrix product computes an entire output row. The horizontal plane contains the product fibers for every j at the selected i; the example accumulates their exact partial sums together.

Column products
C[:,j] = A B[:,j]

A matrix–vector product computes an entire output column. The vertical plane contains every i at the selected j, exposing how the same matrix A participates in each output.

Outer products
C = Σ_k A[:,k] B[k,:]

A depth slice contributes a rank-at-most-one outer product. The amber plane sweeps along k and its actual products accumulate into C. These nonzero sample slices have rank one; their sum need not gain one rank at every step.

The geometric interpretation is inspired by Inside the Matrix — Basil Hosmer / PyTorch.

Cite this work

If you refer to this work in research or teaching, please cite the following doctoral thesis.

  1. Cristian Ramírez. RISC-V Low-Power Processors: Enhancing Matrix Computations and Deep Learning Convolution Algorithms (2025). Universitat Politècnica de València. PhD thesis.

    Read the thesis in the UPV repository

    BibTeX
    @phdthesis{ramirez2025risc,
      abbr = {PhD Thesis},
      title = {RISC-V Low-Power Processors: Enhancing Matrix Computations and Deep Learning Convolution Algorithms},
      author = {Ramírez, Cristian},
      year = {2025},
      school = {Universitat Polit{\`e}cnica de Val{\`e}ncia},
      type = {PhD thesis},
      html = {https://riunet.upv.es/entities/publication/e3858291-a656-43bb-ab2f-fd3e159d3c73},
      url = {https://riunet.upv.es/entities/publication/e3858291-a656-43bb-ab2f-fd3e159d3c73},
      preview = {phd_tesis_mini.png},
      selected = {true},
      bibtex_show = {true}
    }