Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail to build QNN backend on macOS #8082

Open
nirvanagth opened this issue Jan 31, 2025 · 1 comment
Open

fail to build QNN backend on macOS #8082

nirvanagth opened this issue Jan 31, 2025 · 1 comment
Assignees
Labels
module: qnn Issues related to Qualcomm's QNN delegate and code under backends/qualcomm/ triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@nirvanagth
Copy link

nirvanagth commented Jan 31, 2025

🐛 Describe the bug

I'm following https://github.com/pytorch/executorch/blob/main/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md to build QNN model on my M1 mac. I'm currently stuck at the step to build Build QNN backend with ExecuTorch. there are two errors I encountered.

  1. I'm getting
 CMake Error at backends/qualcomm/runtime/backends/CMakeLists.txt:66 (target_sources):
  Cannot find source file:

    /Users/tianhaogu/Documents/executorch/backends/qualcomm/runtime/backends/htpbackend/arm64/HtpContextCustomConfig.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm
  .ccm .cxxm .c++m .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90
  .f95 .f03 .hip .ispc

when I build

cmake -DPYTHON_EXECUTABLE=python \
    -DCMAKE_INSTALL_PREFIX=cmake-out \
    -DEXECUTORCH_ENABLE_LOGGING=1 \
    -DCMAKE_BUILD_TYPE=Release \
    -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
    -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
    -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
    -DEXECUTORCH_BUILD_QNN=ON \
    -DQNN_SDK_ROOT=${QNN_SDK_ROOT} \
    -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
    -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
    -DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
    -Bcmake-out .

and I can overcome this by hardcode https://github.com/pytorch/executorch/blob/main/backends/qualcomm/runtime/backends/CMakeLists.txt#L48 to be aarch64

  1. then the command
    cmake --build cmake-out -j16 --target install --config Release
    is giving me
    `[ 1%] Building CXX object third-party/gflags/CMakeFiles/gflags_nothreads_static.dir/src/gflags.cc.o
    [ 1%] Building CXX object third-party/gflags/CMakeFiles/gflags_nothreads_static.dir/src/gflags_reporting.cc.o
    [ 1%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_binary.cpp.o
    [ 1%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_parser.cpp.o
    [ 2%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_text.cpp.o
    [ 2%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_csharp.cpp.o
    [ 2%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_kotlin.cpp.o
    [ 2%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/reflection.cpp.o
    [ 2%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/util.cpp.o
    [ 3%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_cpp.cpp.o
    [ 3%] Building CXX object third-party/gflags/CMakeFiles/gflags_nothreads_static.dir/src/gflags_completions.cc.o
    [ 3%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_dart.cpp.o
    [ 5%] Built target pthreadpool
    [ 7%] Built target cpuinfo
    [ 9%] Built target cpuinfo_internals
    [ 10%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_kotlin_kmp.cpp.o
    /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/idl_parser.cpp:17:10: fatal error: 'algorithm' file not found
    17 | #include
    | ^~~~~~~~~~~
    /Users/tianhaogu/Documents/executorch/third-party/gflags/src/gflags_reporting.cc:51:10: fatal error: 'cstdio' file not found
    51 | #include
    | ^~~~~~~~
    In file included from /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/idl_gen_binary.cpp:19:
    /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/idl_gen_binary.h:20:10: fatal error: 'memory' file not found
    20 | #include
    | ^~~~~~~~
    [ 11%] Building CXX object kernels/optimized/CMakeFiles/eigen_blas.dir/third-party/eigen/blas/single.cpp.o
    In file included from /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/idl_gen_csharp.cpp:19:
    In file included from /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/idl_gen_csharp.h:20:
    /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/include/flatbuffers/code_generator.h:20:10: fatal error: 'string' file not found
    20 | #include
    | ^~~~~~~~
    In file included from /Users/tianhaogu/Documents/executorch/third-party/gflags/src/gflags.cc:91:
    /Users/tianhaogu/Documents/executorch/cmake-out/third-party/gflags/include/gflags/gflags.h:81:10: fatal error: 'string' file not found
    81 | #include
    | ^~~~~~~~
    In file included from /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/idl_gen_kotlin.cpp:19:
    In file included from /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/idl_gen_kotlin.h:20:
    /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/include/flatbuffers/code_generator.h:20:10: fatal error: 'string' file not found
    20 | #include
    | ^~~~~~~~
    [ 11%] Building CXX object kernels/optimized/CMakeFiles/eigen_blas.dir/third-party/eigen/blas/double.cpp.o
    /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/util.cpp:20:10: fatal error: 'cstring' file not found
    20 | #inclIn file included from /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/reflection.cpp:17ude :

    | In file included from ^~~~~~~~~/Users/tianhaogu/Documents/executorch/third-party/flatbuffers/include/flatbuffers/reflection.h
    :25:
    In file included from /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/include/flatbuffers/reflection_generated.h:7:
    /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/include/flatbuffers/flatbuffers.h:20:10: fatal error: 'algorithm' file not found
    20 | #include
    | ^~~~~~~~~~~
    In file included from /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/idl_gen_cpp.cpp:19:
    In file included from /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/idl_gen_cpp.h:20:
    /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/include/flatbuffers/code_generator.h:20:10: fatal error: 'string' file not found
    20 | #include
    | ^~~~~~~~
    In file included from /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/idl_gen_text.cpp:18:
    In file included from /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/idl_gen_text.h:20:
    /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/include/flatbuffers/code_generator.h:20:10: fatal error: 'string' file not found
    20 | #include
    | ^~~~~~~~
    [ 11%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_go.cpp.o
    /Users/tianhaogu/Documents/executorch/third-party/gflags/src/gflags_completions.cc:49:10: fatal error: 'cstdio' file not found
    49 | #include
    | ^~~~~~~~
    In file included from /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/idl_gen_dart.cpp:18:
    In file included from /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/idl_gen_dart.h:20:
    /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/include/flatbuffers/code_generator.h:20:10: fatal error: 'string' file not found
    20 | #include
    | ^~~~~~~~
    /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/idl_gen_kotlin_kmp.cpp:19:10: fatal error: 'functional' file not found
    19 | #include
    | ^~~~~~~~~~~~
    In file included from In file included from /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/double.cpp/Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/single.cpp::1615:
    :
    In file included from In file included from /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/level1_impl.h/Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/level1_impl.h::10:
    In file included from /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/common.h:21:
    In file included from /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/../Eigen/Core:19:
    /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/../Eigen/src/Core/util/Macros.h:10714:
    In file included from /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/common.h:21:
    In file included from /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/../Eigen/Core:19:
    /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/../Eigen/src/Core/util/Macros.h:714:10: fatal error: 'cmath' file not found
    : 714 | #in10c:l udefatal error: <c'cmath' file not foundmath>

    | ^~~~~~~
    714 | #include
    | ^~~~~~~
    In file included from /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/idl_gen_go.cpp:19:
    In file included from /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/src/idl_gen_go.h:20:
    /Users/tianhaogu/Documents/executorch/third-party/flatbuffers/include/flatbuffers/code_generator.h:20:10: fatal error: 'string' file not found
    20 | #include
    | ^~~~~~~~
    1 error generated.
    make[2]: *** [third-party/flatbuffers/CMakeFiles/flatc.dir/src/util.cpp.o] Error 1
    make[2]: *** Waiting for unfinished jobs....
    11 error error generated.
    generated.
    make[2]: *** [third-party/gflags/CMakeFiles/gflags_nothreads_static.dir/src/gflags_completions.cc.o] Error 1
    make[2]: *** Waiting for unfinished jobs....
    1 error generated.
    make[2]: *** [third-party/gflags/CMakeFiles/gflags_nothreads_static.dir/src/gflags_reporting.cc.o] Error 1
    1 error generated.
    make[2]: *** [third-party/flatbuffers/CMakeFiles/flatc.dir/src/reflection.cpp.o] Error 1
    make[2]: *** [third-party/gflags/CMakeFiles/gflags_nothreads_static.dir/src/gflags.cc.o] Error 1
    make[1]: *** [third-party/gflags/CMakeFiles/gflags_nothreads_static.dir/all] Error 2
    make[1]: *** Waiting for unfinished jobs....
    1 error generated.
    make[2]: *** [third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_binary.cpp.o] Error 1
    1 error generated.
    1 error generated.
    1 error generated.
    make[2]: *** [third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_csharp.cpp.o] Error 1
    make[2]: *** [third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_text.cpp.o] Error 1
    make[2]: *** [third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_cpp.cpp.o] Error 1
    [ 11%] Building CXX object kernels/optimized/CMakeFiles/eigen_blas.dir/third-party/eigen/blas/complex_single.cpp.o
    1 error generated.
    make[2]: *** [third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_dart.cpp.o] Error 1
    1 error generated.
    1 error generated.
    make[2]: *** [third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_parser.cpp.o] Error 1
    make[2]: *** [third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_kotlin.cpp.o] Error 1
    [ 11%] Building CXX object kernels/optimized/CMakeFiles/eigen_blas.dir/third-party/eigen/blas/complex_double.cpp.o
    1 error generated.
    make[2]: *** [third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_kotlin_kmp.cpp.o] Error 1
    1 error generated.
    In file included from /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/complex_single.cpp:16:
    In file included from /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/level1_impl.h:10:
    In file included from /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/common.h:21:
    In file included from /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/../Eigen/Core:19:
    /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/../Eigen/src/Core/util/Macros.h:714:10: fatal error: 'cmath' file not found
    714 | #include
    | ^~~~~~~
    make[2]: *** [third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_go.cpp.o] Error 1
    make[1]: *** [third-party/flatbuffers/CMakeFiles/flatc.dir/all] Error 2
    In file included from /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/complex_double.cpp:16:
    In file included from /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/level1_impl.h:10:
    In file included from /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/common.h:21:
    In file included from /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/../Eigen/Core:19:
    /Users/tianhaogu/Documents/executorch/kernels/optimized/third-party/eigen/blas/../Eigen/src/Core/util/Macros.h:714:10: fatal error: 'cmath' file not found
    714 | #include
    | ^~~~~~~
    1 error generated.
    1 error generated.
    make[2]: *** [kernels/optimized/CMakeFiles/eigen_blas.dir/third-party/eigen/blas/double.cpp.o] Error 1
    make[2]: *** Waiting for unfinished jobs....
    make[2]: *** [kernels/optimized/CMakeFiles/eigen_blas.dir/third-party/eigen/blas/single.cpp.o] Error 1
    1 error generated.
    1 error generated.
    make[2]: *** [kernels/optimized/CMakeFiles/eigen_blas.dir/third-party/eigen/blas/complex_double.cpp.o] Error 1
    make[2]: *** [kernels/optimized/CMakeFiles/eigen_blas.dir/third-party/eigen/blas/complex_single.cpp.o] Error 1
    make[1]: *** [kernels/optimized/CMakeFiles/eigen_blas.dir/all] Error 2
    make: *** [all] Error 2
    `

