2022-09-28 11:46:25 +00:00
|
|
|
// 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 nvml
|
|
|
|
|
|
|
|
// nvml.UnitGetCount()
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) UnitGetCount() (int, Return) {
|
2022-09-28 11:46:25 +00:00
|
|
|
var UnitCount uint32
|
|
|
|
ret := nvmlUnitGetCount(&UnitCount)
|
|
|
|
return int(UnitCount), ret
|
|
|
|
}
|
|
|
|
|
|
|
|
// nvml.UnitGetHandleByIndex()
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) UnitGetHandleByIndex(index int) (Unit, Return) {
|
|
|
|
var unit nvmlUnit
|
|
|
|
ret := nvmlUnitGetHandleByIndex(uint32(index), &unit)
|
|
|
|
return unit, ret
|
2022-09-28 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nvml.UnitGetUnitInfo()
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) UnitGetUnitInfo(unit Unit) (UnitInfo, Return) {
|
|
|
|
return unit.GetUnitInfo()
|
2022-09-28 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
func (unit nvmlUnit) GetUnitInfo() (UnitInfo, Return) {
|
|
|
|
var info UnitInfo
|
|
|
|
ret := nvmlUnitGetUnitInfo(unit, &info)
|
|
|
|
return info, ret
|
2022-09-28 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nvml.UnitGetLedState()
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) UnitGetLedState(unit Unit) (LedState, Return) {
|
|
|
|
return unit.GetLedState()
|
2022-09-28 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
func (unit nvmlUnit) GetLedState() (LedState, Return) {
|
|
|
|
var state LedState
|
|
|
|
ret := nvmlUnitGetLedState(unit, &state)
|
|
|
|
return state, ret
|
2022-09-28 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nvml.UnitGetPsuInfo()
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) UnitGetPsuInfo(unit Unit) (PSUInfo, Return) {
|
|
|
|
return unit.GetPsuInfo()
|
2022-09-28 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
func (unit nvmlUnit) GetPsuInfo() (PSUInfo, Return) {
|
|
|
|
var psu PSUInfo
|
|
|
|
ret := nvmlUnitGetPsuInfo(unit, &psu)
|
|
|
|
return psu, ret
|
2022-09-28 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nvml.UnitGetTemperature()
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) UnitGetTemperature(unit Unit, ttype int) (uint32, Return) {
|
|
|
|
return unit.GetTemperature(ttype)
|
2022-09-28 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
func (unit nvmlUnit) GetTemperature(ttype int) (uint32, Return) {
|
|
|
|
var temp uint32
|
|
|
|
ret := nvmlUnitGetTemperature(unit, uint32(ttype), &temp)
|
|
|
|
return temp, ret
|
2022-09-28 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nvml.UnitGetFanSpeedInfo()
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) UnitGetFanSpeedInfo(unit Unit) (UnitFanSpeeds, Return) {
|
|
|
|
return unit.GetFanSpeedInfo()
|
2022-09-28 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
func (unit nvmlUnit) GetFanSpeedInfo() (UnitFanSpeeds, Return) {
|
|
|
|
var fanSpeeds UnitFanSpeeds
|
|
|
|
ret := nvmlUnitGetFanSpeedInfo(unit, &fanSpeeds)
|
|
|
|
return fanSpeeds, ret
|
2022-09-28 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nvml.UnitGetDevices()
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) UnitGetDevices(unit Unit) ([]Device, Return) {
|
|
|
|
return unit.GetDevices()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (unit nvmlUnit) GetDevices() ([]Device, Return) {
|
|
|
|
var deviceCount uint32 = 1 // Will be reduced upon returning
|
2022-09-28 11:46:25 +00:00
|
|
|
for {
|
2024-04-14 08:24:25 +00:00
|
|
|
devices := make([]nvmlDevice, deviceCount)
|
|
|
|
ret := nvmlUnitGetDevices(unit, &deviceCount, &devices[0])
|
2022-09-28 11:46:25 +00:00
|
|
|
if ret == SUCCESS {
|
2024-04-14 08:24:25 +00:00
|
|
|
return convertSlice[nvmlDevice, Device](devices[:deviceCount]), ret
|
2022-09-28 11:46:25 +00:00
|
|
|
}
|
|
|
|
if ret != ERROR_INSUFFICIENT_SIZE {
|
|
|
|
return nil, ret
|
|
|
|
}
|
2024-04-14 08:24:25 +00:00
|
|
|
deviceCount *= 2
|
2022-09-28 11:46:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// nvml.UnitSetLedState()
|
2024-04-14 08:24:25 +00:00
|
|
|
func (l *library) UnitSetLedState(unit Unit, color LedColor) Return {
|
|
|
|
return unit.SetLedState(color)
|
2022-09-28 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 08:24:25 +00:00
|
|
|
func (unit nvmlUnit) SetLedState(color LedColor) Return {
|
|
|
|
return nvmlUnitSetLedState(unit, color)
|
2022-09-28 11:46:25 +00:00
|
|
|
}
|