Skip to content

Conversation

@almarklein
Copy link
Member

@almarklein almarklein commented Mar 26, 2024

Considerations

The idea is to allow users to specify a specific GPU, which is particularly useful in a multi-GPU setup. The tricky bits are that the kinds of GPU's differ widely between systems, and there's a human choice in the loop. You don't want to prompt the user for input each time a script is run. Instead you want a simple way to present the user with the options on the current system, and do this once. Then in subsequent runs allow the user to specify one of these options using a string.

This PR simply makes it easier to enumerate adapters and get a description of each. The user is responsible for the selection mechanism, because this is always fuzzy, and we don't know the best approach yet, see #482. When we do, we will add a builtin selection mechanism to either pygfx or wgpu.utils.

Tasks

  • Add gpu.enumerate_adapters().
  • Add adapter.summary, which is a single-line string that describes the adapter.
  • Add a unit test.
  • Update docs.

@almarklein
Copy link
Member Author

@Korijn @kushalkolar thoughts about the current API?

The idea is that in pygfx there will be a set_gpu_preference() similar to our current enable_wgpu_features() that must be called before the first renderer is created.

Fastplotlib can provide a similar function that calls into the pygfx one.

@kushalkolar
Copy link
Contributor

The idea is that in pygfx there will be a set_gpu_preference() similar to our current enable_wgpu_features() that must be called before the first renderer is created.

Fastplotlib can provide a similar function that calls into the pygfx one.

Sounds good to me!

@Korijn
Copy link
Collaborator

Korijn commented Mar 26, 2024

@Korijn @kushalkolar thoughts about the current API?

No objections here.

@almarklein
Copy link
Member Author

I actually feel a bit uncomfortable with the current state of this pr, because the gpu selection is very fuzzy and arguably arbitrary, while everything else in wgpu-py is very well-defined. I want to propose a slightly different approach:

  • In wgpu-py, expose gpu.enumerate_adapters(), producing adapter instances.
  • Add an Adapter.summary property, that is a one-line description of the adapter. (The same line that is now produced by .enumerate_adapter_info).
  • With these changes, we have pretty good building blocks for people to select a GPU using their own rules.
  • The gpu selection process can then be implemented either in wgpu.utils or in pygfx.set_gpu_preference.

@almarklein
Copy link
Member Author

I created #482 to dive a bit deeper into what info we can extract from the adapter_info.

@toloudis
Copy link

I actually feel a bit uncomfortable with the current state of this pr, because the gpu selection is very fuzzy and arguably arbitrary, while everything else in wgpu-py is very well-defined. I want to propose a slightly different approach:

  • In wgpu-py, expose gpu.enumerate_adapters(), producing adapter instances.

Watching from afar, as I originated the enumerate_adapters PR in wgpu-native... I agree this is a good approach - just expose enumerate_adapters as a Python call and leave the selection to callers to do their own evaluation. This is a great alternative to using the standard "webgpu selection rules" to auto-select.

@almarklein
Copy link
Member Author

Ok, I reduced this PR to only adding gpu.enumerate_adapters() and adapter.summary. This makes selecting an adapter much easier for downstream code. When we know more about the best way to select an adapter, we may add a utility.

@almarklein almarklein marked this pull request as ready for review March 28, 2024 10:05
@almarklein almarklein requested a review from Korijn as a code owner March 28, 2024 10:05
@Korijn Korijn merged commit d28cac9 into main Mar 28, 2024
@Korijn Korijn deleted the gpu-select branch March 28, 2024 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants