Skip to content

Commit 95dd5dd

Browse files
committed
Fix rpath
1 parent 92d2596 commit 95dd5dd

File tree

2 files changed

+50
-38
lines changed

2 files changed

+50
-38
lines changed

CMakeLists.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,9 @@ if(EXECUTORCH_BUILD_PYBIND)
800800
torch
801801
)
802802

803+
# RPATH for _portable_lib.so
804+
set(_portable_lib_rpath "$ORIGIN/../../../torch/lib")
805+
803806
if(EXECUTORCH_BUILD_EXTENSION_MODULE)
804807
# Always use static linking for pybindings to avoid runtime symbol
805808
# resolution issues
@@ -834,6 +837,7 @@ if(EXECUTORCH_BUILD_PYBIND)
834837

835838
if(EXECUTORCH_BUILD_QNN)
836839
list(APPEND _dep_libs qnn_executorch_backend)
840+
string(APPEND _portable_lib_rpath ":$ORIGIN/../../backends/qualcomm")
837841
endif()
838842

839843
if(EXECUTORCH_BUILD_ENN)
@@ -885,19 +889,19 @@ if(EXECUTORCH_BUILD_PYBIND)
885889
target_compile_options(portable_lib PUBLIC ${_pybind_compile_options})
886890
target_link_libraries(portable_lib PRIVATE ${_dep_libs})
887891

888-
# Set RPATH to find PyTorch libraries relative to the installation location
889-
# This goes from executorch/extension/pybindings up to site-packages, then to
890-
# torch/lib. Don't do this to APPLE, as it will error out on the following
891-
# error:
892+
# Set RPATH to find PyTorch and backend libraries relative to the installation
893+
# location. This goes from executorch/extension/pybindings up to site-packages,
894+
# then to torch/lib. If QNN is enabled, also add backends/qualcomm/.
895+
# Don't do this to APPLE, as it will error out on the following error:
892896
#
893897
if(APPLE)
894898
# Skip setting @loader_path for APPLE, since it causes error like ld:
895899
# duplicate LC_RPATH '@loader_path' in '<site-packages>/torch/lib/
896900
# libtorch_cpu.dylib'
897901
else()
898902
set_target_properties(
899-
portable_lib PROPERTIES BUILD_RPATH "$ORIGIN/../../../torch/lib"
900-
INSTALL_RPATH "$ORIGIN/../../../torch/lib"
903+
portable_lib PROPERTIES BUILD_RPATH "${_portable_lib_rpath}"
904+
INSTALL_RPATH "${_portable_lib_rpath}"
901905
)
902906
endif()
903907

backends/qualcomm/CMakeLists.txt

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,50 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES
3535
endif()
3636

3737
if(NOT DEFINED QNN_SDK_ROOT)
38-
if(_qnn_host_is_linux_x86)
39-
find_package(
40-
Python3
41-
COMPONENTS Interpreter
42-
REQUIRED
43-
)
44-
message(STATUS "QNN_SDK_ROOT not provided, downloading Qualcomm SDK")
45-
execute_process(
46-
COMMAND
47-
${Python3_EXECUTABLE}
48-
${EXECUTORCH_SOURCE_DIR}/backends/qualcomm/scripts/download_qnn_sdk.py
49-
--print-sdk-path
50-
WORKING_DIRECTORY ${EXECUTORCH_SOURCE_DIR}
51-
RESULT_VARIABLE _qnn_sdk_download_result
52-
OUTPUT_VARIABLE _qnn_sdk_download_output
53-
ERROR_VARIABLE _qnn_sdk_download_error
54-
OUTPUT_STRIP_TRAILING_WHITESPACE
55-
)
56-
if(NOT _qnn_sdk_download_result EQUAL 0 OR _qnn_sdk_download_output
57-
STREQUAL ""
58-
)
38+
if(_qnn_host_is_linux_x86)
39+
set(_qnn_default_sdk_dir
40+
"${CMAKE_CURRENT_LIST_DIR}/sdk/qnn"
41+
)
42+
43+
if(EXISTS "${_qnn_default_sdk_dir}" AND EXISTS "${_qnn_default_sdk_dir}/lib")
44+
message(STATUS "Found cached Qualcomm SDK at ${_qnn_default_sdk_dir}")
45+
set(QNN_SDK_ROOT
46+
${_qnn_default_sdk_dir}
47+
CACHE PATH "Qualcomm SDK root directory" FORCE
48+
)
49+
else()
50+
message(STATUS "QNN_SDK_ROOT not provided, downloading Qualcomm SDK")
51+
execute_process(
52+
COMMAND
53+
${PYTHON_EXECUTABLE}
54+
${EXECUTORCH_SOURCE_DIR}/backends/qualcomm/scripts/download_qnn_sdk.py
55+
--print-sdk-path
56+
WORKING_DIRECTORY ${EXECUTORCH_SOURCE_DIR}
57+
RESULT_VARIABLE _qnn_sdk_download_result
58+
OUTPUT_VARIABLE _qnn_sdk_download_output
59+
ERROR_VARIABLE _qnn_sdk_download_error
60+
OUTPUT_STRIP_TRAILING_WHITESPACE
61+
)
62+
if(NOT _qnn_sdk_download_result EQUAL 0 OR _qnn_sdk_download_output
63+
STREQUAL ""
64+
)
65+
message(
66+
FATAL_ERROR
67+
"Failed to download Qualcomm SDK. stdout: ${_qnn_sdk_download_output}\n"
68+
"stderr: ${_qnn_sdk_download_error}"
69+
)
70+
endif()
71+
set(QNN_SDK_ROOT
72+
${_qnn_sdk_download_output}
73+
CACHE PATH "Qualcomm SDK root directory" FORCE
74+
)
75+
endif()
76+
else()
5977
message(
6078
FATAL_ERROR
61-
"Failed to download Qualcomm SDK. stdout: ${_qnn_sdk_download_output}\n"
62-
"stderr: ${_qnn_sdk_download_error}"
79+
"Please define QNN_SDK_ROOT, e.g. cmake <..> -DQNN_SDK_ROOT=<...>"
6380
)
6481
endif()
65-
set(QNN_SDK_ROOT
66-
${_qnn_sdk_download_output}
67-
CACHE PATH "Qualcomm SDK root directory" FORCE
68-
)
69-
else()
70-
message(
71-
FATAL_ERROR
72-
"Please define QNN_SDK_ROOT, e.g. cmake <..> -DQNN_SDK_ROOT=<...>"
73-
)
7482
endif()
7583
endif()
7684

0 commit comments

Comments
 (0)