diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/ExecutionProvider.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/ExecutionProvider.cpp index 6c347ebdca7c1..d24bf3350b292 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/ExecutionProvider.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/ExecutionProvider.cpp @@ -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), @@ -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, @@ -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) diff --git a/onnxruntime/core/providers/dml/dml_provider_factory.cc b/onnxruntime/core/providers/dml/dml_provider_factory.cc index b2688094a6d78..9ba1c35efb27b 100644 --- a/onnxruntime/core/providers/dml/dml_provider_factory.cc +++ b/onnxruntime/core/providers/dml/dml_provider_factory.cc @@ -1,9 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include #include +#define INITGUID +#include +#include +#undef INITGUID + +#include "directx/d3d12.h" + #include #ifndef _GAMING_XBOX #include @@ -157,12 +163,15 @@ static ComPtr 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; @@ -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, @@ -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; } @@ -533,12 +546,21 @@ std::shared_ptr 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 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); } diff --git a/onnxruntime/core/providers/dml/dml_provider_factory_creator.h b/onnxruntime/core/providers/dml/dml_provider_factory_creator.h index a4c7870cde7a7..61d0cba0e1f98 100644 --- a/onnxruntime/core/providers/dml/dml_provider_factory_creator.h +++ b/onnxruntime/core/providers/dml/dml_provider_factory_creator.h @@ -11,7 +11,7 @@ #include "core/providers/providers.h" #include "core/providers/dml/dml_provider_factory.h" -#include +#include #include namespace onnxruntime {