Skip to content
Open
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
152 changes: 69 additions & 83 deletions kleidiai-examples/audiogen/app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,114 +1,100 @@
#
# SPDX-FileCopyrightText: Copyright 2025 Arm Limited and/or its affiliates <open-source-office@arm.com>
# SPDX-FileCopyrightText: Copyright 2025-2026 Arm Limited and/or its affiliates <open-source-office@arm.com>
#
# SPDX-License-Identifier: Apache-2.0
#

cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.20)

project(audiogen_runner)

include(ExternalProject)
project(audiogen_runner LANGUAGES C CXX)

message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
message(STATUS "CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME}")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(CMAKE_TOOLCHAIN_FILE)
list(APPEND TOOLCHAIN_CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE})
endif()

if(ANDROID_ABI)
list(APPEND TOOLCHAIN_CMAKE_ARGS -DANDROID_ABI=${ANDROID_ABI})
endif()

if(NOT TF_SRC_PATH)
include(FetchContent)
include(FetchContent)

FetchContent_Declare(
tensorflow_src
GIT_REPOSITORY https://github.com/tensorflow/tensorflow.git
GIT_TAG 5baea41aa158ce6c3396726bd84fda5cd81737a0
)
FetchContent_Declare(
litert
GIT_REPOSITORY https://github.com/google-ai-edge/LiteRT.git
GIT_TAG c3eb2c5884c099206487d717e1782ba512ef2871
)

FetchContent_MakeAvailable(tensorflow_src)
FetchContent_GetProperties(litert)
if(NOT litert_POPULATED)
FetchContent_Populate(litert)
endif()

set(TENSORFLOW_SOURCE_DIR ${tensorflow_src_SOURCE_DIR} CACHE STRING "" FORCE)
# Disable GPU support before adding the LiteRT subdirectory.
set(LITERT_ENABLE_GPU OFF CACHE BOOL "Disable LiteRT GPU support")

