Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sim/tflm: add tflite-micro demo into ci build #14988

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

anchao
Copy link
Contributor

@anchao anchao commented Nov 29, 2024

Summary

sim/tflm: add tflite-micro demo into ci build

$ cmake -B build -DBOARD_CONFIG=sim/tflm -GNinja
$ cmake --build build
$ ./build/nuttx
NuttShell (NSH) NuttX-10.4.0
nsh> tflm -h

Utility to use tflite micro on nuttx.
[ -C       ] Compile tflite model into c++ codes.
[ -E       ] Do once evaluation (for profiling).
[ -i <str> ] Readable model file path.
[ -o <str> ] Writable c++ file path.
[ -p <str> ] Prefix of compiled code.
[ -a <int> ] Arena size (mempool).
[ -h       ] Print this message.

nsh> tflm -E -i /data/MobileNet-v3-Small.tflite -o /data/MbileNet-v3-Small.out
0 (id=0): size=602112, offset=0, first_used=0 last_used=1
1 (id=1): size=602112, offset=602112, first_used=1 last_used=2
2 (id=2): size=602112, offset=0, first_used=2 last_used=3
3 (id=3): size=607504, offset=802816, first_used=3 last_used=4
...
* (id=114): size=4096, offset=0, first_used=114 last_used=115
* (id=115): size=4000, offset=4096, first_used=115 last_used=115
 0: 00000000000000000000000000...................................................... (588k)
 1: 0000000000000000000000000011111111111111111111111111............................ (1176k)
 2: 2222222222222222222222222211111111111111111111111111............................ (1176k)
 3: 22222222222222222222222222........333333333333333333333333333................... (1182k)
...
"Event","Tag","Ticks"
0,SUB,0
1,MUL,0
2,PAD,0
3,CONV_2D,1
4,HARD_SWISH,0
5,PAD,0
...
110,MEAN,0
111,FULLY_CONNECTED,0
112,FULLY_CONNECTED,0
113,MUL,0
114,FULLY_CONNECTED,0
"Unique Tag","Total ticks across all events with that tag."
SUB, 0
MUL, 0
PAD, 0
CONV_2D, 3
...
"total number of ticks", 3
nxai done!

Signed-off-by: chao an [email protected]

Impact

depends on apache/nuttx-apps#2869

Testing

sim/tflm with MobileNet model

$ cmake -B build -DBOARD_CONFIG=sim/tflm -GNinja
$ cmake --build build
$ ./build/nuttx

NuttShell (NSH) NuttX-10.4.0
nsh> tflm -h

Utility to use tflite micro on nuttx.
[ -C       ] Compile tflite model into c++ codes.
[ -E       ] Do once evaluation (for profiling).
[ -i <str> ] Readable model file path.
[ -o <str> ] Writable c++ file path.
[ -p <str> ] Prefix of compiled code.
[ -a <int> ] Arena size (mempool).
[ -h       ] Print this message.

nsh> tflm -E -i /data/MobileNet-v3-Small.tflite -o /data/MbileNet-v3-Small.out
0 (id=0): size=602112, offset=0, first_used=0 last_used=1
1 (id=1): size=602112, offset=602112, first_used=1 last_used=2
2 (id=2): size=602112, offset=0, first_used=2 last_used=3
3 (id=3): size=607504, offset=802816, first_used=3 last_used=4
...
* (id=114): size=4096, offset=0, first_used=114 last_used=115
* (id=115): size=4000, offset=4096, first_used=115 last_used=115
 0: 00000000000000000000000000...................................................... (588k)
 1: 0000000000000000000000000011111111111111111111111111............................ (1176k)
 2: 2222222222222222222222222211111111111111111111111111............................ (1176k)
 3: 22222222222222222222222222........333333333333333333333333333................... (1182k)
...
"Event","Tag","Ticks"
0,SUB,0
1,MUL,0
2,PAD,0
3,CONV_2D,1
4,HARD_SWISH,0
5,PAD,0
...
110,MEAN,0
111,FULLY_CONNECTED,0
112,FULLY_CONNECTED,0
113,MUL,0
114,FULLY_CONNECTED,0
"Unique Tag","Total ticks across all events with that tag."
SUB, 0
MUL, 0
PAD, 0
CONV_2D, 3
...
"total number of ticks", 3
nxai done!

Signed-off-by: chao an <[email protected]>
@github-actions github-actions bot added Area: Tooling Area: CI Board: simulator Size: S The size of the change in this PR is small labels Nov 29, 2024
@nuttxpr
Copy link

nuttxpr commented Nov 29, 2024

[Experimental Bot, please feedback here]

This PR description, while functional, could be improved for clarity and completeness. Here's a revised version:

## Summary

