Benchmark an architecture-specific schedule within the whole workload
Separate mathematical portability from kernel support, hardware-specific scheduling, and end-to-end performance.
On this page
The question for today
What you’ll understand
- Distinguish an attention identity from a hardware-specific optimized schedule.
- Specify shape, backend, dtype, and timing boundaries.
- Calculate the end-to-end limit of a kernel-only speedup.
Online softmax algebra can be implemented on many processors, but a fast attention kernel is a schedule designed around a particular memory hierarchy and execution engine. Thread partitioning, asynchronous copies, matrix instructions, register pressure, and supported numerical formats vary across architectures. A performance result therefore belongs to a named hardware/software configuration and workload. Portability should preserve the operator and correctness contract first, then seek an appropriate schedule on the new target; copying one tile size or quoting another GPU’s speedup does not establish either correctness or useful performance.
Algorithm families exploit different execution features
FlashAttention established an I/O-aware exact tiling approach; FlashAttention-2 improves parallelism and work partitioning; FlashAttention-3 studies Hopper-oriented asynchrony and low precision. These are not interchangeable product labels for one universally optimal binary. The FA3 paper’s Hopper schedule overlaps data movement, matrix operations, and softmax-related work using architectural facilities. Its low-precision variants also need a numerical-accuracy contract rather than inheriting every claim made for a higher-precision calculation.
Pin implementation support to a release. For example, the FlashAttention 2.8.3 README scopes its Hopper beta to H100/H800 with CUDA at least 12.3 and lists FP16/BF16 forward/backward plus FP8 forward. Its separate CUDA and ROCm backends have their own feature matrices. These are support statements for that version, not promises about every accelerator or future release. Verify the actual chosen backend and its accepted head dimensions, layouts, masks, and backward capabilities.
Measure the workload you intend to accelerate
Separate forward training, forward-plus-backward, prefill, and incremental decoding. State batch size, query/key lengths, query/KV head counts, head width, dtype, accumulation mode, causal alignment, dropout, and layout. Include preprocessing, packing, compilation, and cache-update costs when they belong to the production request, while reporting isolated kernel time separately. A favorable training result does not establish the same benefit for one-query decode against a large cache.
Warm up compilation and allocations before steady-state timing, or report cold-start latency as a separate target. Use synchronized device events or another documented method that waits for the measured work, and control unrelated concurrent work. Record medians and tails across repetitions instead of selecting the fastest run. Measure memory under the same semantic features, and check that an unsupported feature did not silently trigger a different backend or remove required work.
Report constraints alongside results
A portability benchmark should include a precise device model, toolkit, compiler, framework, kernel revision, backend, clock/power conditions where relevant, and reproducible inputs. Validate outputs and gradients on that target before interpreting timings. Compare against a strong available baseline with the same semantics; a dense low-precision fused kernel and a higher-precision unfused reference are useful for accuracy analysis but are not automatically a fair latency contest.
Report both the mechanism and its practical boundary. If a faster kernel reduces only a small fraction of request time, improve another bottleneck or reconsider whether the integration cost is worthwhile. If data movement dominates, a schedule with better reuse may help; if synchronization or matrix utilization dominates, a bandwidth-only explanation is incomplete. End-to-end evidence should decide whether the architecture-specific optimization improves the intended workload rather than merely producing an attractive isolated throughput number.
Work it through
A threefold kernel speedup gives a smaller request speedup
A serial request spends 6 ms in attention and 4 ms in unchanged other work. On the same workload and device, a new kernel reduces attention to 2 ms. Ignore overlap, queuing, and any new preprocessing cost for this calculation.
The isolated attention speedup is 6/2=3. Baseline request latency is 6+4=10 ms. These two measurements have different boundaries, so the factor of three should not be attached to the whole request.
New request latency is 4+6/3=6 ms, giving total speedup 10/6=5/3≈1.6667. The unchanged four milliseconds now account for two thirds of the request, so additional attention improvements face a smaller remaining opportunity.
Even an infinitely fast attention kernel would leave 4 ms of other work, giving a maximum speedup of 10/4=2.5 in this serial model. Actual overlap or extra packing costs would require measuring a revised critical path rather than reusing these numbers.
A measured threefold kernel improvement becomes a 1.6667-fold request improvement under the stated additive model. Hardware-specific peak throughput alone cannot determine that request outcome.
The living notebook
Explore the model
Interactive lab · roofline
A synthetic bandwidth improvement can hit a compute ceiling
Reset, set Operational intensity I to 8 FLOP/byte and Memory bandwidth B to 80 GB/s. Predict ceiling 640 GFLOP/s before Step. Reset, set I to 8 and B to 160, predict the fixed 1000 GFLOP/s compute ceiling rather than 1280 before Step. Playback traces the roof and does not change the controls. These are synthetic values, not an NVIDIA or AMD product specification or an attention benchmark.
- Attainable ceiling
- 640 GFLOP/s
- Ridge intensity
- 12.5 FLOP/byte
- Ceiling regime
- Memory-bound ceiling
Synthetic roofline ceiling min(1000, B·I), in GFLOP/s, with B in decimal GB/s and I in FLOP/byte. Playback traces the roof without changing the selected kernel. This upper-bound model is not a measured throughput prediction, hardware comparison or price model. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA changed hardware resource helps only until another modeled limit becomes active.
Pause & reason
Check your understanding
Your turn
Try it yourself
A serial request takes 8 ms: 2 ms attention and 6 ms other work. A replacement makes attention four times faster with no other changes. Find new latency, total speedup, and the infinite-kernel-speed limit.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Keep the unchanged six milliseconds in both calculations.
Compare with the solution
Attention becomes 2/4=0.5 ms, so new request latency is 6.5 ms and total speedup is 8/6.5=16/13≈1.23077. Even zero attention time leaves 6 ms, giving an upper limit of 8/6=4/3≈1.33333 under the same serial additive assumptions. A fourfold isolated speedup is therefore not a fourfold request speedup.
Keep the idea
Take it with you
- Port the operator contract before tuning the target-specific schedule.
- Pin hardware, software, semantics, backend, and timing boundary.
- Kernel speedups are limited by the rest of the measured workload.
Read further
Original sources and deeper explanations to follow at your own pace.
- Dao et al.: FlashAttention, original v2 algorithm and I/O analysis
- Dao: FlashAttention-2, original work partitioning algorithm
- Shah et al.: FlashAttention-3, Hopper asynchrony and low precision
- FlashAttention 2.8.3: versioned kernel interface and feature contracts
- NVIDIA CUDA 12.6: best practices for synchronized device timing
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.