diff --git a/backends/qualcomm/CMakeLists.txt b/backends/qualcomm/CMakeLists.txt index cefc330d3d6..babdb96d8bc 100644 --- a/backends/qualcomm/CMakeLists.txt +++ b/backends/qualcomm/CMakeLists.txt @@ -58,6 +58,7 @@ add_compile_options("-Wall" "-Werror" "-Wno-sign-compare") # which can be ignored by GNU. So we make it a warning, not an error in GNU. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") add_compile_options("-Wno-error=attributes") + add_link_options("-flto=auto") endif() if(CMAKE_BUILD_TYPE STREQUAL "Release") @@ -67,7 +68,6 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release") # --gc-sections is added by torch. add_compile_options( "-O3" "-ffunction-sections" "-fdata-sections" "-frtti" - "-Wno-unused-command-line-argument" ) endif() @@ -259,6 +259,22 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") pybind11_strip(PyQnnWrapperAdaptor) endif() + if(CMAKE_BUILD_TYPE STREQUAL "Release") + # need to allow exceptions in pybind + set(_pybind_compile_options + -Wno-deprecated-declarations + -fPIC + -frtti + -fexceptions + ) + target_compile_options( + PyQnnManagerAdaptor PUBLIC ${_pybind_compile_options} + ) + target_compile_options( + PyQnnWrapperAdaptor PUBLIC ${_pybind_compile_options} + ) + endif() + add_subdirectory( ${QNN_EXECUTORCH_ROOT_DIR}/aot/python ${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/python diff --git a/backends/qualcomm/scripts/build.sh b/backends/qualcomm/scripts/build.sh index 70cc0399f22..be317a2d64b 100755 --- a/backends/qualcomm/scripts/build.sh +++ b/backends/qualcomm/scripts/build.sh @@ -64,9 +64,13 @@ if [ "$BUILD_AARCH64" = true ]; then echo "Please export ANDROID_NDK_ROOT=/path/to/android_ndkXX" exit -1 fi + BUILD_ROOT=$PRJ_ROOT/$CMAKE_AARCH64 if [ "$CLEAN" = true ]; then rm -rf $BUILD_ROOT && mkdir $BUILD_ROOT + else + # Force rebuild flatccrt for the correct platform + cd $BUILD_ROOT/sdk && make clean fi cd $BUILD_ROOT @@ -103,15 +107,17 @@ if [ "$BUILD_AARCH64" = true ]; then fi if [ "$BUILD_X86_64" = true ]; then - # Build python interface BUILD_ROOT=$PRJ_ROOT/$CMAKE_X86_64 if [ "$CLEAN" = true ]; then rm -rf $BUILD_ROOT && mkdir $BUILD_ROOT + else + # Force rebuild flatccrt for the correct platform + cd $BUILD_ROOT/sdk && make clean fi + cd $BUILD_ROOT - # TODO: Use CMAKE_BUILD_TYPE=RelWithDebInfo, and handle flatcc issues cmake \ - -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DCMAKE_INSTALL_PREFIX=$BUILD_ROOT \ -DQNN_SDK_ROOT=${QNN_SDK_ROOT} \ -DEXECUTORCH_BUILD_QNN=ON \ @@ -131,7 +137,7 @@ if [ "$BUILD_X86_64" = true ]; then CMAKE_PREFIX_PATH="${BUILD_ROOT}/lib/cmake/ExecuTorch;${BUILD_ROOT}/third-party/gflags;" cmake $PRJ_ROOT/$EXAMPLE_ROOT \ - -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DCMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH \ -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \ -DPYTHON_EXECUTABLE=$PYTHON_EXECUTABLE \ diff --git a/examples/qualcomm/CMakeLists.txt b/examples/qualcomm/CMakeLists.txt index 6bfbdea0583..f0fa4728c22 100644 --- a/examples/qualcomm/CMakeLists.txt +++ b/examples/qualcomm/CMakeLists.txt @@ -77,7 +77,8 @@ list(PREPEND _qnn_executor_runner__srcs ) # preprocess llama runner src files list(TRANSFORM _qnn_llama_runner__srcs PREPEND "${EXECUTORCH_SOURCE_DIR}/") -list(FILTER _qnn_llama_runner__srcs EXCLUDE REGEX ".*runner.cpp$") +list(FILTER _qnn_llama_runner__srcs EXCLUDE REGEX ".*(/runner/).*") +message(ERROR ${_qnn_llama_runner__srcs}) list(PREPEND _qnn_llama_runner__srcs ${CMAKE_CURRENT_LIST_DIR}/executor_runner/qnn_llama_runner.cpp ${CMAKE_CURRENT_LIST_DIR}/llama2/runner/runner.cpp @@ -85,7 +86,7 @@ list(PREPEND _qnn_llama_runner__srcs ) # preprocess qaihub llama runner src files list(TRANSFORM _qnn_qaihub_llama_runner__srcs PREPEND "${EXECUTORCH_SOURCE_DIR}/") -list(FILTER _qnn_qaihub_llama_runner__srcs EXCLUDE REGEX ".*runner.cpp*$") +list(FILTER _qnn_qaihub_llama_runner__srcs EXCLUDE REGEX ".*(/runner/).*") list(PREPEND _qnn_qaihub_llama_runner__srcs ${CMAKE_CURRENT_LIST_DIR}/executor_runner/qnn_qaihub_llama_runner.cpp ${CMAKE_CURRENT_LIST_DIR}/llama2/qaihub_runner/runner.cpp @@ -103,9 +104,6 @@ target_link_libraries( qnn_executor_runner qnn_executorch_backend full_portable_ops_lib etdump ${FLATCCRT_LIB} gflags ) -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - target_link_options(qnn_executor_runner PUBLIC -fsanitize=undefined) -endif() # build llama runner add_executable(qnn_llama_runner ${_qnn_llama_runner__srcs}) diff --git a/examples/qualcomm/llama2/qaihub_runner/runner.cpp b/examples/qualcomm/llama2/qaihub_runner/runner.cpp index 2f8a01f4e97..58f257ca7d8 100644 --- a/examples/qualcomm/llama2/qaihub_runner/runner.cpp +++ b/examples/qualcomm/llama2/qaihub_runner/runner.cpp @@ -11,18 +11,17 @@ #include #include +#include #include #include +#include +#include +#include #include #include #include -#include -#include -#include -#include - #if defined(__aarch64__) #include "arm_neon.h" #endif diff --git a/examples/qualcomm/llama2/runner/runner.cpp b/examples/qualcomm/llama2/runner/runner.cpp index 009bb6b2094..502aa318d09 100644 --- a/examples/qualcomm/llama2/runner/runner.cpp +++ b/examples/qualcomm/llama2/runner/runner.cpp @@ -11,18 +11,17 @@ #include #include +#include #include #include +#include +#include +#include #include #include #include -#include -#include -#include -#include - namespace torch { namespace executor { diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index 8f677000c80..79903fc315e 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -62,6 +62,10 @@ set(FLATCC_REFLECTION OFF CACHE BOOL "" ) +set(FLATCC_DEBUG_CLANG_SANITIZE + OFF + CACHE BOOL "" +) set(_flatcc_source_dir ${CMAKE_CURRENT_SOURCE_DIR}/../third-party/flatcc) add_subdirectory(${_flatcc_source_dir} ${CMAKE_BINARY_DIR}/third-party/flatcc)