mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-14 20:48:00 +00:00
### Description
- Makes QNN EP a shared library **by default** when building with
`--use_qnn` or `--use_qnn shared_lib`. Generates the following build
artifacts:
- **Windows**: `onnxruntime_providers_qnn.dll` and
`onnxruntime_providers_shared.dll`
- **Linux**: `libonnxruntime_providers_qnn.so` and
`libonnxruntime_providers_shared.so`
- **Android**: Not supported. Must build QNN EP as a static library.
- Allows QNN EP to still be built as a static library with `--use_qnn
static_lib`. This is primarily for the Android QNN AAR package.
- Unit tests run for both the static and shared QNN EP builds.
### Detailed changes
- Updates Java bindings to support both shared and static QNN EP builds.
- Provider bridge API:
- Adds logging sink ETW to the provider bridge. Allows EPs to register
ETW callbacks for ORT logging.
- Adds a variety of methods for onnxruntime objects that are needed by
QNN EP.
- QNN EP:
- Adds `ort_api.h` and `ort_api.cc` that encapsulates the API provided
by ORT in a manner that allows the EP to be built as either a shared or
static library.
- Adds custom function to transpose weights for Conv and Gemm (instead
of adding util to provider bridge API).
- Adds custom function to quantize data for LeakyRelu (instead of adding
util to provider bridge API).
- Adds custom ETW tracing for QNN profiling events:
- shared library: defines its own TraceLogging provider handle
- static library: uses ORT's TraceLogging provider handle and existing
telemetry provider.
- ORT-QNN Packages:
- **Python**: Pipelines build QNN EP as a shared library by default.
User can build a local python wheel with QNN EP as a static library by
passing `--use_qnn static_lib`.
- **NuGet**: Pipelines build QNN EP as a shared library by default.
`build.py` currently enforces QNN EP to be built as a shared library.
Can add support for building a QNN NuGet package with static later if
deemed necessary.
- **Android**: Pipelines build QNN EP as a **static library**.
`build.py` enforces QNN EP to be built as a static library. Packaging
multiple shared libraries into an Android AAR package is not currently
supported due to the added need to also distribute a shared libcpp.so
library.
### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
91 lines
4.7 KiB
CMake
91 lines
4.7 KiB
CMake
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
|
|
add_compile_definitions(USE_QNN=1)
|
|
|
|
if(onnxruntime_BUILD_QNN_EP_STATIC_LIB)
|
|
add_compile_definitions(BUILD_QNN_EP_STATIC_LIB=1)
|
|
endif()
|
|
|
|
file(GLOB_RECURSE
|
|
onnxruntime_providers_qnn_ep_srcs CONFIGURE_DEPENDS
|
|
"${ONNXRUNTIME_ROOT}/core/providers/qnn/*.h"
|
|
"${ONNXRUNTIME_ROOT}/core/providers/qnn/*.cc"
|
|
)
|
|
|
|
if(onnxruntime_BUILD_QNN_EP_STATIC_LIB)
|
|
#
|
|
# Build QNN EP as a static library
|
|
#
|
|
set(onnxruntime_providers_qnn_srcs ${onnxruntime_providers_qnn_ep_srcs})
|
|
source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_qnn_srcs})
|
|
onnxruntime_add_static_library(onnxruntime_providers_qnn ${onnxruntime_providers_qnn_srcs})
|
|
onnxruntime_add_include_to_target(onnxruntime_providers_qnn onnxruntime_common onnxruntime_framework onnx
|
|
onnx_proto protobuf::libprotobuf-lite
|
|
flatbuffers::flatbuffers Boost::mp11)
|
|
add_dependencies(onnxruntime_providers_qnn onnx ${onnxruntime_EXTERNAL_DEPENDENCIES})
|
|
set_target_properties(onnxruntime_providers_qnn PROPERTIES CXX_STANDARD_REQUIRED ON)
|
|
set_target_properties(onnxruntime_providers_qnn PROPERTIES FOLDER "ONNXRuntime")
|
|
target_include_directories(onnxruntime_providers_qnn PRIVATE ${ONNXRUNTIME_ROOT}
|
|
${onnxruntime_QNN_HOME}/include/QNN
|
|
${onnxruntime_QNN_HOME}/include)
|
|
set_target_properties(onnxruntime_providers_qnn PROPERTIES LINKER_LANGUAGE CXX)
|
|
|
|
# ignore the warning unknown-pragmas on "pragma region"
|
|
if(NOT MSVC)
|
|
target_compile_options(onnxruntime_providers_qnn PRIVATE "-Wno-unknown-pragmas")
|
|
endif()
|
|
else()
|
|
#
|
|
# Build QNN EP as a shared library
|
|
#
|
|
file(GLOB_RECURSE
|
|
onnxruntime_providers_qnn_shared_lib_srcs CONFIGURE_DEPENDS
|
|
"${ONNXRUNTIME_ROOT}/core/providers/shared_library/*.h"
|
|
"${ONNXRUNTIME_ROOT}/core/providers/shared_library/*.cc"
|
|
)
|
|
set(onnxruntime_providers_qnn_srcs ${onnxruntime_providers_qnn_ep_srcs}
|
|
${onnxruntime_providers_qnn_shared_lib_srcs})
|
|
|
|
source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_qnn_srcs})
|
|
onnxruntime_add_shared_library_module(onnxruntime_providers_qnn ${onnxruntime_providers_qnn_srcs})
|
|
onnxruntime_add_include_to_target(onnxruntime_providers_qnn ${ONNXRUNTIME_PROVIDERS_SHARED} ${GSL_TARGET} onnx
|
|
onnxruntime_common Boost::mp11 safeint_interface)
|
|
target_link_libraries(onnxruntime_providers_qnn PRIVATE ${ONNXRUNTIME_PROVIDERS_SHARED} ${ABSEIL_LIBS} ${CMAKE_DL_LIBS})
|
|
add_dependencies(onnxruntime_providers_qnn onnxruntime_providers_shared ${onnxruntime_EXTERNAL_DEPENDENCIES})
|
|
target_include_directories(onnxruntime_providers_qnn PRIVATE ${ONNXRUNTIME_ROOT}
|
|
${CMAKE_CURRENT_BINARY_DIR}
|
|
${onnxruntime_QNN_HOME}/include/QNN
|
|
${onnxruntime_QNN_HOME}/include)
|
|
|
|
# Set linker flags for function(s) exported by EP DLL
|
|
if(UNIX)
|
|
target_link_options(onnxruntime_providers_qnn PRIVATE
|
|
"LINKER:--version-script=${ONNXRUNTIME_ROOT}/core/providers/qnn/version_script.lds"
|
|
"LINKER:--gc-sections"
|
|
"LINKER:-rpath=\$ORIGIN"
|
|
)
|
|
elseif(WIN32)
|
|
set_property(TARGET onnxruntime_providers_qnn APPEND_STRING PROPERTY LINK_FLAGS
|
|
"-DEF:${ONNXRUNTIME_ROOT}/core/providers/qnn/symbols.def")
|
|
else()
|
|
message(FATAL_ERROR "onnxruntime_providers_qnn unknown platform, need to specify shared library exports for it")
|
|
endif()
|
|
|
|
# Set compile options
|
|
if(MSVC)
|
|
target_compile_options(onnxruntime_providers_qnn PUBLIC /wd4099 /wd4005)
|
|
else()
|
|
# ignore the warning unknown-pragmas on "pragma region"
|
|
target_compile_options(onnxruntime_providers_qnn PRIVATE "-Wno-unknown-pragmas")
|
|
endif()
|
|
|
|
set_target_properties(onnxruntime_providers_qnn PROPERTIES LINKER_LANGUAGE CXX)
|
|
set_target_properties(onnxruntime_providers_qnn PROPERTIES CXX_STANDARD_REQUIRED ON)
|
|
set_target_properties(onnxruntime_providers_qnn PROPERTIES FOLDER "ONNXRuntime")
|
|
|
|
install(TARGETS onnxruntime_providers_qnn
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
endif()
|