pytorch / executorch

On-device AI across mobile, embedded and edge for PyTorch
https://pytorch.org/executorch/
Other
2.13k stars 353 forks source link

Building an ExecuTorch Android Demo App failing from main branch #5387

Closed Abhyuday98 closed 1 month ago

Abhyuday98 commented 1 month ago

🐛 Describe the bug

When I follow the documentation on the following link: Building an ExecuTorch Android Demo App cloning --branch v0.3.0 everything works as intended.

However, when I try to do the same on the main branch, the build fails.

The Below commands give the desired output:

cd executorch

# Update and pull submodules
git submodule sync
git submodule update --init

# Install ExecuTorch pip package and its dependencies, as well as
# development tools like CMake.
# If developing on a Mac, make sure to install the Xcode Command Line Tools first.
./install_requirements.sh --pybind xnnpack

# Clean and configure the CMake build system. Compiled programs will appear in the executorch/cmake-out directory we create here.
(rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake ..)

# Build the executor_runner target
cmake --build cmake-out --target executor_runner -j9

Next, when I run the following commands:

python -m examples.xnnpack.aot_compiler --model_name="dl3" --delegate
mkdir -p examples/demo-apps/android/ExecuTorchDemo/app/src/main/assets/
cp dl3_xnnpack_fp32.pte examples/demo-apps/android/ExecuTorchDemo/app/src/main/assets/

# XNNPACK
# 1. Build the CMake target for the library with XNNPACK backend:

export ANDROID_NDK=<path-to-android-ndk>
export ANDROID_ABI=arm64-v8a

rm -rf cmake-android-out && mkdir cmake-android-out

# Build the core executorch library
cmake . -DCMAKE_INSTALL_PREFIX=cmake-android-out \
  -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
  -DANDROID_ABI="${ANDROID_ABI}" \
  -DANDROID_PLATFORM=android-24 \
  -DEXECUTORCH_BUILD_XNNPACK=ON \
  -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
  -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
  -Bcmake-android-out

cmake --build cmake-android-out -j16 --target install

# 2. Build the android extension
cmake extension/android \
  -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}"/build/cmake/android.toolchain.cmake \
  -DANDROID_ABI="${ANDROID_ABI}" \
  -DANDROID_PLATFORM=android-24 \
  -DCMAKE_INSTALL_PREFIX=cmake-android-out \
  -Bcmake-android-out/extension/android

cmake --build cmake-android-out/extension/android -j16

# 3. Deploy to Device via XNNPACK
mkdir -p examples/demo-apps/android/ExecuTorchDemo/app/src/main/jniLibs/arm64-v8a
cp cmake-android-out/extension/android/libexecutorch_jni.so \
   examples/demo-apps/android/ExecuTorchDemo/app/src/main/jniLibs/arm64-v8a/libexecutorch.so

Failing at 2. Build the android extension

Output:

cmake extension/android \
  -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}"/build/cmake/android.toolchain.cmake \
  -DANDROID_ABI="${ANDROID_ABI}" \
  -DANDROID_PLATFORM=android-24 \
  -DCMAKE_INSTALL_PREFIX=cmake-android-out \
  -Bcmake-android-out/extension/android

cmake --build cmake-android-out/extension/android -j16
-- The C compiler identification is Clang 14.0.6
-- The CXX compiler identification is Clang 14.0.6
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/abhyuday-samadder/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/abhyuday-samadder/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning (dev) at CMakeLists.txt:30 (find_package):
  Policy CMP0144 is not set: find_package uses upper-case <PACKAGENAME>_ROOT
  variables.  Run "cmake --help-policy CMP0144" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  CMake variable EXECUTORCH_ROOT is set to:

    /home/abhyuday-samadder/Desktop/opensource/facebook/main_executorch/executorch/extension/android/../..

  For compatibility, find_package is ignoring the variable, but code in a
  .cmake module might still use it.
This warning is for project developers.  Use -Wno-dev to suppress it.

etdump library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
bundled_program library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
flatccrt library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
coremldelegate library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
mpsdelegate library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
qnn_executorch_backend library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
extension_runner_util library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
extension_tensor library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
vulkan_backend library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
optimized_kernels library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
cpublas library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
eigen_blas library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
optimized_ops_lib library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
optimized_native_cpu_ops_lib library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
quantized_kernels library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
quantized_ops_lib library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
quantized_ops_aot_lib library is not found.
            If needed rebuild with the proper options in CMakeLists.txt
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/abhyuday-samadder/Desktop/opensource/facebook/main_executorch/executorch/cmake-android-out/extension/android
[  5%] Building CXX object third-party/fbjni/CMakeFiles/fbjni.dir/cxx/fbjni/ByteBuffer.cpp.o
[ 11%] Building CXX object third-party/fbjni/CMakeFiles/fbjni.dir/cxx/fbjni/OnLoad.cpp.o
[ 17%] Building CXX object third-party/fbjni/CMakeFiles/fbjni.dir/cxx/fbjni/ReadableByteChannel.cpp.o
[ 23%] Building CXX object third-party/fbjni/CMakeFiles/fbjni.dir/cxx/fbjni/detail/Environment.cpp.o
[ 29%] Building CXX object third-party/fbjni/CMakeFiles/fbjni.dir/cxx/fbjni/detail/Exceptions.cpp.o
[ 35%] Building CXX object third-party/fbjni/CMakeFiles/fbjni.dir/cxx/fbjni/detail/Hybrid.cpp.o
[ 41%] Building CXX object third-party/fbjni/CMakeFiles/fbjni.dir/cxx/fbjni/detail/Meta.cpp.o
[ 52%] Building CXX object third-party/fbjni/CMakeFiles/fbjni.dir/cxx/fbjni/detail/utf8.cpp.o
[ 52%] Building CXX object third-party/fbjni/CMakeFiles/fbjni.dir/cxx/fbjni/detail/References.cpp.o
[ 58%] Building CXX object third-party/fbjni/CMakeFiles/fbjni.dir/cxx/fbjni/fbjni.cpp.o
[ 70%] Building CXX object third-party/fbjni/CMakeFiles/fbjni.dir/cxx/lyra/lyra.cpp.o
[ 70%] Building CXX object third-party/fbjni/CMakeFiles/fbjni.dir/cxx/lyra/cxa_throw.cpp.o
[ 76%] Building CXX object third-party/fbjni/CMakeFiles/fbjni.dir/cxx/lyra/lyra_breakpad.cpp.o
[ 82%] Building CXX object third-party/fbjni/CMakeFiles/fbjni.dir/cxx/lyra/lyra_exceptions.cpp.o
[ 88%] Linking CXX shared library libfbjni.so
[ 88%] Built target fbjni
[ 94%] Building CXX object CMakeFiles/executorch_jni.dir/jni/jni_layer.cpp.o
[100%] Linking CXX shared library libexecutorch_jni.so
ld: error: unable to find library -lextension_runner_util
ld: error: unable to find library -lextension_tensor
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[2]: *** [CMakeFiles/executorch_jni.dir/build.make:109: libexecutorch_jni.so] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:100: CMakeFiles/executorch_jni.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2

