Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Documentation/applications/math/gemmlowp/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=======================
``gemmlowp`` gemmlowp
=======================

``apps/math/gemmlowp`` vendors Google `gemmlowp
<https://github.com/google/gemmlowp>`_, a small low-precision matrix
library used by TensorFlow Lite Micro.

Enable ``CONFIG_MATH_GEMMLOWP``. The build downloads a pinned snapshot
(``719139ce755a0f31cbf1c37f7f98adcc7fc9f425``). Headers are added from
``apps/math/gemmlowp/gemmlowp``.

:doc:`../../mlearning/tflite-micro/index` depends on this package.
12 changes: 12 additions & 0 deletions Documentation/applications/math/kissfft/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
===================
``kissfft`` KissFFT
===================

Comment thread
acassis marked this conversation as resolved.
``apps/math/kissfft`` vendors `KissFFT
<https://github.com/mborgerding/kissfft>`_ (tag ``v130``) and applies
``kissfft.patch``. It compiles ``kiss_fft.c`` and ``tools/kiss_fftr.c``.

Enable ``CONFIG_MATH_KISSFFT``. Include path:
``apps/math/kissfft/kissfft``.

:doc:`../../mlearning/tflite-micro/index` depends on this package.
12 changes: 12 additions & 0 deletions Documentation/applications/math/ruy/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=============
``ruy`` Ruy
=============

``apps/math/ruy`` vendors Google `Ruy <https://github.com/google/ruy>`_,
a matrix-multiplication library used by TensorFlow Lite Micro.

Enable ``CONFIG_MATH_RUY``. The build downloads a pinned snapshot
(``d37128311b445e758136b8602d1bbd2a755e115d``). Headers are added from
``apps/math/ruy/ruy``.

:doc:`../../mlearning/tflite-micro/index` depends on this package.
5 changes: 3 additions & 2 deletions Documentation/applications/mlearning/cmsis-nn/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ TensorFlow Lite Micro uses when ``CONFIG_MLEARNING_CMSIS_NN`` is enabled.
It is distinct from :doc:`../cmsis/index`, which vendors the older CMSIS 5
tree (DSP plus NN) for NNABLA.

Enable with ``CONFIG_MLEARNING_CMSIS_NN``. The Makefile downloads a pinned
CMSIS-NN commit and compiles:
Enable with ``CONFIG_MLEARNING_CMSIS_NN``. The Makefile and CMake build
download a pinned CMSIS-NN commit
(``72e1ebf623ab1660a3e14e4e36fdcddce46f1991``) and compile:

- Activation functions
- Basic math
Expand Down
6 changes: 5 additions & 1 deletion Documentation/applications/mlearning/cmsis/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
``apps/mlearning/cmsis`` fetches `CMSIS 5
<https://github.com/ARM-software/CMSIS_5>`_ and builds CMSIS-DSP and
CMSIS-NN from that tree. Default version is ``5.8.0``
(``CONFIG_CMSIS_VER``).
(``CONFIG_CMSIS_VER``). ARM archived the CMSIS 5 repository on 18
December 2025; NuttX still vendors this tree because NNABLA uses the
CHW helpers in ``cmsis-nn-support_nnabla.patch``. There is no CMake
build for this package.

This package is aimed at NNABLA and generic DSP use. For TensorFlow Lite
Micro kernel acceleration, use :doc:`../cmsis-nn/index` instead.
``CONFIG_CMSIS_NN`` here is not ``CONFIG_MLEARNING_CMSIS_NN``.

Enable ``CONFIG_CMSIS`` from :menuselection:`Application Configuration -->
Machine Learning Support --> CMSIS Libraries`.
Expand Down
9 changes: 6 additions & 3 deletions Documentation/applications/mlearning/darknet/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
Only Look Once) object detection.

Enable ``CONFIG_DARKNET_YOLO``. ``CONFIG_DARKNET_YOLO_VER`` is the Git
branch fetched at build time (default ``master``). The Makefile compiles
the core Darknet sources (network, parser, convolutional and connected
layers, YOLO/region/detection layers, RNN/GRU/LSTM, and image helpers).
branch fetched at build time (default ``master``), not a commit pin.
Upstream ``pjreddie/darknet`` is unmaintained, so the fetched tree can
change between builds. There is no NuttX example application and no
CMake build; the Makefile compiles the core Darknet sources (network,
parser, convolutional and connected layers, YOLO/region/detection
layers, RNN/GRU/LSTM, and image helpers).

Include path: ``apps/mlearning/darknet/darknet/include``.

Expand Down
14 changes: 10 additions & 4 deletions Documentation/applications/mlearning/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ Enable the libraries from::

The following packages are available:

- :doc:`cmsis/index` — ARM CMSIS 5 DSP and NN libraries
- :doc:`cmsis/index` — ARM CMSIS 5 DSP and NN libraries (Makefile only)
- :doc:`cmsis-nn/index` — standalone ARM CMSIS-NN kernels for TensorFlow Lite Micro
- :doc:`darknet/index` — Darknet YOLO object detection
- :doc:`libnnablart/index` — Sony NNABLA C inference runtime
- :doc:`darknet/index` — Darknet YOLO object detection (Makefile only)
- :doc:`libnnablart/index` — Sony NNABLA C inference runtime (Makefile only)
- :doc:`tflite-micro/index` — TensorFlow Lite for Microcontrollers

