Skip to content

Commit

Permalink
Enable generic feature level devices in DML EP (microsoft#20114)
Browse files Browse the repository at this point in the history
### Description
Enable NPUs supporting DXCORE_ADAPTER_ATTRIBUTE_D3D12_GENERIC_ML and
D3D_FEATURE_LEVEL_1_0_GENERIC with DML EP. This also begins ingesting DX
headers through the DirectX-Headers repo.

Note that this includes an update to cgamanifest.json for onnx-tensorrt
which is triggered during re-generation due to a prior changes to
deps.txt.

### 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. -->
  • Loading branch information
jeffbloo authored and Ted Themistokleous committed May 7, 2024
1 parent 224a2fe commit a923cbe
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 29 deletions.
12 changes: 11 additions & 1 deletion cgmanifests/generated/cgmanifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
"component": {
"type": "git",
"git": {
"commitHash": "a43ce67187bab219520fd80f21af8bbd4354bc8c",
"commitHash": "bacfaaa951653cd4e72efe727a543567cb38f7de",
"repositoryUrl": "https://github.com/onnx/onnx-tensorrt.git"
},
"comments": "onnx_tensorrt"
Expand Down Expand Up @@ -341,6 +341,16 @@
},
"comments": "composable_kernel"
}
},
{
"component": {
"type": "git",
"git": {
"commitHash": "de28d93dfa9ebf3e473127c1c657e1920a5345ee",
"repositoryUrl": "https://github.com/microsoft/DirectX-Headers.git"
},
"comments": "directx_headers"
}
}
]
}
1 change: 1 addition & 0 deletions cmake/deps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ cutlass;https://github.com/NVIDIA/cutlass/archive/refs/tags/v3.1.0.zip;757f90a79
utf8_range;https://github.com/protocolbuffers/utf8_range/archive/72c943dea2b9240cd09efde15191e144bc7c7d38.zip;9925739c9debc0efa2adcb194d371a35b6a03156
extensions;https://github.com/microsoft/onnxruntime-extensions/archive/94142d8391c9791ec71c38336436319a2d4ac7a0.zip;4365ac5140338b4cb75a39944a4be276e3829b3c
composable_kernel;https://github.com/ROCmSoftwarePlatform/composable_kernel/archive/5356c4a943a35e74d7cdc69486afcb8703b9a59a.zip;522382c2af437e09124287e5879ab64af5b2e299
directx_headers;https://github.com/microsoft/DirectX-Headers/archive/refs/tags/v1.613.1.zip;47653509a3371eabb156360f42faf582f314bf2e
11 changes: 11 additions & 0 deletions cmake/external/dml.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,14 @@ else()
set(DML_PACKAGE_DIR ${dml_INCLUDE_DIR}/..)
endif()
endif()

FetchContent_Declare(
directx_headers
URL ${DEP_URL_directx_headers}
URL_HASH SHA1=${DEP_SHA1_directx_headers}
)

FetchContent_Populate(directx_headers)
set(directx_headers_INCLUDE_DIRS "${directx_headers_SOURCE_DIR}/include")

include_directories(BEFORE ${directx_headers_INCLUDE_DIRS})
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <wrl/client.h>
#include <wrl/implements.h>
#include <d3d12.h>
#include "directx/d3d12.h"
#include "DmlResourceWrapper.h"

namespace Dml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#pragma once

#include <wrl/client.h>
#include <d3d12.h>
#include "directx/d3d12.h"
#include <wil/wrl.h>
#include <wil/result_macros.h>
#include "External/D3DX12/d3dx12.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,7 @@ namespace Dml
}
}

// ORT release pipelines agent pools do not have 19H1 SDK installed which defines D3D_FEATURE_LEVEL_1_0_CORE.
// Once ORT/WinML github project can be built with VS2019, we can update these pools to use install the 19H1 SDK
// using the command line installer tool with VS2019
// Task 24384515: Update ORT AIInfra release agent pool to install 19H1 SDK on VM bootstrap
#define D3D_FEATURE_LEVEL_1_0_CORE_PRIVATE ((D3D_FEATURE_LEVEL)0x1000)

