Skip to content

Commit

Permalink
Merge pull request #15 from anira-project/refine-bela-support
Browse files Browse the repository at this point in the history
Benchmarks now part of test suite and full armv7l support
  • Loading branch information
faressc authored Dec 5, 2024
2 parents 76ff777 + f1b74d2 commit 5ee903d
Show file tree
Hide file tree
Showing 42 changed files with 332 additions and 210 deletions.
19 changes: 16 additions & 3 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
CMAKE_BUILD_ARGS:
required: true
description: "The cmake build arguments"
TARGETS:
required: false
description: "The targets to build"

runs:
using: "composite"
Expand Down Expand Up @@ -42,8 +45,18 @@ runs:
echo "Unknown OS";
fi;
# Build the project
- name: cmake build
- name: build targets
shell: bash
run: cmake --build build --config ${{ inputs.BUILD_TYPE }} --parallel ${{ inputs.CMAKE_BUILD_PARALLEL_LEVEL }}
run: |
TARGETS=${{ inputs.TARGETS }}
if [ -n "${TARGETS}" ]; then
for target in ${TARGETS[@]}; do
echo "Building target: $target"
cmake --build build --config ${{ inputs.BUILD_TYPE }} --parallel ${{ inputs.CMAKE_BUILD_PARALLEL_LEVEL }} --target $target
done
else
echo "Building all targets"
cmake --build build --config ${{ inputs.BUILD_TYPE }} --parallel ${{ inputs.CMAKE_BUILD_PARALLEL_LEVEL }}
fi
59 changes: 59 additions & 0 deletions .github/workflows/build_benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: build_benchmark

on:
workflow_call:
workflow_dispatch: # lets you run a build from github.com
# Runs the workflow on all push events
pull_request:
branches:
- main
- develop

env:
SCCACHE_GHA_ENABLED: "true"

# When pushing new commits, cancel any workflows with the same name on that branch
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build_test:
name: ${{ matrix.name }}
strategy:
fail-fast: false # show all errors for each platform (vs. cancel jobs on error)
matrix:
include:
- name: Linux-x86_64
os: ubuntu-latest
- name: macOS-x86_64
os: macOS-latest
- name: macOS-arm64
os: macOS-latest
- name: Windows-x86_64
os: windows-latest

runs-on: ${{ matrix.os }}
steps:
- name: get repo and submodules
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: setup
uses: ./.github/actions/setup
- name: add juce deps
shell: bash
run: |
if [ "${{ matrix.name }}" == "Linux-x86_64" ]; then
sudo apt install libxrandr-dev libxinerama-dev libxcursor-dev libfreetype6-dev libasound2-dev
fi
- name: build
uses: ./.github/actions/build
with:
BUILD_TYPE: Release
CMAKE_BUILD_PARALLEL_LEVEL: 4
TARGETS: (cnn-size-benchmark advanced-benchmark simple-benchmark)
CMAKE_BUILD_ARGS: "-DBUILD_SHARED_LIBS=ON -DANIRA_WITH_BENCHMARK=ON -DANIRA_WITH_EXAMPLES=ON"
- name: test
uses: ./.github/actions/test
4 changes: 2 additions & 2 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ on:
env:
SCCACHE_GHA_ENABLED: "true"

# When pushing new commits, cancel any running builds on that branch
# When pushing new commits, cancel any workflows with the same name on that branch
concurrency:
group: ${{ github.ref }}
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
Expand Down
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cmake-build*
logs/
results/
venv/
extras/desktop/models/stateful-rnn/stateful-lstm/
extras/desktop/models/hybrid-nn/GuitarLSTM/
extras/desktop/models/cnn/steerable-nafx/
extras/desktop/models/model-pool/example-models/
extras/models/stateful-rnn/stateful-lstm/
extras/models/hybrid-nn/GuitarLSTM/
extras/models/cnn/steerable-nafx/
extras/models/model-pool/example-models/
10 changes: 3 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ execute_process(COMMAND git describe --tags --abbrev=0
string(SUBSTRING ${PROJECT_VERSION_SHORT} 1 -1 PROJECT_VERSION_SHORT)
string(SUBSTRING ${PROJECT_VERSION_FULL} 1 -1 PROJECT_VERSION_FULL)

message(STATUS "Project version: ${PROJECT_VERSION_SHORT} (${PROJECT_VERSION_FULL})")

# ==============================================================================
# Setup the project
# ==============================================================================
Expand All @@ -65,7 +63,9 @@ if(APPLE)
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 "Selected processor architecture: ${CMAKE_SYSTEM_PROCESSOR}")