``CONFIG_CMSIS_NN`` (nested under CMSIS Libraries) is not the same
option as ``CONFIG_MLEARNING_CMSIS_NN`` (standalone CMSIS-NN used by
TFLM). CMake currently builds ``tflite-micro`` and ``cmsis-nn`` only.

A ready-to-build simulator configuration is ``sim:tflm``. See
:doc:`/platforms/sim/sim/boards/sim/index`.
:doc:`/platforms/sim/sim/boards/sim/index`. The kernel also has an
optional AI-engine character driver (``CONFIG_AI_ENGINE``); see
:doc:`/components/drivers/character/aie`.

.. toctree::
:glob:
Expand Down
5 changes: 4 additions & 1 deletion Documentation/applications/mlearning/libnnablart/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
networks produced by Neural Network Libraries.

Enable ``CONFIG_NNABLA_RT``. ``CONFIG_NNABLA_RT_VER`` selects the upstream
tag (default ``1.24.0``). The Makefile downloads that release and compiles
tag (default ``1.24.0``). Sony's later ``nnabla-c-runtime`` tags go
through ``v1.38.0``; NuttX has not moved the default. Sony has placed
NNABLA in maintenance. There is no NuttX example application and no
CMake build. The Makefile downloads the selected release and compiles
the runtime plus a subset of operators, including:

- Activations (ReLU, sigmoid, tanh, softmax, ELU, leaky ReLU, Swish, ...)
Expand Down
43 changes: 29 additions & 14 deletions Documentation/applications/mlearning/tflite-micro/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ TensorFlow Lite for Microcontrollers (TFLM) is a C++ interpreter for
running ``.tflite`` models on memory-constrained targets. NuttX integrates
it from ``apps/mlearning/tflite-micro``.

The build downloads a pinned TFLM snapshot from
The build downloads a pinned TFLM snapshot
(``cfa4c91d1b36c37c7c104b9c664615e59f1abfe3``, 24 February 2024) from
https://github.com/tensorflow/tflite-micro and applies NuttX patches that
add INT8-only operator registrations and an ``extern "C"`` entry point for
the hello-world example.
Expand All @@ -16,10 +17,14 @@ Dependencies

``CONFIG_TFLITEMICRO`` depends on all of:

- ``CONFIG_SYSTEM_FLATBUFFERS`` — FlatBuffers headers (``apps/system/flatbuffers``)
- ``CONFIG_MATH_GEMMLOWP`` — gemmlowp (``apps/math/gemmlowp``)
- ``CONFIG_MATH_KISSFFT`` — KissFFT (``apps/math/kissfft``)
- ``CONFIG_MATH_RUY`` — Ruy (``apps/math/ruy``)
- ``CONFIG_SYSTEM_FLATBUFFERS`` — FlatBuffers headers
(:doc:`../../system/flatbuffers/index`)
- ``CONFIG_MATH_GEMMLOWP`` — gemmlowp
(:doc:`../../math/gemmlowp/index`)
- ``CONFIG_MATH_KISSFFT`` — KissFFT
(:doc:`../../math/kissfft/index`)
- ``CONFIG_MATH_RUY`` — Ruy
(:doc:`../../math/ruy/index`)

TFLM is C++, so the configuration also needs C++ support (``CONFIG_HAVE_CXX``
and a C++ standard library such as ``CONFIG_LIBCXX``).
Expand Down Expand Up @@ -95,10 +100,12 @@ unpacked tree under ``apps/mlearning/tflite-micro/tflite-micro``.
Using the ``tflm`` tool
=======================

``tflm`` loads a ``.tflite`` file from the filesystem, constructs a
``tflite::MicroInterpreter``, calls ``AllocateTensors()``, and can invoke
the model once for profiling or emit compiled C++ (when TFLM was built
with ``TFLITE_MODEL_COMPILER``).
``tflm`` is a host-oriented NSH helper for ``sim:tflm``. It loads a
``.tflite`` file from the filesystem with ``ifstream``, allocates the
tensor arena with ``new``, constructs a ``tflite::MicroInterpreter``,
and calls ``AllocateTensors()``. That heap-and-filesystem path is
intentional on the simulator. On-target applications should embed the
model as a C array; see *Embedding a model in an application* below.

.. code-block:: console

Expand All @@ -116,10 +123,16 @@ with ``TFLITE_MODEL_COMPILER``).
``-i`` is required. ``-o`` is required only with ``-C``. Defaults are
prefix ``NXAI`` and arena size 8192 bytes.

The built-in operator resolver registers eight generic (float and
``-C`` appears in the help text but is not functional in NuttX builds.
Model compilation requires ``TFLITE_MODEL_COMPILER``, which neither the
Makefile nor the CMake integration defines. ``tflm -C`` prints
``Not supported compiling``.

The built-in operator resolver registers nine generic (float and
quantized) ops:

- ``CONV_2D``
- ``DEPTHWISE_CONV_2D``
- ``MAX_POOL_2D``
- ``QUANTIZE``
- ``DEQUANTIZE``
Expand Down Expand Up @@ -184,17 +197,19 @@ and the NuttX apps tree next to ``nuttx`` (``../apps`` or
nsh> tflm -E -i /path/to/model.tflite -a 8192

The tool fails with ``AllocateTensors failed`` if the arena is too
small or the model uses operators outside the eight registered ops.
small or the model uses operators outside the nine registered ops.

CMake is equivalent: ``cmake -B build -DBOARD_CONFIG=sim:tflm -GNinja``
then ``cmake --build build`` and ``./build/nuttx``.

Embedding a model in an application
===================================

TFLM is designed for targets without a filesystem and without dynamic
allocation for the model itself. Typical NuttX applications compile the
``.tflite`` file into a C array and pass it to ``tflite::GetModel()``.
The TFLM library is designed for targets without a filesystem and
without dynamic allocation for the model itself. The ``tflm`` NSH tool
is an exception used on ``sim:tflm``. Typical on-target applications
compile the ``.tflite`` file into a C array and pass it to
``tflite::GetModel()``.

The CMake helper ``tflite_generate_data()`` in
``apps/mlearning/tflite-micro/CMakeLists.txt`` wraps ``xxd -i`` for that
Expand Down
13 changes: 13 additions & 0 deletions Documentation/applications/system/flatbuffers/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=============================
``flatbuffers`` FlatBuffers
=============================

``apps/system/flatbuffers`` vendors Google `FlatBuffers
<https://github.com/google/flatbuffers>`_ ``v23.5.26`` and applies
``flatbuffers.patch``. TensorFlow Lite Micro uses the headers to read
``.tflite`` model schemas.

Enable ``CONFIG_SYSTEM_FLATBUFFERS``. Include path:
``apps/system/flatbuffers/flatbuffers/include``.

:doc:`../../mlearning/tflite-micro/index` depends on this package.
22 changes: 22 additions & 0 deletions Documentation/components/drivers/character/aie.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
========================
AI Engine (AIE) Drivers
========================

``drivers/aie`` is an upper-half character driver for hardware neural
processing units. Enable ``CONFIG_AI_ENGINE``. There is no in-tree
lower-half or board configuration yet; a platform must implement
``struct aie_ops_s`` and call ``aie_register()``.

The public header is ``include/nuttx/aie/ai_engine.h``. Ioctl commands:

- ``AIE_CMD_LOAD`` — load a model. The argument is a model pointer
passed to ``ops->init()``. A second load on the same file returns
``-EINVAL``.
- ``AIE_CMD_FEED_INPUT`` — feed one input tensor via ``ops->feed_input()``.
- ``AIE_CMD_GET_OUTPUT`` — read one output tensor via ``ops->get_output()``.

Other ioctl numbers are forwarded to ``ops->control()`` when that
callback is provided, otherwise ``-ENOSYS``.

This kernel driver is independent of the application-level TinyML
packages under :doc:`/applications/mlearning/index`.
1 change: 1 addition & 0 deletions Documentation/components/drivers/character/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Character device drivers have these properties:
:maxdepth: 2

1wire.rst
aie.rst
analog/index.rst
bch.rst
can.rst
Expand Down
5 changes: 5 additions & 0 deletions Documentation/components/drivers/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ Subdirectories of ``nuttx/drivers``

1wire device drivers.

* ``aie/`` :doc:`character/aie`

Upper-half character driver for hardware AI / NPU engines.
See ``include/nuttx/aie/ai_engine.h``.

* ``analog/`` :doc:`character/analog/index`

This directory holds implementations of analog device drivers.
Expand Down
25 changes: 25 additions & 0 deletions drivers/aie/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ##############################################################################
# drivers/aie/CMakeLists.txt
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################

if(CONFIG_AI_ENGINE)
target_sources(drivers PRIVATE ai_engine.c)
endif()
5 changes: 4 additions & 1 deletion drivers/aie/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ config AI_ENGINE
bool "AI Engine Acceleration Support"
default n
---help---
Drivers for various AI engine devices.
Upper-half character driver for hardware AI / NPU engines.
A board or architecture lower-half must implement struct
aie_ops_s and call aie_register(). There is no in-tree
lower-half yet. See include/nuttx/aie/ai_engine.h.
6 changes: 4 additions & 2 deletions include/nuttx/aie/ai_engine.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/****************************************************************************
* include/nuttx/aie/ai_engine.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
Expand Down Expand Up @@ -85,10 +87,10 @@ struct aie_lowerhalf_s
****************************************************************************/

/****************************************************************************
* Name: ai_engine_register
* Name: aie_register
*
* Description:
* Register all ai engine related drivers.
* Register an AI engine character driver at path.
*
****************************************************************************/

Expand Down
Loading