Skip to content

Commit

Permalink
Enable generic feature level support with DirectML EP
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbloo committed Mar 28, 2024
1 parent 22bc4a1 commit 51bc4b8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
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
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>

Check warning on line 7 in onnxruntime/core/providers/dml/dml_provider_factory.cc

View workflow job for this annotation

GitHub Actions / Lint C++

[cpplint] reported by reviewdog 🐶 Found C system header after C++ system header. Should be: dml_provider_factory.h, c system, c++ system, other. [build/include_order] [4] Raw Output: onnxruntime/core/providers/dml/dml_provider_factory.cc:7: Found C system header after C++ system header. Should be: dml_provider_factory.h, c system, c++ system, other. [build/include_order] [4]
#include <directx/dxcore.h>

Check warning on line 8 in onnxruntime/core/providers/dml/dml_provider_factory.cc

View workflow job for this annotation

GitHub Actions / Lint C++

[cpplint] reported by reviewdog 🐶 Found C system header after C++ system header. Should be: dml_provider_factory.h, c system, c++ system, other. [build/include_order] [4] Raw Output: onnxruntime/core/providers/dml/dml_provider_factory.cc:8: Found C system header after C++ system header. Should be: dml_provider_factory.h, c system, c++ system, other. [build/include_order] [4]
#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()));
}

Check warning on line 559 in onnxruntime/core/providers/dml/dml_provider_factory.cc

View workflow job for this annotation

GitHub Actions / Lint C++

[cpplint] reported by reviewdog 🐶 Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] Raw Output: onnxruntime/core/providers/dml/dml_provider_factory.cc:559: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "core/providers/providers.h"
#include "core/providers/dml/dml_provider_factory.h"

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

Check warning on line 14 in onnxruntime/core/providers/dml/dml_provider_factory_creator.h

View workflow job for this annotation

GitHub Actions / Lint C++

[cpplint] reported by reviewdog 🐶 Found C system header after other header. Should be: dml_provider_factory_creator.h, c system, c++ system, other. [build/include_order] [4] Raw Output: onnxruntime/core/providers/dml/dml_provider_factory_creator.h:14: Found C system header after other header. Should be: dml_provider_factory_creator.h, c system, c++ system, other. [build/include_order] [4]
#include <vector>

namespace onnxruntime {
Expand Down

0 comments on commit 51bc4b8

Please sign in to comment.