From 70e67ddd2b86aa4d85a69d4b242d29ab54556459 Mon Sep 17 00:00:00 2001 From: Adrian Tsai Date: Fri, 30 Apr 2021 00:49:30 -0700 Subject: [PATCH] Update DirectML version to 1.5.1 and enable ARM/ARM64 builds with DML (#7511) * Update DirectML to version 1.5.1 * Enable --use_dml with ARM and ARM64 * Add ARM/ARM64 binaries to nuget packages --- cmake/external/dml.cmake | 6 +- cmake/onnxruntime_providers.cmake | 4 - cmake/winml_unittests.cmake | 4 +- packages.config | 2 +- setup.py | 2 +- .../azure-pipelines/nuget/templates/gpu.yml | 76 ++++++++++++++++++- .../nuget/templates/windowsai.yml | 36 ++++----- .../nuget/generate_nuspec_for_native_nuget.py | 2 +- winml/adapter/winml_adapter_dml.cpp | 2 +- 9 files changed, 102 insertions(+), 32 deletions(-) diff --git a/cmake/external/dml.cmake b/cmake/external/dml.cmake index c8267520748ed..df258efd0ebe5 100644 --- a/cmake/external/dml.cmake +++ b/cmake/external/dml.cmake @@ -20,18 +20,18 @@ if (NOT onnxruntime_USE_CUSTOM_DIRECTML) set(NUGET_CONFIG ${PROJECT_SOURCE_DIR}/../NuGet.config) set(PACKAGES_CONFIG ${PROJECT_SOURCE_DIR}/../packages.config) get_filename_component(PACKAGES_DIR ${CMAKE_CURRENT_BINARY_DIR}/../packages ABSOLUTE) - set(DML_PACKAGE_DIR ${PACKAGES_DIR}/Microsoft.AI.DirectML.1.4.2) + set(DML_PACKAGE_DIR ${PACKAGES_DIR}/Microsoft.AI.DirectML.1.5.1) set(DML_SHARED_LIB DirectML.dll) # Restore nuget packages, which will pull down the DirectML redist package add_custom_command( - OUTPUT ${DML_PACKAGE_DIR}/bin/x64-win/DirectML.lib ${DML_PACKAGE_DIR}/bin/x86-win/DirectML.lib + OUTPUT ${DML_PACKAGE_DIR}/bin/x64-win/DirectML.lib ${DML_PACKAGE_DIR}/bin/x86-win/DirectML.lib ${DML_PACKAGE_DIR}/bin/arm-win/DirectML.lib ${DML_PACKAGE_DIR}/bin/arm64-win/DirectML.lib DEPENDS ${PACKAGES_CONFIG} ${NUGET_CONFIG} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/nuget/src/nuget restore ${PACKAGES_CONFIG} -PackagesDirectory ${PACKAGES_DIR} -ConfigFile ${NUGET_CONFIG} VERBATIM) include_directories(BEFORE "${DML_PACKAGE_DIR}/include") - add_custom_target(RESTORE_PACKAGES ALL DEPENDS ${DML_PACKAGE_DIR}/bin/x64-win/DirectML.lib ${DML_PACKAGE_DIR}/bin/x86-win/DirectML.lib) + add_custom_target(RESTORE_PACKAGES ALL DEPENDS ${DML_PACKAGE_DIR}/bin/x64-win/DirectML.lib ${DML_PACKAGE_DIR}/bin/x86-win/DirectML.lib ${DML_PACKAGE_DIR}/bin/arm-win/DirectML.lib ${DML_PACKAGE_DIR}/bin/arm64-win/DirectML.lib) add_dependencies(RESTORE_PACKAGES nuget) else() include_directories(${dml_INCLUDE_DIR}) diff --git a/cmake/onnxruntime_providers.cmake b/cmake/onnxruntime_providers.cmake index 7a7807ad63fca..5d0a5aad0fd3e 100644 --- a/cmake/onnxruntime_providers.cmake +++ b/cmake/onnxruntime_providers.cmake @@ -798,10 +798,6 @@ if (onnxruntime_USE_DML) add_definitions(-DDML_TARGET_VERSION_USE_LATEST=1) if (NOT onnxruntime_USE_CUSTOM_DIRECTML) - if(NOT onnxruntime_target_platform STREQUAL "x86" AND NOT onnxruntime_target_platform STREQUAL "x64") - message(FATAL_ERROR "Target platform ${onnxruntime_target_platform} is not supported by DML") - endif() - foreach(file "DirectML.dll" "DirectML.pdb" "DirectML.Debug.dll" "DirectML.Debug.pdb") add_custom_command(TARGET onnxruntime_providers_dml POST_BUILD diff --git a/cmake/winml_unittests.cmake b/cmake/winml_unittests.cmake index e5461c647c426..aeda8068e5c94 100644 --- a/cmake/winml_unittests.cmake +++ b/cmake/winml_unittests.cmake @@ -201,7 +201,7 @@ add_winml_test( ) target_delayload(winml_test_api dxgi.dll d3d12.dll api-ms-win-core-file-l1-2-2.dll api-ms-win-core-synch-l1-2-1.dll) if (onnxruntime_USE_DML) - target_delayload(winml_test_api directml.dll) + target_delayload(winml_test_api DirectML.dll) endif() if (EXISTS ${dxcore_header}) target_delayload(winml_test_api ext-ms-win-dxcore-l1-*.dll) @@ -215,7 +215,7 @@ add_winml_test( ) target_delayload(winml_test_scenario d2d1.dll d3d11.dll dxgi.dll d3d12.dll api-ms-win-core-libraryloader-l1-2-1.dll api-ms-win-core-file-l1-2-2.dll api-ms-win-core-synch-l1-2-1.dll) if (onnxruntime_USE_DML) - target_delayload(winml_test_scenario directml.dll) + target_delayload(winml_test_scenario DirectML.dll) endif() if (EXISTS ${dxcore_header}) target_delayload(winml_test_scenario ext-ms-win-dxcore-l1-*.dll) diff --git a/packages.config b/packages.config index 7b9b1339a5e2e..7a1e950b1e615 100644 --- a/packages.config +++ b/packages.config @@ -1,6 +1,6 @@  - + diff --git a/setup.py b/setup.py index 1e714b07c1bd8..40f330de1c9f4 100644 --- a/setup.py +++ b/setup.py @@ -190,7 +190,7 @@ def run(self): libs.extend(['onnxruntime_providers_tensorrt.dll']) libs.extend(['onnxruntime_providers_openvino.dll']) # DirectML Libs - libs.extend(['directml.dll']) + libs.extend(['DirectML.dll']) # Nuphar Libs libs.extend(['tvm.dll']) if nightly_build: diff --git a/tools/ci_build/github/azure-pipelines/nuget/templates/gpu.yml b/tools/ci_build/github/azure-pipelines/nuget/templates/gpu.yml index f89b07018a1eb..96d53cf863f0b 100644 --- a/tools/ci_build/github/azure-pipelines/nuget/templates/gpu.yml +++ b/tools/ci_build/github/azure-pipelines/nuget/templates/gpu.yml @@ -71,6 +71,50 @@ jobs: mkdir $(Build.ArtifactStagingDirectory)\testdata copy $(Build.BinariesDirectory)\RelWithDebInfo\RelWithDebInfo\custom_op_library.* $(Build.ArtifactStagingDirectory)\testdata +- template: ../../templates/win-ci-2019.yml + parameters: + AgentPool : 'onnxruntime-gpu-winbuild' + ArtifactName: 'drop-win-dml-arm64-zip' + JobName: 'Windows_CI_GPU_DML_Dev_arm64' + BuildCommand: --build_dir $(Build.BinariesDirectory) --arm64 --skip_submodule_sync --build_shared_lib --enable_onnx_tests --enable_wcos --use_telemetry --use_dml --use_winml --cmake_generator "Visual Studio 16 2019" + BuildArch: 'x64' + EnvSetupScript: 'setup_env.bat' + sln_platform: 'arm64' + DoDebugBuild: 'false' + DoNugetPack : 'true' + DoCompliance: ${{ parameters.DoCompliance }} + DoEsrp: ${{ parameters.DoEsrp }} + RunTests: 'false' + NuPackScript: | + msbuild $(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.proj /p:Configuration=RelWithDebInfo /p:TargetArchitecture=arm64 /t:CreatePackage /p:OrtPackageId=Microsoft.ML.OnnxRuntime.DirectML + cd $(Build.BinariesDirectory)\RelWithDebInfo\RelWithDebInfo\ + ren Microsoft.ML.OnnxRuntime.DirectML.* win-dml-arm64.zip + copy $(Build.BinariesDirectory)\RelWithDebInfo\RelWithDebInfo\win-dml-arm64.zip $(Build.ArtifactStagingDirectory) + mkdir $(Build.ArtifactStagingDirectory)\testdata + copy $(Build.BinariesDirectory)\RelWithDebInfo\RelWithDebInfo\custom_op_library.* $(Build.ArtifactStagingDirectory)\testdata + +- template: ../../templates/win-ci-2019.yml + parameters: + AgentPool : 'onnxruntime-gpu-winbuild' + ArtifactName: 'drop-win-dml-arm-zip' + JobName: 'Windows_CI_GPU_DML_Dev_arm' + BuildCommand: --build_dir $(Build.BinariesDirectory) --arm --skip_submodule_sync --build_shared_lib --enable_onnx_tests --enable_wcos --use_telemetry --use_dml --use_winml --cmake_generator "Visual Studio 16 2019" + BuildArch: 'x64' + EnvSetupScript: 'setup_env.bat' + sln_platform: 'arm' + DoDebugBuild: 'false' + DoNugetPack : 'true' + DoCompliance: ${{ parameters.DoCompliance }} + DoEsrp: ${{ parameters.DoEsrp }} + RunTests: 'false' + NuPackScript: | + msbuild $(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.proj /p:Configuration=RelWithDebInfo /p:TargetArchitecture=arm /t:CreatePackage /p:OrtPackageId=Microsoft.ML.OnnxRuntime.DirectML + cd $(Build.BinariesDirectory)\RelWithDebInfo\RelWithDebInfo\ + ren Microsoft.ML.OnnxRuntime.DirectML.* win-dml-arm.zip + copy $(Build.BinariesDirectory)\RelWithDebInfo\RelWithDebInfo\win-dml-arm.zip $(Build.ArtifactStagingDirectory) + mkdir $(Build.ArtifactStagingDirectory)\testdata + copy $(Build.BinariesDirectory)\RelWithDebInfo\RelWithDebInfo\custom_op_library.* $(Build.ArtifactStagingDirectory)\testdata + - job: 'Linux_CI_GPU_Dev' workspace: clean: all @@ -118,6 +162,8 @@ jobs: - Windows_CI_GPU_CUDA_Dev - Windows_CI_GPU_DML_Dev - Windows_CI_GPU_DML_Dev_x86 + - Windows_CI_GPU_DML_Dev_arm64 + - Windows_CI_GPU_DML_Dev_arm - Linux_CI_GPU_Dev condition: succeeded() steps: @@ -139,6 +185,18 @@ jobs: artifactName: 'drop-win-dml-x86-zip' targetPath: '$(Build.BinariesDirectory)/nuget-artifact-dml' + - task: DownloadPipelineArtifact@0 + displayName: 'Download Pipeline Artifact - NuGet DirectML arm64' + inputs: + artifactName: 'drop-win-dml-arm64-zip' + targetPath: '$(Build.BinariesDirectory)/nuget-artifact-dml' + + - task: DownloadPipelineArtifact@0 + displayName: 'Download Pipeline Artifact - NuGet DirectML arm' + inputs: + artifactName: 'drop-win-dml-arm-zip' + targetPath: '$(Build.BinariesDirectory)/nuget-artifact-dml' + - task: DownloadPipelineArtifact@0 displayName: 'Download Pipeline Artifact - Linux' inputs: @@ -194,6 +252,22 @@ jobs: move win-x86\runtimes\win-x86\native\onnxruntime.lib %%~ni\runtimes\win-x86\native\onnxruntime.lib move win-x86\runtimes\win-x86\native\onnxruntime.pdb %%~ni\runtimes\win-x86\native\onnxruntime.pdb + unzip win-dml-arm64.zip -d win-arm64 + mkdir %%~ni\runtimes\win-arm64 + mkdir %%~ni\runtimes\win-arm64\native + + move win-arm64\runtimes\win-arm64\native\onnxruntime.dll %%~ni\runtimes\win-arm64\native\onnxruntime.dll + move win-arm64\runtimes\win-arm64\native\onnxruntime.lib %%~ni\runtimes\win-arm64\native\onnxruntime.lib + move win-arm64\runtimes\win-arm64\native\onnxruntime.pdb %%~ni\runtimes\win-arm64\native\onnxruntime.pdb + + unzip win-dml-arm.zip -d win-arm + mkdir %%~ni\runtimes\win-arm + mkdir %%~ni\runtimes\win-arm\native + + move win-arm\runtimes\win-arm\native\onnxruntime.dll %%~ni\runtimes\win-arm\native\onnxruntime.dll + move win-arm\runtimes\win-arm\native\onnxruntime.lib %%~ni\runtimes\win-arm\native\onnxruntime.lib + move win-arm\runtimes\win-arm\native\onnxruntime.pdb %%~ni\runtimes\win-arm\native\onnxruntime.pdb + pushd %%~ni zip -r ..\%%~ni.zip . popd @@ -221,7 +295,7 @@ jobs: parameters: NugetPath: '$(Build.ArtifactStagingDirectory)' NugetPackage: 'Microsoft.ML.OnnxRuntime.DirectML*nupkg' - PlatformsSupported: 'win-x64,win-x86' + PlatformsSupported: 'win-x64,win-x86,win-arm64,win-arm' VerifyNugetSigning: ${{ parameters.DoEsrp }} - task: PublishPipelineArtifact@0 diff --git a/tools/ci_build/github/azure-pipelines/nuget/templates/windowsai.yml b/tools/ci_build/github/azure-pipelines/nuget/templates/windowsai.yml index edefa7e34cf3d..1e0b270e45fa6 100644 --- a/tools/ci_build/github/azure-pipelines/nuget/templates/windowsai.yml +++ b/tools/ci_build/github/azure-pipelines/nuget/templates/windowsai.yml @@ -22,25 +22,25 @@ jobs: - template: ../../templates/windowsai-nuget-build.yml parameters: BuildArch: 'x86' - -- job: WindowsAI_CPU_ARM64 + +- job: WindowsAI_DirectML_ARM64 timeoutInMinutes: 120 workspace: clean: all pool: - name: 'Win-CPU-2021' + name: 'onnxruntime-gpu-winbuild' demands: [] steps: - template: ../../templates/windowsai-nuget-build.yml parameters: BuildArch: 'arm64' -- job: WindowsAI_CPU_ARM +- job: WindowsAI_DirectML_ARM timeoutInMinutes: 120 workspace: clean: all pool: - name: 'Win-CPU-2021' + name: 'onnxruntime-gpu-winbuild' demands: [] steps: - template: ../../templates/windowsai-nuget-build.yml @@ -73,12 +73,12 @@ jobs: BuildArch: 'x86' Runtime: 'static' -- job: WindowsAI_CPU_ARM64_StaticRuntime +- job: WindowsAI_DirectML_ARM64_StaticRuntime timeoutInMinutes: 120 workspace: clean: all pool: - name: 'Win-CPU-2021' + name: 'onnxruntime-gpu-winbuild' demands: [ ] steps: - template: ../../templates/windowsai-nuget-build.yml @@ -86,12 +86,12 @@ jobs: BuildArch: 'arm64' Runtime: 'static' -- job: WindowsAI_CPU_ARM_StaticRuntime +- job: WindowsAI_DirectML_ARM_StaticRuntime timeoutInMinutes: 120 workspace: clean: all pool: - name: 'Win-CPU-2021' + name: 'onnxruntime-gpu-winbuild' demands: [ ] steps: - template: ../../templates/windowsai-nuget-build.yml @@ -158,16 +158,16 @@ jobs: dependsOn: - WindowsAI_DirectML_X64 - WindowsAI_DirectML_X86 - - WindowsAI_CPU_ARM64 - - WindowsAI_CPU_ARM + - WindowsAI_DirectML_ARM64 + - WindowsAI_DirectML_ARM - WindowsAI_CPU_X64_Store - WindowsAI_CPU_X86_Store - WindowsAI_CPU_ARM64_Store - WindowsAI_CPU_ARM_Store - WindowsAI_DirectML_X64_StaticRuntime - WindowsAI_DirectML_X86_StaticRuntime - - WindowsAI_CPU_ARM64_StaticRuntime - - WindowsAI_CPU_ARM_StaticRuntime + - WindowsAI_DirectML_ARM64_StaticRuntime + - WindowsAI_DirectML_ARM_StaticRuntime condition: succeeded() steps: - task: DownloadPipelineArtifact@0 @@ -181,15 +181,15 @@ jobs: inputs: artifactName: 'Microsoft.AI.MachineLearning.x86' targetPath: '$(Build.BinariesDirectory)/nuget-artifact-x86' - + - task: DownloadPipelineArtifact@0 - displayName: 'Download Pipeline Artifact - NuGet CPU ARM64' + displayName: 'Download Pipeline Artifact - NuGet DirectML arm64' inputs: artifactName: 'Microsoft.AI.MachineLearning.arm64' targetPath: '$(Build.BinariesDirectory)/nuget-artifact-arm64' - task: DownloadPipelineArtifact@0 - displayName: 'Download Pipeline Artifact - NuGet CPU ARM' + displayName: 'Download Pipeline Artifact - NuGet DirectML arm' inputs: artifactName: 'Microsoft.AI.MachineLearning.arm' targetPath: '$(Build.BinariesDirectory)/nuget-artifact-arm' @@ -231,13 +231,13 @@ jobs: targetPath: '$(Build.BinariesDirectory)/nuget-artifact-x86-static-runtime' - task: DownloadPipelineArtifact@0 - displayName: 'Download Pipeline Artifact - NuGet CPU ARM64 StaticRuntime' + displayName: 'Download Pipeline Artifact - NuGet DirectML arm64 StaticRuntime' inputs: artifactName: 'Microsoft.AI.MachineLearning.arm64.StaticRuntime' targetPath: '$(Build.BinariesDirectory)/nuget-artifact-arm64-static-runtime' - task: DownloadPipelineArtifact@0 - displayName: 'Download Pipeline Artifact - NuGet CPU ARM StaticRuntime' + displayName: 'Download Pipeline Artifact - NuGet DirectML arm StaticRuntime' inputs: artifactName: 'Microsoft.AI.MachineLearning.arm.StaticRuntime' targetPath: '$(Build.BinariesDirectory)/nuget-artifact-arm-static-runtime' diff --git a/tools/nuget/generate_nuspec_for_native_nuget.py b/tools/nuget/generate_nuspec_for_native_nuget.py index 256c7a7d0e69c..2f05ac59a881a 100644 --- a/tools/nuget/generate_nuspec_for_native_nuget.py +++ b/tools/nuget/generate_nuspec_for_native_nuget.py @@ -76,7 +76,7 @@ def generate_repo_url(list, repo_url, commit_id): def generate_dependencies(list, package_name, version): - dml_dependency = '' + dml_dependency = '' if (package_name == 'Microsoft.AI.MachineLearning'): list.append('') diff --git a/winml/adapter/winml_adapter_dml.cpp b/winml/adapter/winml_adapter_dml.cpp index c3cfe12f3db8b..deb12a4f3a3c0 100644 --- a/winml/adapter/winml_adapter_dml.cpp +++ b/winml/adapter/winml_adapter_dml.cpp @@ -39,7 +39,7 @@ static std::string CurrentModulePath() { Microsoft::WRL::ComPtr CreateDmlDevice(ID3D12Device* d3d12Device) { // Dynamically load DML to avoid WinML taking a static dependency on DirectML.dll - auto directml_dll = CurrentModulePath() + "\\directml.dll"; + auto directml_dll = CurrentModulePath() + "\\DirectML.dll"; wil::unique_hmodule dmlDll(LoadLibraryExA(directml_dll.c_str(), nullptr, 0)); THROW_LAST_ERROR_IF(!dmlDll);