I had similar symptom with #5570 which i had issue with when running ./install_executorch.sh but I've already set the xcode to be correct path in my environment.

Versions

Collecting environment information...
PyTorch version: 2.6.0.dev20250104
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 15.3 (arm64)
GCC version: Could not collect
Clang version: 16.0.0 (clang-1600.0.26.6)
CMake version: version 3.31.4
Libc version: N/A

Python version: 3.10.0 (default, Mar 3 2022, 03:54:28) [Clang 12.0.0 ] (64-bit runtime)
Python platform: macOS-15.3-arm64-arm-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Apple M1 Pro

Versions of relevant libraries:
[pip3] executorch==0.6.0a0+733973
[pip3] numpy==2.2.2
[pip3] torch==2.6.0.dev20250104
[pip3] torchao==0.8.0+git11333ba2
[pip3] torchaudio==2.6.0.dev20250104
[pip3] torchsr==1.0.4
[pip3] torchvision==0.22.0.dev20250104
[conda] executorch 0.6.0a0+733973 pypi_0 pypi
[conda] numpy 2.2.2 pypi_0 pypi
[conda] torch 2.6.0.dev20250104 pypi_0 pypi
[conda] torchao 0.8.0+git11333ba2 pypi_0 pypi
[conda] torchaudio 2.6.0.dev20250104 pypi_0 pypi
[conda] torchsr 1.0.4 pypi_0 pypi
[conda] torchvision 0.22.0.dev20250104 pypi_0 pypi

cc @cccclai

@cccclai
Copy link
Contributor

cccclai commented Jan 31, 2025

QNN only supports linux and windows, and we only verify the QNN backend build on linux at the moment and looking into windows build. However, the error message seems like a mismatch flatbuffers issue. Were you able to run ./install_executorch.sh?

@manuelcandales manuelcandales added module: qnn Issues related to Qualcomm's QNN delegate and code under backends/qualcomm/ triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: qnn Issues related to Qualcomm's QNN delegate and code under backends/qualcomm/ triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

3 participants