From 98c573976b0d042e8001a1c7a68f5e9c30cd24d2 Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 12:31:10 -0700 Subject: [PATCH 01/20] adding linux x64 qnn python job --- .../azure-pipelines/py-packaging-pipeline.yml | 6 ++ .../templates/py-linux-qnn.yml | 98 +++++++++++++++++++ .../templates/py-packaging-stage.yml | 16 +++ 3 files changed, 120 insertions(+) create mode 100644 tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml diff --git a/tools/ci_build/github/azure-pipelines/py-packaging-pipeline.yml b/tools/ci_build/github/azure-pipelines/py-packaging-pipeline.yml index 8107c1a890973..7263239c6c7f0 100644 --- a/tools/ci_build/github/azure-pipelines/py-packaging-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/py-packaging-pipeline.yml @@ -44,6 +44,11 @@ parameters: type: boolean default: true +- name: enable_linux_x64_qnn + displayName: 'Whether Linux x86_64 package with QNN EP is built.' + type: boolean + default: true + - name: build_py_parameters displayName: 'Specify extra build parameters' type: string @@ -80,6 +85,7 @@ stages: enable_windows_arm64_qnn: ${{ parameters.enable_windows_arm64_qnn }} enable_windows_arm64ec_qnn: ${{ parameters.enable_windows_arm64ec_qnn }} enable_windows_x64_qnn: ${{ parameters.enable_windows_x64_qnn }} + enable_linux_x64_qnn: ${{ parameters.enable_linux_x64_qnn }} build_py_parameters: ${{ parameters.build_py_parameters }} cmake_build_type: ${{ parameters.cmake_build_type }} qnn_sdk_version: ${{ parameters.qnn_sdk_version }} diff --git a/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml b/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml new file mode 100644 index 0000000000000..42fd87d655e11 --- /dev/null +++ b/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml @@ -0,0 +1,98 @@ +parameters: +- name: machine_pool + type: string + +- name: cmake_build_type + type: string + default: 'Release' + values: + - Debug + - Release + - RelWithDebInfo + - MinSizeRel + +- name: device + type: string + default: 'CPU' + +- name: with_cache + type: boolean + default: false + +- name: extra_build_arg + type: string + default: '' + +- name: QnnSdk + displayName: QNN SDK version + type: string + default: 2.26.0.240828 + +jobs: +- job: Linux_py_qnn_Wheels_x64 + timeoutInMinutes: 240 + workspace: + clean: all + pool: ${{ parameters.machine_pool }} + variables: + # The build machine pool doesn't have dotnet, so it can't run CG. + - name: skipComponentGovernanceDetection + value: true + - name: ORT_CACHE_DIR + value: $(Agent.TempDirectory)/ort_ccache + - name: TODAY + value: $[format('{0:dd}{0:MM}{0:yyyy}', pipeline.startTime)] + - name: extra_build_args + ${{ if ne(parameters.extra_build_arg, '') }}: + value: -x ${{ parameters.extra_build_arg }} + ${{ if eq(parameters.extra_build_arg, '') }}: + value: '' + steps: + - task: mspremier.PostBuildCleanup.PostBuildCleanup-task.PostBuildCleanup@3 + displayName: 'Clean Agent Directories' + condition: always() + + - checkout: self + clean: true + submodules: none + + - template: jobs/download_linux_qnn_sdk.yml + parameters: + QnnSDKVersion: ${{ parameters.QnnSdk }} + + - template: set-nightly-build-option-variable-step.yml + + - template: get-docker-image-steps.yml + parameters: + Dockerfile: tools/ci_build/github/linux/docker/inference/x86_64/python/cpu/Dockerfile + Context: tools/ci_build/github/linux/docker/inference/x86_64/python/cpu + DockerBuildArgs: "--build-arg BUILD_UID=$( id -u )" + Repository: onnxruntimecpubuildpythonx86_64_qnn + + - template: linux-build-step-with-cache.yml + parameters: + WithCache: ${{parameters.with_cache}} + Today: $(TODAY) + AdditionalKey: Linux_py_qnn_Wheels_x64 + CacheDir: $(ORT_CACHE_DIR) + ChangeEveryCommit: true + BuildStep: + - task: Bash@3 + displayName: 'Build Python Wheel' + inputs: + targetType: filePath + filePath: tools/ci_build/github/linux/run_python_dockerbuild.sh + arguments: -i onnxruntimecpubuildpythonx86_64_qnn -d "${{ parameters.device }}" -c ${{ parameters.cmake_build_type }} $(extra_build_args) + ${{ if eq(parameters.with_cache, 'true') }}: + env: + ADDITIONAL_DOCKER_PARAMETER: "--volume $(ORT_CACHE_DIR):/cache -e CCACHE_DIR=/cache -e ORT_BUILD_WITH_CACHE=1" + + - task: PublishBuildArtifacts@1 + displayName: 'Publish Artifact: Linux ONNXRuntime QNN python wheel' + inputs: + PathtoPublish: '$(Build.BinariesDirectory)/dist' + ArtifactName: onnxruntime-linux-qnn-x64 + + - template: component-governance-component-detection-steps.yml + parameters : + condition : 'succeeded' diff --git a/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml b/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml index 451e5ad2d44c7..e673388b943b7 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml @@ -50,6 +50,11 @@ parameters: type: boolean default: true +- name: enable_linux_x64_qnn + displayName: 'Whether Linux x86_64 package with QNN EP is built.' + type: boolean + default: true + - name: cmake_build_type type: string displayName: 'Linux packages cmake build type. Linux Only.' @@ -534,3 +539,14 @@ stages: MACHINE_POOL: 'Onnxruntime-QNNEP-Windows-2022-CPU' QNN_SDK: ${{ parameters.qnn_sdk_version }} BUILD_PY_PARAMETERS: ${{ parameters.build_py_parameters }} + + - ${{ if eq(parameters.enable_linux_x64_qnn, true) }}: + - stage: Python_Packaging_Linux_x64_QNN + dependsOn: [] + jobs: + - template: py-linux-qnn.yml + parameters: + arch: 'x86_64' + machine_pool: 'onnxruntime-Ubuntu2204-AMD-CPU' + extra_build_arg: ${{ parameters.build_py_parameters }} + cmake_build_type: ${{ parameters.cmake_build_type }} From 461907077771301e9c8e9b6af98305abc804f997 Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 12:43:50 -0700 Subject: [PATCH 02/20] format --- .../github/azure-pipelines/templates/py-linux-qnn.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml b/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml index 42fd87d655e11..9aa01ecdef2b7 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml @@ -57,8 +57,8 @@ jobs: submodules: none - template: jobs/download_linux_qnn_sdk.yml - parameters: - QnnSDKVersion: ${{ parameters.QnnSdk }} + parameters: + QnnSDKVersion: ${{ parameters.QnnSdk }} - template: set-nightly-build-option-variable-step.yml From 115f8322ea158027114ff1bdad2964b541d73a47 Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 12:46:43 -0700 Subject: [PATCH 03/20] fix --- .../github/azure-pipelines/templates/py-packaging-stage.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml b/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml index e673388b943b7..c438033edc29f 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-packaging-stage.yml @@ -546,7 +546,6 @@ stages: jobs: - template: py-linux-qnn.yml parameters: - arch: 'x86_64' machine_pool: 'onnxruntime-Ubuntu2204-AMD-CPU' extra_build_arg: ${{ parameters.build_py_parameters }} cmake_build_type: ${{ parameters.cmake_build_type }} From c547e0aed24d34fb29ae90cc289b6d6c6bd8d76d Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 13:42:49 -0700 Subject: [PATCH 04/20] test --- .../github/azure-pipelines/templates/py-linux-qnn.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml b/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml index 9aa01ecdef2b7..3ee6ea62ccbe5 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml @@ -82,10 +82,9 @@ jobs: inputs: targetType: filePath filePath: tools/ci_build/github/linux/run_python_dockerbuild.sh - arguments: -i onnxruntimecpubuildpythonx86_64_qnn -d "${{ parameters.device }}" -c ${{ parameters.cmake_build_type }} $(extra_build_args) - ${{ if eq(parameters.with_cache, 'true') }}: - env: - ADDITIONAL_DOCKER_PARAMETER: "--volume $(ORT_CACHE_DIR):/cache -e CCACHE_DIR=/cache -e ORT_BUILD_WITH_CACHE=1" + arguments: -i onnxruntimecpubuildpythonx86_64_qnn -d "${{ parameters.device }}" -c ${{ parameters.cmake_build_type }} -x --use_qnn --qnn_home /qnn_sdk + env: + ADDITIONAL_DOCKER_PARAMETER: "--volume $(QnnSDKRootDir):/qnn_sdk" - task: PublishBuildArtifacts@1 displayName: 'Publish Artifact: Linux ONNXRuntime QNN python wheel' From c586b4c4e5ff90746e52ba6712766e6036c8be1c Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 14:06:05 -0700 Subject: [PATCH 05/20] test --- .../github/azure-pipelines/templates/py-linux-qnn.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml b/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml index 3ee6ea62ccbe5..09827a6ce9ab5 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml @@ -43,10 +43,8 @@ jobs: - name: TODAY value: $[format('{0:dd}{0:MM}{0:yyyy}', pipeline.startTime)] - name: extra_build_args - ${{ if ne(parameters.extra_build_arg, '') }}: - value: -x ${{ parameters.extra_build_arg }} - ${{ if eq(parameters.extra_build_arg, '') }}: - value: '' + value: "-x '--use_qnn --qnn_home /qnn_sdk'" + steps: - task: mspremier.PostBuildCleanup.PostBuildCleanup-task.PostBuildCleanup@3 displayName: 'Clean Agent Directories' @@ -82,7 +80,7 @@ jobs: inputs: targetType: filePath filePath: tools/ci_build/github/linux/run_python_dockerbuild.sh - arguments: -i onnxruntimecpubuildpythonx86_64_qnn -d "${{ parameters.device }}" -c ${{ parameters.cmake_build_type }} -x --use_qnn --qnn_home /qnn_sdk + arguments: -i onnxruntimecpubuildpythonx86_64_qnn -d "${{ parameters.device }}" -c ${{ parameters.cmake_build_type }} $(extra_build_args) env: ADDITIONAL_DOCKER_PARAMETER: "--volume $(QnnSDKRootDir):/qnn_sdk" From 06b813bde5dd062c6bc6536e55fb40da2c39f1fc Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 14:17:28 -0700 Subject: [PATCH 06/20] escape --- .../ci_build/github/azure-pipelines/templates/py-linux-qnn.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml b/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml index 09827a6ce9ab5..5d777e289a7dd 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml @@ -43,7 +43,7 @@ jobs: - name: TODAY value: $[format('{0:dd}{0:MM}{0:yyyy}', pipeline.startTime)] - name: extra_build_args - value: "-x '--use_qnn --qnn_home /qnn_sdk'" + value: "-x \"--use_qnn --qnn_home /qnn_sdk\"" steps: - task: mspremier.PostBuildCleanup.PostBuildCleanup-task.PostBuildCleanup@3 From 1c981521c86894900ca85313d74fdfb55ebe0236 Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 14:34:32 -0700 Subject: [PATCH 07/20] escape --- .../ci_build/github/azure-pipelines/templates/py-linux-qnn.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml b/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml index 5d777e289a7dd..d70af7b420a0b 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml @@ -43,7 +43,7 @@ jobs: - name: TODAY value: $[format('{0:dd}{0:MM}{0:yyyy}', pipeline.startTime)] - name: extra_build_args - value: "-x \"--use_qnn --qnn_home /qnn_sdk\"" + value: "-x \\\"--use_qnn --qnn_home /qnn_sdk\\\"" steps: - task: mspremier.PostBuildCleanup.PostBuildCleanup-task.PostBuildCleanup@3 From 3e8a728ebb28a2e1b1327ccae963da567e844df4 Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 15:05:49 -0700 Subject: [PATCH 08/20] fix --- .../github/azure-pipelines/templates/py-linux-qnn.yml | 8 +++++--- .../ci_build/github/linux/build_linux_python_package.sh | 9 +++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml b/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml index d70af7b420a0b..6220a9a46c312 100644 --- a/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml +++ b/tools/ci_build/github/azure-pipelines/templates/py-linux-qnn.yml @@ -13,7 +13,7 @@ parameters: - name: device type: string - default: 'CPU' + default: 'NPU' - name: with_cache type: boolean @@ -43,8 +43,10 @@ jobs: - name: TODAY value: $[format('{0:dd}{0:MM}{0:yyyy}', pipeline.startTime)] - name: extra_build_args - value: "-x \\\"--use_qnn --qnn_home /qnn_sdk\\\"" - + ${{ if ne(parameters.extra_build_arg, '') }}: + value: -x ${{ parameters.extra_build_arg }} + ${{ if eq(parameters.extra_build_arg, '') }}: + value: '' steps: - task: mspremier.PostBuildCleanup.PostBuildCleanup-task.PostBuildCleanup@3 displayName: 'Clean Agent Directories' diff --git a/tools/ci_build/github/linux/build_linux_python_package.sh b/tools/ci_build/github/linux/build_linux_python_package.sh index e7909fa4ffccb..ccc201cbc8843 100755 --- a/tools/ci_build/github/linux/build_linux_python_package.sh +++ b/tools/ci_build/github/linux/build_linux_python_package.sh @@ -13,12 +13,12 @@ PYTHON_EXES=("/opt/python/cp38-cp38/bin/python3.8" "/opt/python/cp39-cp39/bin/py while getopts "d:p:x:c:" parameter_Option do case "${parameter_Option}" in -#GPU or CPU. +#GPU|CPU|NPU. d) BUILD_DEVICE=${OPTARG};; p) PYTHON_EXES=${OPTARG};; x) EXTRA_ARG=${OPTARG};; c) BUILD_CONFIG=${OPTARG};; -*) echo "Usage: $0 -d [-p ] [-x ] [-c ]" +*) echo "Usage: $0 -d [-p ] [-x ] [-c ]" exit 1;; esac done @@ -55,6 +55,11 @@ if [ "$BUILD_DEVICE" == "GPU" ]; then BUILD_ARGS+=("--nvcc_threads=1" "--use_cuda" "--use_tensorrt" "--cuda_version=$SHORT_CUDA_VERSION" "--tensorrt_home=/usr" "--cuda_home=/usr/local/cuda-$SHORT_CUDA_VERSION" "--cudnn_home=/usr/local/cuda-$SHORT_CUDA_VERSION" "--cmake_extra_defines" "CMAKE_CUDA_ARCHITECTURES=52;60;61;70;75;80") fi +if [ "$BUILD_DEVICE" == "NPU" ]; then + #Enable QNN EP + BUILD_ARGS+=("--use_qnn" "--qnn_home=/qnn_sdk") +fi + for PYTHON_EXE in "${PYTHON_EXES[@]}" do rm -rf /build/"$BUILD_CONFIG" From bd70e167ae5397b34ba5a402d06caa0f2f48c65e Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 16:41:23 -0700 Subject: [PATCH 09/20] add qnn_ctx_gen tool --- cmake/onnxruntime_python.cmake | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmake/onnxruntime_python.cmake b/cmake/onnxruntime_python.cmake index 574cffbb716b3..f1955376de0c8 100644 --- a/cmake/onnxruntime_python.cmake +++ b/cmake/onnxruntime_python.cmake @@ -1027,6 +1027,12 @@ if (onnxruntime_USE_QNN) ${QNN_LIB_FILES} $/onnxruntime/capi/ ) + add_custom_command( + TARGET onnxruntime_pybind11_state POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $ + $/onnxruntime/tools/ + ) if (EXISTS "${onnxruntime_QNN_HOME}/Qualcomm AI Hub Proprietary License.pdf") add_custom_command( TARGET onnxruntime_pybind11_state POST_BUILD From aee669d212c0fbd31fa2d68b75a741580436159b Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 17:56:11 -0700 Subject: [PATCH 10/20] add setup.py --- cmake/onnxruntime_python.cmake | 2 +- setup.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cmake/onnxruntime_python.cmake b/cmake/onnxruntime_python.cmake index f1955376de0c8..b96a634471d7d 100644 --- a/cmake/onnxruntime_python.cmake +++ b/cmake/onnxruntime_python.cmake @@ -1031,7 +1031,7 @@ if (onnxruntime_USE_QNN) TARGET onnxruntime_pybind11_state POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ - $/onnxruntime/tools/ + $/onnxruntime/capi/ ) if (EXISTS "${onnxruntime_QNN_HOME}/Qualcomm AI Hub Proprietary License.pdf") add_custom_command( diff --git a/setup.py b/setup.py index ac8f465851484..1ac35c300d671 100644 --- a/setup.py +++ b/setup.py @@ -348,6 +348,16 @@ def finalize_options(self): libs.append(providers_cuda_or_rocm) libs.append(providers_tensorrt_or_migraphx) libs.append(providers_cann) + # QNN + qnn_deps = [ + "libQnnCpu.so", + "libQnnHtp.so", + "libQnnSaver.so", + "libQnnSystem.so", + "libHtpPrepare.so", + "onnxruntime_qnn_ctx_gen" + ] + libs.extend(qnn_deps) if nightly_build: libs.extend(["libonnxruntime_pywrapper.so"]) elif platform.system() == "Darwin": From a4ff9e34475e48ffa4ed9a24a57181066efa42a9 Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 18:04:34 -0700 Subject: [PATCH 11/20] fix --- .../azure-pipelines/orttraining-py-packaging-pipeline-cpu.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/ci_build/github/azure-pipelines/orttraining-py-packaging-pipeline-cpu.yml b/tools/ci_build/github/azure-pipelines/orttraining-py-packaging-pipeline-cpu.yml index 5ecb35aa25a56..a71e10f95f3e1 100644 --- a/tools/ci_build/github/azure-pipelines/orttraining-py-packaging-pipeline-cpu.yml +++ b/tools/ci_build/github/azure-pipelines/orttraining-py-packaging-pipeline-cpu.yml @@ -25,3 +25,4 @@ stages: enable_windows_arm64_qnn: false enable_windows_arm64ec_qnn: false enable_windows_x64_qnn: false + enable_linux_x64_qnn: false From afe362126e97defe6c0079fa6ec00a666903aac1 Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 19:54:49 -0700 Subject: [PATCH 12/20] fix --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1ac35c300d671..680997d40cf63 100644 --- a/setup.py +++ b/setup.py @@ -357,7 +357,7 @@ def finalize_options(self): "libHtpPrepare.so", "onnxruntime_qnn_ctx_gen" ] - libs.extend(qnn_deps) + dl_libs.extend(qnn_deps) if nightly_build: libs.extend(["libonnxruntime_pywrapper.so"]) elif platform.system() == "Darwin": From 7f1bfb6f013d75505cfcfc9cbe8ce98aa3301a64 Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 20:02:31 -0700 Subject: [PATCH 13/20] fix --- cmake/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 3d4f055bb6f53..1609626d15d3e 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -838,7 +838,8 @@ if (onnxruntime_USE_QNN) 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") + 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" \ + "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/libHtpPrepare.so" "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/HtpPrepare.dll") if (${QNN_ARCH_ABI} STREQUAL "aarch64-windows-msvc" OR ${QNN_ARCH_ABI} STREQUAL "arm64x-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" From 452e26b73bb3a18dd9ff9b74c0d9dce1b2050bc3 Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 20:22:47 -0700 Subject: [PATCH 14/20] fix --- cmake/CMakeLists.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 1609626d15d3e..2c3267ef4b782 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -838,14 +838,19 @@ if (onnxruntime_USE_QNN) 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" \ - "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/libHtpPrepare.so" "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/HtpPrepare.dll") + 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" OR ${QNN_ARCH_ABI} STREQUAL "arm64x-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() + if (${QNN_ARCH_ABI} STREQUAL "x64_64-linux-clang") + list(APPEND QNN_LIB_FILES "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/libHtpPrepare.so") + endif() + if (${QNN_ARCH_ABI} STREQUAL "x86_64-windows-msvc") + list(APPEND QNN_LIB_FILES "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/HtpPrepare.dll") + endif() message(STATUS "QNN lib files: " ${QNN_LIB_FILES}) endif() endif() From 412207cfc28e22c1b3832ef2ad8845f4f9d8eb04 Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 21:18:09 -0700 Subject: [PATCH 15/20] try 2.34 --- setup.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/setup.py b/setup.py index 680997d40cf63..89b806fd172a1 100644 --- a/setup.py +++ b/setup.py @@ -116,6 +116,7 @@ def parse_arg_remove_string(argv, arg_name_equal): "manylinux2014_s390x", "manylinux_2_28_x86_64", "manylinux_2_28_aarch64", + "manylinux_2_34_x86_64", ] is_manylinux = environ.get("AUDITWHEEL_PLAT", None) in manylinux_tags @@ -260,6 +261,8 @@ def run(self): cann_dependencies = ["libascendcl.so", "libacl_op_compiler.so", "libfmk_onnx_parser.so"] + #qnn_dependencies = ["libQnnCpu.so", "libQnnHtp.so", "libQnnSaver.so", "libQnnSystem.so", "libHtpPrepare.so", "onnxruntime_qnn_ctx_gen"] + dest = "onnxruntime/capi/libonnxruntime_providers_openvino.so" if path.isfile(dest): subprocess.run( @@ -283,6 +286,7 @@ def run(self): file = glob(path.join(self.dist_dir, "*linux*.whl"))[0] logger.info("repairing %s for manylinux1", file) auditwheel_cmd = ["auditwheel", "-v", "repair", "-w", self.dist_dir, file] + #for i in cuda_dependencies + rocm_dependencies + tensorrt_dependencies + cann_dependencies + qnn_dependencies: for i in cuda_dependencies + rocm_dependencies + tensorrt_dependencies + cann_dependencies: auditwheel_cmd += ["--exclude", i] logger.info("Running %s", " ".join([shlex.quote(arg) for arg in auditwheel_cmd])) From 42a535815cfe01d0907d087f2562123e1c2517fd Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 21:26:40 -0700 Subject: [PATCH 16/20] exclude qnn bins --- setup.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 89b806fd172a1..a4f907d41bbd2 100644 --- a/setup.py +++ b/setup.py @@ -116,7 +116,6 @@ def parse_arg_remove_string(argv, arg_name_equal): "manylinux2014_s390x", "manylinux_2_28_x86_64", "manylinux_2_28_aarch64", - "manylinux_2_34_x86_64", ] is_manylinux = environ.get("AUDITWHEEL_PLAT", None) in manylinux_tags @@ -261,7 +260,7 @@ def run(self): cann_dependencies = ["libascendcl.so", "libacl_op_compiler.so", "libfmk_onnx_parser.so"] - #qnn_dependencies = ["libQnnCpu.so", "libQnnHtp.so", "libQnnSaver.so", "libQnnSystem.so", "libHtpPrepare.so", "onnxruntime_qnn_ctx_gen"] + qnn_dependencies = ["libQnnCpu.so", "libQnnHtp.so", "libQnnSaver.so", "libQnnSystem.so", "libHtpPrepare.so", "onnxruntime_qnn_ctx_gen"] dest = "onnxruntime/capi/libonnxruntime_providers_openvino.so" if path.isfile(dest): @@ -286,8 +285,7 @@ def run(self): file = glob(path.join(self.dist_dir, "*linux*.whl"))[0] logger.info("repairing %s for manylinux1", file) auditwheel_cmd = ["auditwheel", "-v", "repair", "-w", self.dist_dir, file] - #for i in cuda_dependencies + rocm_dependencies + tensorrt_dependencies + cann_dependencies + qnn_dependencies: - for i in cuda_dependencies + rocm_dependencies + tensorrt_dependencies + cann_dependencies: + for i in cuda_dependencies + rocm_dependencies + tensorrt_dependencies + cann_dependencies + qnn_dependencies: auditwheel_cmd += ["--exclude", i] logger.info("Running %s", " ".join([shlex.quote(arg) for arg in auditwheel_cmd])) try: From b2ab1919959ee6aeadbd7f6026b0fdf0a96bfc18 Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 22:22:02 -0700 Subject: [PATCH 17/20] skip qnn audit --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index a4f907d41bbd2..83f48748bdf0f 100644 --- a/setup.py +++ b/setup.py @@ -59,6 +59,7 @@ def parse_arg_remove_string(argv, arg_name_equal): is_migraphx = False is_rocm = False is_openvino = False +is_qnn = False # The following arguments are mutually exclusive if wheel_name_suffix == "gpu": # TODO: how to support multiple CUDA versions? @@ -87,6 +88,7 @@ def parse_arg_remove_string(argv, arg_name_equal): # keep the same name since AzureEP will release with CpuEP by default. pass elif parse_arg_remove_boolean(sys.argv, "--use_qnn"): + is_qnn = True package_name = "onnxruntime-qnn" if is_rocm or is_migraphx: @@ -260,8 +262,6 @@ def run(self): cann_dependencies = ["libascendcl.so", "libacl_op_compiler.so", "libfmk_onnx_parser.so"] - qnn_dependencies = ["libQnnCpu.so", "libQnnHtp.so", "libQnnSaver.so", "libQnnSystem.so", "libHtpPrepare.so", "onnxruntime_qnn_ctx_gen"] - dest = "onnxruntime/capi/libonnxruntime_providers_openvino.so" if path.isfile(dest): subprocess.run( @@ -280,12 +280,12 @@ def run(self): pass _bdist_wheel.run(self) - if is_manylinux and not disable_auditwheel_repair and not is_openvino: + if is_manylinux and not disable_auditwheel_repair and not is_openvino and not is_qnn: assert self.dist_dir is not None file = glob(path.join(self.dist_dir, "*linux*.whl"))[0] logger.info("repairing %s for manylinux1", file) auditwheel_cmd = ["auditwheel", "-v", "repair", "-w", self.dist_dir, file] - for i in cuda_dependencies + rocm_dependencies + tensorrt_dependencies + cann_dependencies + qnn_dependencies: + for i in cuda_dependencies + rocm_dependencies + tensorrt_dependencies + cann_dependencies: auditwheel_cmd += ["--exclude", i] logger.info("Running %s", " ".join([shlex.quote(arg) for arg in auditwheel_cmd])) try: From 2281b6ed561f12950b30f5f6ec723073719b8fca Mon Sep 17 00:00:00 2001 From: George Wu Date: Tue, 17 Sep 2024 23:19:23 -0700 Subject: [PATCH 18/20] fix ordering --- setup.py | 2 +- tools/ci_build/build.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 83f48748bdf0f..2433b63a3631e 100644 --- a/setup.py +++ b/setup.py @@ -89,7 +89,7 @@ def parse_arg_remove_string(argv, arg_name_equal): pass elif parse_arg_remove_boolean(sys.argv, "--use_qnn"): is_qnn = True - package_name = "onnxruntime-qnn" + package_name = "onnxruntime-qnn" if not nightly_build else "ort-qnn-nightly" if is_rocm or is_migraphx: package_name = "onnxruntime-rocm" if not nightly_build else "ort-rocm-nightly" diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 8535f1e8c85a0..8c2451778420c 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -2277,10 +2277,10 @@ def build_python_wheel( args.append("--wheel_name_suffix=directml") elif use_cann: args.append("--use_cann") - elif use_azure: - args.append("--use_azure") elif use_qnn: args.append("--use_qnn") + elif use_azure: + args.append("--use_azure") run_subprocess(args, cwd=cwd) From d67ea95630256ed8148cb4183d14cb65f8b3723b Mon Sep 17 00:00:00 2001 From: George Wu Date: Wed, 18 Sep 2024 07:37:19 -0700 Subject: [PATCH 19/20] fix lib list --- cmake/CMakeLists.txt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 2c3267ef4b782..246675b72f4e6 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -838,19 +838,16 @@ if (onnxruntime_USE_QNN) 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") + 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" + "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/libHtpPrepare.so" + "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/HtpPrepare.dll") if (${QNN_ARCH_ABI} STREQUAL "aarch64-windows-msvc" OR ${QNN_ARCH_ABI} STREQUAL "arm64x-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() - if (${QNN_ARCH_ABI} STREQUAL "x64_64-linux-clang") - list(APPEND QNN_LIB_FILES "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/libHtpPrepare.so") - endif() - if (${QNN_ARCH_ABI} STREQUAL "x86_64-windows-msvc") - list(APPEND QNN_LIB_FILES "${onnxruntime_QNN_HOME}/lib/${QNN_ARCH_ABI}/HtpPrepare.dll") - endif() message(STATUS "QNN lib files: " ${QNN_LIB_FILES}) endif() endif() From f27024083185e3c10e645a5db0e2a7603e5b0cc4 Mon Sep 17 00:00:00 2001 From: George Wu Date: Wed, 18 Sep 2024 10:23:37 -0700 Subject: [PATCH 20/20] lint --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2433b63a3631e..7a6a2f71f9b52 100644 --- a/setup.py +++ b/setup.py @@ -357,7 +357,7 @@ def finalize_options(self): "libQnnSaver.so", "libQnnSystem.so", "libHtpPrepare.so", - "onnxruntime_qnn_ctx_gen" + "onnxruntime_qnn_ctx_gen", ] dl_libs.extend(qnn_deps) if nightly_build: