jaypipes / ghw

Go HardWare discovery/inspection library
Apache License 2.0
1.62k stars 174 forks source link

added gpu driver query for windows #331

Closed hingino closed 1 year ago

hingino commented 1 year ago

Description

GPU does not currently return driver version for Windows. Adding these 3 lines reliably returns driver version

Test

package main

import (
    "fmt"

    "github.com/jaypipes/ghw"
)

type gpuInfo struct {
    Vendor        string
    Name          string
    OfflineDriver string
}

func GetGpuData() []gpuInfo {
    gpus := []gpuInfo{}

    cards, err := ghw.GPU()
    if err != nil {
        fmt.Printf("Error getting GPU info: %v", err)
    }

    for _, card := range cards.GraphicsCards {
        gpu := gpuInfo{
            Name:          card.DeviceInfo.Product.Name,
            Vendor:        card.DeviceInfo.Vendor.Name,
            OfflineDriver: card.DeviceInfo.Driver,
        }

        gpus = append(gpus, gpu)
    }

    return gpus
}

func main() {
    gpus := GetGpuData()

    for _, gpu := range gpus {
        println("GPU Vendor: ", gpu.Vendor)
        println("GPU Name: ", gpu.Name)
        println("Driver: ", gpu.OfflineDriver)
    }
}

Returns before update

GPU Vendor:  NVIDIA
GPU Name:  NVIDIA GeForce RTX 3060 Ti
Driver:

Return after update

GPU Vendor:  NVIDIA
GPU Name:  NVIDIA GeForce RTX 3060 Ti
Driver:  31.0.15.3118