Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom filters for processing accelerators #395

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mlorenzofr
Copy link
Contributor

This PR implements the feature to add a filter for hardware acceleration detection as described in issue #394.
This is just a draft, let's review it and we can change anything we feel is appropriate 😉

Copy link
Collaborator

@ffromani ffromani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initial review

/cc @jaypipes

Comment on lines +969 to +978
#### filters
The `ghw.Accelerator()` function accepts a slice of filters, of type string, as parameter
in format `[<vendor>]:[<device>][:<class>]`, (same is the _lspci_ command).

Some filter examples:
* `::0302`. Select 3D controller cards.
* `10de::0302`. Select Nvidia (`10de`) 3D controller cards (`0302`).
* `1da3:1060:1200`. Select Habana Labs (`1da3`) Gaudi3 (`1060`) processing accelerator cards (`1200`).
* `1002::`. Select AMD ATI hardware.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the filtering functionality is something we want, no questions about it.
I imagined it a bit higher level though. Like, pass a single function which takes a pci.Device object and return (bool, string) to convey if it should be accepted, and if not why. Or perhaps we can just (ab)use a error as return value: if nil, accept, if not err.Error() can tell us why.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like

func Accelerator(filters ...func(dev *pci.Device) bool)

accelDev := &AcceleratorDevice{
Address: device.Address,
PCIDevice: device,
if len(i.DiscoveryFilters) > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the way I envisioned is that the user should be able to feed more filters in addition to the unavoidable buliltin
isAccelerator := func(dev *pci.Device) bool {}

probably using a different interface to maximize the safety: user-provided filters should never be allowed to modify the pci.Devices passed to them (or, equivalently, any change made should be discarded)

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.

2 participants