Skip to content

Commit 92079a2

Browse files
committed
Arm backend: Make the executor_runner VGF build for Android
To run the executor_runner application on Android for VGF delegated models, you need to build the libvgf.a for Android and link against it when building ExecuTorch and the executor_runner application. This commit makes it possible to run VGF workloads on an Android device with executor_runner. Signed-off-by: George Gekov <george.gekov@arm.com> Change-Id: I0059c7174cd9452952f346157b4d5b5b5daf1aba
1 parent 46f9696 commit 92079a2

3 files changed

Lines changed: 171 additions & 5 deletions

File tree

‎backends/arm/CMakeLists.txt‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,30 @@ if(EXECUTORCH_BUILD_VGF)
192192
)
193193
endif()
194194

195-
if(EXISTS
196-
"${EXECUTORCH_ROOT}/examples/arm/arm-scratch/ml-sdk-for-vulkan-manifest/"
195+
set(EXECUTORCH_VGF_ROOT
196+
""
197+
CACHE PATH
198+
"Path to a VGF installation containing include/ and lib/libvgf.a"
199+
)
200+
201+
if(EXECUTORCH_VGF_ROOT)
202+
message(STATUS "libvgf sourced from ${EXECUTORCH_VGF_ROOT}")
203+
set(LIBVGF_PATH "${EXECUTORCH_VGF_ROOT}")
204+
set(LIBVGF_STATIC "${LIBVGF_PATH}/lib/libvgf.a")
205+
if(NOT EXISTS "${LIBVGF_STATIC}")
206+
message(FATAL_ERROR "EXECUTORCH_VGF_ROOT does not contain lib/libvgf.a: "
207+
"${EXECUTORCH_VGF_ROOT}"
208+
)
209+
endif()
210+
if(NOT EXISTS "${LIBVGF_PATH}/include/vgf/decoder.hpp")
211+
message(
212+
FATAL_ERROR "EXECUTORCH_VGF_ROOT does not contain the VGF headers: "
213+
"${EXECUTORCH_VGF_ROOT}"
214+
)
215+
endif()
216+
elseif(
217+
EXISTS
218+
"${EXECUTORCH_ROOT}/examples/arm/arm-scratch/ml-sdk-for-vulkan-manifest/"
197219
)
198220
message(STATUS "libvgf sourced from local scratch tree")
199221

‎backends/arm/runtime/VGFSetup.cpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,8 +2956,7 @@ bool VgfRepr::process_vgf(
29562956
VkDataGraphPipelineCreateInfoARM graph_pipeline_info{
29572957
.sType = VK_STRUCTURE_TYPE_DATA_GRAPH_PIPELINE_CREATE_INFO_ARM,
29582958
.pNext = &shader_info,
2959-
.flags = VK_PIPELINE_CREATE_2_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT |
2960-
VK_PIPELINE_CREATE_2_EARLY_RETURN_ON_FAILURE_BIT_KHR,
2959+
.flags = 0,
29612960
.layout = segment.vk_pipeline_layout,
29622961
.resourceInfoCount =
29632962
static_cast<uint32_t>(data_graph_resources.size()),
@@ -2973,7 +2972,10 @@ bool VgfRepr::process_vgf(
29732972
nullptr,
29742973
&segment.vk_pipeline);
29752974
if (result != VK_SUCCESS) {
2976-
ET_LOG(Error, "Failed to create DataGraphPipeline");
2975+
ET_LOG(
2976+
Error,
2977+
"Failed to create DataGraphPipeline, error %d",
2978+
static_cast<int>(result));
29772979
return false;
29782980
}
29792981

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2026 Arm Limited and/or its affiliates.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Build the executor_runner application for the Arm VGF backend for
8+
# deployment on an Android device.
9+
#
10+
# Usage:
11+
# export ANDROID_HOME=/path/to/Android/sdk
12+
# export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/<version>
13+
# ./backends/arm/scripts/build_executor_runner_vgf_android.sh
14+
#
15+
16+
set -eu
17+
18+
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
19+
source "${script_dir}/utils.sh"
20+
21+
et_root_dir=$(cd "${script_dir}/../../.." && pwd)
22+
mlsdk_dir="${et_root_dir}/examples/arm/arm-scratch/ml-sdk-for-vulkan-manifest"
23+
output_dir="${et_root_dir}/cmake-out-vgf-android"
24+
build_type=Release
25+
android_abi=arm64-v8a
26+
android_platform=android-28
27+
build_with_etdump=false
28+
build_devtools=OFF
29+
build_event_tracer=OFF
30+
31+
help() {
32+
echo "Usage: $(basename "$0") [options]"
33+
echo "Note: this developer build script is not a stable public API."
34+
echo "Options:"
35+
echo " --output=<DIR> Build directory (default: ${output_dir})"
36+
echo " --build-type=<TYPE> CMake build type (default: ${build_type})"
37+
echo " --android-abi=<ABI> Android ABI (default: ${android_abi})"
38+
echo " --android-platform=<API> Android platform (default: ${android_platform})"
39+
echo " --etdump Build with ETDump profiling support"
40+
}
41+
42+
for arg in "$@"; do
43+
case ${arg} in
44+
-h | --help)
45+
help
46+
exit 0
47+
;;
48+
--output=*) output_dir="${arg#*=}" ;;
49+
--build-type=*) build_type="${arg#*=}" ;;
50+
--android-abi=*) android_abi="${arg#*=}" ;;
51+
--android-platform=*) android_platform="${arg#*=}" ;;
52+
--etdump) build_with_etdump=true ;;
53+
*)
54+
echo "Unknown option: ${arg}" >&2
55+
help >&2
56+
exit 1
57+
;;
58+
esac
59+
done
60+
61+
android_ndk=${ANDROID_NDK_HOME:-${ANDROID_NDK:-}}
62+
if [[ -z ${android_ndk} ]]; then
63+
echo "Set ANDROID_NDK_HOME or ANDROID_NDK to the Android NDK directory." >&2
64+
exit 1
65+
fi
66+
67+
toolchain_file="${android_ndk}/build/cmake/android.toolchain.cmake"
68+
vgf_source_dir="${mlsdk_dir}/sw/vgf-lib"
69+
flatbuffers_dir="${mlsdk_dir}/dependencies/flatbuffers"
70+
vgf_build_dir="${output_dir}/vgf-lib"
71+
vgf_install_dir="${output_dir}/vgf-install"
72+
executorch_build_dir="${output_dir}/executorch"
73+
74+
[[ -f ${toolchain_file} ]] || {
75+
echo "Android CMake toolchain not found: ${toolchain_file}" >&2
76+
exit 1
77+
}
78+
[[ -f ${vgf_source_dir}/CMakeLists.txt ]] || {
79+
echo "VGF source not found: ${vgf_source_dir}" >&2
80+
echo "Install the MLSDK source tree with examples/arm/setup.sh first." >&2
81+
exit 1
82+
}
83+
[[ -f ${flatbuffers_dir}/CMakeLists.txt ]] || {
84+
echo "MLSDK FlatBuffers source not found: ${flatbuffers_dir}" >&2
85+
exit 1
86+
}
87+
88+
mkdir -p "${output_dir}"
89+
90+
if [[ ${build_with_etdump} == true ]]; then
91+
build_devtools=ON
92+
build_event_tracer=ON
93+
fi
94+
95+
# Cross-compile the VGF library for Android
96+
cmake \
97+
-S "${vgf_source_dir}" \
98+
-B "${vgf_build_dir}" \
99+
-DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" \
100+
-DANDROID_ABI="${android_abi}" \
101+
-DANDROID_PLATFORM="${android_platform}" \
102+
-DCMAKE_BUILD_TYPE="${build_type}" \
103+
-DCMAKE_INSTALL_PREFIX="${vgf_install_dir}" \
104+
-DCMAKE_INSTALL_LIBDIR=lib \
105+
-DFLATBUFFERS_PATH="${flatbuffers_dir}" \
106+
-DML_SDK_VGF_LIB_BUILD_TOOLS=OFF \
107+
-DML_SDK_VGF_LIB_BUILD_TESTS=OFF \
108+
-DML_SDK_VGF_LIB_BUILD_PYLIB=OFF \
109+
-DML_SDK_VGF_LIB_BUILD_SHARED=OFF
110+
111+
parallel_jobs="$(get_parallel_jobs)"
112+
113+
cmake --build "${vgf_build_dir}" --target vgf --parallel "${parallel_jobs}"
114+
cmake --install "${vgf_build_dir}"
115+
116+
# Cross-compile ExecuTorch for Android and link against the Android build of the libvgf.a
117+
cmake \
118+
-S "${et_root_dir}" \
119+
-B "${executorch_build_dir}" \
120+
-DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" \
121+
-DANDROID_ABI="${android_abi}" \
122+
-DANDROID_PLATFORM="${android_platform}" \
123+
-DCMAKE_BUILD_TYPE="${build_type}" \
124+
-DEXECUTORCH_PAL_DEFAULT=android \
125+
-DEXECUTORCH_VGF_ROOT="${vgf_install_dir}" \
126+
-DEXECUTORCH_BUILD_VGF=ON \
127+
-DEXECUTORCH_BUILD_VULKAN=OFF \
128+
-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON \
129+
-DEXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL=ON \
130+
-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
131+
-DEXECUTORCH_BUILD_XNNPACK=OFF \
132+
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=OFF \
133+
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
134+
-DEXECUTORCH_ENABLE_LOGGING=ON \
135+
-DEXECUTORCH_BUILD_DEVTOOLS="${build_devtools}" \
136+
-DEXECUTORCH_ENABLE_EVENT_TRACER="${build_event_tracer}"
137+
138+
cmake --build "${executorch_build_dir}" \
139+
--target executor_runner \
140+
--parallel "${parallel_jobs}"
141+
142+
echo "Android VGF executor runner: ${executorch_build_dir}/executor_runner"

0 commit comments

Comments
 (0)