Add custom filters for processing accelerators#395
Add custom filters for processing accelerators#395mlorenzofr wants to merge 1 commit intojaypipes:mainfrom
Conversation
Signed-off-by: Manuel Lorenzo <mlorenzofr@redhat.com>
106b5a7 to
6d0a25f
Compare
| #### 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. | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
something like
func Accelerator(filters ...func(dev *pci.Device) bool)
| accelDev := &AcceleratorDevice{ | ||
| Address: device.Address, | ||
| PCIDevice: device, | ||
| if len(i.DiscoveryFilters) > 0 { |
There was a problem hiding this comment.
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)
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 😉