
14 November 2026 · ML System reading notes · 3/6
ML System 03: Hardware Accelerators
Part three is chapter 7 of the book: hardware accelerators, finally down at the chip itself. I got two things wrong while reading it: I assumed one thread maps to one Tensor Core, and when I saw how different the book's Ascend and NVIDIA architecture diagrams look, I assumed the difference was that Ascend is a SoC and NVIDIA isn't. This part sorts those out: what's inside a GPU, how you write kernels for it, and what really separates Ascend from NVIDIA.
What's inside an accelerator
The book uses NVIDIA's GV100, from the Volta architecture, as its example. It's built in nested layers:
| Level | Count | What's inside |
|---|---|---|
| Whole chip | 1 | 6 GPCs, 8 memory controllers of 512 bits each |
| GPC (GPU Processing Cluster) | 6 | 7 TPCs each |
| TPC (Texture Processing Cluster) | 6 × 7 = 42 | 2 SMs each |
| SM (Streaming Multiprocessor) | 42 × 2 = 84 | 64 FP32 units, 64 INT32 units, 32 FP64 units, 8 Tensor Cores, 4 texture units |
The book lists five kinds of storage: the register file, shared memory, global memory, constant memory and texture memory.
Threads and Tensor Cores aren't one-to-one
At first I thought each thread got its own Tensor Core. But a thread is a software task and a Tensor Core is a hardware unit, and a whole warp (32 threads) shares the Tensor Cores.
First, what a warp is. A GPU doesn't schedule threads one at a time. It groups 32 threads into a warp, and the warp is the basic unit of scheduling. The 32 threads in a warp move in lockstep, all executing the same instruction at the same time.
Each SM in the GV100 is split into 4 partitions. Each partition has 1 warp scheduler, 16 FP32 units and 2 Tensor Cores, so the 4 partitions add up to the 8 Tensor Cores per SM in the table.
When a warp makes one WMMA call (the CUDA interface that lets a warp drive the Tensor Cores; more on it in the programming section below), its 32 threads hand their data together to the 2 Tensor Cores in their partition. Each thread holds only a small piece of the matrix in its own registers, called a fragment. The multiplication itself happens in the Tensor Core.
An SM keeps dozens of warps resident at once (up to 64 on Volta) but has only 8 Tensor Cores. The scheduler switches between warps quickly: whenever one is waiting on data from memory, another warp steps in to compute. That's how a GPU uses huge numbers of threads to hide memory latency.
Even CUDA cores aren't one per thread. A partition has only 16 FP32 units, so a warp's 32 threads execute in two passes.
A Tensor Core is like a big stamping press. A team of 32 works it together, each person feeding in part of the material at the same moment, and one press stamps out a 16×16 block of results. Dozens of teams take turns on the machine.
How to get the accelerator working for you
The book describes two paths. The first is calling a programming API, which comes in three levels; the lower you go, the more control you get. The second is an operator compiler: instead of writing the kernel by hand, you describe what to compute and let the compiler generate it.
Path one: three levels of programming API
| Level | Example | What it's like |
|---|---|---|
| Operator library | cuBLAS, cuDNN | One function call does it, the least effort; but new or unusual operators are missing or poorly optimized, and nothing can be fused |
| Programming primitive | CUDA's WMMA | Half-built: a whole warp drives the Tensor Cores through one small matrix multiply-accumulate |
| Instruction | PTX's mma instruction | You manage even which register holds what; the best performance and the most flexibility, used by DeepSeek's DeepGEMM and FlashAttention |
WMMA stands for warp matrix multiply-accumulate. MMA is matrix multiply-accumulate: the one thing a Tensor Core can do is multiply two small matrices and add the result into an accumulator matrix. Put together, WMMA is a whole warp cooperating to have the Tensor Cores do one small matrix multiply-accumulate. Using it takes four steps:
fill_fragment: zero the accumulator;load_matrix_sync: load the small tiles;mma_sync: multiply-accumulate;store_matrix_sync: write the result back.
The "sync" in the names means all 32 threads must call the function together. A large matrix multiplication is just cut into many 16×16 tiles and accumulated in a loop.
PTX (Parallel Thread Execution) sits in the middle of the compilation chain. Turning CUDA code into machine code that runs on the GPU takes two steps:
CUDA C++ --nvcc--> PTX --ptxas--> SASS
SASS is the real machine code, and it differs for every GPU generation. PTX is the layer in between: it works across generations, it's documented, and you can write it by hand. It plays the role of LLVM IR in the GPU world. mma is the PTX instruction that drives the Tensor Cores directly to do a matrix multiply-accumulate.
WMMA versus PTX mma
The name of an mma instruction is itself a list of parameters, for example:
mma.sync.aligned.m8n8k4.row.row.f32.f16.f16.f32
m8n8k4 is the tile shape, row.row is the layout of A and B, and the last four are the data types of D, A, B and C: multiply in FP16, accumulate in FP32, the classic mixed-precision setup.
The key difference is the operands. In WMMA a fragment is a black box. In mma the operands are registers directly, and which element goes in which register of which thread has to follow the documentation exactly. It's tedious, but in return you can compose shapes freely, use ldmatrix to load from shared memory straight into registers in whatever layout you need, and schedule the pipeline of moving data and computing in fine detail.
The instructions change every generation: Volta has m8n8k4, Ampere m16n8k16, Hopper moves to wgmma (4 warps compute a bigger tile together, reading data straight from shared memory), and Blackwell has yet another set. So kernels written in PTX by hand often have to be rewritten for each GPU generation, which is exactly the value of operator compilers like Triton. In practice most people don't write raw PTX either. They use NVIDIA's open-source CUTLASS / CuTe, C++ template libraries that help you write kernels at this level.
Who takes path one
At the operator-library level, almost everyone. PyTorch, TensorFlow and TensorRT all call these libraries heavily underneath. When you write x @ W, the framework ends up calling cuBLAS for you.
At the primitive and instruction levels, a few teams chasing peak performance:
- NVIDIA itself: cuBLAS and cuDNN are written at this level, and it open-sourced CUTLASS / CuTe;
- FlashAttention (Tri Dao's group): built on CUTLASS;
- DeepSeek: DeepGEMM, FlashMLA and DeepEP, partly written all the way down in PTX;
- inference engine teams: the kernels in vLLM, SGLang and TensorRT-LLM, such as PagedAttention and the quantized matrix multiply Marlin;
- kernel teams at large-model companies: the most important kernels each have someone hand-tuning them at this level.
Calling libraries is everyone's daily work. The people writing primitives and instructions are the ones building the libraries and the ones squeezing every last bit out of the hardware. Few people can do this, which is why kernel engineers are in such demand.
Path two: separating computation from schedule
As the previous part covered, a new operator produced by fusion has no ready-made kernel, so an operator compiler has to generate one on the spot. This chapter explains the idea behind it: keep the computation and the schedule apart.
- Computation: what to compute, for example . This never changes.
- Schedule: how to compute it. Tiles of 64×64 or 128×32, whether to move A or B first, which loop levels run in parallel.
One computation has countless possible schedules, and their performance can differ by tens of times. The operator compiler's job is to find the best one, either from templates people write or by automatic search. The flow is the same as an ordinary compiler: describe the computation in a DSL, lower it to IR, optimize the schedule (tiling, loop transformations), map it to hardware instructions, and generate the kernel.
The book's examples are TVM (Tianqi Chen) and Ansor, built on it, which searches for schedules automatically; MLIR, which is closer to a set of building blocks for making compilers than a ready-made compiler; and Huawei's TBE and AKG, both based on TVM. Triton belongs here too: you write the computation in Python and leave tiling and scheduling to Triton. It's what torch.compile uses to generate fused kernels.
A DSA (domain-specific architecture) like Ascend leans on operator compilers even more, for two reasons. First, it has many kinds of instructions, with 1D, 2D and 3D vector instructions plus the Cube (Ascend's unit dedicated to matrix math, covered below), and data has to be moved explicitly between several levels of buffers, which makes hand-writing hard. Second, shapes vary endlessly, and an operator library can't be tuned to the optimum for every one.
Which path PyTorch takes
Both, depending on the mode:
| Mode | Large matmul, convolution | Attention | Small operators |
|---|---|---|---|
| eager | library calls (cuBLAS / cuDNN) | hand-written kernel (FlashAttention behind scaled_dot_product_attention) | PyTorch's own prewritten CUDA kernels |
| torch.compile | still cuBLAS by default; with max-autotune, Triton generates a few variants and benchmarks them against cuBLAS | same as eager | Inductor generates fused Triton kernels on the spot (path two) |
Mixing is the industry norm: standard large operators go to highly optimized libraries or hand-written kernels, and the scattered pieces that need fusing go to a compiler. Ascend works the same way. CANN (Ascend's software stack, covered in the last section) has both an operator library and TBE / AKG; the hardware is just harder to write by hand, so it relies more on the compiler.
GEMM: the main computation in deep learning
GEMM stands for General Matrix Multiplication:
Here is and is . With and it's an ordinary matrix multiplication. means the result is added onto the existing (a bias or a residual, say), which saves a separate addition.
The name comes from BLAS: GE means general, a matrix with no special structure such as symmetric or triangular, and MM means matrix times matrix. In the same naming scheme, GEMV is matrix times vector.
Most computation in deep learning ends up as GEMM: Linear layers, and "scores × " in attention, the FFN and the MoE experts, and convolution (turned into GEMM with im2col). In large models it usually accounts for over 90% of the compute, which is why Tensor Cores are designed for GEMM, and why DeepSeek put it in the name of DeepGEMM.
It connects to batching, too. Generating a token at batch size 1 is "weight matrix × vector", which is GEMV: each weight is read in and used only once, so it's memory-bound. Batching turns it into GEMM, where each weight is used many times, and only then is the compute kept busy. GEMM's compute grows as while its data grows as , so the bigger the matrix, the better the deal.
Are Ascend and NVIDIA basically the same thing?
The two architecture diagrams in the book look very different, and at first I assumed the difference was "Ascend is an SoC and NVIDIA isn't". The two do follow very different design ideas, but the difference lies mainly in how the compute core is designed, and has little to do with being an SoC.
SoC is a product form, and both make them
- Ascend 910: besides dozens of AI compute cores, the chip integrates ARM CPU cores, an image and video decoding module (DVPP), network interfaces and more. The Ascend 310 for edge devices is a typical SoC that works on its own once plugged in.
- NVIDIA H100: basically a "pure GPU", mostly a large number of SMs, caches and memory controllers, with no general-purpose CPU cores. It needs an external CPU to direct it, and the GV100 above is built the same way.
- NVIDIA makes SoCs too: Jetson Orin is an SoC with a CPU, a GPU and dedicated AI accelerators, and Grace Hopper packages NVIDIA's own ARM CPU together with a GPU.
The real difference: how the compute core is designed
| NVIDIA GPU | Ascend NPU (Da Vinci architecture) | |
|---|---|---|
| Origin | a general-purpose parallel processor that grew out of graphics rendering | a domain-specific accelerator (DSA) designed for AI from the start |
| Compute units | many SMs, each with lots of CUDA cores (scalar) + Tensor Cores (matrix) | each AI Core has a Cube (matrix) + Vector + Scalar unit |
| Programming model | launch thousands of threads, each computing a small piece (SIMT); flexible | like directing an assembly line: data is moved explicitly between several buffer levels (L1, L0A/L0B/L0C, UB), then handed to the Cube |
| Good at | computing almost anything | very efficient at large matrix multiplications, struggles with irregular computation |
An analogy: a GPU is a huge factory with tens of thousands of workers, and any job can be split up among them. A Da Vinci core is an automated production line built for matrix multiplication: extremely fast at its one job, but any new variation means re-planning the line.
Why moving a model from NVIDIA to Ascend is hard
CUDA kernels are written around the idea of tens of thousands of threads. On Ascend they have to be rewritten in Ascend C around explicit data movement plus Cube compute, and small edits won't make the old code run. That's why the DeepSeek V4 report only says its fused kernels were "verified on Ascend"; a real port needs Huawei's help.
Is CANN the counterpart of CUDA?
CANN corresponds to NVIDIA's whole software stack: CUDA itself plus cuDNN, NCCL, TensorRT and the rest. The name stands for Compute Architecture for Neural Networks, and Huawei describes it as a "heterogeneous computing architecture", meaning the CPU (host) directs and the NPU (device) computes.
| Role | NVIDIA | Ascend CANN |
|---|---|---|
| Kernel language | CUDA C++ | Ascend C |
| Runtime API | CUDA Runtime | AscendCL |
| Ready-made operator libraries | cuBLAS, cuDNN | CANN operator library |
| Multi-device communication | NCCL | HCCL |
| Graph compilation and fusion | TensorRT / XLA and similar | Graph Engine (GE) |
| Offline model compilation | TensorRT (ONNX → engine) | ATC (ONNX → .om) |
CANN isn't a framework. MindSpore is the counterpart of PyTorch, and CANN sits one layer below MindSpore / torch_npu. It can't run CUDA code directly either; CUDA kernels have to be rewritten in Ascend C.
People often say CUDA is NVIDIA's moat, and this layer is what they mean. Catching up on the chip is relatively easy. The hard part is the whole software layer: the operator libraries, the toolchain, the community, and the huge amount of CUDA code already written.