Skip to content

Commit

Permalink
[QNN EP] refactor QNN deps/copy logic. start copying deps to target p…
Browse files Browse the repository at this point in the history
…ython loc… (microsoft#20317)

copy QNN deps when building python bindings as well.
tweak the wildcard to only copy QNN related files. latest sdk from
Qualcomm (>= 2.21) also include SNPE dll's which we don't want to
include.
  • Loading branch information
jywu-msft authored Apr 16, 2024
1 parent caf692e commit 08d208b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 34 deletions.
32 changes: 32 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,38 @@ if (onnxruntime_USE_QNN)
list(APPEND ORT_PROVIDER_FLAGS -DUSE_QNN=1)
list(APPEND ORT_PROVIDER_CMAKE_FLAGS -Donnxruntime_USE_QNN=1)
list(APPEND ONNXRUNTIME_PROVIDER_NAMES qnn)
if (NOT QNN_ARCH_ABI)
string(TOLOWER ${onnxruntime_target_platform} GEN_PLATFORM)
if(MSVC)
message(STATUS "Building MSVC for architecture ${CMAKE_SYSTEM_PROCESSOR} with CMAKE_GENERATOR_PLATFORM as ${GEN_PLATFORM}")
if (${GEN_PLATFORM} STREQUAL "arm64")
set(QNN_ARCH_ABI aarch64-windows-msvc)
else()
set(QNN_ARCH_ABI x86_64-windows-msvc)
endif()
else()
if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
set(QNN_ARCH_ABI aarch64-android-clang6.0)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
if (${GEN_PLATFORM} STREQUAL "x86_64")
set(QNN_ARCH_ABI x86_64-linux-clang)
else()
set(QNN_ARCH_ABI aarch64-android)
endif()
endif()
endif()
endif()

if (MSVC OR ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
file(GLOB QNN_LIB_FILES LIST_DIRECTORIES false "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/libQnn*.so" "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/Qnn*.dll")
if (${QNN_ARCH_ABI} STREQUAL "aarch64-windows-msvc")
file(GLOB EXTRA_HTP_LIB LIST_DIRECTORIES false "${onnxruntime_QNN_HOME}/lib/hexagon-v68/unsigned/libQnnHtpV68Skel.so"
"${onnxruntime_QNN_HOME}/lib/hexagon-v73/unsigned/libQnnHtpV73Skel.so"
"${onnxruntime_QNN_HOME}/lib/hexagon-v73/unsigned/libqnnhtpv73.cat")
list(APPEND QNN_LIB_FILES ${EXTRA_HTP_LIB})
endif()
message(STATUS "QNN lib files: " ${QNN_LIB_FILES})
endif()
endif()
if (onnxruntime_USE_SNPE)
list(APPEND ORT_PROVIDER_FLAGS -DUSE_SNPE=1)
Expand Down
9 changes: 9 additions & 0 deletions cmake/onnxruntime_python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,15 @@ if (onnxruntime_USE_COREML)
)
endif()

if (onnxruntime_USE_QNN)
add_custom_command(
TARGET onnxruntime_pybind11_state POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${QNN_LIB_FILES}
$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
)
endif()

endif()
if (onnxruntime_ENABLE_LANGUAGE_INTEROP_OPS)
include(onnxruntime_language_interop_ops.cmake)
Expand Down
38 changes: 4 additions & 34 deletions cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -982,41 +982,11 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
endif()

if (onnxruntime_USE_QNN)
if (NOT QNN_ARCH_ABI)
string(TOLOWER ${onnxruntime_target_platform} GEN_PLATFORM)
if(MSVC)
message(STATUS "Building MSVC for architecture ${CMAKE_SYSTEM_PROCESSOR} with CMAKE_GENERATOR_PLATFORM as ${GEN_PLATFORM}")
if (${GEN_PLATFORM} STREQUAL "arm64")
set(QNN_ARCH_ABI aarch64-windows-msvc)
else()
set(QNN_ARCH_ABI x86_64-windows-msvc)
endif()
else()
if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
set(QNN_ARCH_ABI aarch64-android-clang6.0)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
if (${GEN_PLATFORM} STREQUAL "x86_64")
set(QNN_ARCH_ABI x86_64-linux-clang)
else()
set(QNN_ARCH_ABI aarch64-android)
endif()
endif()
endif()
endif()

if (MSVC OR ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
file(GLOB QNN_LIB_FILES LIST_DIRECTORIES false "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/*.so" "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/*.dll")
if (${QNN_ARCH_ABI} STREQUAL "aarch64-windows-msvc")
file(GLOB EXTRA_HTP_LIB LIST_DIRECTORIES false "${onnxruntime_QNN_HOME}/lib/hexagon-v68/unsigned/libQnnHtpV68Skel.so"
"${onnxruntime_QNN_HOME}/lib/hexagon-v73/unsigned/libQnnHtpV73Skel.so"
"${onnxruntime_QNN_HOME}/lib/hexagon-v73/unsigned/libqnnhtpv73.cat")
list(APPEND QNN_LIB_FILES ${EXTRA_HTP_LIB})
endif()
message(STATUS "QNN lib files: " ${QNN_LIB_FILES})
add_custom_command(
TARGET ${test_data_target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${QNN_LIB_FILES} $<TARGET_FILE_DIR:${test_data_target}>
)
add_custom_command(
TARGET ${test_data_target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${QNN_LIB_FILES} $<TARGET_FILE_DIR:${test_data_target}>
)
endif()
endif()

Expand Down

0 comments on commit 08d208b

Please sign in to comment.