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
18 changes: 0 additions & 18 deletions backends/samsung/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions backends/samsung/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
10 changes: 10 additions & 0 deletions backends/samsung/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand Down
61 changes: 61 additions & 0 deletions examples/samsung/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 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)

add_compile_options(-Wall -Werror -fPIC)

message("Build Samsung Android Examples")

set(__enn_executor_runner__srcs
${CMAKE_CURRENT_LIST_DIR}/executor_runner/enn_executor_runner.cpp
)

add_executable(enn_executor_runner ${__enn_executor_runner__srcs})

target_include_directories(enn_executor_runner PRIVATE ${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
extension_data_loader portable_ops_lib
)

set_target_properties(
enn_executor_runner PROPERTIES CXX_VISIBILITY_PRESET hidden
)
19 changes: 15 additions & 4 deletions examples/samsung/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -42,15 +42,26 @@ 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 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_android/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
Expand Down
45 changes: 45 additions & 0 deletions examples/samsung/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/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}

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

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 "$@"
Loading