There are multiple NVML Go bindings lying around GitHub. But they either are unmaintained or require configuring compiler flags. This package uses cgo and aims to be usable without any configuration.
Currently very few functionalities are exported from the underlying C library because those are what I need. But if you want more features, please submit an issue and I'll be happy to implement.
Following is an easy example that displays processes information on all devices.
package main
import (
"fmt"
"github.com/hotpxl/nvml"
)
func main() {
s, err := nvml.NewSession()
if err != nil {
panic(err)
}
defer s.Close()
devices, err := s.GetAllDevices()
if err != nil {
panic(err)
}
for _, d := range devices {
p, err := d.Processes()
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", p)
}
}
A second example cmd/nvml-monitor monitors device information and uploads to etcd.