From 0396adb3049f6a9071665cf7c99840995752dd3b Mon Sep 17 00:00:00 2001 From: Jiseong Oh Date: Wed, 15 Oct 2025 10:32:19 +0900 Subject: [PATCH 1/2] Build System - separate backend and example builds. To keep backend and example artifacts distinct. AS-IS: - The backend library and 'enn_executor_runner' were built together. - The example artifact 'enn_executor_runner' was placed under 'backend/samsung', it is not proper location for example artifacts. TO-BE: - Build the backend library first, then let the example projects refer to already-built backend library. - Adjust CMakeLists so that 'enn_executor_runner' is compiled in the 'examples/samsung/' directory and its output is placed in there. Signed-off-by: Jiseong.oh --- backends/samsung/CMakeLists.txt | 18 ------- backends/samsung/README.md | 9 ++-- examples/samsung/CMakeLists.txt | 88 +++++++++++++++++++++++++++++++++ examples/samsung/README.md | 17 +++++-- examples/samsung/build.sh | 40 +++++++++++++++ 5 files changed, 147 insertions(+), 25 deletions(-) create mode 100644 examples/samsung/CMakeLists.txt create mode 100755 examples/samsung/build.sh diff --git a/backends/samsung/CMakeLists.txt b/backends/samsung/CMakeLists.txt index 1f647c5bbe2..c8b4bedbc4a 100644 --- a/backends/samsung/CMakeLists.txt +++ b/backends/samsung/CMakeLists.txt @@ -146,24 +146,6 @@ if(${ANDROID}) executorch_target_link_options_shared_lib(enn_backend) target_compile_options(enn_backend PRIVATE -Wno-deprecated-declarations) - set(__enn_executor_runner_srcs - ${EXECUTORCH_SOURCE_DIR}/examples/samsung/executor_runner/enn_executor_runner.cpp - ) - add_executable(enn_executor_runner ${__enn_executor_runner_srcs}) - add_dependencies(enn_executor_runner enn_backend) - target_link_libraries( - enn_executor_runner - PRIVATE enn_logging - enn_backend - gflags - executorch - extension_data_loader - portable_ops_lib - android - ) - set_target_properties( - enn_executor_runner PROPERTIES CXX_VISIBILITY_PRESET hidden - ) install( TARGETS enn_backend enn_logging EXPORT ExecuTorchTargets diff --git a/backends/samsung/README.md b/backends/samsung/README.md index bc48bad830a..249cd5bea11 100644 --- a/backends/samsung/README.md +++ b/backends/samsung/README.md @@ -49,13 +49,16 @@ Generates python artifacts that allow user call `Compile` interface to lower a m ./backends/samsung/build.sh -b x86_64 ``` -### Build ENN Executor Runner +### Build Backend Delegate ```bash ./backends/samsung/build.sh -b android --ndk ${ANDROID_NDK} ``` -ANDROID_ABI=arm64-v8a is default, necessary runtime executable generated in `build_exynos_android` directory. +ANDROID_ABI=arm64-v8a is default, necessary runtime backend library generated in `build_samsung_android` directory. -### Build Anroid Extension +### Build Executable +Please see the [README.md](../../examples/samsung/README.md). + +### Build Android Extension This is later exposed Java app. Please turn on CMake option `EXECUTORCH_BUILD_ENN`, and ENN runtime will be added. ```bash cmake extension/android \ diff --git a/examples/samsung/CMakeLists.txt b/examples/samsung/CMakeLists.txt new file mode 100644 index 00000000000..29d2f084973 --- /dev/null +++ b/examples/samsung/CMakeLists.txt @@ -0,0 +1,88 @@ +# Copyright (c) 2025 Samsung Electronics Co. LTD +# All rights reserved +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +cmake_minimum_required(VERSION 3.15) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +project(samsung_example) + +# Source root directory for executorch. +if(NOT EXECUTORCH_ROOT) + set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) +endif() + +include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake) + +if(NOT PYTHON_EXECUTABLE) + resolve_python_executable() +endif() + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE RelWithDebInfo) +endif() + +if(CMAKE_TOOLCHAIN_FILE MATCHES ".*(iOS|ios\.toolchain)\.cmake$") + message(FATAL_ERROR "ios is not supported by Samsung AI system.") +endif() + +# prebuilt libraries. executorch package should contain portable_ops_lib, +# etdump, bundled_program. +find_package(executorch CONFIG REQUIRED) +target_compile_options(executorch INTERFACE -DET_EVENT_TRACER_ENABLED) +find_package(gflags REQUIRED) + +set(_common_compile_options -Wno-deprecated-declarations -fPIC) + +# +# The `__srcs` lists are defined by executorch_load_build_variables. +# +executorch_load_build_variables() + +set(EXECUTORCH_SRCS_FILE + "${CMAKE_CURRENT_BINARY_DIR}/../../executorch_srcs.cmake" +) + +get_filename_component( + EXECUTORCH_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE +) + +add_compile_options(-Wall -Werror -fPIC) + +message("Build Samsung Android Examples") + +link_directories(${EXECUTORCH_ROOT}/build_samsung_android/lib) + +add_library(lib_portable_ops STATIC IMPORTED) + +set_target_properties( + lib_portable_ops + PROPERTIES + IMPORTED_LOCATION + "${EXECUTORCH_ROOT}/build_samsung_android/lib/libportable_ops_lib.a" +) + +set(__enn_executor_runner__srcs + ${CMAKE_CURRENT_LIST_DIR}/executor_runner/enn_executor_runner.cpp +) + +add_executable(enn_executor_runner ${__enn_executor_runner__srcs}) + +add_dependencies(enn_executor_runner enn_backend) + +target_include_directories( + enn_executor_runner PUBLIC ${_common_include_directories} + ${EXECUTORCH_ROOT}/.. +) + +target_link_libraries( + enn_executor_runner PRIVATE enn_logging enn_backend gflags executorch + extension_data_loader portable_ops_lib +) + +set_target_properties( + enn_executor_runner PROPERTIES CXX_VISIBILITY_PRESET hidden +) diff --git a/examples/samsung/README.md b/examples/samsung/README.md index 8b21c48a34f..bca0b6dc347 100644 --- a/examples/samsung/README.md +++ b/examples/samsung/README.md @@ -1,9 +1,9 @@ -# Exynos backend Examples +# Exynos Backend examples This directory contains examples for some AI models. -Please make sure you have built the library and executable before -you start, if you have no idea how to build, please refer to [backend README](../../backends/samsung/README.md). +Please make sure you have built the library before you start, +if you have no idea how to build, please refer to [backend README](../../backends/samsung/README.md). ## Environment We set up `PYTHONPATH` because it's easier to develop and import executorch Python APIs. @@ -42,15 +42,24 @@ Examples use "PerformanceMode.HIGH_PERFORMANCE" mode, this mode is experimental. If you want to use this mode on your model, verify your model on devicefarm which can use samsung developer society site firstly for checking stability. (https://soc-developer.semiconductor.samsung.com/) +## Building Executable +### Prerequisites +Please set up the backend before building the executable, See the [backend README](../../backends/samsung/README.md) for details. +### Building 'enn_executor_runner' for Andoird +``` +${EXECUTORCH_ROOT}/examples/samsung/build.sh +``` +After the build completes, `enn_executor_runner` can be found at `${EXECUTORCH_ROOT}/build_samsung_andorid/examples/samsung/` ## Execution + After lowering, we could get a pte model and then run it on mobile phone. #### Step 1: Push required ENN libraries and executor runner to device ```bash DEVICE_DIR=/data/local/tmp/executorch adb shell mkdir ${DEVICE_DIR} -adb push ${EXECUTORCH_ROOT}/cmake-android-out/backends/samsung/enn_executor_runner ${DEVICE_DIR} +adb push ${EXECUTORCH_ROOT}/build_samsung_android/examples/samsung/enn_executor_runner ${DEVICE_DIR} ``` #### Step 2: Indicate dynamic linkers and execute model diff --git a/examples/samsung/build.sh b/examples/samsung/build.sh new file mode 100755 index 00000000000..a081ae1d676 --- /dev/null +++ b/examples/samsung/build.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +set -e + +BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +PROJECT_DIR=$(realpath ${BASE_DIR}/../../) + +echo PROJECT_DIR=${PROJECT_DIR} + +ANDROID_ABI=arm64-v8a +ANDROID_PLATFORM=android-28 # Trace requires over android-23 + +echo ANDROID_NDK_ROOT=${ANDROID_NDK_ROOT} +echo ANDROID_ABI=${ANDROID_ABI} +echo ANDROID_PLATFORM=${ANDROID_PLATFORM} + +main() { + cd "$PROJECT_DIR" + local build_dir_root="build_samsung_android" + local example_root="examples/samsung" + local build_dir_example="$PROJECT_DIR/${build_dir_root}/${example_root}" + local cmake_prefix_path="$PROJECT_DIR/${build_dir_root}/lib/cmake/ExecuTorch;$PROJECT_DIR/${build_dir_root}/third-party/gflags;$PROJECT_DIR/${build_dir_root}/lib/cmake/tokenizers;$PROJECT_DIR/${build_dir_root}/lib/cmake/re2;$PROJECT_DIR/${build_dir_root}/lib/cmake/absl;" + + echo build_dir=${build_dir_root} + echo build_dir_example=${build_dir_example} + echo cmake_prefix_path=${cmake_prefix_path} + + cmake -DCMAKE_PREFIX_PATH=${cmake_prefix_path} \ + -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake" \ + -DANDROID_NDK=$ANDROID_NDK \ + -DANDROID_ABI="$ANDROID_ABI" \ + -DANDROID_PLATFORM=$ANDROID_PLATFORM \ + -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \ + -DCMAKE_BUILD_TYPE=Release \ + -B"${build_dir_example}" \ + "$PROJECT_DIR/${example_root}" + cmake --build build_samsung_android/examples/samsung/ --config Release +} + +main "$@" From 7263631d1e1e528b53fe165e276ce088d2872713 Mon Sep 17 00:00:00 2001 From: "jiseong.oh" Date: Sat, 5 Sep 2026 06:52:37 +0000 Subject: [PATCH 2/2] Drop dead/hard codes about build paths - fixed dead/hard build paths - Fixed typo and added NDK path. Signed-off-by: jiseong.oh --- backends/samsung/build.sh | 10 ++++++++++ examples/samsung/CMakeLists.txt | 31 ++----------------------------- examples/samsung/README.md | 8 +++++--- examples/samsung/build.sh | 5 +++++ 4 files changed, 22 insertions(+), 32 deletions(-) diff --git a/backends/samsung/build.sh b/backends/samsung/build.sh index a4871feb50c..e6258152785 100755 --- a/backends/samsung/build.sh +++ b/backends/samsung/build.sh @@ -66,7 +66,17 @@ function build_android() { ANDROID_ABI=arm64-v8a ANDROID_PLATFORM=android-28 # Trace requires over android-23 + local host_flatcc=${X86_64_BUILD_DIR}/third-party/flatcc_ep/bin/flatcc + local flatcc_args=() + if [[ -x ${host_flatcc} ]]; then + flatcc_args=(-DFLATCC_EXECUTABLE=${host_flatcc}) + else + echo "Warning: ${host_flatcc} not found. Build the x86_64 target first" \ + "('-b x86_64' or '-b all') if executor_runner fails to link libflatccrt.a." + fi + cmake \ + "${flatcc_args[@]}" \ -DCMAKE_INSTALL_PREFIX=${ANDROID_BUILD_DIR} \ -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake" \ -DANDROID_NDK=${ANDROID_NDK} \ diff --git a/examples/samsung/CMakeLists.txt b/examples/samsung/CMakeLists.txt index 29d2f084973..28a6dcc6660 100644 --- a/examples/samsung/CMakeLists.txt +++ b/examples/samsung/CMakeLists.txt @@ -37,46 +37,19 @@ find_package(gflags REQUIRED) set(_common_compile_options -Wno-deprecated-declarations -fPIC) -# -# The `__srcs` lists are defined by executorch_load_build_variables. -# -executorch_load_build_variables() - -set(EXECUTORCH_SRCS_FILE - "${CMAKE_CURRENT_BINARY_DIR}/../../executorch_srcs.cmake" -) - -get_filename_component( - EXECUTORCH_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE -) - add_compile_options(-Wall -Werror -fPIC) message("Build Samsung Android Examples") -link_directories(${EXECUTORCH_ROOT}/build_samsung_android/lib) - -add_library(lib_portable_ops STATIC IMPORTED) - -set_target_properties( - lib_portable_ops - PROPERTIES - IMPORTED_LOCATION - "${EXECUTORCH_ROOT}/build_samsung_android/lib/libportable_ops_lib.a" -) - set(__enn_executor_runner__srcs ${CMAKE_CURRENT_LIST_DIR}/executor_runner/enn_executor_runner.cpp ) add_executable(enn_executor_runner ${__enn_executor_runner__srcs}) -add_dependencies(enn_executor_runner enn_backend) +target_include_directories(enn_executor_runner PRIVATE ${EXECUTORCH_ROOT}/..) -target_include_directories( - enn_executor_runner PUBLIC ${_common_include_directories} - ${EXECUTORCH_ROOT}/.. -) +target_compile_options(enn_executor_runner PRIVATE ${_common_compile_options}) target_link_libraries( enn_executor_runner PRIVATE enn_logging enn_backend gflags executorch diff --git a/examples/samsung/README.md b/examples/samsung/README.md index bca0b6dc347..a64169bd9a1 100644 --- a/examples/samsung/README.md +++ b/examples/samsung/README.md @@ -45,11 +45,13 @@ firstly for checking stability. (https://soc-developer.semiconductor.samsung.com ## Building Executable ### Prerequisites Please set up the backend before building the executable, See the [backend README](../../backends/samsung/README.md) for details. -### Building 'enn_executor_runner' for Andoird -``` +### Building 'enn_executor_runner' for Android +```bash +export EXYNOS_AI_LITECORE_ROOT=/path/to/enn_sdk +export ANDROID_NDK_ROOT=/path/to/android_ndk ${EXECUTORCH_ROOT}/examples/samsung/build.sh ``` -After the build completes, `enn_executor_runner` can be found at `${EXECUTORCH_ROOT}/build_samsung_andorid/examples/samsung/` +After the build completes, `enn_executor_runner` can be found at `${EXECUTORCH_ROOT}/build_samsung_android/examples/samsung/` ## Execution diff --git a/examples/samsung/build.sh b/examples/samsung/build.sh index a081ae1d676..4568180777a 100755 --- a/examples/samsung/build.sh +++ b/examples/samsung/build.sh @@ -7,6 +7,11 @@ PROJECT_DIR=$(realpath ${BASE_DIR}/../../) echo PROJECT_DIR=${PROJECT_DIR} +if [[ -z ${ANDROID_NDK_ROOT} ]]; then + echo "Please export ANDROID_NDK_ROOT" + exit 1 +fi + ANDROID_ABI=arm64-v8a ANDROID_PLATFORM=android-28 # Trace requires over android-23