-
Notifications
You must be signed in to change notification settings - Fork 349
staging: Add tensorflow micro module. #9938
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| #!/bin/bash | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # Copyright(c) 2025 Intel Corporation. All rights reserved. | ||
|
|
||
| # fail immediately on any errors | ||
| set -e | ||
|
|
||
| # Array of TFLM Git repository URLs. Add or remove repositories as needed. | ||
| declare -a REPOS=( | ||
| "https://github.com/thesofproject/nnlib-hifi4" | ||
| "https://github.com/tensorflow/tflite-micro" | ||
| "https://github.com/thesofproject/flatbuffers" | ||
| "https://github.com/google/gemmlowp" | ||
| "https://github.com/google/ruy" | ||
| ) | ||
|
|
||
| # Commit ID to check for (optional). If specified, the script will update | ||
| # the repository if this commit ID is not found. Leave empty to skip. | ||
| declare -a COMMIT_ID=( | ||
| "cdedfb1a1044eb774915de21b63a1b6aa93276f6" | ||
| "e86d97b6237f88ab5925c0b41e3e3589a1560d86" | ||
| "f5acabf4e1a3fcba024081bb1871a2ed59aa1c28" | ||
| "719139ce755a0f31cbf1c37f7f98adcc7fc9f425" | ||
| "d37128311b445e758136b8602d1bbd2a755e115d" | ||
| ) | ||
|
|
||
| # Directory where repositories will be cloned/updated. | ||
| BASE_DIR="$HOME/work/sof" # Or any other desired location | ||
|
|
||
| # Function to check if a commit ID exists in a repository | ||
| check_commit() { | ||
| local repo_dir="$1" | ||
| local commit_id="$2" | ||
|
|
||
| if [ -z "$commit_id" ]; then | ||
| return 0 # Skip check if no commit ID is provided | ||
| fi | ||
|
|
||
| if ! git -C "$repo_dir" rev-parse --quiet --verify "$commit_id" >/dev/null 2>&1; then | ||
| return 1 # Commit ID not found | ||
| else | ||
| return 0 # Commit ID found | ||
| fi | ||
| } | ||
|
|
||
|
|
||
| # Function to update the repository | ||
| update_repo() { | ||
| local repo_dir="$1" | ||
| echo "Updating repository: $repo_dir" | ||
| git -C "$repo_dir" fetch --all | ||
| git -C "$repo_dir" pull | ||
| } | ||
|
|
||
| # Main script logic | ||
| mkdir -p "$BASE_DIR" | ||
|
|
||
| for ((i = 0; i < ${#REPOS[@]}; i++)); do | ||
| echo "Counter: $i, Value: ${REPOS[i]}" | ||
| repo_url=${REPOS[i]} | ||
|
|
||
| repo_name=$(basename "$repo_url" .git) # Extract repo name | ||
| repo_dir="$BASE_DIR/$repo_name" | ||
|
|
||
| if [ ! -d "$repo_dir" ]; then | ||
| echo "Cloning repository: $repo_url" | ||
| git clone "$repo_url" "$repo_dir" || { echo "git clone failed for $repo_url"; exit 1; } | ||
| elif ! check_commit "$repo_dir" "${COMMIT_ID[i]}"; then | ||
| update_repo "$repo_dir" | ||
| else | ||
| echo "Repository $repo_name is up to date." | ||
| fi | ||
| done | ||
|
|
||
| echo "All repositories processed." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| config COMP_TENSORFLOW | ||
| tristate "Tensorflow Micro component" | ||
| default n | ||
| depends on SOF_STAGING | ||
| depends on CPP | ||
| depends on STD_CPP17 | ||
| help | ||
| Select for Tensorflow component support. This module supports | ||
| Tensorflow Micro library. It is used for running machine learning | ||
| models on DSP. It is a lightweight version of Tensorflow library | ||
| designed for microcontrollers and embedded systems. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # SOF Tensorflow Micro Integration | ||
|
|
||
| The TFLM module integrates tensorflow micro into SOF as an audio classifiction and in the future an audio processing module. This module is currently still work in progress, and needs a few features to be completed before its ready for production. | ||
|
|
||
| ## Building | ||
|
|
||
| Please run ```./scripts/tensorflow-clone.sh``` before building as this will clone all dependencies required to build tensor flow micro with optimized xtensa kernels. | ||
|
|
||
| Please select the following in Kconfig | ||
| ``` | ||
| CONFIG_CPP=y | ||
| CONFIG_STD_CPP17=y | ||
| CONFIG_SOF_STAGING=y | ||
| ``` | ||
|
|
||
| To build as built-in, select ```CONFIG_COMP_TENSORFLOW=y``` in Kconfig and build. | ||
|
|
||
| To build as a llext module, select ```CONFIG_COMP_TENSORFLOW=m``` in Kconfig and the build. | ||
|
|
||
| ## Running | ||
|
|
||
| The TFLM SOF module needs features created by the MFCC module as its input. This step is still in progress. The following pipeline will be used | ||
|
|
||
| ``` Mic --> MFCC --> TFLM --> Classification ``` | ||
|
|
||
| ## TODO | ||
|
|
||
| 1) Create MFCC pipeline and align with TFLM micro_speech audio feature extraction configuration. | ||
|
|
||
| 2) Support compressed output PCM with Classification results. | ||
|
|
||
| 3) Load tflite models via binary kcontrol. | ||
|
|
||
| 4) Support audio processing via TFLM module. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // | ||
| // Copyright(c) 2025 Intel Corporation. All rights reserved. | ||
|
|
||
| #include <stdint.h> | ||
| #include <errno.h> | ||
| #include <assert.h> | ||
| #include <rtos/symbol.h> | ||
|
|
||
| /* | ||
| * Stubs that are needed for linkage of some applications or libraries | ||
| * that come from porting userspace code. Anyone porting should | ||
| * make sure that any code does not depend on working copies of these | ||
| * reentrant functions. We will fail for any caller. | ||
| */ | ||
|
|
||
| struct stat; | ||
| struct _reent; | ||
|
|
||
| size_t _read_r(struct _reent *ptr, int fd, char *buf, size_t cnt) | ||
| { | ||
| errno = -ENOTSUP; | ||
| return -ENOTSUP; | ||
| } | ||
|
|
||
| size_t _write_r(struct _reent *ptr, int fd, char *buf, size_t cnt) | ||
| { | ||
| errno = -ENOTSUP; | ||
| return -ENOTSUP; | ||
| } | ||
|
|
||
| void *_sbrk_r(struct _reent *ptr, ptrdiff_t incr) | ||
| { | ||
| errno = -ENOTSUP; | ||
| return NULL; | ||
| } | ||
|
|
||
| int _lseek_r(struct _reent *ptr, int fd, int pos, int whence) | ||
| { | ||
| errno = -ENOTSUP; | ||
| return -ENOTSUP; | ||
| } | ||
|
|
||
| int _kill_r(struct _reent *ptr, int pid, int sig) | ||
| { | ||
| errno = -ENOTSUP; | ||
| return -ENOTSUP; | ||
| } | ||
|
|
||
| int _getpid_r(struct _reent *ptr) | ||
| { | ||
| errno = -ENOTSUP; | ||
| return -ENOTSUP; | ||
| } | ||
|
|
||
| int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat) | ||
| { | ||
| errno = -ENOTSUP; | ||
| return -ENOTSUP; | ||
| } | ||
|
|
||
| int _close_r(struct _reent *ptr, int fd) | ||
| { | ||
| errno = -ENOTSUP; | ||
| return -ENOTSUP; | ||
| } | ||
|
|
||
| /* TFLM needs exit if build as a llext module only atm */ | ||
| #if CONFIG_COMP_TENSORFLOW == m | ||
| void _exit(int status) | ||
| { | ||
| assert(0); | ||
| while (1) { | ||
| /* spin forever */ | ||
| } | ||
| /* NOTREACHED */ | ||
| } | ||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be an overlay alike sof/app/shell_overlay.conf or sof/app/perf_overlay.conf.