CMSIS-DSP embedded compute library for Cortex-M and Cortex-A
CMSIS-DSP embedded compute library for Cortex-M and Cortex-A
CMSIS-DSP is an optimized compute library for embedded systems (DSP is in the name for legacy reasons).
It provides optimized compute kernels for Cortex-M and for Cortex-A.
Different variants are available according to the core and most of the functions are using a vectorized version when the Helium or Neon extension is available.
This repository contains the CMSIS-DSP library and several other projects:
You don't need any of the other projects to build and use CMSIS-DSP library. Building the other projects may require installation of other libraries (CMSIS), other tools (Arm Virtual Hardware) or CMSIS build tools.
Kernels provided by CMSIS-DSP (list not exhaustive):
Kernels are provided with several datatypes : f64, f32, f16, q31, q15, q7.
DSP++ provides a higher-level C++ API for combining existing CMSIS-DSP kernels into new algorithms while keeping good performance. Its loop fusion feature can combine several operations into a single loop, avoiding temporary arrays and repeated passes over the data.
DSP++ is entirely optional and header-only: it requires no separate library build. Applications using only the C API are unaffected: no code or build changes are needed, and the extension adds no code size, memory or runtime overhead.
DSP++ is currently unsupported in builds with ARM_MATH_NEON enabled. On Cortex-A, enabling this macro to benefit from Neon in the C API also affects DSP++: its incomplete Neon implementation can cause compilation errors, with no automatic scalar fallback. Applications using only the C API can continue to use Neon normally.
The C++ API headers are in dsppp/Include and are included in the CMSIS-DSP pack starting with version 1.18.0. See the DSP++ introduction for an example.
Built on DSP++, the automatic differentiation (autodiff) extension is experimental and is not a new ML framework. Its focus is on-device fine-tuning using a subset of existing CMSIS-DSP kernels. See the autodiff introduction to learn more.
A PythonWrapper is also available and can be installed with:
pip install cmsisdsp
With this wrapper you can design your algorithm in Python using an API as close as possible to the C API. The wrapper is compatible with NumPy. The wrapper is supporting fixed point arithmetic. This wrapper works in google colab.
The goal is to make it easier to move from a design to a final implementation in C.
For any questions or to reach the CMSIS-DSP team, please create a new issue in https://github.com/ARM-software/CMSIS-DSP/issues
CMSIS-DSP is used when you need performance. As consequence CMSIS-DSP should be compiled with the options giving the best performance:
-O3 -ffast-math must be used for best performances.-O3 -ffast-mathGCC is currently not giving good performances when targeting Helium. You should use the Arm compilerWhen float are used, then the fpu should be selected to ensure that the compiler is not using a software float emulation.
When building with Helium support, it will be automatically detected by CMSIS-DSP. For Neon, it is not the case and you must enable the option -DARM_MATH_NEON for the C compilation. With cmake this option is controlled with -DNEON=ON.
-DLOOPUNROLL=ON can also be used when compiling with cmake-DARM_MATH_LOOPUNROLLCompilers are doing unrolling. So this option may not be needed but it is highly dependent on the compiler. With some compilers, this option is needed to get better performances.
Speed of memory is important. If you can map the data and the constant tables used by CMSIS-DSP in DTCM memory then it is better. If you have a cache, enable it.
-fno-builtin-ffreestanding because it enables previous optionsThe library is doing some type punning to process word 32 from memory as a pair of q15 or a quadruple of q7. Those type manipulations are done through memcpy functions. Most compilers should be able to optimize out those function calls when the length to copy is small (4 bytes).
This optimization will not occur when -fno-builtin is used and it will have a very bad impact on the performances.
Some compiler may also require the use of option -munaligned-access to specify that unaligned accesses are used.
f16 data type (half float) has been added to the library. It is useful only if your Cortex has some half float hardware acceleration (for instance with Helium extension). If you don't need f16, you should disable it since it may cause compilation problems. Just define -DDISABLEFLOAT16 when building.
You can build CMSIS-DSP with the open CMSIS-Pack, or cmake, or Makefile and it is also easy to build if you use any other build tool.
The standard way to build is by using the CMSIS pack technology. CMSIS-DSP is available as a pack.
You can use CMSIS-Toolbox or any of the Arm Keil IDEs
If you want to build the FFT example for the Corstone-300 virtual hardware platform, you could just do:
cbuild -O cprj examples_ac6.csolution.yml --update-rte -r --toolchain AC6 -c fftbin.Release+VHT-Corstone-300"
from the Examples/cmsis_build folder and assuming the command line tools and the needed packs have been installed.
There is an example Makefile in Source.
In each source folder (like BasicMathFunctions), you'll see files with no _datatype suffix (like BasicMathFunctions.c and BasicMathFunctionsF16.c).
Those files are all you need in your makefile. They are including all other C files from the source folders.
Then, for the includes you'll need to add the paths: Include, PrivateInclude and, since there is a dependency to CMSIS Core, Core/Include from CMSIS_5/CMSIS.
If you are building for Cortex-A and want to use Neon, you'll also need to include ComputeLibrary/Include and the source file in ComputeLibrary/Source.
Create a CMakeLists.txt and inside add a project.
Add CMSIS-DSP as a subdirectory. The variable CMSISDSP is the path to the CMSIS-DSP repository in below example.
cmake_minimum_required (VERSION 3.14)
# Define the project
project (testcmsisdsp VERSION 0.1)
add_subdirectory(${CMSISDSP}/Source bin_dsp)CMSIS-DSP is dependent on the CMSIS Core includes. So, you should define CMSISCORE on the cmake command line. The path used by CMSIS-DSP will be ${CMSISCORE}/Include.
You should also set the compilation options to use to build the library.
If you build for Helium, you should use any of the option MVEF, MVEI or HELIUM.
If you build for Neon, use NEON and/or NEONEXPERIMENTAL.
Once cmake has generated the makefiles, you can use a GNU Make to build.
make VERBOSE=1CMSIS-DSP can be installed as a cmake package for host builds on Windows, macOS, or Linux. Set CMAKE_INSTALL_PREFIX to the folder where the package must be installed. The installed package exports the target CMSISDSP::CMSISDSP. Headers are installed below include/CMSIS-DSP to avoid conflicts with other packages, but applications still include CMSIS-DSP headers with #include "arm_math.h" when linking with CMSISDSP::CMSISDSP. Package installation is disabled when CMSISCORE is set, since CMSISCORE is used for Cortex-M builds normally handled by CMSIS Toolbox or Zephyr.
For maximum performance on an Arm host with Neon, build in Release, enable HOST and NEON, and use -O3 -ffast-math:
cmake -S . -B build-cmsisdsp-neon \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/path/to/cmsis-dsp-install \
-DHOST=ON \
-DNEON=ON \
-DCMAKE_C_FLAGS_RELEASE="-O3 -ffast-math"
cmake --build build-cmsisdsp-neon
cmake --install build-cmsisdsp-neonFor Windows or x86 host builds, do not enable NEON. HOST=ON removes the dependency on CMSIS Core intrinsics for host compilers. If float16 support is not needed, DISABLEFLOAT16=ON can avoid compiler support issues.
On Linux or macOS x86:
cmake -S . -B build-cmsisdsp-host \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/path/to/cmsis-dsp-install \
-DHOST=ON \
-DDISABLEFLOAT16=ON \
-DCMAKE_C_FLAGS_RELEASE="-O3 -ffast-math"
cmake --build build-cmsisdsp-host
cmake --install build-cmsisdsp-hostOn Windows with Visual Studio:
cmake -S . -B build-cmsisdsp-host `
-G "Visual Studio 17 2022" -A x64 `
-DCMAKE_INSTALL_PREFIX=C:\cmsis-dsp-install `
-DHOST=ON `
-DDISABLEFLOAT16=ON `
-DCMAKE_C_FLAGS_RELEASE="/O2 /fp:fast"
cmake --build build-cmsisdsp-host --config Release
cmake --install build-cmsisdsp-host --config ReleaseFor MSVC, /O2 /fp:fast is the equivalent high-performance setting to -O3 -ffast-math.
An application can then use the installed package with:
find_package(CMSISDSP CONFIG REQUIRED)
target_link_libraries(my_application PRIVATE CMSISDSP::CMSISDSP)The package also installs the DSP++ headers. Linking to CMSISDSP::CMSISDSP makes headers such as dsppp/algorithms.hpp available through the same include path. When using add_subdirectory, the target also exposes dsppp/Include from the source tree.
To request a particular version, use, for example, find_package(CMSISDSP 1.18.0 CONFIG REQUIRED). The package accepts requests with the same major and minor version and a patch version no newer than the installed package (SameMinorVersion). Add EXACT to require an exact version.
CMake detects the version from the latest reachable release tag matching v.. using git describe --tags --abbrev=0. Prerelease tags are excluded. This follows the checked-out commit's history, so a tag on an unrelated branch does not change the package version. If Git or suitable tags are unavailable (including source archives and shallow clones without release tags), it uses the release fallback in `cmake/CMSI
No open issues yet, or sync has not completed.