Programming AMD XDNA NPUs with Open-source Compiler Tools: A FlashAttention Case Study
Organizations: Advanced Micro Devices, Inc., USA. · Integrated Systems Laboratory (IIS), ETH Zürich, Switzerland. · Cornell University, Ithaca, NY, USA.
Abstract
Spatial NPUs such as AMD XDNA place compute tiles beside small local memories and leave data movement between them to software. Mapping a multi-stage workload onto such a device is largely a question of where the intermediate tensors live. We report what we learned making those choices for FlashAttention with the open-source IRON and MLIR-AIR flows. We compare four reference designs on XDNA 1 and XDNA 2: one runs each operator separately, two stream between operators on chip, and one fuses all three attention stages into a single kernel. The fused kernel holds the scores in compute-tile local memory and reduces partial results over the cascade interconnect, so the scores never return to shared MemTile memory. On XDNA 2, it reaches 3.62 TFLOP/s over complete end-to-end execution, twice the IRON design, with 5.3 to 7.2 times the energy efficiency of the integrated GPU on the same chip at 2K tokens and above. It covers twelve LLM configurations, from BERT to DeepSeek, up to 128K tokens. Roofline analysis at each memory level explains this result and shows when to stop. XDNA 1 has lower ridge points, so streaming on chip already reaches the compute-bound regime: the same fusion that doubles throughput on XDNA 2 is nearly wasted on XDNA 1. Comparing a mapping's operational intensity against each level's ridge point predicts which case applies before writing any code. Fuse until the mapping clears that ridge point, then stop. We release the reference designs as maintained open source.
Figures & tables
| Feature | XDNA 1 | XDNA 2 |
| Compute tile array | 4 4 (16 tiles) | 4 8 (32 tiles) |
| Clock frequency | 1.0 GHz | 1.3 GHz 1 1 1 Variable. Fixed at 1.3 GHz in this paper. |
| MAC data type | bfloat16 | bfp16 2 2 2 bfp16 means block floating point. Data I/O uses bfloat16 , and values are vector-cast before computation on XDNA 2. |
| MAC per clk. ( ) | 4 8 4 | 8 8 8 |
| Exp. intrinsic | LUT approximation | Vector exp2 |
| Compute tile memory | 64 KB | 64 KB |
| Arch. | DMA count | Channel count | Bandwidth (GB/s) | Ridge (FLOP/B) |
| XDNA 1 | Shim tile | 4 2 | ||
| MemTile | 4 6 | |||
| Compute tile | 16 2 | |||
| XDNA 2 | Shim tile | 8 2 | ||
| MemTile | 8 6 | |||
| Compute tile | 32 2 |
| Shim tile | MemTile | Compute tile | ||||
| Strategy | Matrices spilled | FLOP/B | Matrices spilled | FLOP/B | Matrices spilled | FLOP/B |
| Layer by layer | , scale | , scale | , scale | |||
| DATO | Seq. Len. | , scale | , scale | |||
| IRON | Seq. Len. | |||||
| MLIR-AIR | Seq. Len. | |||||
| Arch. | Strategy | Shim tile | MemTile | Compute tile | ||||||
| Pred. OI (FLOP/B) | Ridge (FLOP/B) | Pred. Regime | Pred. OI (FLOP/B) | Ridge (FLOP/B) | Pred. Regime | Pred. OI (FLOP/B) | Ridge (FLOP/B) | Pred. Regime | ||
| XDNA 1 | Layer by layer | NR | CB | CB | ||||||
| DATO | Seq. Len. | CB | CB | CB | ||||||
| IRON | Seq. Len. | CB | CB | CB | ||||||
| MLIR-AIR | Seq. Len. | CB | CB | CB | ||||||
| XDNA 2 | Layer by layer | MB | NR | NR | ||||||
| Platform | Seq. Len. | Layer by layer | DATO | IRON | MLIR-AIR | |||||
| Latency (ms) | GFLOP GEMM /s | Latency (ms) | GFLOP GEMM /s | Latency (ms) | GFLOP GEMM /s | Latency (ms) | GFLOP GEMM /s | vs. IRON | ||
| XDNA 1 | 1.39 | |||||||||
| 1.53 | ||||||||||
| 1.23 | ||||||||||
| 1.06 | ||||||||||
| 1.10 | ||||||||||
| Model | Type | Mask | Seq. Len. | Latency ( s) | Throughput (GFLOP/s) | |||
| BERT-Base | 768 | 12/12 | 64 | MHA | Non-causal | 2231.15 | ||
| BERT-Large | 1024 | 16/16 | 64 | MHA | Non-causal | 2282.74 | ||
| GPT-2 Small / OPT-125M | 768 | 12/12 | 64 | MHA | Causal | 2217.71 | ||
| GPT-2 Medium | 1024 | 16/16 | 64 | MHA | Causal | 2280.01 | ||
| GPT-2 Large | 1280 | 20/20 | 64 | MHA | Causal | 2335.24 | ||
| Llama-2 7B | 4096 | 32/32 | 128 | MHA | Causal | 2009.28 |