top of page

Beyond the GEMM: finding the CPU time XNNPACK leaves behind on Graviton

Nov 16
4 min read

In our last post we sped up XNNPACK's 4x16c8 I8MM GEMM kernels on Arm Neoverse. We changed how they load activations (vld1q + vzip instead of per-lane loads). That gave +3–11% on TFLite int8 models with clang and 1.2–1.9x with GCC 11–15. The work is now going upstream as google/XNNPACK#11794. The compiler side of that story, loop-carried vld2q_lane tuples being spilled, became an RFC patch for GCC PR89967.

A faster GEMM only helps the time spent in GEMM. So we asked the next question: once the matrix kernels are fast, where does the rest of the time go? The answer was not where we expected. It was in operators that never reach XNNPACK, and in one XNNPACK operator that runs on a single thread no matter how many you give it.

This post covers three fixes. On the affected models they are worth up to 1.27x single-threaded and up to 2.3x on 4 threads across Graviton3, 4 and 5.


Method: profile per operator, not per model

We profiled nine models on AWS Graviton3 (Neoverse V1), Graviton4 (V2) and Graviton5 (V3), 4 vCPUs each:

  • Models: ResNet50, InceptionV3 and MobileNetV2.

  • Variants: fp32, int8 and dynamic-range quantized.

We used TFLite's benchmark_model --use_xnnpack=true --enable_op_profiling at 1 and 4 threads, plus perf.

  • Builds: TFLite was built from LiteRT with clang 21. XNNPACK included our zip patches.

  • Runs: each run is pinned with taskset, with 10 warmup and 50 timed iterations.

  • /B: we did 3 alternating A/B rounds and report the median.


Per-op profiles show something a whole-model latency number hides. They show which operators the XNNPACK delegate rejected. Those operators run on TFLite's builtin kernels, wh

ich are often single-threaded. They also split the graph into several delegate partitions.


Three gaps stood out:

The pattern is the same in all three. The work is small at one thread, but it does not scale, so its share grows as you add cores. That is Amdahl's law at work inside an ML runtime.


Fix 1: parallel f32→qd8 convert (XNNPACK)

In dynamic-range models, each convolution's fp32 input is quantized on the fly to int8 with per-row scale and zero point (qd8). XNNPACK parallelizes this convert across the batch dimension. For a convolution the "row" is the whole NHWC image, so with batch size 1 there is exactly one tile, and one thread does all of it.

The fix splits a row into chunks when the batch is smaller than the thread count:

  1. Each thread computes a partial min/max over its chunk.

  2. The partial results are merged.

  3. The threads quantize their chunks with the shared parameters.

The output is bit-identical to the serial path. New convert-nc-test cases compare serial against 4-thread output, parameters and row sums for qd8, qd8 with row sums and strides, and qdu8. We broke the min/max merge on purpose, and those tests failed.

On Graviton3 the convert itself dropped from 1.22 ms to 0.50 ms per inference. Single-threaded runs don't take this path and are unchanged.

Upstream: google/XNNPACK#11990.


Fix 2: dynamic-range depthwise convolution (LiteRT XNNPACK delegate)

A dynamic-range model has fp32 activations and a static int8 per-channel filter. The delegate rejected this as "mixed types" for DEPTHWISE_CONV_2D. MobileNetV2 dynamic therefore fell back to TFLite's hybrid depthwise kernel. That kernel is single-threaded and also re-quantizes the input on every call. Each fallback cut the graph into another delegate partition.

Depthwise convolution is cheap in FLOPs, so dequantizing the filter once costs almost nothing. In DelegatePrepare the patch:

  1. Dequantizes the int8 filter to fp32, with one scale per channel.

  2. Registers the buffer with XNNPACK's weight cache through RemapDataBuffer. Without this the cache rejects it as an unknown constant buffer.

  3. Delegates the node as an ordinary fp32 depthwise convolution.

The cost is one fp32 copy of each such filter, about 4x its int8 size.

The results differ from the builtin only by the builtin's own input-quantization error. The new tests check each output against that analytic bound, KH·KW·127·scale_c/255. A mutation that uses one scale for all channels fails both new tests.

The 4-thread gain is much larger than the 1-thread gain. Once the depthwise layers stay inside XNNPACK, the whole network finally scales across cores. Before the fix, MobileNetV2 dynamic ran only 1.6x faster on 4 threads than on 1.

Upstream: google-ai-edge/LiteRT#11795. TensorFlow Lite is in maintenance mode, so delegate features now go to LiteRT.


Fix 3: int8 average pooling (and why we didn't send it)

XNNPACK removed its quantized average-pooling operator in early 2025, and the delegate accepted only float avgpool. As a result, InceptionV3 int8 ran every AVERAGE_POOL_2D on TFLite's single-threaded builtin kernel. At 4 threads that kernel took half the inference time.

Our patch lowered int8 avgpool inside the delegate to dequantize → fp32 avgpool → requantize. All three steps run in the XNNPACK subgraph and are multithreaded. The results are within ±1 of the builtin. 11 new test cases pass, and a deliberate clamp mutation fails 9 of them, which shows the nodes really were delegated.

Before we opened a PR, Google added a native qs8/qu8 average-pooling operator to XNNPACK, with delegate support in review. A native kernel is the better long-term answer, so we didn't send ours. Our numbers show what users can expect once that reaches a release: up to 2x on InceptionV3 int8 at 4 threads.


Takeaways

  • Profile per operator, at the thread count you deploy. At one thread none of these gaps looked serious. At four threads one of them was half the runtime.

  • "Delegated" doesn't mean "all delegated". One rejected op type costs its own time. It also costs the parallelism of everything around it, because it splits the graph.

  • Uarch tuning still has headroom. XNNPACK's GEMM config has a Neoverse V2 case only for fp32, no int8 Neoverse cases, and no V3 entry at all. On dynamic-range models, qd8_f32_qc8w_igemm_4x16c8 takes 49–62% of the time. It doesn't yet use the zip kernels from #11794. That is our next target.


Status

Whileone Techsoft works on performance engineering for Arm and RISC-V servers, from pre-silicon models to upstream libraries. Get in touch if your models leave cores idle.


Comments


bottom of page