Skip to content

Commit 7f34796

Browse files
authored
Qualcomm AI Engine Direct - fix release build issue
Differential Revision: D61026686 Pull Request resolved: #4625
1 parent a70d070 commit 7f34796

File tree

6 files changed

+42
-20
lines changed

6 files changed

+42
-20
lines changed

backends/qualcomm/CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ add_compile_options("-Wall" "-Werror" "-Wno-sign-compare")
5858
# which can be ignored by GNU. So we make it a warning, not an error in GNU.
5959
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
6060
add_compile_options("-Wno-error=attributes")
61+
add_link_options("-flto=auto")
6162
endif()
6263

6364
if(CMAKE_BUILD_TYPE STREQUAL "Release")
@@ -67,7 +68,6 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release")
6768
# --gc-sections is added by torch.
6869
add_compile_options(
6970
"-O3" "-ffunction-sections" "-fdata-sections" "-frtti"
70-
"-Wno-unused-command-line-argument"
7171
)
7272
endif()
7373

@@ -259,6 +259,22 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
259259
pybind11_strip(PyQnnWrapperAdaptor)
260260
endif()
261261

262+
if(CMAKE_BUILD_TYPE STREQUAL "Release")
263+
# need to allow exceptions in pybind
264+
set(_pybind_compile_options
265+
-Wno-deprecated-declarations
266+
-fPIC
267+
-frtti
268+
-fexceptions
269+
)
270+
target_compile_options(
271+
PyQnnManagerAdaptor PUBLIC ${_pybind_compile_options}
272+
)
273+
target_compile_options(
274+
PyQnnWrapperAdaptor PUBLIC ${_pybind_compile_options}
275+
)
276+
endif()
277+
262278
add_subdirectory(
263279
${QNN_EXECUTORCH_ROOT_DIR}/aot/python
264280
${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/python

backends/qualcomm/scripts/build.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ if [ "$BUILD_AARCH64" = true ]; then
6464
echo "Please export ANDROID_NDK_ROOT=/path/to/android_ndkXX"
6565
exit -1
6666
fi
67+
6768
BUILD_ROOT=$PRJ_ROOT/$CMAKE_AARCH64
6869
if [ "$CLEAN" = true ]; then
6970
rm -rf $BUILD_ROOT && mkdir $BUILD_ROOT
71+
else
72+
# Force rebuild flatccrt for the correct platform
73+
cd $BUILD_ROOT/sdk && make clean
7074
fi
7175

7276
cd $BUILD_ROOT
@@ -103,15 +107,17 @@ if [ "$BUILD_AARCH64" = true ]; then
103107
fi
104108

105109
if [ "$BUILD_X86_64" = true ]; then
106-
# Build python interface
107110
BUILD_ROOT=$PRJ_ROOT/$CMAKE_X86_64
108111
if [ "$CLEAN" = true ]; then
109112
rm -rf $BUILD_ROOT && mkdir $BUILD_ROOT
113+
else
114+
# Force rebuild flatccrt for the correct platform
115+
cd $BUILD_ROOT/sdk && make clean
110116
fi
117+
111118
cd $BUILD_ROOT
112-
# TODO: Use CMAKE_BUILD_TYPE=RelWithDebInfo, and handle flatcc issues
113119
cmake \
114-
-DCMAKE_BUILD_TYPE=Debug \
120+
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
115121
-DCMAKE_INSTALL_PREFIX=$BUILD_ROOT \
116122
-DQNN_SDK_ROOT=${QNN_SDK_ROOT} \
117123
-DEXECUTORCH_BUILD_QNN=ON \
@@ -131,7 +137,7 @@ if [ "$BUILD_X86_64" = true ]; then
131137
CMAKE_PREFIX_PATH="${BUILD_ROOT}/lib/cmake/ExecuTorch;${BUILD_ROOT}/third-party/gflags;"
132138

133139
cmake $PRJ_ROOT/$EXAMPLE_ROOT \
134-
-DCMAKE_BUILD_TYPE=Debug \
140+
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
135141
-DCMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH \
136142
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH \
137143
-DPYTHON_EXECUTABLE=$PYTHON_EXECUTABLE \

examples/qualcomm/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,16 @@ list(PREPEND _qnn_executor_runner__srcs
7777
)
7878
# preprocess llama runner src files
7979
list(TRANSFORM _qnn_llama_runner__srcs PREPEND "${EXECUTORCH_SOURCE_DIR}/")
80-
list(FILTER _qnn_llama_runner__srcs EXCLUDE REGEX ".*runner.cpp$")
80+
list(FILTER _qnn_llama_runner__srcs EXCLUDE REGEX ".*(/runner/).*")
81+
message(ERROR ${_qnn_llama_runner__srcs})
8182
list(PREPEND _qnn_llama_runner__srcs
8283
${CMAKE_CURRENT_LIST_DIR}/executor_runner/qnn_llama_runner.cpp
8384
${CMAKE_CURRENT_LIST_DIR}/llama2/runner/runner.cpp
8485
${CMAKE_CURRENT_LIST_DIR}/llama2/runner/runner.h
8586
)
8687
# preprocess qaihub llama runner src files
8788
list(TRANSFORM _qnn_qaihub_llama_runner__srcs PREPEND "${EXECUTORCH_SOURCE_DIR}/")
88-
list(FILTER _qnn_qaihub_llama_runner__srcs EXCLUDE REGEX ".*runner.cpp*$")
89+
list(FILTER _qnn_qaihub_llama_runner__srcs EXCLUDE REGEX ".*(/runner/).*")
8990
list(PREPEND _qnn_qaihub_llama_runner__srcs
9091
${CMAKE_CURRENT_LIST_DIR}/executor_runner/qnn_qaihub_llama_runner.cpp
9192
${CMAKE_CURRENT_LIST_DIR}/llama2/qaihub_runner/runner.cpp
@@ -103,9 +104,6 @@ target_link_libraries(
103104
qnn_executor_runner qnn_executorch_backend full_portable_ops_lib etdump
104105
${FLATCCRT_LIB} gflags
105106
)
106-
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
107-
target_link_options(qnn_executor_runner PUBLIC -fsanitize=undefined)
108-
endif()
109107

110108
# build llama runner
111109
add_executable(qnn_llama_runner ${_qnn_llama_runner__srcs})

examples/qualcomm/llama2/qaihub_runner/runner.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@
1111

1212
#include <executorch/examples/qualcomm/llama2/qaihub_runner/runner.h>
1313
#include <executorch/extension/evalue_util/print_evalue.h>
14+
#include <executorch/extension/llm/runner/util.h>
1415
#include <executorch/extension/llm/tokenizer/bpe_tokenizer.h>
1516
#include <executorch/extension/runner_util/managed_tensor.h>
17+
#include <executorch/runtime/core/exec_aten/exec_aten.h>
18+
#include <executorch/runtime/core/exec_aten/util/scalar_type_util.h>
19+
#include <executorch/runtime/platform/log.h>
1620

1721
#include <ctime>
1822
#include <memory>
1923
#include <sstream>
2024

21-
#include <executorch/examples/models/llama2/runner/util.h>
22-
#include <executorch/runtime/core/exec_aten/exec_aten.h>
23-
#include <executorch/runtime/core/exec_aten/util/scalar_type_util.h>
24-
#include <executorch/runtime/platform/log.h>
25-
2625
#if defined(__aarch64__)
2726
#include "arm_neon.h"
2827
#endif

examples/qualcomm/llama2/runner/runner.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@
1111

1212
#include <executorch/examples/qualcomm/llama2/runner/runner.h>
1313
#include <executorch/extension/evalue_util/print_evalue.h>
14+
#include <executorch/extension/llm/runner/util.h>
1415
#include <executorch/extension/llm/tokenizer/bpe_tokenizer.h>
1516
#include <executorch/extension/runner_util/managed_tensor.h>
17+
#include <executorch/runtime/core/exec_aten/exec_aten.h>
18+
#include <executorch/runtime/core/exec_aten/util/scalar_type_util.h>
19+
#include <executorch/runtime/platform/log.h>
1620

1721
#include <ctime>
1822
#include <memory>
1923
#include <sstream>
2024

21-
#include <executorch/examples/models/llama2/runner/util.h>
22-
#include <executorch/runtime/core/exec_aten/exec_aten.h>
23-
#include <executorch/runtime/core/exec_aten/util/scalar_type_util.h>
24-
#include <executorch/runtime/platform/log.h>
25-
2625
namespace torch {
2726
namespace executor {
2827

sdk/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ set(FLATCC_REFLECTION
6262
OFF
6363
CACHE BOOL ""
6464
)
65+
set(FLATCC_DEBUG_CLANG_SANITIZE
66+
OFF
67+
CACHE BOOL ""
68+
)
6569
set(_flatcc_source_dir ${CMAKE_CURRENT_SOURCE_DIR}/../third-party/flatcc)
6670
add_subdirectory(${_flatcc_source_dir} ${CMAKE_BINARY_DIR}/third-party/flatcc)
6771

0 commit comments

Comments
 (0)