Skip to content

Commit

Permalink
Merge pull request #17 from anira-project/refine-bela-support
Browse files Browse the repository at this point in the history
Bela examples in separate repo; bugfixes
  • Loading branch information
faressc authored Dec 6, 2024
2 parents 5ee903d + 3595853 commit 9f320fb
Show file tree
Hide file tree
Showing 50 changed files with 50 additions and 620 deletions.
19 changes: 15 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ cmake_minimum_required(VERSION 3.15)
# Shall the library be built as a shared library?
option(BUILD_SHARED_LIBS "Build the library as a shared library" ON)
option(ANIRA_WITH_BENCHMARK "Build the library with benchmarking capabilities" OFF)
option(ANIRA_WITH_EXAMPLES "Add Example Targets for desktop plattforms (juce plugin, benchmarks, minimal inference and model examples)" OFF)
option(ANIRA_WITH_BELA_EXAMPLE "Add Example Targets for bela plattform (includes a model)" OFF)
option(ANIRA_WITH_EXAMPLES "Add example targets (juce plugin, benchmarks, minimal inference and model examples)" OFF)
option(ANIRA_WITH_INSTALL "Add install targets" OFF)
option(ANIRA_WITH_TESTS "Add Build Tests" OFF)

Expand Down Expand Up @@ -62,6 +61,14 @@ if(APPLE)
endif()
endif()

if(APPLE)
set(ANIRA_OPERATING_SYSTEM "macOS")
elseif(UNIX)
set(ANIRA_OPERATING_SYSTEM "Linux")
elseif(WIN32)
set(ANIRA_OPERATING_SYSTEM "Windows")
endif()

# Print the processor architecture selected for build. Defaults to CMAKE_HOST_SYSTEM_PROCESSOR when no crosscompile tolchain is defined. CMAKE_HOST_SYSTEM_PROCESSOR is only defined after the project() call. For OSX this value can be overwritten by the CMAKE_OSX_ARCHITECTURES.