Versions

Collecting environment information... PyTorch version: 2.5.0.dev20240901+cpu Is debug build: False CUDA used to build PyTorch: Could not collect ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.1 LTS (x86_64) GCC version: (Ubuntu 13.2.0-23ubuntu4) 13.2.0 Clang version: Could not collect CMake version: version 3.30.3 Libc version: glibc-2.39

Python version: 3.10.14 (main, May 6 2024, 19:42:50) [GCC 11.2.0] (64-bit runtime) Python platform: Linux-6.8.0-44-generic-x86_64-with-glibc2.39 Is CUDA available: False CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: N/A GPU models and configuration: GPU 0: NVIDIA RTX A2000 12GB Nvidia driver version: 550.107.02 cuDNN version: Could not collect HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 39 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 12 On-line CPU(s) list: 0-11 Vendor ID: GenuineIntel Model name: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz CPU family: 6 Model: 158 Thread(s) per core: 2 Core(s) per socket: 6 Socket(s): 1 Stepping: 10 CPU(s) scaling MHz: 88% CPU max MHz: 3200.0000 CPU min MHz: 800.0000 BogoMIPS: 6399.96 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb pti ssbd ibrs ibpb stibp tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm arat pln pts hwp hwp_notify hwp_act_window hwp_epp vnmi md_clear flush_l1d arch_capabilities Virtualization: VT-x L1d cache: 192 KiB (6 instances) L1i cache: 192 KiB (6 instances) L2 cache: 1.5 MiB (6 instances) L3 cache: 12 MiB (1 instance) NUMA node(s): 1 NUMA node0 CPU(s): 0-11 Vulnerability Gather data sampling: Mitigation; Microcode Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled Vulnerability L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable Vulnerability Mds: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Meltdown: Mitigation; PTI Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Mitigation; IBRS Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; IBRS; IBPB conditional; STIBP conditional; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected Vulnerability Srbds: Mitigation; Microcode Vulnerability Tsx async abort: Mitigation; TSX disabled

Versions of relevant libraries: [pip3] executorch==0.4.0a0+ef31608 [pip3] numpy==1.21.3 [pip3] torch==2.5.0.dev20240901+cpu [pip3] torchaudio==2.5.0.dev20240901+cpu [pip3] torchsr==1.0.4 [pip3] torchvision==0.20.0.dev20240901+cpu [conda] executorch 0.4.0a0+ef31608 pypi_0 pypi [conda] numpy 1.21.3 pypi_0 pypi [conda] torch 2.5.0.dev20240901+cpu pypi_0 pypi [conda] torchaudio 2.5.0.dev20240901+cpu pypi_0 pypi [conda] torchsr 1.0.4 pypi_0 pypi [conda] torchvision 0.20.0.dev20240901+cpu pypi_0 pypi

Abhyuday98 commented 1 month ago

Additional Build Flags were required. The following builds successfully:

# Build the core executorch library
cmake . -DCMAKE_INSTALL_PREFIX=cmake-android-out \
  -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
  -DANDROID_ABI="${ANDROID_ABI}" \
  -DANDROID_PLATFORM=android-24 \
  -DEXECUTORCH_BUILD_XNNPACK=ON \
  -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
  -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
  -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
  -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
  -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
  -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
  -DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
  -Bcmake-android-out

cmake --build cmake-android-out -j16 --target install
WuhanMonkey commented 1 month ago

Additional Build Flags were required. The following builds successfully:

# Build the core executorch library
cmake . -DCMAKE_INSTALL_PREFIX=cmake-android-out \
  -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
  -DANDROID_ABI="${ANDROID_ABI}" \
  -DANDROID_PLATFORM=android-24 \
  -DEXECUTORCH_BUILD_XNNPACK=ON \
  -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
  -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
  -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
  -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
  -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
  -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
  -DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
  -Bcmake-android-out

cmake --build cmake-android-out -j16 --target install

This is correct. Thanks @Abhyuday98 for the help here. We are updating the docs with more details here.

Abhyuday98 commented 1 month ago

Happy to help! I've been a big admirer of Pytorch Mobile, and I've used it extensively for on device AI in my company's apps. Now that's it's in Legacy, I'm exploring Executorch. I would actually love to contribute once I wrap my head around this repository