From 86c9ec35f5da62b40534818bdf2e1130cf26e273 Mon Sep 17 00:00:00 2001 From: nums11 Date: Tue, 19 Sep 2023 15:55:57 -0700 Subject: [PATCH] Move hardware adapter check --- onnxruntime/core/providers/dml/dml_provider_factory.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/onnxruntime/core/providers/dml/dml_provider_factory.cc b/onnxruntime/core/providers/dml/dml_provider_factory.cc index c9ede6a9e53e1..46651a5d1c674 100644 --- a/onnxruntime/core/providers/dml/dml_provider_factory.cc +++ b/onnxruntime/core/providers/dml/dml_provider_factory.cc @@ -263,10 +263,16 @@ bool IsHardwareAdapter(ComPtr adapter) { } bool IsGPU(ComPtr compute_adapter) { + // Only considering hardware adapters + if (!IsHardwareAdapter(compute_adapter)) + return false; return compute_adapter->IsAttributeSupported(DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRAPHICS); } bool IsNPU(ComPtr compute_adapter) { + // Only considering hardware adapters + if (!IsHardwareAdapter(compute_adapter)) + return false; return !(compute_adapter->IsAttributeSupported(DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRAPHICS)); } @@ -304,10 +310,6 @@ API_IMPL_BEGIN ORT_THROW_IF_FAILED( d3D12CoreComputeAdapters->GetAdapter(i, candidateAdapter.GetAddressOf())); - // Only considering hardware adapters - if (!IsHardwareAdapter(candidateAdapter)) - continue; - if (dev_filter == OrtDmlDeviceFilter::Gpu) // consider GPUs only { if (IsGPU(candidateAdapter)) {