Home · ASPLOS 2024 · Compilers & Programming Languages

Boost Linear Algebra Computation Performance via Efficient VNNI Utilization

Hao Zhou, Qiukun Han, Heng Shi, Yalin Zhang and Jianguo Yao

Conference
ASPLOS 2024
Published
2024
Pages
149-163
Citations
1

Intel chips have a special instruction, VNNI, that multiplies and accumulates many small integers in one shot — ideal for the quantized matrix math inside neural networks — but ordinary compilers use it badly, often not even recognizing where it applies, and the search-based tools that do use it well need hand-built templates and long tuning runs; this paper (Shanghai Jiao Tong University) presents a compilation method that spots where VNNI fits from the structure of linear algebra itself, then works out how to feed the instruction and hide its latency through smart memory access and reuse, guided by a static cost model instead of brute-force search, reportedly beating leading industrial compilers.

The argument in one glance

  1. Problem

    A powerful instruction for quantized math sits underused because compilers cannot wield it

    Intel processors include a special instruction, the Vector Neural Network Instruction, or VNNI, built for exactly the kind of math that dominates modern machine learning: multiplying and accumulating many small, low-precision integers at once. In one instruction it takes packed eight-bit or sixteen-bit integers, multiplies them pairwise, and adds the products into wider accumulators — a fused dot-product-and-accumulate that computes dense linear algebra, the matrix multiplications and convolutions at the heart of neural networks, far more efficiently than ordinary vector instructions that would need several separate steps. The catch is that having the instruction is not the same as using it well. To benefit, a program's inner loops must be compiled into VNNI instructions with the surrounding data movement arranged so the instruction is kept fed and its latency hidden. Ordinary compilers struggle at this. So the hardware capability is there, but the software that is supposed to turn ordinary linear-algebra code into fast VNNI code frequently leaves most of the benefit on the table.

  2. What people did

    Rely on auto-vectorizers, or on search-based auto-tuning

    There are two established routes to VNNI code. Compilers' automatic vectorizers try to recognize vectorizable patterns in loops and emit vector instructions, including VNNI. Alternatively, auto-tuning frameworks search over many candidate code transformations, measuring their performance, to find a fast implementation for a given operation and machine.

  3. Why it fell short

    Auto-vectorizers miss or mishandle the pattern, and auto-tuning needs templates and long searches

    Both routes fall short for VNNI, according to the abstract. Automatic vectorizers frequently deliver suboptimal VNNI utilization in one of two ways: they fail to recognize VNNI's unique computation pattern at the innermost loops and basic blocks in the first place, so no VNNI instruction is generated, or they do recognize it but produce inferior code through constrained and rudimentary peephole optimizations and pattern-matching — emitting the instruction without arranging the memory access, reuse, and scheduling around it that make it fast. Auto-tuning frameworks can generate proficient code, but they are hampered by two costs: they require sophisticated, hand-crafted pattern templates to describe the space of candidate implementations, and they need extensive, time-consuming search to explore that space. So one path is fast but produces weak code, and the other produces good code but only through heavy manual template engineering and long tuning runs. What is missing is a principled way to generate strong VNNI code directly, without either the crude pattern-matching or the expensive search.

  4. This paper's idea

    Find VNNI opportunities from the structure of linear algebra, and optimize with a cost model

    This paper introduces a compilation methodology that generates high-performance VNNI code by reasoning about the computation rather than pattern-matching or blindly searching. It leverages the salient characteristics of dense linear algebra to identify where VNNI's dot-product-accumulate pattern applies, using the mathematical structure of the computation instead of fragile peephole recognition. Having found the opportunities, it pinpoints the most effective strategies for feeding VNNI's inputs and hiding its execution latency — through efficient memory access, register and cache reuse, and exploited instruction-level parallelism. A tailored static cost analysis model guides this exploration, determining the critical parameters for the code transformation and generation without the extensive empirical search that auto-tuners require. The abstract reports that the resulting framework outperforms state-of-the-art industrial compilers and research works on dense-linear-algebra and neural-network workloads.

Why this problem is worth solving

The instruction exists precisely because this math is everywhere, so extracting its full benefit compounds across an enormous amount of computation.

Dense linear algebra — matrix multiplication and convolution over packed arrays of numbers — is the computational core of neural networks and much scientific computing, and increasingly it is done in low precision, with eight-bit or sixteen-bit integers, to save time and energy. Intel’s Vector Neural Network Instruction is designed for exactly this: it performs a fused multiply-and-accumulate over vectors of low-precision integers, multiplying many element pairs and summing the products into wider accumulators in a single instruction. Doing the same work with conventional vector instructions would take several steps — separate multiplies, widening, and additions — so VNNI is substantially more efficient per unit of work for these dot-product-heavy computations. But an instruction’s efficiency is only realized if the compiled program actually issues it in the right places and keeps it busy. That means the inner loops of a linear-algebra kernel must be transformed so their reductions map onto VNNI’s dot-product-accumulate shape, and the surrounding code must stream the right inputs into the instruction fast enough that it never stalls. When compilers do this poorly, the gap between VNNI’s peak capability and the delivered performance is large, and because this math runs at such volume, that gap is expensive. Closing it is the point of the work.

The two standard tools each fail in a characteristic way, leaving a real gap between them.

A compiler’s automatic vectorizer analyzes loops and tries to replace scalar operations with vector ones, matching code against the patterns it knows how to vectorize. This is fast and automatic, but it is only as good as its pattern recognition and its local, peephole-style rewriting: if it does not recognize VNNI’s particular reduction pattern, it emits nothing special, and if it does, its rudimentary rewriting often fails to arrange the data movement and scheduling that make the instruction fast. At the other extreme, auto-tuning frameworks treat code generation as a search problem: given templates describing many possible ways to implement an operation, they generate candidates, run them, and keep the fastest. This can find excellent code, but it depends on someone writing sophisticated templates for each pattern, and it burns large amounts of time exploring the space empirically for every operation and target. So the field is caught between a cheap method that produces weak VNNI code and an expensive method that produces good code only with heavy human and compute investment. A method that reasons about the structure of the computation to generate strong code directly would sit in the gap neither occupies, which is where this paper aims.

What people did before, and where it broke

  • Compiler auto-vectorization. Recognize vectorizable loop patterns and emit vector instructions, including VNNI. Where it broke. It often fails to recognize VNNI’s distinctive dot-product-accumulate pattern at the innermost loops, so no VNNI is generated at all.
  • Peephole pattern-matching to VNNI. When the pattern is recognized, rewrite it to VNNI through local peephole optimizations. Where it broke. The rewriting is constrained and rudimentary, emitting the instruction but not arranging the memory access, reuse, and scheduling around it, so the code is inferior.
  • Search-based auto-tuning frameworks. Search a template-defined space of implementations, measuring performance, to find fast code. Where it broke. They require sophisticated hand-crafted templates and extensive, time-consuming search, making them costly to build and run.
  • The gap. No approach generated strong VNNI code by reasoning about the structure of the linear-algebra computation itself — identifying opportunities from its mathematical characteristics and choosing input-feeding and latency-hiding strategies with a cost model rather than crude matching or brute search. Doing that is what this paper is described as contributing.

How the framework works

From linear-algebra structure to fast VNNI code, guided by a cost model

  1. new

  2. new

  3. new

  4. new

  5. new

The idea

Recognize the opportunity from the math, not from brittle code patterns. The framework’s first move, as the abstract describes it, is to stop treating VNNI generation as a low-level pattern-matching problem and instead treat it as a consequence of what dense linear algebra is. Because matrix multiplication and convolution have a known reduction structure, the places where VNNI’s dot-product-accumulate applies can be identified from those salient characteristics directly, rather than hoping a peephole optimizer happens to spot the shape in the innermost loop. This is what lets it find opportunities that ordinary auto-vectorizers miss. Recognizing where a specialized vector instruction fits by reasoning about the computation’s structure, rather than scanning for syntactic patterns, is the same principled-vectorization stance the work on automatic generation of vectorizing compilers covered elsewhere on this site takes, deriving how to target a specialized instruction from a description of the computation instead of ad-hoc matching.