ExecutionProviderImpl::ExecutionProviderImpl(IDMLDevice* dmlDevice, ID3D12Device* d3d12Device, ID3D12CommandQueue* queue, bool enableMetacommands, bool enableDynamicGraphFusion)
ExecutionProviderImpl::ExecutionProviderImpl(IDMLDevice* dmlDevice, ID3D12Device* d3d12Device, ID3D12CommandQueue* queue, bool enableMetacommands, bool enableDynamicGraphFusion)
: m_d3d12Device(d3d12Device),
m_dmlDevice(dmlDevice),
m_areMetacommandsEnabled(enableMetacommands),
Expand All @@ -157,7 +151,10 @@ namespace Dml
D3D12_FEATURE_DATA_FEATURE_LEVELS featureLevels = {};

D3D_FEATURE_LEVEL featureLevelsList[] = {
D3D_FEATURE_LEVEL_1_0_CORE_PRIVATE,
#ifndef _GAMING_XBOX
D3D_FEATURE_LEVEL_1_0_GENERIC,
#endif
D3D_FEATURE_LEVEL_1_0_CORE,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_12_0,
Expand All @@ -181,7 +178,7 @@ namespace Dml
m_native16BitShaderOpsSupported = featureOptions.Native16BitShaderOpsSupported;
}

m_isMcdmDevice = (featureLevels.MaxSupportedFeatureLevel == D3D_FEATURE_LEVEL_1_0_CORE_PRIVATE);
m_isMcdmDevice = (featureLevels.MaxSupportedFeatureLevel <= D3D_FEATURE_LEVEL_1_0_CORE);
m_areCustomHeapsSupported = !m_isMcdmDevice;

if (m_isMcdmDevice)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#include <d3d12.h>
#include "directx/d3d12.h"

#include "core/providers/dml/DmlExecutionProvider/inc/DmlExecutionProvider.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "../../../OperatorAuthorHelper/OperatorHelper.h"

#include "../External/D3DX12/d3dx12.h"
#include <d3d12.h>
#include "directx/d3d12.h"

// NOTE: When this operator's implementation is moved into DML, the associated FP16 fallback
// should be removed from IsCustomOpShader(...) in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "../MLOperatorAuthorImpl.h"

#include "../External/D3DX12/d3dx12.h"
#include <d3d12.h>
#include "directx/d3d12.h"

// NOTE: When this operator's implementation is moved into DML, the associated FP16 fallback
// should be removed from IsCustomOpShader(...) in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <d3d12_x.h>
#include <d3dx12_x.h>
#else // Desktop
#include <d3d12.h>
#include "directx/d3d12.h"
#include <d3d12sdklayers.h>
#include "External/D3DX12/d3dx12.h"
#endif
Expand Down
40 changes: 31 additions & 9 deletions onnxruntime/core/providers/dml/dml_provider_factory.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#include <dxcore.h>
#include <vector>

#define INITGUID
#include <guiddef.h>
#include <directx/dxcore.h>
#undef INITGUID

#include "directx/d3d12.h"

