Skip to content

GPU info and identification #482

@almarklein

Description

@almarklein

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

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):

7226AD99-4155-45FE-A8CB-4B76A6ADE7AA_4_5005_c

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:

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 🤔

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions