From 0201cd75e103599856f1ae01290797e61661a1f0 Mon Sep 17 00:00:00 2001 From: Dwayne Robinson Date: Tue, 25 Oct 2022 11:14:43 -0700 Subject: [PATCH] Document generation for operator kernels, enable internal overload of DML EP to initialize on software-only devices (#13428) ### Description The documentation pipeline does not require an actual GPU, and running on GPU-capable agents costs more. So to enable running on CPU-only devices and to potentially consolidate future pipelines, and since the tests are not actually executed on this device anyway (it just needs to initialize the EP for the sake of operator kernel enumeration), add an initialization flag to skip the software device check - this is only an internal overload not exposed in the public API. See https://github.com/microsoft/onnxruntime/pull/13308. ### Motivation and Context - *If it fixes an open issue, please link to the issue here.* NA --- .../core/providers/dml/dml_provider_factory.cc | 13 +++++++++++-- .../providers/dml/dml_provider_factory_creator.h | 1 + onnxruntime/python/onnxruntime_pybind_schema.cc | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/onnxruntime/core/providers/dml/dml_provider_factory.cc b/onnxruntime/core/providers/dml/dml_provider_factory.cc index 8c8bb39f97..c8891cb214 100644 --- a/onnxruntime/core/providers/dml/dml_provider_factory.cc +++ b/onnxruntime/core/providers/dml/dml_provider_factory.cc @@ -105,6 +105,10 @@ bool IsSoftwareAdapter(IDXGIAdapter1* adapter) { } std::shared_ptr DMLProviderFactoryCreator::Create(int device_id) { + return Create(device_id, /*skip_software_device_check*/ false); +} + +std::shared_ptr DMLProviderFactoryCreator::Create(int device_id, bool skip_software_device_check) { #ifdef _GAMING_XBOX ComPtr d3d12_device; D3D12XBOX_CREATE_DEVICE_PARAMETERS params = {}; @@ -120,8 +124,13 @@ std::shared_ptr DMLProviderFactoryCreator::Create(int ComPtr adapter; ORT_THROW_IF_FAILED(dxgi_factory->EnumAdapters1(device_id, &adapter)); - // Disallow using DML with the software adapter (Microsoft Basic Display Adapter) because CPU evaluations are much faster - ORT_THROW_HR_IF(E_INVALIDARG, IsSoftwareAdapter(adapter.Get())); + // Disallow using DML with the software adapter (Microsoft Basic Display Adapter) because CPU evaluations are much + // faster. Some scenarios though call for EP initialization without this check (as execution will not actually occur + // anyway) such as operation kernel registry enumeration for documentation purposes. + if (!skip_software_device_check) + { + ORT_THROW_HR_IF(E_INVALIDARG, IsSoftwareAdapter(adapter.Get())); + } ComPtr d3d12_device; ORT_THROW_IF_FAILED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_GRAPHICS_PPV_ARGS(d3d12_device.ReleaseAndGetAddressOf()))); diff --git a/onnxruntime/core/providers/dml/dml_provider_factory_creator.h b/onnxruntime/core/providers/dml/dml_provider_factory_creator.h index 944a57cc06..3c3f04561d 100644 --- a/onnxruntime/core/providers/dml/dml_provider_factory_creator.h +++ b/onnxruntime/core/providers/dml/dml_provider_factory_creator.h @@ -10,5 +10,6 @@ namespace onnxruntime { struct DMLProviderFactoryCreator { static std::shared_ptr Create(int device_id); + static std::shared_ptr Create(int device_id, bool skip_software_device_check); }; } // namespace onnxruntime diff --git a/onnxruntime/python/onnxruntime_pybind_schema.cc b/onnxruntime/python/onnxruntime_pybind_schema.cc index 15e26c7986..f594b5712a 100644 --- a/onnxruntime/python/onnxruntime_pybind_schema.cc +++ b/onnxruntime/python/onnxruntime_pybind_schema.cc @@ -62,7 +62,7 @@ void addGlobalSchemaFunctions(pybind11::module& m) { onnxruntime::ArmNNProviderFactoryCreator::Create(0), #endif #ifdef USE_DML - onnxruntime::DMLProviderFactoryCreator::Create(0), + onnxruntime::DMLProviderFactoryCreator::Create(0, /*skip_software_device_check*/ true), #endif #ifdef USE_NNAPI onnxruntime::NnapiProviderFactoryCreator::Create(0),