Replace expensive search with a static cost model. The second move addresses the other failure mode. Auto-tuners get good code but only by empirically searching a template-defined space, which is slow and template-hungry; this framework instead uses a tailored static cost analysis model to decide the critical transformation parameters — how to feed inputs, how to reuse registers and cache, how much instruction-level parallelism to exploit — by analysis. Determining the right code-generation choices through a cost model rather than measuring thousands of candidates is what makes the approach both fast to apply and free of hand-written templates. Steering code generation for tensor and linear-algebra kernels by principled reasoning about the schedule rather than a brute-force autotuning search is the same efficiency-of-compilation goal the work on a task-mapping programming paradigm for deep-learning tensor programs covered elsewhere on this site pursues, giving the compiler direct control over how the computation is laid out instead of leaving it to an expensive search.

Optimize the whole neighborhood of the instruction, not just its selection. The abstract is explicit that merely emitting VNNI is not enough — the real performance comes from feeding it well and hiding its latency, through memory access, register and cache reuse, and instruction-level parallelism. So the framework co-optimizes the data movement and scheduling around the instruction, which is exactly where the crude peephole approaches fall down. Generating efficient code for a linear-algebra or tensor computation by carefully orchestrating how data is laid out, reused, and streamed through the compute units, rather than optimizing an operation in isolation, is the same whole-kernel discipline the work on robust code generation of efficient tensor computations covered elsewhere on this site embodies, treating the surrounding data choreography as central to performance rather than an afterthought.

Following a matrix multiply through the framework

Compiling a low-precision matrix multiply to VNNI

An illustrative trace, at the level the abstract describes, of how the framework generates high-performance VNNI code for a dense-linear-algebra kernel. Specific internal details beyond the abstract should be confirmed against the full paper.

Step 1 of 5

A low-precision matrix multiply arrives

The input is a matrix multiplication over eight-bit or sixteen-bit integers, whose inner reduction accumulates products across a dimension — a computation VNNI's fused multiply-accumulate is built for, if the compiler can target it well.

An ordinary auto-vectorizer might not recognize the VNNI opportunity here at all.

Why it works

  • Structural identification finds opportunities peephole matching misses. A generic vectorizer recognizes VNNI only if its narrow pattern-matcher happens to fire → but dense linear algebra has a known reduction structure that reveals where the dot-product-accumulate applies → so the framework locates VNNI opportunities that syntactic matching would overlook.
  • Feeding and latency-hiding are where the real speed lives. Simply emitting a VNNI instruction leaves it stalling on data and latency → but arranging memory access, register and cache reuse, and instruction-level parallelism keeps the instruction fed and busy → so the delivered performance approaches the instruction’s capability rather than a fraction of it.
  • A cost model avoids the auto-tuner’s search cost. Finding good parameters by measuring many candidates is slow and template-dependent → but a tailored static cost analysis model can determine the critical parameters by reasoning → so strong code is generated without extensive empirical search or hand-written templates.
  • Co-optimizing the neighborhood beats optimizing the instruction alone. Peephole rewriting treats the instruction in isolation → but the framework jointly chooses the surrounding data movement and scheduling → so it captures the interactions between instruction selection and its context that determine actual performance.
  • Reasoning from the computation generalizes across the workloads. A pattern tuned to one kernel shape is narrow → but deriving the approach from the salient characteristics of dense linear algebra applies across matrix multiplications, convolutions, and the neural-network workloads built from them → so the abstract reports gains across both dense-linear-algebra and deep-learning benchmarks.