#include <DirectML.h>
#ifndef _GAMING_XBOX
#include <dxgi1_4.h>
Expand Down Expand Up @@ -157,12 +163,15 @@ static ComPtr<IDXCoreAdapterList> EnumerateDXCoreAdapters(IDXCoreAdapterFactory*
// When DXCore APIs are available QI for relevant enumeration interfaces
constexpr bool use_dxcore_workload_enumeration = false;
if (!use_dxcore_workload_enumeration) {
// Get a list of all the adapters that support compute
GUID attributes[]{ DXCORE_ADAPTER_ATTRIBUTE_D3D12_CORE_COMPUTE };
ORT_THROW_IF_FAILED(
adapter_factory->CreateAdapterList(_countof(attributes),
attributes,
adapter_factory->CreateAdapterList(1,
&DXCORE_ADAPTER_ATTRIBUTE_D3D12_GENERIC_ML,
adapter_list.GetAddressOf()));

if (adapter_list->GetAdapterCount() == 0)
{
ORT_THROW_IF_FAILED(adapter_factory->CreateAdapterList(1, &DXCORE_ADAPTER_ATTRIBUTE_D3D12_CORE_COMPUTE, adapter_list.GetAddressOf()));
}
}

return adapter_list;
Expand Down Expand Up @@ -477,6 +486,9 @@ static D3D12_COMMAND_LIST_TYPE CalculateCommandListType(ID3D12Device* d3d12_devi
D3D12_FEATURE_DATA_FEATURE_LEVELS feature_levels = {};

D3D_FEATURE_LEVEL feature_levels_list[] = {
#ifndef _GAMING_XBOX
D3D_FEATURE_LEVEL_1_0_GENERIC,
#endif
D3D_FEATURE_LEVEL_1_0_CORE,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_11_1,
Expand All @@ -492,8 +504,9 @@ static D3D12_COMMAND_LIST_TYPE CalculateCommandListType(ID3D12Device* d3d12_devi
sizeof(feature_levels)
));

auto is_feature_level_1_0_core = (feature_levels.MaxSupportedFeatureLevel == D3D_FEATURE_LEVEL_1_0_CORE);
if (is_feature_level_1_0_core) {
auto use_compute_command_list = (feature_levels.MaxSupportedFeatureLevel <= D3D_FEATURE_LEVEL_1_0_CORE);
if (use_compute_command_list)
{
return D3D12_COMMAND_LIST_TYPE_COMPUTE;
}

Expand Down Expand Up @@ -533,12 +546,21 @@ std::shared_ptr<IExecutionProviderFactory> DMLProviderFactoryCreator::CreateFrom

auto feature_level = D3D_FEATURE_LEVEL_11_0;
if (IsNPU(adapter.Get())) {
feature_level = D3D_FEATURE_LEVEL_1_0_CORE;
feature_level = D3D_FEATURE_LEVEL_1_0_GENERIC;
}

// Create D3D12 Device from DXCore Adapter
ComPtr<ID3D12Device> d3d12_device;
ORT_THROW_IF_FAILED(D3D12CreateDevice(adapter.Get(), feature_level, IID_GRAPHICS_PPV_ARGS(d3d12_device.ReleaseAndGetAddressOf())));
if (feature_level == D3D_FEATURE_LEVEL_1_0_GENERIC) {
// Attempt to create a D3D_FEATURE_LEVEL_1_0_CORE device first, in case the device supports this
// feature level and the D3D runtime does not support D3D_FEATURE_LEVEL_1_0_GENERIC
HRESULT hrUnused = D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_1_0_CORE, IID_GRAPHICS_PPV_ARGS(d3d12_device.ReleaseAndGetAddressOf()));
}

if (!d3d12_device) {
ORT_THROW_IF_FAILED(D3D12CreateDevice(adapter.Get(), feature_level, IID_GRAPHICS_PPV_ARGS(d3d12_device.ReleaseAndGetAddressOf())));
}

return CreateDMLDeviceAndProviderFactory(d3d12_device.Get(), disable_metacommands, enable_dynamic_graph_fusion);
}

Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/core/providers/dml/dml_provider_factory_creator.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include <memory>

#include <wrl/client.h>
#include <d3d12.h>
#include "directx/d3d12.h"
#include "core/framework/provider_options.h"
#include "core/providers/providers.h"
#include "core/providers/dml/dml_provider_factory.h"

#include <dxcore.h>
#include <directx/dxcore.h>
#include <vector>

namespace onnxruntime {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ steps:
packageType: upack
feed: '/7424c8e4-5c62-490e-95c4-79446f31017c'
definition: '517c4f6f-5437-4392-a70d-4f15ec5be2f0'
version: 1.0.145
version: 1.0.149
downloadPath: $(Build.BinariesDirectory)/deps

# The private ADO project
Expand All @@ -22,7 +22,7 @@ steps:
packageType: upack
feed: '/4c7631f5-24c0-4307-8822-1aa8f180c325'
definition: 'fd9dd5ad-b73e-4678-890e-edcf680dbc1a'
version: 1.0.145
version: 1.0.149
downloadPath: $(Build.BinariesDirectory)/deps

# You can add more ADO accounts at here.

0 comments on commit a923cbe

Please sign in to comment.