message(STATUS "Building ${PROJECT_NAME} for ${CMAKE_SYSTEM_NAME} on ${CMAKE_SYSTEM_PROCESSOR}")
Expand Down Expand Up @@ -198,9 +205,13 @@ if(ANIRA_WITH_LIBTORCH)
# The find_package(Torch) adds the libraries libc10.so and libkineto.a as full paths to ${TORCH_LIBRARIES}. This is no problem when we add anira as a subdirectory to another project, but when we install the library, the torch libraries will be link targets of the anira library with full paths and hence not found on other systems. Therefore, we link those libs privately and only add the torch target publicly.
# Also until cmake 3.26, there is a bug where the torch_cpu library is not found when linking publicly https://gitlab.kitware.com/cmake/cmake/-/issues/24163 and anira is added as a subdirectory to another project, see
# But this is necessary for when we install the library since otherwise symbols are not found
# Another problem are that on armv7l with benchmarking enabled, some symbols are not found when linking the torch_cpu library privately
if (CMAKE_VERSION VERSION_LESS "3.26.0" AND NOT (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR))
target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES})
set(TORCH_LIBRARIES_ALL_PRIVATE TRUE)
if(UNIX AND NOT APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
target_link_libraries(${PROJECT_NAME} PUBLIC torch_cpu)
endif()
else()
foreach(TORCH_LIB ${TORCH_LIBRARIES})
if(TORCH_LIB STREQUAL "torch" OR TORCH_LIB STREQUAL "torch_library")
Expand Down Expand Up @@ -250,11 +261,11 @@ endif()
# ==============================================================================

# First we import the extras folder since we need the compile definitions (model paths) for the examples
if(ANIRA_WITH_EXAMPLES OR ANIRA_WITH_BELA_EXAMPLE OR ANIRA_WITH_TESTS)
if(ANIRA_WITH_EXAMPLES OR ANIRA_WITH_TESTS)
add_subdirectory(extras)
endif()

if(ANIRA_WITH_EXAMPLES OR ANIRA_WITH_BELA_EXAMPLE)
if(ANIRA_WITH_EXAMPLES)
add_subdirectory(examples)
endif()

Expand Down
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ Moreover, the following options are available:

- Build anira with benchmark capabilities: `-DANIRA_WITH_BENCHMARK=ON`
- Build example applications, plugins and populate example neural models: `-DANIRA_WITH_EXAMPLES=ON`
- Build a Bela example application: `-DANIRA_WITH_BELA_EXAMPLE=ON`
- Build anira with tests: `-DANIRA_WITH_TESTS=ON`

## Documentation
Expand All @@ -139,12 +138,10 @@ anira allows users to benchmark and compare the inference performance of differe

### Build in examples

- [Simple JUCE Audio Plugin](examples/desktop/juce-audio-plugin/): Demonstrates how to use anira in a real-time audio JUCE / VST3-Plugin.
- [CLAP Plugin Example](examples/desktop/clap-audio-plugin/): Demonstrates how to use anira in a real-time clap plugin.
- [Benchmark](examples/desktop/benchmark/): Demonstrates how to use anira for benchmarking of different neural network models, backends and audio configurations.
- [Minimal Inference](examples/desktop/minimal-inference/): Demonstrates how minimal inference applications can be implemented in all three backends.
- [Bela Example](examples/embedded/bela/bela-inference/): Demonstrates how to use anira in a real-time audio application on the Bela platform.
- [Bela Benchmark](examples/embedded/bela/bela-benchmark/): Demonstrates how to use anira for benchmarking on the Bela platform.
- [Simple JUCE Audio Plugin](examples/juce-audio-plugin/): Demonstrates how to use anira in a real-time audio JUCE / VST3-Plugin.
- [CLAP Plugin Example](examples/clap-audio-plugin/): Demonstrates how to use anira in a real-time clap plugin.
- [Benchmark](examples/benchmark/): Demonstrates how to use anira for benchmarking of different neural network models, backends and audio configurations.
- [Minimal Inference](examples/minimal-inference/): Demonstrates how minimal inference applications can be implemented in all three backends.

### Other examples

Expand Down
2 changes: 1 addition & 1 deletion cmake/SetupLibTorch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ else()
endif()

option(LIBTORCH_ROOTDIR "libtorch root dir")
set(LIBTORCH_DIR_NAME "libtorch-${LIBTORCH_VERSION}${TORCH_BUILD_TYPE}")
set(LIBTORCH_DIR_NAME "libtorch-${LIBTORCH_VERSION}${TORCH_BUILD_TYPE}-${ANIRA_OPERATING_SYSTEM}-${CMAKE_SYSTEM_PROCESSOR}")
set(LIBTORCH_ROOTDIR ${CMAKE_CURRENT_SOURCE_DIR}/modules/${LIBTORCH_DIR_NAME})

if(EXISTS ${LIBTORCH_ROOTDIR}/)
Expand Down
2 changes: 1 addition & 1 deletion cmake/SetupOnnxRuntime.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(LIBONNXRUNTIME_VERSION 1.19.2)

option(ONNXRUNTIME_ROOTDIR "onnxruntime root dir")
set(ONNXRUNTIME_DIR_NAME "onnxruntime-${LIBONNXRUNTIME_VERSION}")
set(ONNXRUNTIME_DIR_NAME "onnxruntime-${LIBONNXRUNTIME_VERSION}-${ANIRA_OPERATING_SYSTEM}-${CMAKE_SYSTEM_PROCESSOR}")
set(ONNXRUNTIME_ROOTDIR ${CMAKE_CURRENT_SOURCE_DIR}/modules/${ONNXRUNTIME_DIR_NAME})

if(EXISTS ${ONNXRUNTIME_ROOTDIR}/)
Expand Down
2 changes: 1 addition & 1 deletion cmake/SetupTensorflowLite.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ else()
endif()

option(TENSORFLOWLITE_ROOTDIR "tensorflowlite root dir")
set(TENSORFLOWLITE_DIR_NAME "tensorflowlite-${LIBTENSORFLOWLITE_VERSION}")
set(TENSORFLOWLITE_DIR_NAME "tensorflowlite-${LIBTENSORFLOWLITE_VERSION}-${ANIRA_OPERATING_SYSTEM}-${CMAKE_SYSTEM_PROCESSOR}")
set(TENSORFLOWLITE_ROOTDIR ${CMAKE_CURRENT_SOURCE_DIR}/modules/${TENSORFLOWLITE_DIR_NAME})

if(EXISTS ${TENSORFLOWLITE_ROOTDIR}/)
Expand Down
13 changes: 0 additions & 13 deletions cmake/Toolchain_Bela.cmake

This file was deleted.

12 changes: 9 additions & 3 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,15 @@ endif()

# the other ones don't have cmake config files so we have to install them manually
if(ANIRA_WITH_ONNXRUNTIME)
install(DIRECTORY "${ONNXRUNTIME_ROOTDIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
if(UNIX AND NOT APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
install(DIRECTORY "${ONNXRUNTIME_ROOTDIR}/include/onnxruntime/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
else()
install(DIRECTORY "${ONNXRUNTIME_ROOTDIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
endif()
install(DIRECTORY "${ONNXRUNTIME_ROOTDIR}/lib/"
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
Expand Down
23 changes: 18 additions & 5 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
if(ANIRA_WITH_EXAMPLES)
add_subdirectory(desktop)
elseif(ANIRA_WITH_BELA_EXAMPLE)
add_subdirectory(embedded/bela)
endif()
add_compile_definitions(
GUITARLSTM_MODELS_PATH_TENSORFLOW="${GUITARLSTM_MODELS_PATH_TENSORFLOW}"
GUITARLSTM_MODELS_PATH_PYTORCH="${GUITARLSTM_MODELS_PATH_PYTORCH}"
STEERABLENAFX_MODELS_PATH_TENSORFLOW="${STEERABLENAFX_MODELS_PATH_TENSORFLOW}"
STEERABLENAFX_MODELS_PATH_PYTORCH="${STEERABLENAFX_MODELS_PATH_PYTORCH}"
STATEFULLSTM_MODELS_PATH_TENSORFLOW="${STATEFULLSTM_MODELS_PATH_TENSORFLOW}"
STATEFULLSTM_MODELS_PATH_PYTORCH="${STATEFULLSTM_MODELS_PATH_PYTORCH}"
SIMPLEGAIN_MODEL_PATH="${SIMPLEGAIN_MODEL_PATH}"
)


if(ANIRA_WITH_BENCHMARK)
add_subdirectory(benchmark)
endif()

add_subdirectory(minimal-inference)
add_subdirectory(juce-audio-plugin)
add_subdirectory(clap-audio-plugin)
File renamed without changes.
File renamed without changes.
18 changes: 0 additions & 18 deletions examples/desktop/CMakeLists.txt

This file was deleted.

9 changes: 0 additions & 9 deletions examples/embedded/bela/CMakeLists.txt

This file was deleted.

30 changes: 0 additions & 30 deletions examples/embedded/bela/SimpleGainConfig.h

This file was deleted.

49 changes: 0 additions & 49 deletions examples/embedded/bela/bela-benchmark/CMakeLists.txt

This file was deleted.

26 changes: 0 additions & 26 deletions examples/embedded/bela/bela-benchmark/cmake/install.cmake

This file was deleted.

78 changes: 0 additions & 78 deletions examples/embedded/bela/bela-benchmark/defineBelaBenchmark.cpp

This file was deleted.

Loading

0 comments on commit 9f320fb

Please sign in to comment.