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

GPU information cannot be queried after virtual machine GPU pass through. By traversing the PCI information, it is found that the driver is not NVIDIA but vfio PCI. Can I add a vendor Name judge whether the PCI identification is GPU #314

Open
huyuan1999 opened this issue Apr 17, 2022 · 5 comments

Comments

@huyuan1999
Copy link

huyuan1999 commented Apr 17, 2022

package main

import (
	"fmt"
	"github.com/jaypipes/ghw"
	"github.com/sirupsen/logrus"
	"os"
	"strings"
)

func Exists(path string) bool {
	_, err := os.Stat(path)
	if err != nil {
		if os.IsExist(err) {
			return true
		}
		return false
	}
	return true
}

func IsDir(path string) bool {
	s, err := os.Stat(path)
	if err != nil {
		return false
	}
	return s.IsDir()
}

func IsFile(path string) bool {
	if Exists(path) {
		return !IsDir(path)
	}
	return false
}

func main() {
	pcidbPath := "/tmp/pci.ids"
	if IsFile(pcidbPath) {
		os.Setenv("PCIDB_PATH", "/tmp/pci.ids")
	}

	pci, err := ghw.PCI()
	if err != nil {
		logrus.Errorln(err)
		return
	}

	for _, devices := range pci.ListDevices() {
		if strings.Index(strings.ToLower(devices.Driver), "nvidia") != -1 || strings.Index(strings.ToLower(devices.Vendor.Name), "nvidia") != -1 {
			fmt.Printf("==================== nvidia %s ====================\n", devices.Address)
			fmt.Println("Address", devices.Address)
			fmt.Println("Vendor.ID", devices.Vendor.ID)
			fmt.Println("Vendor.Name", devices.Vendor.Name)
			fmt.Println("Driver", devices.Driver)
			fmt.Println("devices.Product.ID", devices.Product.ID)
			fmt.Println("devices.Product.VendorID", devices.Product.VendorID)
			fmt.Println("devices.Product.Name", devices.Product.Name)
		}
	}
}

image

@ffromani
Copy link
Collaborator

Hi @huyuan1999 ! Thanks for the report. I understand parts of the problem, because indeed inside a VM a VFIO device can be misreported, but I'm not completely sure what's the question here, could you please elaborate?
Are you requesting for example a way to override the pci.db?

@red-0ne
Copy link

red-0ne commented May 24, 2022

I think what @huyuan1999 is looking for is a way to determine if a PCI device with a nvidia device.Vendor.Name is a GPU or not.
Since device.Driver does not return nvidia but vfio-pci, we cannot rely on that property.

We are facing the same problem here. A possible workaround would be to check if device.Class.Name is a Display controller. @fromanirh is it reasonable to do it that way?

@ydcool
Copy link

ydcool commented Apr 25, 2024

Same issue here, any updates?

@ffromani
Copy link
Collaborator

Thanks for elaborating. Rather than make logic on the name, I'd indeed make logic on device class. I'd use ids rather than names.

@ffromani
Copy link
Collaborator

Is the gpu subpackage returning the correct information?

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

No branches or pull requests

4 participants