Skip to content

Commit

Permalink
Update DirectML version to 1.5.1 and enable ARM/ARM64 builds with DML (
Browse files Browse the repository at this point in the history
…#7511)

* Update DirectML to version 1.5.1
* Enable --use_dml with ARM and ARM64
* Add ARM/ARM64 binaries to nuget packages
  • Loading branch information
Adrian Tsai authored Apr 30, 2021
1 parent 00aaa6d commit 70e67dd
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 32 deletions.
6 changes: 3 additions & 3 deletions cmake/external/dml.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
4 changes: 0 additions & 4 deletions cmake/onnxruntime_providers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmake/winml_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="GoogleTestAdapter" version="0.17.1" targetFramework="net46" />
<package id="Microsoft.AI.DirectML" version="1.4.2" targetFramework="native" />
<package id="Microsoft.AI.DirectML" version="1.5.1" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.201113.7" targetFramework="native" />
</packages>
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
76 changes: 75 additions & 1 deletion tools/ci_build/github/azure-pipelines/nuget/templates/gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
36 changes: 18 additions & 18 deletions tools/ci_build/github/azure-pipelines/nuget/templates/windowsai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,25 +73,25 @@ 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
parameters:
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
Expand Down Expand Up @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion tools/nuget/generate_nuspec_for_native_nuget.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def generate_repo_url(list, repo_url, commit_id):


def generate_dependencies(list, package_name, version):
dml_dependency = '<dependency id="Microsoft.AI.DirectML" version="1.4.2"/>'
dml_dependency = '<dependency id="Microsoft.AI.DirectML" version="1.5.1"/>'

if (package_name == 'Microsoft.AI.MachineLearning'):
list.append('<dependencies>')
Expand Down
2 changes: 1 addition & 1 deletion winml/adapter/winml_adapter_dml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static std::string CurrentModulePath() {

Microsoft::WRL::ComPtr<IDMLDevice> 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);

Expand Down

0 comments on commit 70e67dd

Please sign in to comment.