Skip to content

Commit

Permalink
Add IsGPU and IsNPU
Browse files Browse the repository at this point in the history
  • Loading branch information
nums11 committed Sep 19, 2023
1 parent f103283 commit 1ecd83c
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions onnxruntime/core/providers/dml/dml_provider_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,6 @@ API_IMPL_END
return nullptr;
}

bool IsHardwareAdapter(ComPtr<IDXCoreAdapter> adapter) {
bool isHardware{ false };
THROW_IF_FAILED(adapter->GetProperty(
DXCoreAdapterProperty::IsHardware,
&isHardware));
return isHardware;
}

bool SupportsGraphics(ComPtr<IDXCoreAdapter> adapter) {
return adapter->IsAttributeSupported(DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRAPHICS);
}

ORT_API_STATUS_IMPL(CreateGPUAllocationFromD3DResource, _In_ ID3D12Resource* d3d_resource, _Out_ void** dml_resource) {
API_IMPL_BEGIN
#ifdef USE_DML
Expand All @@ -266,6 +254,22 @@ ORT_API_STATUS_IMPL(FreeGPUAllocation, _In_ void* ptr) {
API_IMPL_END
}

bool IsHardwareAdapter(ComPtr<IDXCoreAdapter> adapter) {
bool isHardware{ false };
THROW_IF_FAILED(adapter->GetProperty(
DXCoreAdapterProperty::IsHardware,
&isHardware));
return isHardware;
}

bool IsGPU(ComPtr<IDXCoreAdapter> compute_adapter) {
return compute_adapter->IsAttributeSupported(DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRAPHICS);
}

bool IsNPU(ComPtr<IDXCoreAdapter> compute_adapter) {
return !(compute_adapter->IsAttributeSupported(DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRAPHICS));
}

ORT_API_STATUS_IMPL(OrtSessionOptionsAppendExecutionProvider_DML2, _In_ OrtSessionOptions* options, OrtDmlDeviceOptions* device_opts) {
API_IMPL_BEGIN
OrtDmlPerformancePreference perf_pref = device_opts->perf_pref;
Expand Down Expand Up @@ -306,19 +310,19 @@ API_IMPL_BEGIN

if (dev_filter == OrtDmlDeviceFilter::Gpu) // consider GPUs only
{
if (SupportsGraphics(candidateAdapter)) {
if (IsGPU(candidateAdapter)) {
ordered_adapters.push_back(candidateAdapter);
}
}
else if(dev_filter == OrtDmlDeviceFilter::Npu) // consider NPUs only
{
if (!SupportsGraphics(candidateAdapter)) {
if (IsNPU(candidateAdapter)) {
ordered_adapters.push_back(candidateAdapter);
}
}
else // consider both GPUs and NPUs
{
if (SupportsGraphics(candidateAdapter)) {
if (IsGPU(candidateAdapter)) {
gpu_adapters.push_back(candidateAdapter);
} else {
npu_adapters.push_back(candidateAdapter);
Expand Down

0 comments on commit 1ecd83c

Please sign in to comment.