What it costs (trade-offs and scope)

  • This account is based on the abstract only. The full paper was not accessible when this page was written, so the mechanisms are described at the level the abstract states; the internal design of the opportunity identification, the feeding and latency-hiding strategies, and the static cost model are not detailed here and should be read from the paper.
  • No quantitative results are available here. The abstract states the framework outperforms state-of-the-art industrial compilers and research works but gives no numbers, baselines, or per-workload figures in what is available; the magnitude of the improvement and the specific competitors must be read from the full paper.
  • It targets VNNI and dense linear algebra. The methodology is built around Intel’s VNNI and the structure of dense-linear-algebra computations; how it extends to other specialized instructions, other architectures, or computations without that regular reduction structure is not established from the abstract.
  • A static cost model trades accuracy for speed. Using analysis instead of measurement avoids search cost but relies on the cost model faithfully ranking transformations; where a static model mispredicts, the chosen parameters could be suboptimal, a tradeoff whose handling is a detail to confirm in the full paper.
  • The benefit depends on low-precision, VNNI-amenable workloads. The gains come from computations that map onto VNNI’s low-precision fused multiply-accumulate; workloads that are not quantized, or whose structure does not fit the instruction, would see less benefit.

The evaluation

Generating code for a VNNI-amenable linear-algebra kernel

PropertyAuto-vectorizerAuto-tuning frameworkThis framework
Finds the VNNI opportunity
Quality of surrounding code
How parameters are chosenFixed heuristics
Manual effort required
Reported outcomeSuboptimal VNNI useProficient but costly
From the paper's abstract. The framework identifies VNNI opportunities from the structure of dense linear algebra, optimizes input feeding and latency hiding through memory access, register and cache reuse, and instruction-level parallelism, and chooses parameters with a static cost model rather than search, reportedly outperforming state-of-the-art industrial compilers and research works on dense-linear-algebra and deep-neural-network workloads. Specific baselines and numbers are in the full paper.Underlined values explain themselves when clicked.

Check yourself

Check your understanding

  1. 1. What is VNNI, and why is using it well not automatic?

  2. 2. How do the two standard tools each fail to produce good VNNI code?

  3. 3. What is the paper's core approach to generating high-performance VNNI code?

  4. 4. What did the paper report, and what should you keep in mind about this summary?

Sources

The paper is “Boost Linear Algebra Computation Performance via Efficient VNNI Utilization” by Hao Zhou, Qiukun Han, Heng Shi, Yalin Zhang, and Jianguo Yao (Shanghai Jiao Tong University), published at ASPLOS 2024 (Volume 3), DOI 10.1145/3620666.3651333.

This explainer is written from the paper’s abstract; the full text was not accessible at the time of writing. The claims traceable to the abstract are: that Intel’s Vector Neural Network Instruction provides higher efficiency on calculating dense linear algebra computations than conventional SIMD instructions; that existing auto-vectorizers frequently deliver suboptimal utilization of VNNI, by either failing to recognize VNNI’s unique computation pattern at the innermost loops and basic blocks, or producing inferior code through constrained and rudimentary peephole optimizations and pattern-matching techniques; that auto-tuning frameworks might generate proficient code but are hampered by the necessity for sophisticated pattern templates and extensive search processes; that the paper introduces a compilation methodology that generates high-performance VNNI-enabled code by leveraging dense linear algebra’s salient characteristics to identify VNNI’s utilization opportunities, then pinpointing the most effective strategies for feeding VNNI’s inputs and hiding VNNI’s execution latency via efficient memory access and register and cache reuse and exploited instruction-level parallelism; that a tailored static cost analysis model guides this exploration, determining critical parameters for effective code transformation and generation; and that the evaluation on dense-linear-algebra and deep-neural-network workloads shows the framework outperforms state-of-the-art industrial compilers and research works. Background explanations of VNNI, auto-vectorization, auto-tuning, and instruction-level parallelism are standard domain context provided to make the abstract’s claims understandable, and the matrix-multiply trace in the step-through is illustrative. The internal mechanism, the static cost model, the specific baselines, and the quantitative results should be confirmed against the full paper, which is available through the ACM Digital Library at the DOI above.

Related papers on Compilers & Programming Languages

See all 162 →