Optimize AArch64 NEON `qs8`/`qu8 -> f32` (`TBL2 + FSUB`) and `bf16 -> f32` (`ZIP1`/`ZIP2` with zero) conversions in XNNPACK and YNNPACK. ```bash bazel build -c opt //bench:vunary_bench //ynnpack/kernels/unary:bench //ynnpack/kernels/ternary:bench bazel-bin/bench/vunary_bench --benchmark_filter="xnn_(qs8_f32|qu8_f32|bf16_f32)_vcvt_ukernel__neon_u32" --benchmark_min_time=100x bazel-bin/ynnpack/kernels/unary/bench --benchmark_filter="convert_bf16_to_fp32_neon" --benchmark_min_time=100x bazel-bin/ynnpack/kernels/ternary/bench --benchmark_filter="dequantize_(int8|uint8)_to_fp32_neon" --benchmark_min_time=100x ``` XNNPACK `vunary_bench` (`neon_u32`, `N=8192`): ```text CPU Architecture qs8 -> f32 qu8 -> f32 bf16 -> f32 -------------------------- ------------ ------------ ------------ ARM Neoverse-N1 +22.5% (5.3G) +31.8% (5.7G) +21.4% (11G) ARM Neoverse-V2 (Axion) +22.5% (5.3G) +31.7% (5.7G) +19.1% (11G) NVIDIA Grace (Neoverse-V2) +22.3% (11G) +33.3% (12G) -32.9% (17G) Ampere Siryn -11.1% (4.8G) +0.8% (5.5G) 0.0% (12G) ARM Cortex-A53 -17.1% (0.1G) -4.3% (0.3G) +2.1% (0.3G) ``` YNNPACK `unary` / `ternary` (`neon`, `N=4096`): ```text CPU Architecture int8 -> f32 uint8 -> f32 bf16 -> f32 -------------------------- ------------ ------------ ------------ ARM Neoverse-N1 +17.6% (3.2G) +26.5% (3.4G) +8.5% (11G) ARM Neoverse-V2 (Axion) +17.7% (3.2G) +26.2% (3.4G) +8.1% (11G) NVIDIA Grace (Neoverse-V2) +25.0% (6.8G) +35.7% (7.3G) +7.4% (21G) Ampere Siryn -15.0% (3.2G) -6.8% (3.6G) +5.6% (12G) ARM Cortex-A53 -9.2% (0.1G) -8.5% (0.1G) +0.1% (0.7G) ``` PiperOrigin-RevId: 996203284
XNNPACK is a highly optimized solution for neural network inference on ARM, x86, WebAssembly, and RISC-V platforms. XNNPACK is not intended for direct use by deep learning practitioners and researchers; instead it provides low-level performance primitives for accelerating high-level machine learning frameworks, such as TensorFlow Lite, TensorFlow.js, PyTorch, ONNX Runtime, ExecuTorch, and MediaPipe.
XNNPACK implements the following neural network operators:
All operators in XNNPACK support NHWC layout, but additionally allow custom stride along the Channel dimension. Thus, operators can consume a subset of channels in the input tensor, and produce a subset of channels in the output tensor, providing a zero-cost Channel Split and Channel Concatenation operations.
The table below presents single-threaded performance of XNNPACK library on three generations of MobileNet models and three generations of Pixel phones.
| Model | Pixel, ms | Pixel 2, ms | Pixel 3a, ms |
|---|---|---|---|
| FP32 MobileNet v1 1.0X | 82 | 86 | 88 |
| FP32 MobileNet v2 1.0X | 49 | 53 | 55 |
| FP32 MobileNet v3 Large | 39 | 42 | 44 |
| FP32 MobileNet v3 Small | 12 | 14 | 14 |
The following table presents multi-threaded (using as many threads as there are big cores) performance of XNNPACK library on three generations of MobileNet models and three generations of Pixel phones.
| Model | Pixel, ms | Pixel 2, ms | Pixel 3a, ms |
|---|---|---|---|
| FP32 MobileNet v1 1.0X | 43 | 27 | 46 |
| FP32 MobileNet v2 1.0X | 26 | 18 | 28 |
| FP32 MobileNet v3 Large | 22 | 16 | 24 |
| FP32 MobileNet v3 Small | 7 | 6 | 8 |
Benchmarked on March 27, 2020 with end2end_bench --benchmark_min_time=5 on an Android/ARM64 build with Android NDK r21 (bazel build -c opt --config android_arm64 :end2end_bench) and neural network models with randomized weights and inputs.
The table below presents multi-threaded performance of XNNPACK library on three generations of MobileNet models and three generations of Raspberry Pi boards.
| Model | RPi Zero W (BCM2835), ms | RPi 2 (BCM2836), ms | RPi 3+ (BCM2837B0), ms | RPi 4 (BCM2711), ms | RPi 4 (BCM2711, ARM64), ms |
|---|---|---|---|---|---|
| FP32 MobileNet v1 1.0X | 3919 | 302 | 114 | 72 | 77 |
| FP32 MobileNet v2 1.0X | 1987 | 191 | 79 | 41 | 46 |
| FP32 MobileNet v3 Large | 1658 | 161 | 67 | 38 | 40 |
| FP32 MobileNet v3 Small | 474 | 50 | 22 | 13 | 15 |
| INT8 MobileNet v1 1.0X | 2589 | 128 | 46 | 29 | 24 |
| INT8 MobileNet v2 1.0X | 1495 | 82 | 30 | 20 | 17 |
Benchmarked on Feb 8, 2022 with end2end-bench --benchmark_min_time=5 on a Raspbian Buster build with CMake (./scripts/build-local.sh) and neural network models with randomized weights and inputs. INT8 inference was evaluated on per-channel quantization schema.
XNNPACK is based on QNNPACK library. Over time its codebase diverged a lot, and XNNPACK API is no longer compatible with QNNPACK.