else()
set(TENSORFLOW_SOURCE_DIR ${TF_SRC_PATH} CACHE STRING "" FORCE)
endif()
set(LITERT_SOURCE_DIR "${litert_SOURCE_DIR}")
set(LITERT_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/litert_build")

set(FLATBUFFERS_SOURCE_DIR ${TENSORFLOW_SOURCE_DIR}/tensorflow/lite/tools/cmake/native_tools/flatbuffers)
set(FLATBUFFERS_BIN_DIR ${CMAKE_BINARY_DIR}/flatbuffers-host-bin)
set(SENTENCEPIECE_SOURCE_DIR ${CMAKE_BINARY_DIR}/sentencepiece)

# Step 1: Build flatc ---
ExternalProject_Add(
flatc_build
PREFIX flatc
DOWNLOAD_COMMAND ""
SOURCE_DIR ${FLATBUFFERS_SOURCE_DIR}
BINARY_DIR ${FLATBUFFERS_BIN_DIR}
INSTALL_COMMAND ""
add_subdirectory(
"${LITERT_SOURCE_DIR}/litert"
"${LITERT_BUILD_DIR}"
EXCLUDE_FROM_ALL
)

# Step 2: Build SentencePiece ---
ExternalProject_Add(
sentencepiece_src
FetchContent_Declare(
sentencepiece
GIT_REPOSITORY https://github.com/google/sentencepiece.git
GIT_TAG v0.2.0
SOURCE_DIR ${SENTENCEPIECE_SOURCE_DIR}
CMAKE_ARGS
-DCMAKE_POLICY_VERSION_MINIMUM=3.5
${TOOLCHAIN_CMAKE_ARGS}
INSTALL_COMMAND ""
)

#Get the path to the sentencepiece lib
ExternalProject_Get_Property(sentencepiece_src BINARY_DIR)
set(SENTENCEPIECE_LIB ${BINARY_DIR}/src/libsentencepiece.a)

## Step 4: Build the audiogen app ---
# Define source
set(SRCS audiogen.cpp)

add_executable(audiogen ${SRCS})
FetchContent_MakeAvailable(sentencepiece)

set(XNNPACK_ENABLE_ARM_SME2 ON CACHE BOOL "" FORCE)
set(TFLITE_HOST_TOOLS_DIR "${FLATBUFFERS_BIN_DIR}/_deps/flatbuffers-build" CACHE PATH "Host tools directory")

# Because flatc is not available at configure time,
# this workaround places a placeholder (an empty file called flatc) at the expected install location.
file(WRITE ${FLATBUFFERS_BIN_DIR}/_deps/flatbuffers-build/flatc "")

# LiteRT CMake configure stage
add_subdirectory(
"${TENSORFLOW_SOURCE_DIR}/tensorflow/lite"
"${CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite"
EXCLUDE_FROM_ALL
add_executable(audiogen
audiogen.cpp
)

# Delete the placeholder flatc file after the LiteRT CMake configuration stage is complete.
file(REMOVE ${FLATBUFFERS_BIN_DIR}/_deps/flatbuffers-build/flatc "")

add_dependencies(tensorflow-lite flatc_build)


# Include headers
target_include_directories(audiogen PRIVATE
${TENSORFLOW_SOURCE_DIR}/tensorflow/lite
${SENTENCEPIECE_SOURCE_DIR}/src
target_include_directories(audiogen
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_BINARY_DIR}/include
${sentencepiece_SOURCE_DIR}/src
)

# Link with dependencies
target_link_libraries(audiogen
tensorflow-lite
${SENTENCEPIECE_LIB}
set(LITERT_LIBS
litert_c_api
litert_cc_api
litert_cc_internal
litert_cc_options
litert_compiler_plugin
litert_core
litert_core_model
litert_runtime
)

# Ensure dependency build order
add_dependencies(audiogen flatc_build sentencepiece_src)

set(LINK_GROUP_START "")
set(LINK_GROUP_END "")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND NOT APPLE)
set(LINK_GROUP_START "-Wl,--start-group")
set(LINK_GROUP_END "-Wl,--end-group")
endif()

target_link_libraries(audiogen
PRIVATE
${LINK_GROUP_START}

absl::die_if_null
absl::flags
absl::flags_parse
absl::log
absl::log_internal_check_op
absl::log_internal_message
absl::string_view
absl::span
absl::status
absl::statusor

${LITERT_LIBS}
tensorflow-lite
sentencepiece-static

${LINK_GROUP_END}
)
26 changes: 7 additions & 19 deletions kleidiai-examples/audiogen/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,15 @@ export LITERT_MODELS_PATH=<path_to_your_litert_models>
```

#### Step 2
Build the audiogen application. Inside the `app` directory, create the `build` folder and navigate into it:
Build the audiogen application from the `app` directory using CMake:

```bash
mkdir build && cd build
```

Next, run CMake using the following command:

```bash
cmake ..
CMAKE_BUILD_PARALLEL_LEVEL=4 cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -S . -B build
```

Then, build the application:
```bash
make -j
cmake --build build --parallel 4
```

#### Step 3
Expand Down Expand Up @@ -104,21 +98,15 @@ export NDK_PATH=$(pwd)/android-ndk-r27c

#### Step 3

Build the audiogen application. Inside the `app` directory, create the `build` folder and navigate into it:

```bash
mkdir build && cd build
```

Next, run CMake using the following command:
Build the audiogen application from the `app` directory using CMake:

```bash
cmake -DCMAKE_TOOLCHAIN_FILE=$NDK_PATH/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a ..
CMAKE_BUILD_PARALLEL_LEVEL=4 cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_TOOLCHAIN_FILE="$NDK_PATH/build/cmake/android.toolchain.cmake" -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-26 -S . -B build
```

Then, build the application:
```bash
make -j
cmake --build build --parallel 4
```
#### Step 4
At this point, you are ready to push the binaries to your Android™ device and run the audiogen application. To do so, use the `adb` tool to push all necessary files into `/data/local/tmp/app`
Expand Down Expand Up @@ -190,4 +178,4 @@ Usage:
```

- **input_audio_path (-i)**: Add input audio file for style transfer
- **sigma_max (-x)**: A hyper parameter to tweak noise level
- **sigma_max (-x)**: A hyper parameter to tweak noise level
Loading