message(STATUS "Building ${PROJECT_NAME} for ${CMAKE_SYSTEM_NAME} on ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "Project version: ${PROJECT_VERSION_SHORT} (${PROJECT_VERSION_FULL})")

# Sets the minimum macOS version, c++20 is only available from macOS 11.0
if (APPLE)
Expand All @@ -82,10 +82,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
# Download and install the selected inference engines
# ==============================================================================

if(NOT ANIRA_WITH_LIBTORCH AND NOT ANIRA_WITH_ONNXRUNTIME AND NOT ANIRA_WITH_TFLITE)
message(FATAL_ERROR "No backend selected. Please select at least one backend by setting one of the following options to ON: ANIRA_WITH_LIBTORCH, ANIRA_WITH_ONNXRUNTIME, or ANIRA_WITH_TFLITE. For example, add '-DANIRA_WITH_LIBTORCH=ON' to your CMake command line.")
endif()

message(STATUS "Selected backends:")

set(BACKEND_SOURCES)
Expand Down
52 changes: 33 additions & 19 deletions cmake/SetupLibTorch.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# torch stopped uploading the binaries for macOS x86_64, but we use self-built binaries
set(LIBTORCH_VERSION 2.4.1)
if(UNIX AND NOT APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
set(LIBTORCH_VERSION 2.5.1)
else()
set(LIBTORCH_VERSION 2.4.1)
endif()

if (NOT WIN32)
set(TORCH_BUILD_TYPE "")
Expand Down Expand Up @@ -33,10 +37,14 @@ else()
if(UNIX AND NOT APPLE)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
set(LIB_LIBTORCH_PRE_BUILD_LIB_NAME "libtorch-${LIBTORCH_VERSION}-Linux-aarch64")
set(LIB_LIBTORCH_PRE_BUILD_LIB_TYPE "zip")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(LIB_LIBTORCH_PRE_BUILD_LIB_NAME "libtorch-${LIBTORCH_VERSION}-Linux-x86_64")
set(LIB_LIBTORCH_PRE_BUILD_LIB_TYPE "zip")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
set(LIB_LIBTORCH_PRE_BUILD_LIB_NAME "pytorch-v${LIBTORCH_VERSION}")
set(LIB_LIBTORCH_PRE_BUILD_LIB_TYPE "tar.gz")
endif()
set(LIB_LIBTORCH_PRE_BUILD_LIB_TYPE "zip")
endif()

if(UNIX AND APPLE)
Expand All @@ -48,12 +56,12 @@ else()
set(LIB_LIBTORCH_PRE_BUILD_LIB_TYPE "zip")
endif()

if (NOT DEFINED LIBTORCH_URL)
if(WIN32)
set(LIBTORCH_URL https://download.pytorch.org/libtorch/cpu/${LIB_LIBTORCH_PRE_BUILD_LIB_NAME}.${LIB_LIBTORCH_PRE_BUILD_LIB_TYPE})
else()
set(LIBTORCH_URL https://github.com/faressc/libtorch-cpp-lib/releases/download/v${LIBTORCH_VERSION}/${LIB_LIBTORCH_PRE_BUILD_LIB_NAME}.${LIB_LIBTORCH_PRE_BUILD_LIB_TYPE})
endif()
if(WIN32)
set(LIBTORCH_URL https://download.pytorch.org/libtorch/cpu/${LIB_LIBTORCH_PRE_BUILD_LIB_NAME}.${LIB_LIBTORCH_PRE_BUILD_LIB_TYPE})
elseif(UNIX AND NOT APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
set(LIBTORCH_URL https://github.com/pelinski/bela-torch/releases/download/v${LIBTORCH_VERSION}/${LIB_LIBTORCH_PRE_BUILD_LIB_NAME}.${LIB_LIBTORCH_PRE_BUILD_LIB_TYPE})
else()
set(LIBTORCH_URL https://github.com/faressc/libtorch-cpp-lib/releases/download/v${LIBTORCH_VERSION}/${LIB_LIBTORCH_PRE_BUILD_LIB_NAME}.${LIB_LIBTORCH_PRE_BUILD_LIB_TYPE})
endif()

message(STATUS "Downloading: ${LIBTORCH_URL}")
Expand All @@ -63,21 +71,27 @@ else()
file(DOWNLOAD ${LIBTORCH_URL} ${LIBTORCH_PATH} STATUS LIBTORCH_DOWNLOAD_STATUS SHOW_PROGRESS)
list(GET LIBTORCH_DOWNLOAD_STATUS 0 LIBTORCH_DOWNLOAD_STATUS_NO)

file(ARCHIVE_EXTRACT
INPUT ${CMAKE_BINARY_DIR}/import/${LIB_LIBTORCH_PRE_BUILD_LIB_NAME}.${LIB_LIBTORCH_PRE_BUILD_LIB_TYPE}
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/modules/libtorch-${LIBTORCH_VERSION}${TORCH_BUILD_TYPE}/)

if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/modules/libtorch-${LIBTORCH_VERSION}${TORCH_BUILD_TYPE}/libtorch)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/modules/libtorch-${LIBTORCH_VERSION}${TORCH_BUILD_TYPE}/libtorch/ DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/modules/libtorch-${LIBTORCH_VERSION}${TORCH_BUILD_TYPE}/)
file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/modules/libtorch-${LIBTORCH_VERSION}${TORCH_BUILD_TYPE}/libtorch/)
if(UNIX AND NOT APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
execute_process(
COMMAND tar -xzf ${LIBTORCH_PATH} -C ${LIBTORCH_ROOTDIR}/
WORKING_DIRECTORY ${LIBTORCH_ROOTDIR}/)
else()
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/modules/libtorch-${LIBTORCH_VERSION}${TORCH_BUILD_TYPE}/${LIB_LIBTORCH_PRE_BUILD_LIB_NAME}/ DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/modules/libtorch-${LIBTORCH_VERSION}${TORCH_BUILD_TYPE}/)
file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/modules/libtorch-${LIBTORCH_VERSION}${TORCH_BUILD_TYPE}/${LIB_LIBTORCH_PRE_BUILD_LIB_NAME}/)
file(ARCHIVE_EXTRACT
INPUT ${LIBTORCH_PATH}
DESTINATION ${LIBTORCH_ROOTDIR}/)
endif()

if(EXISTS ${LIBTORCH_ROOTDIR}/libtorch)
file(COPY ${LIBTORCH_ROOTDIR}/libtorch/ DESTINATION ${LIBTORCH_ROOTDIR}/)
file(REMOVE_RECURSE ${LIBTORCH_ROOTDIR}/libtorch/)
elseif(EXISTS ${LIBTORCH_ROOTDIR}/${LIB_LIBTORCH_PRE_BUILD_LIB_NAME})
file(COPY ${LIBTORCH_ROOTDIR}/${LIB_LIBTORCH_PRE_BUILD_LIB_NAME}/ DESTINATION ${LIBTORCH_ROOTDIR}/)
file(REMOVE_RECURSE ${LIBTORCH_ROOTDIR}/${LIB_LIBTORCH_PRE_BUILD_LIB_NAME}/)
endif()

if(LIBTORCH_DOWNLOAD_STATUS_NO)
message(STATUS "Pre-built library not downloaded. Error occurred, try again and check cmake/SetupLibTorch.cmake")
file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/modules/libtorch-${LIBTORCH_VERSION}${TORCH_BUILD_TYPE})
file(REMOVE_RECURSE ${LIBTORCH_ROOTDIR})
file(REMOVE ${LIBTORCH_PATH})
else()
message(STATUS "Linking downloaded LibTorch pre-built library.")
Expand All @@ -99,7 +113,7 @@ if (MSVC)
endif()
endif()

set(ANIRA_LIBTORCH_SHARED_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules/libtorch-${LIBTORCH_VERSION}${TORCH_BUILD_TYPE}/")
set(ANIRA_LIBTORCH_SHARED_LIB_PATH "${LIBTORCH_ROOTDIR}/")

get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
Expand Down
49 changes: 35 additions & 14 deletions cmake/SetupOnnxRuntime.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,70 @@ else()
if(UNIX AND NOT APPLE)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
set(LIB_ONNXRUNTIME_PRE_BUILD_LIB_NAME "onnxruntime-linux-aarch64-${LIBONNXRUNTIME_VERSION}")
set(LIB_ONNXRUNTIME_PRE_BUILD_LIB_TYPE "tgz")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(LIB_ONNXRUNTIME_PRE_BUILD_LIB_NAME "onnxruntime-linux-x64-${LIBONNXRUNTIME_VERSION}")
set(LIB_ONNXRUNTIME_PRE_BUILD_LIB_TYPE "tgz")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
set(LIB_ONNXRUNTIME_PRE_BUILD_LIB_NAME "onnxruntime-${LIBONNXRUNTIME_VERSION}-Linux-armv7l")
set(LIB_ONNXRUNTIME_PRE_BUILD_LIB_TYPE "tar.gz")
endif()
set(LIB_ONNXRUNTIME_PRE_BUILD_LIB_TYPE "tgz")
endif()

if(UNIX AND APPLE)
set(LIB_ONNXRUNTIME_PRE_BUILD_LIB_NAME "onnxruntime-osx-universal2-${LIBONNXRUNTIME_VERSION}")
set(LIB_ONNXRUNTIME_PRE_BUILD_LIB_TYPE "tgz")
endif()

set(LIBONNXRUNTIME_URL https://github.com/microsoft/onnxruntime/releases/download/v${LIBONNXRUNTIME_VERSION}/${LIB_ONNXRUNTIME_PRE_BUILD_LIB_NAME}.${LIB_ONNXRUNTIME_PRE_BUILD_LIB_TYPE})
set(LIBONNXRUNTIME_PATH ${CMAKE_BINARY_DIR}/import/${LIB_ONNXRUNTIME_PRE_BUILD_LIB_NAME}.${LIB_ONNXRUNTIME_PRE_BUILD_LIB_TYPE})

if(UNIX AND NOT APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
set(LIBONNXRUNTIME_URL https://github.com/faressc/onnxruntime-cpp-lib/releases/download/v${LIBONNXRUNTIME_VERSION}/${LIB_ONNXRUNTIME_PRE_BUILD_LIB_NAME}.${LIB_ONNXRUNTIME_PRE_BUILD_LIB_TYPE})
else()
set(LIBONNXRUNTIME_URL https://github.com/microsoft/onnxruntime/releases/download/v${LIBONNXRUNTIME_VERSION}/${LIB_ONNXRUNTIME_PRE_BUILD_LIB_NAME}.${LIB_ONNXRUNTIME_PRE_BUILD_LIB_TYPE})
endif()

message(STATUS "Downloading: ${LIBONNXRUNTIME_URL}")

set(LIBONNXRUNTIME_PATH ${CMAKE_BINARY_DIR}/import/${LIB_ONNXRUNTIME_PRE_BUILD_LIB_NAME}.${LIB_ONNXRUNTIME_PRE_BUILD_LIB_TYPE})

file(DOWNLOAD ${LIBONNXRUNTIME_URL} ${LIBONNXRUNTIME_PATH} STATUS LIBONNXRUNTIME_DOWNLOAD_STATUS SHOW_PROGRESS)
list(GET LIBONNXRUNTIME_DOWNLOAD_STATUS 0 LIBONNXRUNTIME_DOWNLOAD_STATUS_NO)

file(ARCHIVE_EXTRACT
INPUT ${CMAKE_BINARY_DIR}/import/${LIB_ONNXRUNTIME_PRE_BUILD_LIB_NAME}.${LIB_ONNXRUNTIME_PRE_BUILD_LIB_TYPE}
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/modules/onnxruntime-${LIBONNXRUNTIME_VERSION}/)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/modules/onnxruntime-${LIBONNXRUNTIME_VERSION}/${LIB_ONNXRUNTIME_PRE_BUILD_LIB_NAME}/ DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/modules/onnxruntime-${LIBONNXRUNTIME_VERSION}/)

file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/modules/onnxruntime-${LIBONNXRUNTIME_VERSION}/${LIB_ONNXRUNTIME_PRE_BUILD_LIB_NAME})
if(UNIX AND NOT APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
execute_process(
COMMAND tar -xzf ${LIBONNXRUNTIME_PATH} -C ${ONNXRUNTIME_ROOTDIR}/
WORKING_DIRECTORY ${ONNXRUNTIME_ROOTDIR}/)
else()
file(ARCHIVE_EXTRACT
INPUT ${LIBONNXRUNTIME_PATH}
DESTINATION ${ONNXRUNTIME_ROOTDIR}/)
endif()

if(EXISTS ${ONNXRUNTIME_ROOTDIR}/${LIB_ONNXRUNTIME_PRE_BUILD_LIB_NAME}/)
file(COPY ${ONNXRUNTIME_ROOTDIR}/${LIB_ONNXRUNTIME_PRE_BUILD_LIB_NAME}/ DESTINATION ${ONNXRUNTIME_ROOTDIR}/)
file(REMOVE_RECURSE ${ONNXRUNTIME_ROOTDIR}/${LIB_ONNXRUNTIME_PRE_BUILD_LIB_NAME})
endif()

if(LIBONNXRUNTIME_DOWNLOAD_STATUS_NO)
message(STATUS "Pre-built library not downloaded. Error occurred, try again and check cmake/SetupOnnxRuntime.cmake")
file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/modules/onnxruntime-${LIBONNXRUNTIME_VERSION})
file(REMOVE_RECURSE ${ONNXRUNTIME_ROOTDIR})
file(REMOVE ${LIBONNXRUNTIME_PATH})
else()
message(STATUS "Linking downloaded ONNX-Runtime pre-built library.")
endif()
endif()

set(ANIRA_ONNXRUNTIME_SHARED_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules/onnxruntime-${LIBONNXRUNTIME_VERSION}")
set(ANIRA_ONNXRUNTIME_SHARED_LIB_PATH "${ONNXRUNTIME_ROOTDIR}")

# Set the variable in the parent scope as well
get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
set(ANIRA_ONNXRUNTIME_SHARED_LIB_PATH "${ANIRA_ONNXRUNTIME_SHARED_LIB_PATH}" PARENT_SCOPE)
endif()

list(APPEND BACKEND_BUILD_HEADER_DIRS "${ONNXRUNTIME_ROOTDIR}/include")
if(UNIX AND NOT APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
list(APPEND BACKEND_BUILD_HEADER_DIRS "${ONNXRUNTIME_ROOTDIR}/include/onnxruntime")
else()
list(APPEND BACKEND_BUILD_HEADER_DIRS "${ONNXRUNTIME_ROOTDIR}/include")
endif()

list(APPEND BACKEND_BUILD_LIBRARY_DIRS "${ONNXRUNTIME_ROOTDIR}/lib")
21 changes: 13 additions & 8 deletions cmake/SetupTensorflowLite.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set(TENSORFLOWLITE_ROOTDIR ${CMAKE_CURRENT_SOURCE_DIR}/modules/${TENSORFLOWLITE_
if(EXISTS ${TENSORFLOWLITE_ROOTDIR}/)
message(STATUS "Tensorflow Lite library found at ${TENSORFLOWLITE_ROOTDIR}")
else()
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/modules/tensorflowlite-${LIBTENSORFLOWLITE_VERSION}/)
file(MAKE_DIRECTORY ${TENSORFLOWLITE_ROOTDIR}/)
message(STATUS "Tensorflow Lite library not found - downloading pre-built library.")

if(WIN32)
Expand All @@ -23,6 +23,8 @@ else()
set(LIB_TENSORFLOWLITE_PRE_BUILD_LIB_NAME "tensorflowlite_c-${LIBTENSORFLOWLITE_VERSION}-Linux-aarch64")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(LIB_TENSORFLOWLITE_PRE_BUILD_LIB_NAME "tensorflowlite_c-${LIBTENSORFLOWLITE_VERSION}-Linux-x86_64")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
set(LIB_TENSORFLOWLITE_PRE_BUILD_LIB_NAME "tensorflowlite_c-${LIBTENSORFLOWLITE_VERSION}-Linux-armv7l")
endif()
endif()

Expand All @@ -35,23 +37,26 @@ else()
endif()

set(LIBTENSORFLOWLITE_URL https://github.com/faressc/tflite-c-lib/releases/download/v${LIBTENSORFLOWLITE_VERSION}/${LIB_TENSORFLOWLITE_PRE_BUILD_LIB_NAME}.zip)

message(STATUS "Downloading ${LIBTENSORFLOWLITE_URL}")

set(LIBTENSORFLOWLITE_PATH ${CMAKE_BINARY_DIR}/import/${LIB_TENSORFLOWLITE_PRE_BUILD_LIB_NAME}.zip)

file(DOWNLOAD ${LIBTENSORFLOWLITE_URL} ${LIBTENSORFLOWLITE_PATH} STATUS LIBTENSORFLOWLITE_DOWNLOAD_STATUS SHOW_PROGRESS)
list(GET LIBTENSORFLOWLITE_DOWNLOAD_STATUS 0 LIBTENSORFLOWLITE_DOWNLOAD_STATUS_NO)

file(ARCHIVE_EXTRACT
INPUT ${CMAKE_BINARY_DIR}/import/${LIB_TENSORFLOWLITE_PRE_BUILD_LIB_NAME}.zip
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/modules/tensorflowlite-${LIBTENSORFLOWLITE_VERSION}/)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/modules/tensorflowlite-${LIBTENSORFLOWLITE_VERSION}/${LIB_TENSORFLOWLITE_PRE_BUILD_LIB_NAME}/ DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/modules/tensorflowlite-${LIBTENSORFLOWLITE_VERSION}/)
INPUT ${LIBTENSORFLOWLITE_PATH}
DESTINATION ${TENSORFLOWLITE_ROOTDIR}/)

file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/modules/tensorflowlite-${LIBTENSORFLOWLITE_VERSION}/${LIB_TENSORFLOWLITE_PRE_BUILD_LIB_NAME})
if(EXISTS ${TENSORFLOWLITE_ROOTDIR}/${LIB_TENSORFLOWLITE_PRE_BUILD_LIB_NAME}/)
file(COPY ${TENSORFLOWLITE_ROOTDIR}/${LIB_TENSORFLOWLITE_PRE_BUILD_LIB_NAME}/ DESTINATION ${TENSORFLOWLITE_ROOTDIR}/)
file(REMOVE_RECURSE ${TENSORFLOWLITE_ROOTDIR}/${LIB_TENSORFLOWLITE_PRE_BUILD_LIB_NAME})
endif()

if(LIBtensorflowlite_DOWNLOAD_STATUS_NO)
if(LIBTENSORFLOWLITE_DOWNLOAD_STATUS_NO)
message(STATUS "Pre-built library not downloaded. Error occurred, try again and check cmake/SetupTensorflowLite.cmake")
file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/modules/tensorflowlite-${LIBTENSORFLOWLITE_VERSION})
file(REMOVE_RECURSE ${TENSORFLOWLITE_ROOTDIR})
file(REMOVE ${LIBTENSORFLOWLITE_PATH})
else()
message(STATUS "Linking downloaded TensorflowLite pre-built library.")
Expand Down
2 changes: 1 addition & 1 deletion cmake/Toolchain_Bela.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# targets
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv7a)
set(CMAKE_SYSTEM_PROCESSOR armv7l)

# compiler settings
set(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabihf-gcc)
Expand Down
2 changes: 1 addition & 1 deletion cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ endif()
# in this case we set the rpath to the directories where the other libraries are installed
# $ORIGIN in Linux is a special token that gets replaced by the directory of the library at runtime from that point we could navigate to the other libraries
# The same token for macOS is @loader_path
if(LINUX OR BELA)
if(UNIX AND NOT APPLE)
set_target_properties(${PROJECT_NAME}
PROPERTIES
INSTALL_RPATH "$ORIGIN"
Expand Down
Loading

0 comments on commit 5ee903d

Please sign in to comment.