AI Accelerators
1. Custom Kernel Integration
Custom kernels can optimize for new architectures, allow developing new algorithms and can improve hardware perf on existing kernels on specific workloads.
For example, flash-attention is a custom kernel that optimizes the attention mechanism in transformers with:
- Operator fusion.
- Block tiling: seperate
, , into small tiles (blocks), caching tiles in SRAM. - Re-computation: recompute attention matrix
and in the backward pass.
FOR CHEAT SHEET, COPY THE ALGORITHM FROM THE SLIDES!!
To actually create the kernel, either:
- Write a CUDA Kernel with a Python binding.
- Use Triton (DSL for DL) to write a kernel in Python and compile it to CUDA.
2. AI Hardware
GPUs are a mature ecosystem supporting massive parallelism, but are not energy efficient and have instruction decode overhead. A domain specific architecture (DSA) may be better suited for AI, trading generality for efficiency.
2.1 Systolic Arrays
Systolic arrays use a grid of Processing Elements (PEs) that compute and pass data to neighbors in a rhythmic fashion.
For example, a dot product of two vectors

This reduces wiring complexity, improves scalability and can reuse data.
- We must control input streams to ensure data arrives at the correct PE on the correct clock cyucle. Inputs are streamed horizontally and vertically through each PE. Use bubbles to synchronize data streams.
- Results are streamed out, so collection may introduce latency until all PEs complete.
Each PE has registers for input
2.1.1 Streaming Dataflow
Streamflow is a systolic array that uses streaming dataflow to reduce memory bandwidth requirements. There are different strategies for GEMM:
- C-Stay A-B-Stream (Output Stationary): accumulated result
stays in the PE, while and are streamed through the array. We dont need to preload weights, and has good support for large dimension reduction. However, extra cycles for output drain and low data locality for weights. - A-Stay B-C-Stream (Input Stationary): input
stays in the PE, while and are streamed through the array. - B-Stay A-C-Stream (Weight Stationary): weight
stays in the PE, while and are streamed through the array. This has data reuse for weights and streaming output generation but extra cycles needed for weight preload.
2.1.2 Convolution
We can either:
- Use im2col to convert convolution into GEMM, but this has high memory overhead and has data repeats.
- Use a line buffer: a dedicated hardware module that stores a few rows of the input feature map and streams them to the PEs. This reduces memory bandwidth requirements and allows for streaming convolution. High memory efficiency but low generality for varied kernel sizes.
2.2 Scale up vs Scale out
- Scale-Up: Add more compute within a node. Shared memory architecture, and electronic interconnects dominate. O-E-O conversion (optical-electrical-optical, e.g.
NVLink) is a bottleneck. - Scale-Out: Add more nodes. Each node has its own memory and accelerators. Hybric electric/optical interconnects (e.g.
Infiniband).
2.3 Reconfigurable Architecture
Reconfigurable Architecture adapts hardware structure for specific tasks. Can be fine-grained (bit-level / gate-level, longer runtime cost), or coarse-grained (block-level changes, shorter runtime cost). Tradeoffs between flexibility and performance.
2.3.1 FPGA
Field Programmable Gate Array (FPGA): Fine-grained reconfigurable hardware that can be programmed to perform specific tasks. Consists of configurable logic blocks (CLB) containing:
- Look-up Tables (LUTs): Small memory elements that can be programmed to implement simple logic functions.
- Flip-Flops: Basic storage elements that can hold a single bit of data.
- Multiplexers: Used to select between different inputs to the CLB.
FPGAs have on-chip SRAM and a programmable interconnect linking CLBs, DSPs (Digital Signal Processors - high speed multiply-accumulate units), and I/O blocks.
Allow bit-level control and have a flexible interconnect - allowing programmers to build custom datapaths with irregular parallelism and application-specific pipelines.
However, FPGAs have limited resources and lower clock speeds, so are well suited only for low-latency or edge applications.
2.3.2 CGRA
Coarse-Grained Reconfigurable Architecture (CGRA): Consists of PEs that can be reconfigured at a coarser level than FPGAs. Each PE can perform more complex operations and has its own local memory. CGRAs are well-suited for data-parallel applications and can achieve high performance with lower power consumption compared to traditional processors.