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- Truncation (rounding to integer towards zero) 53- PReLU 54 55All 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. 56 57## Performance 58 59### Mobile phones 60 61The table below presents **single-threaded** performance of XNNPACK library on three generations of MobileNet models and three generations of Pixel phones. 62 63| Model | Pixel, ms | Pixel 2, ms | Pixel 3a, ms | 64| ----------------------- | :-------: | :---------: | :----------: | 65| FP32 MobileNet v1 1.0X | 82 | 86 | 88 | 66| FP32 MobileNet v2 1.0X | 49 | 53 | 55 | 67| FP32 MobileNet v3 Large | 39 | 42 | 44 | 68| FP32 MobileNet v3 Small | 12 | 14 | 14 | 69 70The 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. 71 72| Model | Pixel, ms | Pixel 2, ms | Pixel 3a, ms | 73| ----------------------- | :-------: | :---------: | :----------: | 74| FP32 MobileNet v1 1.0X | 43 | 27 | 46 | 75| FP32 MobileNet v2 1.0X | 26 | 18 | 28 | 76| FP32 MobileNet v3 Large | 22 | 16 | 24 | 77| FP32 MobileNet v3 Small | 7 | 6 | 8 | 78 79Benchmarked 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. 80 81### Raspberry Pi 82 83The table below presents **multi-threaded** performance of XNNPACK library on three generations of MobileNet models and three generations of Raspberry Pi boards. 84 85| Model | RPi Zero W (BCM2835), ms | RPi 2 (BCM2836), ms | RPi 3+ (BCM2837B0), ms | RPi 4 (BCM2711), ms | RPi 4 (BCM2711, ARM64), ms | 86| ----------------------- | :----------------------: | :-----------------: | :--------------------: | :-----------------: | :------------------------: | 87| FP32 MobileNet v1 1.0X | 3937 | 299 | 114 | 72 | 76 | 88| FP32 MobileNet v2 1.0X | 1987 | 187 | 79 | 41 | 44 | 89| FP32 MobileNet v3 Large | 1658 | 158 | 67 | 38 | 41 | 90| FP32 MobileNet v3 Small | 487 | 50 | 23 | 13 | 14 | 91| INT8 MobileNet v1 1.0X | 2598 | 169 | 61 | 29 | 24 | 92| INT8 MobileNet v2 1.0X | 1487 | 109 | 40 | 20 | 17 | 93 94Benchmarked on Oct 15, 2021 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. 95 96## Publications 97 98- 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)). 99- Erich Elsen, Marat Dukhan, Trevor Gale, Karen Simonyan "Fast Sparse ConvNets". 100 [Paper on ArXiv](https://arxiv.org/abs/1911.09723), [pre-trained sparse 101 models](https://github.com/google-research/google-research/tree/master/fastconvnets). 102- Marat Dukhan, Artsiom Ablavatski "The Two-Pass Softmax Algorithm". 103 [Paper on ArXiv](https://arxiv.org/abs/2001.04438). 104- Yury Pisarchyk, Juhyun Lee "Efficient Memory Management for Deep Neural Net Inference". 105 [Paper on ArXiv](https://arxiv.org/abs/2001.03288). 106 107## Ecosystem 108 109### Machine Learning Frameworks 110 111- [TensorFlow Lite](https://blog.tensorflow.org/2020/07/accelerating-tensorflow-lite-xnnpack-integration.html). 112- [TensorFlow.js WebAssembly backend](https://blog.tensorflow.org/2020/03/introducing-webassembly-backend-for-tensorflow-js.html). 113- [PyTorch Mobile](https://pytorch.org/mobile). 114- [MediaPipe for the Web](https://developers.googleblog.com/2020/01/mediapipe-on-web.html). 115- [Alibaba HALO (Heterogeneity-Aware Lowering and Optimization)](https://github.com/alibaba/heterogeneity-aware-lowering-and-optimization) 116- [Samsung ONE (On-device Neural Engine)](https://github.com/Samsung/ONE) 117 118## Acknowledgements 119 120XNNPACK 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. 121