Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/dcgm/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ func Introspect() (Status, error) {
return introspect()
}

// GetVersionInfo returns build environment information for the DCGM client library.
func GetVersionInfo() (VersionInfo, error) {
return versionInfo()
}

// GetHostengineVersionInfo returns build environment information for the DCGM host engine.
// Requires an active connection (Init must have been called).
func GetHostengineVersionInfo() (VersionInfo, error) {
return hostengineVersionInfo()
}

// GetSupportedMetricGroups returns all supported metric groups for the specified GPU
func GetSupportedMetricGroups(gpuID uint) ([]MetricGroup, error) {
return getSupportedMetricGroups(gpuID)
Expand Down
62 changes: 62 additions & 0 deletions pkg/dcgm/version_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dcgm

/*
#include "dcgm_agent.h"
#include "dcgm_structs.h"
*/
import "C"

import (
"unsafe"
)

// VersionInfo holds DCGM build environment information.
// RawBuildInfoString contains key-value pairs (e.g. version, arch, buildid, commit)
// separated by semicolons; each pair is "key:value".
type VersionInfo struct {
RawBuildInfoString string
}

func versionInfo() (VersionInfo, error) {
var cVersionInfo C.dcgmVersionInfo_t
cVersionInfo.version = makeVersion2(unsafe.Sizeof(cVersionInfo))

result := C.dcgmVersionInfo(&cVersionInfo)
if err := errorString(result); err != nil {
return VersionInfo{}, &Error{msg: C.GoString(C.errorString(result)), Code: result}
}

return VersionInfo{
RawBuildInfoString: C.GoString(&cVersionInfo.rawBuildInfoString[0]),
}, nil
}

func hostengineVersionInfo() (VersionInfo, error) {
var cVersionInfo C.dcgmVersionInfo_t
cVersionInfo.version = makeVersion2(unsafe.Sizeof(cVersionInfo))

result := C.dcgmHostengineVersionInfo(handle.handle, &cVersionInfo)
if err := errorString(result); err != nil {
return VersionInfo{}, &Error{msg: C.GoString(C.errorString(result)), Code: result}
}

return VersionInfo{
RawBuildInfoString: C.GoString(&cVersionInfo.rawBuildInfoString[0]),
}, nil
}
34 changes: 34 additions & 0 deletions tests/hostengine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,37 @@ func TestHostEngineStatusWithLoad(t *testing.T) {
t.Error("CPU usage should not be negative")
}
}

// TestGetVersionInfo verifies DCGM client library version/build info can be retrieved.
func TestGetVersionInfo(t *testing.T) {
cleanup, err := dcgm.Init(dcgm.Embedded)
if err != nil {
t.Fatalf("Failed to initialize DCGM: %v", err)
}
defer cleanup()

info, err := dcgm.GetVersionInfo()
if err != nil {
t.Fatalf("VersionInfo failed: %v", err)
}

t.Logf("DCGM library build info: %q", info.RawBuildInfoString)
// Build info is optional and format is implementation-defined; we only require no error.
}

// TestGetHostengineVersionInfo verifies DCGM host engine version/build info can be retrieved.
func TestGetHostengineVersionInfo(t *testing.T) {
cleanup, err := dcgm.Init(dcgm.Embedded)
if err != nil {
t.Fatalf("Failed to initialize DCGM: %v", err)
}
defer cleanup()

info, err := dcgm.GetHostengineVersionInfo()
if err != nil {
t.Fatalf("GetHostengineVersionInfo failed: %v", err)
}

t.Logf("DCGM host engine build info: %q", info.RawBuildInfoString)
// Build info is optional and format is implementation-defined; we only require no error.
}