-
-
Notifications
You must be signed in to change notification settings - Fork 50
Description
Purpose
In certain use-cases it's important for users to be able to select a specific GPU. In some cases a user may have installed multiple GPU's of the same kind. This issue is to to explore the possibilities.
Related issues/prs
- Add more adapter info #483
- Provide more control to select a specific GPU #481
- Order of adapters with enumerate_adapters gfx-rs/wgpu#5442
- More details in docs of enumerate_adapters #489
- Add functions to select a specific gpu pygfx#709
Adapter info
The adapter info makes quite a journey ...
- As per the WebGPU spec, the adapter has a
request_adapter_info()method that produces a dict. - The webgpu spec on the GPUAdapterInfo interface lists just four fields (vendor, architecture, device, description), and these may even be empty when in the browser, for security reasons. In wgpu-py we produce the required fields, and more.
- In wgpu-core the AdapterInfo struct lists these fields: name, vendor (id), device (id), device_type, driver, driver_info, backend.
- In webgpu.h the AdapterProperties struct specifies these fields: vendorID, vendorName, architecture, deviceID, name, driverDescription, adapterType, backendType
- In wgpu-native the Rust struct is mapped to the C struct.
- And in wgpu-py we map the C struct to the WebGPU dict.
This sketch shows how the fields are mapped at each step (if you can decipher my handwriting):
Addressing a GPU when multiple are present
In a typical multi-gpu setup, you likely want to address the GPU's by index, because the GPU's look the same in terms of their properties. However, this means the order must be consistent and match e.g. pytorch.
Or ... there should be some sort of UUID to identify a device. On Vulkan there is pipelineCacheUUID from VkPhysicalDeviceProperties. On Metal there is the device's registryId property. TODO: is any of this exposed by Torch? Looks like its not?
Some refs:
- https://stackoverflow.com/questions/52815708/order-of-cuda-devices
- Order of adapters with enumerate_adapters gfx-rs/wgpu#5442
- vkEnumeratePhysicalDevices should return the primary GPU first KhronosGroup/Vulkan-Loader#153
Testing
To get a nice list of devices on your machine:
import json
import wgpu
for adapter in wgpu.gpu.enumerate_adapters():
print(json.dumps(adapter.request_adapter_info(), indent=4))Feel free to post the result in a comment below. Would be nice to have some real life examples.
Observations
editing as more comes in
- Vendor and description are empty in quite a few cases.
- Device name seems always present.
- But multiple adaptes with the same device name can be present, with different backend_type.
- The vendor_id and device_id together seem to be pretty unique to identify a device (check as more comes in), but can be the same with differen backends.
- Multiple GPU's of the same type look exactly the same 🤔
