1# XNNPACK 2 3XNNPACK is a highly optimized library of floating-point neural network inference operators for ARM, WebAssembly, and x86 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](https://www.tensorflow.org/lite), [TensorFlow.js](https://www.tensorflow.org/js), [PyTorch](https://pytorch.org/), and [MediaPipe](https://mediapipe.dev). 4 5## Supported Architectures 6 7- ARM64 on Android, Linux, macOS, and iOS (including WatchOS and tvOS) 8- ARMv7 (with NEON) on Android 9- ARMv6 (with VFPv2) on Linux 10- x86 and x86-64 (up to AVX512) on Windows, Linux, macOS, Android, and iOS simulator 11- WebAssembly MVP 12- WebAssembly SIMD 13- RISC-V (RV32GV and RV64GC) 14 15## Operator Coverage 16 17XNNPACK implements the following neural network operators: 18 19- 2D Convolution (including grouped and depthwise) 20- 2D Deconvolution (AKA Transposed Convolution) 21- 2D Average Pooling 22- 2D Max Pooling 23- 2D ArgMax Pooling (Max Pooling + indices) 24- 2D Unpooling 25- 2D Bilinear Resize 26- 2D Depth-to-Space (AKA Pixel Shuffle) 27- Add (including broadcasting, two inputs only) 28- Subtract (including broadcasting) 29- Divide (including broadcasting) 30- Maximum (including broadcasting) 31- Minimum (including broadcasting) 32- Multiply (including broadcasting) 33- Squared Difference (including broadcasting) 34- Global Average Pooling 35- Channel Shuffle 36- Fully Connected 37- Abs (absolute value) 38- Bankers' Rounding (rounding to nearest, ties to even) 39- Ceiling (rounding to integer above) 40- Clamp (includes ReLU and ReLU6) 41- Convert (includes fixed-point and half-precision quantization and 42 dequantization) 43- Copy 44- ELU 45- Floor (rounding to integer below) 46- HardSwish 47- Leaky ReLU 48- Negate 49- Sigmoid 50- Softmax 51- Square 52- Transpose 53- Truncation (rounding to integer towards zero) 54- PReLU 55 56All operators in XNNPACK support NHWC layout, but additionally allow custom stride along the **C**hannel 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. 57 58## Performance 59 60### Mobile phones 61 62The table below presents **single-threaded** performance of XNNPACK library on three generations of MobileNet models and three generations of Pixel phones. 63 64| Model | Pixel, ms | Pixel 2, ms | Pixel 3a, ms | 65| ----------------------- | :-------: | :---------: | :----------: | 66| FP32 MobileNet v1 1.0X | 82 | 86 | 88 | 67| FP32 MobileNet v2 1.0X | 49 | 53 | 55 | 68| FP32 MobileNet v3 Large | 39 | 42 | 44 | 69| FP32 MobileNet v3 Small | 12 | 14 | 14 | 70 71The 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. 72 73| Model | Pixel, ms | Pixel 2, ms | Pixel 3a, ms | 74| ----------------------- | :-------: | :---------: | :----------: | 75| FP32 MobileNet v1 1.0X | 43 | 27 | 46 | 76| FP32 MobileNet v2 1.0X | 26 | 18 | 28 | 77| FP32 MobileNet v3 Large | 22 | 16 | 24 | 78| FP32 MobileNet v3 Small | 7 | 6 | 8 | 79 80Benchmarked 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. 81 82### Raspberry Pi 83 84The table below presents **multi-threaded** performance of XNNPACK library on three generations of MobileNet models and three generations of Raspberry Pi boards. 85 86| Model | RPi Zero W (BCM2835), ms | RPi 2 (BCM2836), ms | RPi 3+ (BCM2837B0), ms | RPi 4 (BCM2711), ms | RPi 4 (BCM2711, ARM64), ms | 87| ----------------------- | :----------------------: | :-----------------: | :--------------------: | :-----------------: | :------------------------: | 88| FP32 MobileNet v1 1.0X | 3919 | 302 | 114 | 72 | 77 | 89| FP32 MobileNet v2 1.0X | 1987 | 191 | 79 | 41 | 46 | 90| FP32 MobileNet v3 Large | 1658 | 161 | 67 | 38 | 40 | 91| FP32 MobileNet v3 Small | 474 | 50 | 22 | 13 | 15 | 92| INT8 MobileNet v1 1.0X | 2589 | 128 | 46 | 29 | 24 | 93| INT8 MobileNet v2 1.0X | 1495 | 82 | 30 | 20 | 17 | 94 95Benchmarked 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. 96 97## Publications 98 99- Marat Dukhan "The Indirect Convolution Algorithm". Presented on [Efficient Deep Learning for Compute Vision (ECV) 2019](https://sites.google.com/corp/view/ecv2019/) workshop ([slides](https://drive.google.com/file/d/1ZayB3By5ZxxQIRtN7UDq_JvPg1IYd3Ac/view), [paper on ArXiv](https://arxiv.org/abs/1907.02129)). 100- Erich Elsen, Marat Dukhan, Trevor Gale, Karen Simonyan "Fast Sparse ConvNets". 101 [Paper on ArXiv](https://arxiv.org/abs/1911.09723), [pre-trained sparse 102 models](https://github.com/google-research/google-research/tree/master/fastconvnets). 103- Marat Dukhan, Artsiom Ablavatski "The Two-Pass Softmax Algorithm". 104 [Paper on ArXiv](https://arxiv.org/abs/2001.04438). 105- Yury Pisarchyk, Juhyun Lee "Efficient Memory Management for Deep Neural Net Inference". 106 [Paper on ArXiv](https://arxiv.org/abs/2001.03288). 107 108## Ecosystem 109 110### Machine Learning Frameworks 111 112- [TensorFlow Lite](https://blog.tensorflow.org/2020/07/accelerating-tensorflow-lite-xnnpack-integration.html). 113- [TensorFlow.js WebAssembly backend](https://blog.tensorflow.org/2020/03/introducing-webassembly-backend-for-tensorflow-js.html). 114- [PyTorch Mobile](https://pytorch.org/mobile). 115- [MediaPipe for the Web](https://developers.googleblog.com/2020/01/mediapipe-on-web.html). 116- [Alibaba HALO (Heterogeneity-Aware Lowering and Optimization)](https://github.com/alibaba/heterogeneity-aware-lowering-and-optimization) 117- [Samsung ONE (On-device Neural Engine)](https://github.com/Samsung/ONE) 118 119## Acknowledgements 120 121XNNPACK is a based on [QNNPACK](https://github.com/pytorch/QNNPACK) library. Over time its codebase diverged a lot, and XNNPACK API is no longer compatible with QNNPACK. 122