2023-11-15 20:38:54 +00:00
|
|
|
// Copyright (c) 2022, 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 nvml
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
// GpmMetricsGetType includes interface types for GpmSample instead of nvmlGpmSample
|
|
|
|
type GpmMetricsGetType struct {
|
|
|
|
Version uint32
|
|
|
|
NumMetrics uint32
|
|
|
|
Sample1 GpmSample
|
|
|
|
Sample2 GpmSample
|
|
|
|
Metrics [98]GpmMetric
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GpmMetricsGetType) convert() *nvmlGpmMetricsGetType {
|
|
|
|
out := &nvmlGpmMetricsGetType{
|
|
|
|
Version: g.Version,
|
|
|
|
NumMetrics: g.NumMetrics,
|
|
|
|
Sample1: g.Sample1.(nvmlGpmSample),
|
|
|
|
Sample2: g.Sample2.(nvmlGpmSample),
|
|
|
|
}
|
|
|
|
for i := range g.Metrics {
|
|
|
|
out.Metrics[i] = g.Metrics[i]
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *nvmlGpmMetricsGetType) convert() *GpmMetricsGetType {
|
|
|
|
out := &GpmMetricsGetType{
|
|
|
|
Version: g.Version,
|
|
|
|
NumMetrics: g.NumMetrics,
|
|
|
|
Sample1: g.Sample1,
|
|
|
|
Sample2: g.Sample2,
|
|
|
|
}
|
|
|
|
for i := range g.Metrics {
|
|
|
|
out.Metrics[i] = g.Metrics[i]
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2023-11-15 20:38:54 +00:00
|
|
|
// nvml.GpmMetricsGet()
|
|
|
|
type GpmMetricsGetVType struct {
|
2024-06-14 13:27:46 +00:00
|
|
|
metricsGet *GpmMetricsGetType
|
2023-11-15 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) GpmMetricsGetV(metricsGet *GpmMetricsGetType) GpmMetricsGetVType {
|
2024-06-14 13:27:46 +00:00
|
|
|
return GpmMetricsGetVType{metricsGet}
|
2023-11-15 20:38:54 +00:00
|
|
|
}
|
2024-06-14 13:27:46 +00:00
|
|
|
|
|
|
|
// nvmlGpmMetricsGetStub is a stub function that can be overridden for testing.
|
|
|
|
var nvmlGpmMetricsGetStub = nvmlGpmMetricsGet
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
func (metricsGetV GpmMetricsGetVType) V1() Return {
|
|
|
|
metricsGetV.metricsGet.Version = 1
|
2024-06-14 13:27:46 +00:00
|
|
|
return gpmMetricsGet(metricsGetV.metricsGet)
|
2023-11-15 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) GpmMetricsGet(metricsGet *GpmMetricsGetType) Return {
|
|
|
|
metricsGet.Version = GPM_METRICS_GET_VERSION
|
2024-06-14 13:27:46 +00:00
|
|
|
return gpmMetricsGet(metricsGet)
|
|
|
|
}
|
|
|
|
|
|
|
|
func gpmMetricsGet(metricsGet *GpmMetricsGetType) Return {
|
|
|
|
nvmlMetricsGet := metricsGet.convert()
|
|
|
|
ret := nvmlGpmMetricsGetStub(nvmlMetricsGet)
|
|
|
|
*metricsGet = *nvmlMetricsGet.convert()
|
|
|
|
return ret
|
2023-11-15 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nvml.GpmSampleFree()
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) GpmSampleFree(gpmSample GpmSample) Return {
|
|
|
|
return gpmSample.Free()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gpmSample nvmlGpmSample) Free() Return {
|
|
|
|
return nvmlGpmSampleFree(gpmSample)
|
2023-11-15 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nvml.GpmSampleAlloc()
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) GpmSampleAlloc() (GpmSample, Return) {
|
|
|
|
var gpmSample nvmlGpmSample
|
|
|
|
ret := nvmlGpmSampleAlloc(&gpmSample)
|
|
|
|
return gpmSample, ret
|
2023-11-15 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nvml.GpmSampleGet()
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) GpmSampleGet(device Device, gpmSample GpmSample) Return {
|
|
|
|
return gpmSample.Get(device)
|
2023-11-15 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
func (device nvmlDevice) GpmSampleGet(gpmSample GpmSample) Return {
|
|
|
|
return gpmSample.Get(device)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gpmSample nvmlGpmSample) Get(device Device) Return {
|
2024-05-19 08:12:32 +00:00
|
|
|
return nvmlGpmSampleGet(nvmlDeviceHandle(device), gpmSample)
|
2023-11-15 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nvml.GpmQueryDeviceSupport()
|
|
|
|
type GpmSupportV struct {
|
2024-04-14 08:24:25 +00:00
|
|
|
device nvmlDevice
|
2023-11-15 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) GpmQueryDeviceSupportV(device Device) GpmSupportV {
|
|
|
|
return device.GpmQueryDeviceSupportV()
|
2023-11-15 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
func (device nvmlDevice) GpmQueryDeviceSupportV() GpmSupportV {
|
|
|
|
return GpmSupportV{device}
|
2023-11-15 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
func (gpmSupportV GpmSupportV) V1() (GpmSupport, Return) {
|
|
|
|
var gpmSupport GpmSupport
|
|
|
|
gpmSupport.Version = 1
|
|
|
|
ret := nvmlGpmQueryDeviceSupport(gpmSupportV.device, &gpmSupport)
|
|
|
|
return gpmSupport, ret
|
2023-11-15 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) GpmQueryDeviceSupport(device Device) (GpmSupport, Return) {
|
|
|
|
return device.GpmQueryDeviceSupport()
|
2023-11-15 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
func (device nvmlDevice) GpmQueryDeviceSupport() (GpmSupport, Return) {
|
|
|
|
var gpmSupport GpmSupport
|
|
|
|
gpmSupport.Version = GPM_SUPPORT_VERSION
|
|
|
|
ret := nvmlGpmQueryDeviceSupport(device, &gpmSupport)
|
|
|
|
return gpmSupport, ret
|
2023-11-15 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nvml.GpmMigSampleGet()
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) GpmMigSampleGet(device Device, gpuInstanceId int, gpmSample GpmSample) Return {
|
|
|
|
return gpmSample.MigGet(device, gpuInstanceId)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (device nvmlDevice) GpmMigSampleGet(gpuInstanceId int, gpmSample GpmSample) Return {
|
|
|
|
return gpmSample.MigGet(device, gpuInstanceId)
|
2023-11-15 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
func (gpmSample nvmlGpmSample) MigGet(device Device, gpuInstanceId int) Return {
|
2024-05-19 08:12:32 +00:00
|
|
|
return nvmlGpmMigSampleGet(nvmlDeviceHandle(device), uint32(gpuInstanceId), gpmSample)
|
2023-11-15 20:38:54 +00:00
|
|
|
}
|
2024-06-14 13:27:46 +00:00
|
|
|
|
|
|
|
// nvml.GpmQueryIfStreamingEnabled()
|
|
|
|
func (l *library) GpmQueryIfStreamingEnabled(device Device) (uint32, Return) {
|
|
|
|
return device.GpmQueryIfStreamingEnabled()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (device nvmlDevice) GpmQueryIfStreamingEnabled() (uint32, Return) {
|
|
|
|
var state uint32
|
|
|
|
ret := nvmlGpmQueryIfStreamingEnabled(device, &state)
|
|
|
|
return state, ret
|
|
|
|
}
|
|
|
|
|
|
|
|
// nvml.GpmSetStreamingEnabled()
|
|
|
|
func (l *library) GpmSetStreamingEnabled(device Device, state uint32) Return {
|
|
|
|
return device.GpmSetStreamingEnabled(state)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (device nvmlDevice) GpmSetStreamingEnabled(state uint32) Return {
|
|
|
|
return nvmlGpmSetStreamingEnabled(device, state)
|
|
|
|
}
|