Repository navigation
Discover GPUs through D3DKMT on WSL2 - #34007
Open
mingyue (mingyueliuh) wants to merge 1 commit into
Open
mingyue (mingyueliuh) wants to merge 1 commit into
mingyue (mingyueliuh) wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The WSL discovery path can leak adapter handles when D3DKMTCloseAdapter is unavailable, and focused tests for enumeration, cleanup, and fallback behavior are missing.
2 open issues
What changed in this PR
Adds WSL2 GPU discovery through dynamically loaded D3DKMT functions, allowing ONNX Runtime to identify real GPU hardware for execution-provider device matching.
Changes:
- Enumerates adapters through
libdxcore.so, preferring EnumAdapters3 and falling back to EnumAdapters2. - Replaces Microsoft placeholder devices when WSL discovery returns adapters, preserving vendor/device IDs and LUID metadata.
- Includes the new discovery implementation in Linux builds.
| File | Description |
|---|---|
onnxruntime/core/platform/linux/wsl_device_discovery.h |
Declares WSL GPU descriptors and discovery API. |
onnxruntime/core/platform/linux/wsl_device_discovery.cc |
Loads D3DKMT functions and queries adapter identifiers. |
onnxruntime/core/platform/linux/device_discovery.cc |
Integrates WSL adapters and removes replaced placeholders. |
cmake/onnxruntime_common.cmake |
Adds WSL discovery files to Linux builds. |
Review effort: Balanced
| } | ||
|
|
||
| bool IsAvailable() const { | ||
| return query_adapter_info != nullptr && (enum_adapters3 != nullptr || enum_adapters2 != nullptr); |
|
|
||
| } // namespace | ||
|
|
||
| Status GetGpuDevices(std::vector<WslGpuInfo>& gpu_devices_out) { |
Linux GPU discovery only sees a Microsoft virtual display adapter under WSL2, so execution providers that match OrtHardwareDevice register no devices. Enumerate adapters through libdxcore.so and replace those placeholders with the real vendor and device IDs. Co-authored-by: Flora Cui <flora.cui@amd.com> Signed-off-by: mingyue <mingyue@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
Linux GPU discovery scans
/sys/class/drm/card*/deviceand falls back to/sys/bus/pci/devices. Under WSL2 the GPU is paravirtualized through/dev/dxg:/sys/class/drmholds nocard*entries, and the only device the PCI scan finds is a Microsoft virtual display adapter — vendor0x1414, device0x008e, class0x030200— standing in for the real hardware.This adds a third discovery tier that enumerates adapters through the D3DKMT entry points exported by
libdxcore.soand reads the vendor/device IDs fromKMTQAITYPE_PHYSICALADAPTERDEVICEIDS. When it yields adapters, the Microsoft placeholders that those descriptors replace are dropped from the list.Implementation notes:
Env::LoadDynamicLibrary, not linked, and the whole path is gated on/dev/dxgexisting — nothing is loaded off WSL2.D3DKMTEnumAdapters3is preferred where available becauseD3DKMTEnumAdapters2cannot report compute-only adapters; it falls back toEnumAdapters2when the symbol is absent.Motivation and Context
DiscoverDevicesForPlatform()reported a GPU whose vendor and device IDs belong to no vendor's runtime. Every execution provider that selects its device by matching against the discoveredOrtHardwareDevicelist therefore registered zeroOrtEpDevices on WSL2, even though the vendor runtime enumerated the GPU and inference worked through the olderappend_execution_providerpath. Autoep selection,OrtEpDeviceenumeration, and anything built on top of them were unusable.