clvk icon indicating copy to clipboard operation
clvk copied to clipboard

Support CL_DEVICE_VENDOR query

Open kpet opened this issue 7 years ago • 3 comments

kpet avatar Sep 16 '18 11:09 kpet

Currently, querying the vendor still returns FIXME

But I think it should be possible to get a vendor name from the PCI VendorID.

Running vulkaninfo --summary will list a VendorID and DeviceID for each "GPU."

NOTE: The llvmpipe VendorID is not a PCI ID, I think, because it exceeds 0xffff.

Devices:
========
GPU0:
	apiVersion         = 1.3.238
	driverVersion      = 23.0.2
	vendorID           = 0x8086
	deviceID           = 0x4680
	deviceType         = PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
	deviceName         = Intel(R) UHD Graphics 770 (ADL-S GT1)
	driverID           = DRIVER_ID_INTEL_OPEN_SOURCE_MESA
	driverName         = Intel open-source Mesa driver
	driverInfo         = Mesa 23.0.2
	conformanceVersion = 1.3.0.0
	deviceUUID         = fd8cf190-0bdb-4dd5-b941-a7eb5b383e9c
	driverUUID         = 9bb8225e-db2e-6a20-282d-526794955fa9
GPU1:
	apiVersion         = 1.3.238
	driverVersion      = 23.0.2
	vendorID           = 0x1002
	deviceID           = 0x67df
	deviceType         = PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
	deviceName         = AMD Radeon RX 580 Series (RADV POLARIS10)
	driverID           = DRIVER_ID_MESA_RADV
	driverName         = radv
	driverInfo         = Mesa 23.0.2
	conformanceVersion = 1.2.7.1
	deviceUUID         = 00000000-0100-0000-0000-000000000000
	driverUUID         = 414d442d-4d45-5341-2d44-525600000000
GPU2:
	apiVersion         = 1.3.238
	driverVersion      = 0.0.1
	vendorID           = 0x10005
	deviceID           = 0x0000
	deviceType         = PHYSICAL_DEVICE_TYPE_CPU
	deviceName         = llvmpipe (LLVM 15.0.7, 256 bits)
	driverID           = DRIVER_ID_MESA_LLVMPIPE
	driverName         = llvmpipe
	driverInfo         = Mesa 23.0.2 (LLVM 15.0.7)
	conformanceVersion = 1.3.1.1
	deviceUUID         = 6d657361-3233-2e30-2e32-000000000000
	driverUUID         = 6c6c766d-7069-7065-5555-494400000000

An ugly, but simple approach would be to hard-code the most common IDs, like Intel, NVIDIA, AMD. But that would lack completeness.

On Linux, another possibility would be to check if /usr/share/misc/pci.ids exists, and parse that.

I'm willing to make a PR if either approach appeals to you, or if there is a better approach. I wonder if there is an existing software library that does this? That could optionally be linked in.

UPDATE Linking another dependency seems unnecessary, as the parsing is quite trivial:

$ grep "^1002" /usr/share/misc/pci.ids 
1002  Advanced Micro Devices, Inc. [AMD/ATI]
$ grep "^8086" /usr/share/misc/pci.ids 
8086  Intel Corporation

We could just read that file info memory, and search for the ID following a newline character.

A read per lookup is probably simplest. If retaining between lookups, we would need to free the memory at the end.

stolk avatar Jun 03 '23 22:06 stolk

We could consider adding a string in cvk_device_properties as we already have Intel, AMD, Swiftshader and Nvidia deviceID hard coded there.

rjodinchr avatar Jun 04 '23 08:06 rjodinchr

A full implementation for that query is not that simple which is why it still hasn't been done. We need to handle:

  1. Vendor IDs allocated by Khronos (like the one used for llvmpipe). There are few of these. We could hard-code a list but it's bound to become out of date. An automated flow from the Vulkan XML isn't that simple and feels a bit overkill just for this.

  2. PCI vendor IDs. I agree it would be easy enough to cobble something that works together on Linux but it's a bit more work to do cleanly and in a way that works on all platforms. We can't rely on the file being present on the system by default (and shouldn't be installing it ourselves) and I think we're likely to want to support linking it into clvk as well (probably configured at build time). Having said that we could maybe attempt to detect the presence of the file at runtime using a list of known locations as a first step and search it with a C++ regular expression. Ideally we'd digest the file into a data structure that's easy to search (and does not contain the info we don't need) but it's quite a bit more work and would also require a flow to keep the file up to date.

How hard can it be to report a vendor name :D?

I've got a work-in-progress patch for 1 that I've been sitting on for too long, I'll update it with @rjodinchr's suggestion and create a PR so at least we have something better than "FIXME". @stolk You're more than welcome to propose a PR to handle the PCI DB properly.

kpet avatar Jun 04 '23 11:06 kpet