DSP Libraries
HiFi 5 Signal Processing Library
Overview
The HiFi 5 NatureDSP (NDSP) library, also known as the NatureDSP signal processing library, provides a large number of highly optimized DSP functions for HiFi 5 DSP.
This source code repository contains ANSI-C compatible C functions for general signal processing (filtering, correlation, convolution), mathematical operations, and vector operations, specifically optimized for high-density signal processing. The library supports both fixed-point and single-precision floating-point data types.
Pre-compiled HiFi 5 NDSP libraries are provided in {DSP_SDK}/lib/lib_hifi5. For other requirements, you can also compile them yourself by downloading the official repository code.
More Information
Official Documentation: Located in the NDSP_HiFi5/library/doc directory after extracting the GitHub repository archive
Function Support
The NDSP library contains implementations of the following functions:
FIR filters and correlation functions
IIR filters
Mathematical operations
Complex mathematical operations
Vector operations
Matrix operations
Matrix decomposition and inversion functions
Fitting/interpolation
Fast Fourier Transform
Mel-Frequency Cepstral Coefficients (MFCC) functions
Image processing
For more details, please refer to the official Cadence documentation.
HiFi 5 Neural Network Library
Introduction
The HiFi 5 Neural Network (NN) library is an implementation of neural network layers and low-level operations optimized for HiFi processors. This library focuses on the speech and audio domain and is designed for related neural networks.
The low-level NN kernels in the library are optimized for HiFi and form the foundation of NN layers, providing generic and concise interfaces. NN layers are implemented based on these low-level kernels and can accept input data with up to four-dimensional shapes, generating output with corresponding shapes.
Weights (or coefficients) and biases required for layer operations are stored externally. The shapes of inputs, outputs, weights, and biases strictly follow the design specifications of each layer.
Precompiled HiFi 5 neural network libraries are provided in {DSP_SDK}/lib/xa_nnlib. For other requirements, you can also download the official repository code to compile manually.
Operation Support
Low-level Kernels
Matrix-vector multiplication kernel
Convolution kernel
Activation function kernel
Pooling kernel
Basic operation kernel
Fully connected kernel
Normalization kernel
Reshuffling kernel
These kernels support fixed-point 8-bit, 16-bit, single-precision floating-point (float32/f32), and half-precision floating-point (float16/f16) data types for weights/coefficients, biases, inputs, and outputs.
Additionally, some kernels also support 8-bit and 16-bit quantized data types defined in TensorFlow (TF) and TensorFlowLite-Micro (TFLM). These data types use 8-bit/16-bit quantized values (asym8u - asymmetric 8-bit unsigned, asym8s - asymmetric 8-bit signed, sym8s - symmetric 8-bit signed) for weights/coefficients, inputs, and outputs. Biases are 32-bit quantized values.
Layers
GRU layer (8x16, 16x16 precision)
LSTM layer (8x16, 16x16 precision)
CNN layer (8x8, 8x16, 16x16, and float32xfloat32 precision)
TensorFlow Lite Micro Operators
The HiFi 5 NN library low-level kernels can be used to implement some TensorFlow Lite Micro operators. For applicable operators, the HiFi 5 NN library supports both rounding modes available in TensorFlow Lite Micro.
For more details, please refer to the official Cadence documentation.
Acceleration Performance
Using the HiFi 5 neural network library can significantly improve the inference speed of neural networks.
Take {DSP_SDK}/example/tflite_micro/tflm_mnist as an example:
Example |
Time without nnlib (milliseconds) |
Time with nnlib (milliseconds) |
Speedup |
|---|---|---|---|
tflm_mnist |
2378 |
72 |
33 |
nnlib Compilation Example
This chapter uses xa_nnlib v2.3.0 as an example to introduce how to compile the nnlib library. There are two compilation methods: importing the xws file through the Xplorer GUI for compilation, and compiling in a Linux command-line environment.
Compiling with Xplorer GUI
If you are using Xplorer with a graphical interface, you can complete the compilation by importing the xws file. The specific steps are as follows:
Download the corresponding version of the xws file from the nnlib-hifi5 GitHub repository. Taking v2.3.0 as an example, the corresponding file link is: https://github.com/foss-xtensa/nnlib-hifi5/blob/master/xws/xa_hifi5_nnlib_lib_2_3_0_api_1_6_src.xws
Open the Xplorer graphical interface.
In the menu bar at the top of Xplorer, select
File->Import->Xtensa Xplorer->Import Xtensa Xplorer Workspacein sequence.In
Select Workspace File (.xws), choose the xws file downloaded in step 1, and clickNext.On the
Select Projects to be Importedpage, selectlibxa_nnlibfrom theProjectslist on the left, and then clickFinish.After successful import, set
P:libxa_nnlib,C:HIFI5_PROD_1123_asic_UPG, andT:Releasein the toolbar at the top of Xplorer, then clickBuild Activeto compile. After compilation, the generated library file isxa_nnlib.a.Note
Select the correct configuration according to your needs:
HIFI5_PROD_1123_asic_UPGorHIFI5_PROD_1123_asic_wUPG.
Linux Command Line Compilation
If you are using Xplorer without a graphical interface in a Linux environment, you can compile using the command-line method as follows:
Set the following environment variables according to your actual environment:
export XTENSA_BASE=/opt/xtensa/XtDevTools/install export XTENSA_TOOLS_VERSION=RI-2021.8-linux # Xplorer version export XTENSA_CORE=HIFI5_PROD_1123_asic_UPG # UPG or wUPG export XTENSA_SYSTEM=${XTENSA_BASE}/builds/${XTENSA_TOOLS_VERSION}/${XTENSA_CORE}/config export PATH="/opt/xtensa/XtDevTools/install/tools/RI-2021.8-linux/XtensaTools/bin:$PATH"
Download the source code for version v2.3.0:
git clone https://github.com/foss-xtensa/nnlib-hifi5.git cd nnlib-hifi5 git checkout f5363c5 # commit ID corresponding to v2.3.0
Note
If you need to download another version, please check the official commit history to find the commit ID corresponding to that version.
Compile:
cd xa_nnlib/build xt-make -f makefile clean all install
After compilation, the generated library file is
xa_nnlib.a.