How does aNeural Networkthink inSilicon?
$ trace_inference --depth=full
# Follow a single token from a Python string to a tensor in HBM,
# through a Tensor Core, back to a vocabulary probability.
The Input
Raw text becomes discrete tokens, then dense floating-point vectors. A vocabulary lookup is the first lookup table in the network.
Tokenization
01.AVocab
01.BEmbedding Tensor
01.CThe Layer
A single Linear layer is one matrix multiplication and one bias add, followed by a non-linearity. The matmul is the entire reason for the rest of this page.
Forward Pass
02.AActivation
02.BFLOPs Calculator
02.CMatrix Multiplication
C[i][j] = Σₖ A[i][k] × B[k][j]. Naively O(n³) — but real hardware runs tiled, vectorized, and on dedicated silicon.
Dot-Product Stepping
03.ANaive vs Tiled
03.Bfor j in range(N):
for k in range(N):
C[i][j] += A[i][k] * B[k][j]
for jj in range(0, N, T):
# load A[ii:ii+T, :] → SMEM
for kk in range(0, N, T):
# load B[:, kk:kk+T] → SMEM
# 2×2 micro-kernel → registers
Memory Pattern
03.CThe Math Library
PyTorch never writes a matrix-multiply kernel. It dispatches down a hardware-aware stack to BLAS, then to intrinsics, then to silicon.
GPU Path
04.ACPU Path
04.BKernel Launch Overhead
04.CThe GPU Execution Model
The GPU is a hierarchy of parallelism. A single matmul launches thousands of threads, mapped across Streaming Multiprocessors.
GPU Die
05.AInside an SM
05.BThread Hierarchy
05.COccupancy Calculator
05.DTensor Cores
Specialized matrix-multiply-accumulate silicon. A single Tensor Core does 128 FP16 FMA per cycle — and Hopper's FP8 doubles that.
MMA in One Cycle
06.APTX / SASS
06.Btorch.backends.cuda.matmul.allow_tf32 = True routes FP32 matmul through TF32 Tensor Cores — silent ~8× speedup.Throughput by Precision
06.CThe CPU Path
On CPU, parallelism comes from wide SIMD registers and many cores, not thousands of threads. AVX-512 + AMX tile are the equivalent of a Tensor Core.
AVX-512 SIMD Lanes
07.A_mm512_fmadd_ps(a, b, c) // a*b+c, all 16 lanesCache Hierarchy
07.BCPU Die
07.CPipeline
07.DMemory & the Roofline
The fastest matmul is the one that didn't have to read memory. Modern inference is bounded by data movement, not FLOPs.
Roofline Model
08.AMemory Waterfall
08.BInterconnect
08.CEnd-to-End Timeline
One forward pass of a single transformer block, from Python call to Python string. Each bar is a real kernel, each color a kind of work.
Gantt: One Token Forward Pass (GPT-2 ~125M)
09.ATO INSPECT KERNEL
+ HARDWARE
The Output
The matmul produced a vector of 50,257 raw numbers. Softmax turns them into a probability distribution. Sampling picks the next token.
Raw Logits
10.ASoftmax → Sample
10.BDecoded Output
10.CThe round trip took microseconds.
A single token touched a tokenizer, an embedding table, twelve transformer blocks, a softmax, and a vocabulary lookup. The hardware traversed Python, CUDA driver, PTX, SASS, Tensor Cores, SMEM, registers, HBM, and back. Every stage exists for a reason — and removing any of them makes the network 10–1000× slower.