From 4dc23ab79cdd993fd85d7936e4ad3520a2106d24 Mon Sep 17 00:00:00 2001 From: Douglas Wightman Date: Thu, 12 Feb 2026 13:26:33 -0700 Subject: [PATCH 1/2] Enable GetVersionInfo and GetHostengineVersionInfo APIs --- pkg/dcgm/api.go | 11 +++++++ pkg/dcgm/version_info.go | 62 ++++++++++++++++++++++++++++++++++++++++ tests/hostengine_test.go | 34 ++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 pkg/dcgm/version_info.go diff --git a/pkg/dcgm/api.go b/pkg/dcgm/api.go index ab92dbc..a88e185 100644 --- a/pkg/dcgm/api.go +++ b/pkg/dcgm/api.go @@ -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) diff --git a/pkg/dcgm/version_info.go b/pkg/dcgm/version_info.go new file mode 100644 index 0000000..0378e51 --- /dev/null +++ b/pkg/dcgm/version_info.go @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2020, 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 +} diff --git a/tests/hostengine_test.go b/tests/hostengine_test.go index 93d1fdd..757fa5a 100644 --- a/tests/hostengine_test.go +++ b/tests/hostengine_test.go @@ -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. +} From 9d225daf6872923a79318ce0cda1e8f858d3bb4a Mon Sep 17 00:00:00 2001 From: Douglas Wightman Date: Fri, 13 Feb 2026 10:30:16 -0700 Subject: [PATCH 2/2] Update header year --- pkg/dcgm/version_info.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/dcgm/version_info.go b/pkg/dcgm/version_info.go index 0378e51..afb2ab2 100644 --- a/pkg/dcgm/version_info.go +++ b/pkg/dcgm/version_info.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. + * 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.