Go bindings for NVIDIA Data Center GPU Manager (DCGM).
go-dcgm provides Go bindings for NVIDIA Data Center GPU Manager (DCGM). DCGM manages and monitors NVIDIA GPUs in cluster environments. DCGM Exporter uses these bindings to publish GPU telemetry to Prometheus.
This repository contains the pkg/dcgm package, sample programs, and the
field-constant generator.
- Linux with an NVIDIA GPU and driver supported by DCGM. See the DCGM support matrix.
- DCGM 4 installed on the host. The bindings load
libdcgm.so.4at runtime. - cgo enabled when building.
Connection strings in standalone mode require DCGM 4.5.0 or later.
go get github.com/NVIDIA/go-dcgmcleanup, err := dcgm.Init(dcgm.Embedded)
if err != nil {
log.Fatal(err)
}
defer cleanup()
gpus, err := dcgm.GetSupportedDevices()
if err != nil {
log.Fatal(err)
}
for _, gpu := range gpus {
info, err := dcgm.GetDeviceInfo(gpu)
if err != nil {
log.Fatal(err)
}
fmt.Printf("GPU %d: %s (%s)\n", gpu, info.Identifiers.Model, info.UUID)
}dcgm.Init supports three modes:
Embeddedruns the DCGM host engine inside your process.Standaloneconnects to a runningnv-hostengineover TCP or a Unix socket.StartHostenginestartsnv-hostengineas a child process and stops it on cleanup.
See the samples for complete programs, including device information, health checks, policies, diagnostics, and a REST API.
RunDiag returns hierarchical DiagResults. New code should use
results.Tests; each test includes its status, per-entity results, errors,
information, and extra data. DiagResults.Software and DiagResult remain
available as a deprecated compatibility view. See the diagnostic
sample.
The repository uses Task for common commands and Bazel for Go and cgo builds. See CONTRIBUTING.md for the pinned tool versions, or open the repository in a Dev Containers compatible editor to use the same environment as CI.
These checks do not need a GPU:
task build
task test
task validateThese need a GPU host with DCGM installed:
task test:integration
task test:raceAfter updating pkg/dcgm/dcgm_fields.h, regenerate the field constants with
task generate and confirm them with task generate:check. See Updating DCGM
Fields for the full process.
Read CONTRIBUTING.md before submitting a change. For community support, open an issue.
Report potential security vulnerabilities through the NVIDIA Product Security process, not through a public issue.
go-dcgm is licensed under the Apache License, Version 2.0.