microsoft / DirectML

DirectML is a high-performance, hardware-accelerated DirectX 12 library for machine learning. DirectML provides GPU acceleration for common machine learning tasks across a broad range of supported hardware and drivers, including all DirectX 12-capable GPUs from vendors such as AMD, Intel, NVIDIA, and Qualcomm.
MIT License
2.24k stars 299 forks source link

Modify DirectML_ESRGAN's default adapter selection. #667

Open wonchung-microsoft opened 1 week ago

wonchung-microsoft commented 1 week ago

Modify DirectML_ESRGAN sample to by default try NPU first then retry GPU. If adapter specified through param, stay with the specified param.

wonchung-microsoft commented 1 week ago

@microsoft-github-policy-service agree company="Microsoft"

wonchung-microsoft commented 3 days ago

This isn't the right logic to filter adapters correctly, because you can't rely on name substrings to be consistent across hardware. Specifying a substring to match with the adapter description is only a convenience for users that want to select between adapters they've already enumerated and seen the description of. For example, on one of my desktops I get the following adapter descriptions:

Adapter[0]: NVIDIA GeForce RTX 4080 (SELECTED)
Adapter[1]: Intel(R) UHD Graphics 770
Adapter[2]: Microsoft Basic Render Driver

With your logic, it would try to find "NPU" and fail to match any adapter. Then it would try to find "GPU" and also fail to find any adapter. QC happens to use "GPU" and "NPU" in their adapter descriptions, but this isn't generically true.

If you want to the sample to prioritize NPU then you have to look for GENERIC_ML adapters that don't support graphics. Then, if that fails, you fall back to the first adapter that is at least supporting CORE_COMPUTE or GRAPHICS.

The logic in this sample already has fallback for D3D feature level, and you'd just want to modify it to also check for DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRAPHICS or similar. You might reference this code too: https://github.com/microsoft/DirectML/blob/master/Samples/DirectMLNpuInference/main.cpp

@jstoecker I have made updates accordingly. Could you take a look? Thanks!