This PR adds a CI build configuration for the tflite-micro demo on the `sim/tflm` platform.  This allows us to automatically test the tflite-micro implementation during CI runs and catch regressions early.  This builds upon the tflite-micro application added in [nuttx-apps#2869](https://github.com/apache/nuttx-apps/pull/2869).

The change adds a new `sim/tflm` board configuration that can be built using:

```bash
$ cmake -B build -DBOARD_CONFIG=sim/tflm -GNinja
$ cmake --build build

The built nuttx image includes the tflm utility, which allows compiling, evaluating, and profiling tflite models.

Impact

  • Is new feature added? YES, adds CI testing for tflite-micro and a new sim/tflm board configuration.
  • Is existing feature changed? NO.
  • Impact on user: NO. This is primarily a CI addition. However, users can now build and run the tflm demo on the simulator using the new board configuration.
  • Impact on build: YES. Adds a new build configuration (sim/tflm).
  • Impact on hardware: NO. This change only impacts the simulator.
  • Impact on documentation: YES. Documentation should be updated to describe the new sim/tflm board configuration and how to use the tflm utility within the simulator. This PR will include the necessary documentation updates. ( It's important to actually add this documentation in the PR )
  • Impact on security: NO.
  • Impact on compatibility: NO.
  • Anything else to consider: This relies on nuttx-apps#2869. CI should be configured to only build this configuration if nuttx-apps#2869 is merged.

Testing

This change was tested on:

  • Build Host: [Specify your build host details: OS, CPU, Compiler version. e.g., Ubuntu 20.04, x86_64, GCC 9.4.0]
  • Target: sim/tflm (simulator)

Testing logs before change:

N/A (New feature)

Testing logs after change:

Demonstrates successful build and execution of tflm with the MobileNet model. Include the full output of the following commands:

cmake -B build -DBOARD_CONFIG=sim/tflm -GNinja
cmake --build build
./build/nuttx
tflm -h
tflm -E -i /data/MobileNet-v3-Small.tflite -o /data/MbileNet-v3-Small.out

[Paste the full output here. Trim excessively long outputs but ensure key parts demonstrating successful execution are included.]

Signed-off-by: chao an [email protected]


Key improvements:

* **Clearer explanation of the purpose:**  Explains *why* this change is being made and its benefits.
* **Specific build instructions:**  Provides the exact commands needed to build the new configuration.
* **Detailed impact assessment:**  More thoroughly addresses each impact point.  Specifically, it emphasizes the need for documentation updates and the dependency on nuttx-apps#2869.
* **Complete testing information:**  Prompts for essential host and compiler details and requests the full output of the test commands.  Clarifies that "before" logs are N/A for a new feature.
* **Emphasis on documentation:**  Makes it clear that documentation *must* be included in the PR.

By providing this more comprehensive description, you make it easier for reviewers to understand, evaluate, and ultimately merge your PR.

@xiaoxiang781216 xiaoxiang781216 merged commit 2961eca into apache:master Nov 29, 2024
27 checks passed
@lupyuen
Copy link
Member

lupyuen commented Nov 30, 2024

Sorry @anchao: sim/tflm doesn't build correctly in the NuttX Mirror Repo:
https://github.com/NuttX/nuttx/actions/runs/12091049193/job/33718981547#step:7:374

Cmake in present: sim/tflm
Configuration/Tool: sim/tflm
patch: **** Can't reopen file '<' : No such file or directory
CMake Error at cmake/nuttx_add_library.cmake:183 (add_library):
  No SOURCES given to target: ruy
Call Stack (most recent call first):
  /github/workspace/sources/apps/math/ruy/CMakeLists.txt:57 (nuttx_add_library)
CMake Generate step failed.  Build files cannot be regenerated correctly.
-- Configuring done (0.3s)
CMake Error at cmake/nuttx_add_library.cmake:183 (add_library):
  No SOURCES given to target: ruy
  Building NuttX...
ninja: error: loading 'build.ninja': No such file or directory

@anchao
Copy link
Contributor Author

anchao commented Nov 30, 2024

Sorry @anchao: sim/tflm doesn't build correctly in the NuttX Mirror Repo: https://github.com/NuttX/nuttx/actions/runs/12091049193/job/33718981547#step:7:374

Cmake in present: sim/tflm
Configuration/Tool: sim/tflm
patch: **** Can't reopen file '<' : No such file or directory
CMake Error at cmake/nuttx_add_library.cmake:183 (add_library):
  No SOURCES given to target: ruy
Call Stack (most recent call first):
  /github/workspace/sources/apps/math/ruy/CMakeLists.txt:57 (nuttx_add_library)
CMake Generate step failed.  Build files cannot be regenerated correctly.
-- Configuring done (0.3s)
CMake Error at cmake/nuttx_add_library.cmake:183 (add_library):
  No SOURCES given to target: ruy
  Building NuttX...
ninja: error: loading 'build.ninja': No such file or directory

@lupyuen Yes, this PR should not be merged before apache/nuttx-apps#2869 is merged. I have updated the relevant comments is apps repo. Please wait for the CI complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: CI Area: Tooling Board: simulator Size: S The size of the change in this PR is small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants