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
75 changes: 75 additions & 0 deletions scripts/tensorflow-clone.sh
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."
3 changes: 3 additions & 0 deletions src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ if(NOT CONFIG_COMP_MODULE_SHARED_LIBRARY_BUILD)
if(CONFIG_COMP_VOLUME)
add_subdirectory(volume)
endif()
if(CONFIG_COMP_TENSORFLOW)
add_subdirectory(tensorflow)
endif()
if(CONFIG_DTS_CODEC)
add_subdirectory(codec)
endif()
Expand Down
2 changes: 2 additions & 0 deletions src/audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ rsource "asrc/Kconfig"

rsource "tdfb/Kconfig"

rsource "tensorflow/Kconfig"

config COMP_MODULE_ADAPTER
bool "Module adapter"
default y
Expand Down
465 changes: 465 additions & 0 deletions src/audio/tensorflow/CMakeLists.txt

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/audio/tensorflow/Kconfig
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.
34 changes: 34 additions & 0 deletions src/audio/tensorflow/README.md
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
Copy link
Collaborator

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.

```

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.
78 changes: 78 additions & 0 deletions src/audio/tensorflow/llext-wrap.c
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
Loading
Loading