Manuscript Offprint

arXiv:2610.29489

Reorienting the Vector Axis: Restructuring FlashAttention for Long-Vector Processors

Emmanuel Irabor, Marc Casas

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Emmanuel Irabor

Barcelona Supercomputing Center

Barcelona, Spain

emmanuel.onyekachukwu@bsc.es

Marc Casas

Barcelona Supercomputing Center

Universitat Politècnica de Catalunya (UPC)

Barcelona, Spain

marc.casas@bsc.es

Abstract—A Transformer is built around attention, and because every token attends to every other, the cost of that one operation grows with the square of the sequence length and comes to dominate the layer on long sequences. FlashAttention made that cost manageable by working through the attention matrix in tiles and updating the softmax as it goes. Almost all the work since has targeted GPUs.

Vector processors efficiently run High-Performance Computing (HPC) workloads. Modern commercial vector architectures feature large physical vector register files with hundreds of kilobytes of storage capacity. Because a single register holds up to 512 single-precision numbers, one instruction can execute 512 element operations, significantly reducing loop bookkeeping per result. These savings are proportional to how much of the register an instruction actually utilizes, making the choice of which loop to vectorize a first-order decision rather than a tuning detail. We port PyTorch's CPU FlashAttention kernel to a RISC-V CPU with 2KB vector registers and find that it achieves 5.17 of the 32 peak floating-point operations per cycle the core can issue (16.2% of peak). The kernel walks each tile one query row at a time, leaving suboptimal dimensions to dictate vector instruction lengths. The product against V is vectorized along the head dimension—64 elements here, compared to the 512 elements a register holds. In the softmax, each query row requires a maximum and a sum: two reductions that collapse a full register to a single scalar once per tile. Additionally, because the hardware lacks a native exponential instruction, the softmax computes exponents via a polynomial whose coefficients compete with tile data for vector registers and cause spilling.

We propose two techniques. The first transposes the two matrices the kernel builds, the tile of scores and the running output, so that queries lie along the contiguous axis. This leaves the algorithm and its values unchanged but puts the vector length of every part of the kernel under one controllable parameter, the number of queries in a tile, so it can be chosen to match the machine's vector length. It also makes the maximum and the sum run along the query axis, which removes both reductions. The second moves the polynomial's coefficients into scalar registers, which stops the spilling and cuts the softmax region's vector memory instructions by 78.7%.

On silicon the two together cut whole-kernel cycles by 1.84 to 2.08×2.08\times at a head dimension of 64, raising floating-point utilisation from 16.2% to 29.7% of peak. An FPGA of the same design ranks the changes identically and scores them higher, at 2.71×2.71\times, so the silicon figure is the conservative one.

I. INTRODUCTION

Vector processors utilizing Single Instruction Multiple Data (SIMD) paradigms offer superior throughput for High-Performance Computing (HPC) tasks. By executing a single instruction across multiple data streams simultaneously, SIMD reduces instruction-fetch overhead in the processor front-end while conveying extensive semantic context directly to the underlying hardware. These inherent efficiencies drove the dominance of early vector designs from the 1970s through the 1990s, highlighted by systems such as the CDC STAR-100 [1] and Cray-1 [2]. Even as the 1990s saw the rise of massively parallel supercomputers containing thousands of nodes, vector-based execution retained its utility [3], [4], prompting chip manufacturers to integrate SIMD extensions into mainstream general-purpose microprocessors [5], [6]. Today, as conventional performance scaling hits diminishing returns alongside skyrocketing demand for floating-point acceleration in modern workloads, vector processing is undergoing a major revival across both industry [7] and academia [8]–[10].

This resurgence has propelled out-of-order (OoO) vector machines into mainstream commercial production, with NEC's SX-Aurora TSUBASA standing as a prime real-world implementation [11], [12]. To maximize SIMD data-parallelism, vector registers now span a wide range, from the 512 bits of Arm's SVE in Fugaku [13], [14] to the 16 384 bits of NEC's SX-Aurora [15] and of RISC-V designs [16], [17].

Despite the relevance of vector architectures, FlashAttention [18], [19], the standard implementation of attention, and almost all of the engineering that followed it, target GPUs [20], [21]. This paper proposes several novel techniques to efficiently run FlashAttention on vector architectures featuring long register widths. What changes at this width is which architectural decisions matter. On a 128-bit unit, any loop with a handful of iterations fills the datapath, making the choice of which loop to vectorize a mere tuning detail. On a register holding 512 elements, however, a loop over a head dimension of 64 utilizes only an eighth of its capacity, and no instruction scheduler can recover the remaining throughput. PyTorch's CPU FlashAttention walks each score tile one query row at a time—a traversal that forces the key block to dictate the vector length of the score product and softmax, while leaving the head dimension to set the vector length for the value product. Recent RISC-V kernels retain one of these axes [22] or pack multiple heads into a single register once capacity exceeds the head dimension [23]; neither approach alters the underlying traversal.

This paper reorients the recurrence. We transpose the score tile and the running output, an outer-loop vectorisation [24] of the query loop, so that the query axis becomes the contiguous axis of both. One tile parameter then sets the vector length of every region and can be set to the register width, and the per-query maximum and sum become vectors instead of reductions. The paper contributes:

  • a region-level characterisation, on silicon, of FlashAttention-2 on a 16384-bit RISC-V processor that separates each region's vector-length limit from its access-pattern limit (Section III);

  • a software exponential whose polynomial coefficients are held in scalar rather than vector registers, which removes spill traffic that a 32-register file otherwise makes unavoidable (Section IV);

• reorientation of the recurrence, with an instruction-count model of when it wins (Section V);

  • an evaluation on the EPAC chip and an FPGA that separates orientation from the softmax work: reorientation alone is worth 1.43×1.43 \times in cycles (Section VII).

None of this is a comparison against a GPU or a short-vector CPU, and none is needed for the claim, which is conditional: given a long-vector machine and a query block longer than the head dimension, the orientation in which the recurrence is evaluated decides the vector length of every region, and with a query block as long as the register it removes about 30% of the kernel's cycles at no change in the arithmetic performed.

References (45)