|
1 | 1 | --- |
2 | | -title: Understand LiteRT, XNNPACK, KleidiAI and SME2 |
| 2 | +title: Explore LiteRT, XNNPACK, KleidiAI, and SME2 |
3 | 3 | weight: 2 |
4 | 4 |
|
5 | 5 | ### FIXED, DO NOT MODIFY |
6 | 6 | layout: learningpathall |
7 | 7 | --- |
8 | 8 |
|
9 | | -## LiteRT, XNNPACK, KleidiAI and SME2 |
| 9 | +## Inside the LiteRT software stack |
10 | 10 |
|
11 | | -LiteRT (Lite Runtime), formerly known as TensorFlow Lite, is a runtime for on-device AI. |
12 | | -The default CPU acceleration library used by LiteRT is XNNPACK. |
| 11 | +LiteRT (Lightweight Runtime, formerly TensorFlow Lite) is a runtime for on-device AI on Arm platforms. The default CPU acceleration library used by LiteRT is XNNPACK. |
13 | 12 |
|
14 | | -XNNPACK is an open-source library that provides highly optimized implementations of neural-network operators. It continuously integrates KleidiAI library to leverage new CPU features such as SME2. |
| 13 | +XNNPACK is an open-source library that provides highly optimized implementations of neural-network operators. It continuously integrates the KleidiAI library to use new CPU features such as Scalable Matrix Extension 2 (SME2). |
15 | 14 |
|
16 | | -KleidiAI is a library developed by Arm that offers performance-critical micro-kernels leveraging Arm architecture features, such as SME2. |
| 15 | +KleidiAI is a library developed by Arm that offers performance-critical micro-kernels using Arm architecture features, such as SME2. |
17 | 16 |
|
18 | | -Both XNNPACK and KleidiAI are external dependencies of LiteRT. LiteRT specifies the versions of these libraries to use. |
19 | | -When LiteRT is built with both XNNPACK and KleidiAI enabled, XNNPACK invokes KleidiAI’s micro-kernels at runtime to accelerate operators with supported data types; otherwise, it falls back to its own implementation. |
| 17 | +The software stack for LiteRT is shown below. |
20 | 18 |
|
21 | | -The software stack for LiteRT is as follows. |
| 19 | + |
22 | 20 |
|
23 | | - |
| 21 | +## How KleidiAI works in LiteRT |
24 | 22 |
|
| 23 | +To understand how KleidiAI SME2 micro-kernels work in LiteRT, think about a LiteRT model with one fully connected operator using the FP32 data type. The following diagrams illustrate the execution workflow of XNNPACK’s implementation compared with the workflow when KleidiAI SME2 is enabled in XNNPACK. |
25 | 24 |
|
26 | | -## Understand how KleidiAI works in LiteRT |
| 25 | +### LiteRT → XNNPACK workflow |
27 | 26 |
|
28 | | -To understand how KleidiAI SME2 micro-kernel works in LiteRT, a LiteRT model with one Fully Connected operator with FP32 datatype is used as an example. |
| 27 | + |
| 28 | +A fully connected operator multiplies two matrices: the input activations (LHS) and the weights (RHS). |
29 | 29 |
|
30 | | -The following illustrates the execution workflow of XNNPACK’s implementation compared with the workflow when KleidiAI SME2 is enabled in XNNPACK. |
| 30 | +When LiteRT loads a model, it reads the operators and builds a computation graph. If you select the CPU as the accelerator, LiteRT uses XNNPACK by default. |
31 | 31 |
|
32 | | -### LiteRT → XNNPACK workflow |
| 32 | +XNNPACK scans the computation graph and looks for operators it can optimize. It packs the weight matrix to prepare for efficient computation. On Arm platforms, XNNPACK uses NEON instructions to speed up this packing and the matrix multiplication. |
33 | 33 |
|
34 | | - |
| 34 | +At runtime, XNNPACK checks the hardware and chooses the best available micro-kernel. During inference, it splits the matrices into smaller tiles and runs the multiplications in parallel across multiple threads, using NEON instructions for faster processing. |
35 | 35 |
|
36 | | -A Fully Connected operator can be essentially implemented as a matrix multiplication. |
| 36 | +### LiteRT → XNNPACK → KleidiAI workflow |
37 | 37 |
|
38 | | -When LiteRT loads a model, it parses the operators and create a computation graph. If the CPU is selected as the accelerator, LiteRT uses XNNPACK by default. |
| 38 | + |
39 | 39 |
|
40 | | -XNNPACK traverses the operators in the graph and tries to replace them with its own implementations. During this stage, XNNPACK performs the necessary packing of the weight matrix. To speed up the packing process, XNNPACK uses NEON instructions for Arm platform. XNNPACK provides different implementations for different hardware platforms. At runtime, it detects the hardware capabilities and selects the appropriate micro-kernel. |
| 40 | +When KleidiAI and SME2 are enabled at build time, the KleidiAI SME2 micro-kernels are compiled into XNNPACK. |
41 | 41 |
|
42 | | -During model inference, XNNPACK performs matrix multiplication on the activation matrix (the left-hand side matrix, LHS) and the repacked weight matrix (the right-hand side matrix, RHS). In this stage, XNNPACK applies tiling strategies to the matrices and performs parallel multiplication across the resulting tiles using multiple threads. To accelerate the computation, XNNPACK uses NEON instructions. |
| 42 | +During the model loading stage, when XNNPACK optimizes the subgraph, it checks the operator’s data type to determine whether a KleidiAI implementation is available. If KleidiAI supports it, XNNPACK bypasses its own default implementation. As a result, RHS packing is performed using the KleidiAI SME packing micro-kernel. Because KleidiAI typically requires packing of the LHS, a flag is also set during this stage. |
43 | 43 |
|
| 44 | +During model inference, the LHS packing micro-kernel is invoked. After the LHS is packed, XNNPACK performs the matrix multiplication. At this point, the KleidiAI SME micro-kernel is used to compute the matrix product. |
44 | 45 |
|
45 | | -### LiteRT → XNNPACK → KleidiAI workflow |
| 46 | +## What you've accomplished and what's next |
46 | 47 |
|
47 | | - |
| 48 | +In this section, you explored how LiteRT leverages XNNPACK and KleidiAI to accelerate fully connected operators on Arm platforms. You learned how XNNPACK uses NEON instructions for efficient matrix operations and how enabling KleidiAI with SME2 further optimizes performance by introducing specialized micro-kernels for packing and matrix multiplication. |
48 | 49 |
|
49 | | -When KleidiAI and SME2 are enabled at building stage, the KleidiAI SME2 micro-kernels are compiled into the XNNPACK. |
| 50 | +You have completed the overview of LiteRT, XNNPACK, KleidiAI, and SME2 integration. Next, you’ll dive deeper into building and benchmarking models with these technologies. |
50 | 51 |
|
51 | | -During the model loading stage, when XNNPACK optimizes the subgraph, it checks the operator’s data type to determine whether a KleidiAI implementation is available. If KleidiAI supports it, XNNPACK bypasses its own default implementation. As a result, RHS packing is performed using the KleidiAI SME packing micro-kernel. In addition, because KleidiAI typically requires packing of the LHS, a flag is also set during this stage. |
52 | 52 |
|
53 | | -During model inference, the LHS packing micro-kernel is invoked. After the LHS is packed, XNNPACK performs the matrix multiplication. At this point, the KleidiAI SME micro-kernel is used to compute the matrix product. |
0 commit comments