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..afb2ab2 --- /dev/null +++ b/pkg/dcgm/version_info.go @@ -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 +} 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. +}