diff --git a/.gitignore b/.gitignore index ad5126f..e801c21 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.swp *.swo -pkg/nvml/ +.cache +coverage.out* diff --git a/Makefile b/Makefile index bc980ea..dabb108 100644 --- a/Makefile +++ b/Makefile @@ -139,12 +139,11 @@ bindings: .create-bindings .strip-autogen-comment .strip-nvml-h-linenumber .create-bindings: $(PKG_BINDINGS_DIR)/nvml.h $(SOURCES) | $(PKG_BINDINGS_DIR) cp $(GEN_BINDINGS_DIR)/nvml.yml $(PKG_BINDINGS_DIR) c-for-go -out $(PKG_DIR) $(PKG_BINDINGS_DIR)/nvml.yml - cp $(GEN_BINDINGS_DIR)/*.go $(PKG_BINDINGS_DIR) cd $(PKG_BINDINGS_DIR); \ go tool cgo -godefs types.go > types_gen.go; \ go fmt types_gen.go; \ cd -> /dev/null - rm -rf $(PKG_BINDINGS_DIR)/nvml.yml $(PKG_BINDINGS_DIR)/types.go $(PKG_BINDINGS_DIR)/_obj + rm -rf $(PKG_BINDINGS_DIR)/nvml.yml $(PKG_BINDINGS_DIR)/cgo_helpers.go $(PKG_BINDINGS_DIR)/types.go $(PKG_BINDINGS_DIR)/_obj .strip-autogen-comment: SED_SEARCH_STRING := // WARNING: This file has automatically been generated on .strip-autogen-comment: SED_REPLACE_STRING := // WARNING: THIS FILE WAS AUTOMATICALLY GENERATED. @@ -160,12 +159,16 @@ bindings: .create-bindings .strip-autogen-comment .strip-nvml-h-linenumber test-bindings: bindings clean-bindings: - rm -rf $(PKG_BINDINGS_DIR) - git checkout $(PKG_BINDINGS_DIR) - rm -rf $(PKG_BINDINGS_DIR)/nvml.h + rm -f $(PKG_BINDINGS_DIR)/cgo_helpers.go + rm -f $(PKG_BINDINGS_DIR)/cgo_helpers.h + rm -f $(PKG_BINDINGS_DIR)/const.go + rm -f $(PKG_BINDINGS_DIR)/doc.go + rm -f $(PKG_BINDINGS_DIR)/nvml.go + rm -f $(PKG_BINDINGS_DIR)/nvml.h + rm -f $(PKG_BINDINGS_DIR)/types_gen.go # Update nvml.h from the Anaconda package repository -update-nvml-h: JQ ?= $(DOCKER) run -i --rm -v "$(PWD):$(PWD)" -w "$(PWD)" stedolan/jq:latest +update-nvml-h: JQ ?= $(DOCKER) run -i --rm -v "$(PWD):$(PWD)" -w "$(PWD)" backplane/jq:latest update-nvml-h: NVML_DEV_PACKAGES_INFO := $(shell \ wget -qO - https://api.anaconda.org/package/nvidia/cuda-nvml-dev/files | \ $(JQ) '.[] | select(.attrs.subdir=="linux-64") | .version + "@" + .upload_time[:19] + "@" + .full_name' | \ diff --git a/README.md b/README.md index db63fa6..4ba7830 100644 --- a/README.md +++ b/README.md @@ -321,7 +321,7 @@ symbols include the following (as defined in `nvml.h`): The actual versions that these API calls are assigned to will depend on the version of the NVIDIA driver (and hence the version of `libnvidia-ml.so` that you have linked in). These updates happen in the `updateVersionedSymbols()` -function of `gen/nvml/lib.go` as seen below. +function of `pkg/nvml/lib.go` as seen below. ```go // Default all versioned APIs to v1 (to infer the types) @@ -366,8 +366,8 @@ The files below define a set of "glue" code between the auto-generated bindings from `c-for-go` and the manual wrappers providing a more user-friendly API to the end user. -- `gen/nvml/cgo_helpers.go` -- `gen/nvml/return.go` +- `pkg/nvml/cgo_helpers_atatic.go` +- `pkg/nvml/return.go` The `cgo_helpers.go` file defines functions that help in dealing with the types coming out of the C API and turning them into more usable Go types. It is @@ -391,12 +391,12 @@ bindings from `c-for-go`. Only these manual wrappers are expected as part of the API for the package -- the auto-generated bindings are only available for internal use. -- `gen/nvml/init.go` -- `gen/nvml/system.go` -- `gen/nvml/event_set.go` -- `gen/nvml/vgpu.go` -- `gen/nvml/unit.go` -- `gen/nvml/device.go` +- `pkg/nvml/init.go` +- `pkg/nvml/system.go` +- `pkg/nvml/event_set.go` +- `pkg/nvml/vgpu.go` +- `pkg/nvml/unit.go` +- `pkg/nvml/device.go` These wrappers add boiler-plate code around the auto-generated bindings so that the end-user doesn't have to do this themselves every time a call is made. @@ -475,7 +475,7 @@ should be straightforward so long as we keep good pace with each new release. At present, all test code is under the following file: -- `gen/nvml/nvml_test.go` +- `pkg/nvml/nvml_test.go` The test coverage is fairly sparse and could be greatly improved. diff --git a/gen/nvml/api.go b/gen/nvml/api.go deleted file mode 100644 index 4885e8e..0000000 --- a/gen/nvml/api.go +++ /dev/null @@ -1,37 +0,0 @@ -/** -# Copyright 2023 NVIDIA CORPORATION -# -# 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 - -// Library defines a set of functions defined on the underlying dynamic library. -type Library interface { - Lookup(string) error -} - -// dynamicLibrary is an interface for abstacting the underlying library. -// This also allows for mocking and testing. - -//go:generate moq -stub -out dynamicLibrary_mock.go . dynamicLibrary -type dynamicLibrary interface { - Lookup(string) error - Open() error - Close() error -} - -// Interface represents the interface for the NVML library. -type Interface interface { - GetLibrary() Library -} diff --git a/gen/nvml/device.go b/gen/nvml/device.go deleted file mode 100644 index 91a7baa..0000000 --- a/gen/nvml/device.go +++ /dev/null @@ -1,2652 +0,0 @@ -// 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 - -import ( - "unsafe" -) - -// EccBitType -type EccBitType = MemoryErrorType - -// nvml.DeviceGetCount() -func DeviceGetCount() (int, Return) { - var DeviceCount uint32 - ret := nvmlDeviceGetCount(&DeviceCount) - return int(DeviceCount), ret -} - -// nvml.DeviceGetHandleByIndex() -func DeviceGetHandleByIndex(Index int) (Device, Return) { - var Device Device - ret := nvmlDeviceGetHandleByIndex(uint32(Index), &Device) - return Device, ret -} - -// nvml.DeviceGetHandleBySerial() -func DeviceGetHandleBySerial(Serial string) (Device, Return) { - var Device Device - ret := nvmlDeviceGetHandleBySerial(Serial+string(rune(0)), &Device) - return Device, ret -} - -// nvml.DeviceGetHandleByUUID() -func DeviceGetHandleByUUID(Uuid string) (Device, Return) { - var Device Device - ret := nvmlDeviceGetHandleByUUID(Uuid+string(rune(0)), &Device) - return Device, ret -} - -// nvml.DeviceGetHandleByPciBusId() -func DeviceGetHandleByPciBusId(PciBusId string) (Device, Return) { - var Device Device - ret := nvmlDeviceGetHandleByPciBusId(PciBusId+string(rune(0)), &Device) - return Device, ret -} - -// nvml.DeviceGetName() -func DeviceGetName(Device Device) (string, Return) { - Name := make([]byte, DEVICE_NAME_V2_BUFFER_SIZE) - ret := nvmlDeviceGetName(Device, &Name[0], DEVICE_NAME_V2_BUFFER_SIZE) - return string(Name[:clen(Name)]), ret -} - -func (Device Device) GetName() (string, Return) { - return DeviceGetName(Device) -} - -// nvml.DeviceGetBrand() -func DeviceGetBrand(Device Device) (BrandType, Return) { - var _type BrandType - ret := nvmlDeviceGetBrand(Device, &_type) - return _type, ret -} - -func (Device Device) GetBrand() (BrandType, Return) { - return DeviceGetBrand(Device) -} - -// nvml.DeviceGetIndex() -func DeviceGetIndex(Device Device) (int, Return) { - var Index uint32 - ret := nvmlDeviceGetIndex(Device, &Index) - return int(Index), ret -} - -func (Device Device) GetIndex() (int, Return) { - return DeviceGetIndex(Device) -} - -// nvml.DeviceGetSerial() -func DeviceGetSerial(Device Device) (string, Return) { - Serial := make([]byte, DEVICE_SERIAL_BUFFER_SIZE) - ret := nvmlDeviceGetSerial(Device, &Serial[0], DEVICE_SERIAL_BUFFER_SIZE) - return string(Serial[:clen(Serial)]), ret -} - -func (Device Device) GetSerial() (string, Return) { - return DeviceGetSerial(Device) -} - -// nvml.DeviceGetCpuAffinity() -func DeviceGetCpuAffinity(Device Device, NumCPUs int) ([]uint, Return) { - CpuSetSize := uint32((NumCPUs-1)/int(unsafe.Sizeof(uint(0))) + 1) - CpuSet := make([]uint, CpuSetSize) - ret := nvmlDeviceGetCpuAffinity(Device, CpuSetSize, &CpuSet[0]) - return CpuSet, ret -} - -func (Device Device) GetCpuAffinity(NumCPUs int) ([]uint, Return) { - return DeviceGetCpuAffinity(Device, NumCPUs) -} - -// nvml.DeviceSetCpuAffinity() -func DeviceSetCpuAffinity(Device Device) Return { - return nvmlDeviceSetCpuAffinity(Device) -} - -func (Device Device) SetCpuAffinity() Return { - return DeviceSetCpuAffinity(Device) -} - -// nvml.DeviceClearCpuAffinity() -func DeviceClearCpuAffinity(Device Device) Return { - return nvmlDeviceClearCpuAffinity(Device) -} - -func (Device Device) ClearCpuAffinity() Return { - return DeviceClearCpuAffinity(Device) -} - -// nvml.DeviceGetMemoryAffinity() -func DeviceGetMemoryAffinity(Device Device, NumNodes int, Scope AffinityScope) ([]uint, Return) { - NodeSetSize := uint32((NumNodes-1)/int(unsafe.Sizeof(uint(0))) + 1) - NodeSet := make([]uint, NodeSetSize) - ret := nvmlDeviceGetMemoryAffinity(Device, NodeSetSize, &NodeSet[0], Scope) - return NodeSet, ret -} - -func (Device Device) GetMemoryAffinity(NumNodes int, Scope AffinityScope) ([]uint, Return) { - return DeviceGetMemoryAffinity(Device, NumNodes, Scope) -} - -// nvml.DeviceGetCpuAffinityWithinScope() -func DeviceGetCpuAffinityWithinScope(Device Device, NumCPUs int, Scope AffinityScope) ([]uint, Return) { - CpuSetSize := uint32((NumCPUs-1)/int(unsafe.Sizeof(uint(0))) + 1) - CpuSet := make([]uint, CpuSetSize) - ret := nvmlDeviceGetCpuAffinityWithinScope(Device, CpuSetSize, &CpuSet[0], Scope) - return CpuSet, ret -} - -func (Device Device) GetCpuAffinityWithinScope(NumCPUs int, Scope AffinityScope) ([]uint, Return) { - return DeviceGetCpuAffinityWithinScope(Device, NumCPUs, Scope) -} - -// nvml.DeviceGetTopologyCommonAncestor() -func DeviceGetTopologyCommonAncestor(Device1 Device, Device2 Device) (GpuTopologyLevel, Return) { - var PathInfo GpuTopologyLevel - ret := nvmlDeviceGetTopologyCommonAncestor(Device1, Device2, &PathInfo) - return PathInfo, ret -} - -func (Device1 Device) GetTopologyCommonAncestor(Device2 Device) (GpuTopologyLevel, Return) { - return DeviceGetTopologyCommonAncestor(Device1, Device2) -} - -// nvml.DeviceGetTopologyNearestGpus() -func DeviceGetTopologyNearestGpus(device Device, Level GpuTopologyLevel) ([]Device, Return) { - var Count uint32 - ret := nvmlDeviceGetTopologyNearestGpus(device, Level, &Count, nil) - if ret != SUCCESS { - return nil, ret - } - if Count == 0 { - return []Device{}, ret - } - DeviceArray := make([]Device, Count) - ret = nvmlDeviceGetTopologyNearestGpus(device, Level, &Count, &DeviceArray[0]) - return DeviceArray, ret -} - -func (Device Device) GetTopologyNearestGpus(Level GpuTopologyLevel) ([]Device, Return) { - return DeviceGetTopologyNearestGpus(Device, Level) -} - -// nvml.DeviceGetP2PStatus() -func DeviceGetP2PStatus(Device1 Device, Device2 Device, P2pIndex GpuP2PCapsIndex) (GpuP2PStatus, Return) { - var P2pStatus GpuP2PStatus - ret := nvmlDeviceGetP2PStatus(Device1, Device2, P2pIndex, &P2pStatus) - return P2pStatus, ret -} - -func (Device1 Device) GetP2PStatus(Device2 Device, P2pIndex GpuP2PCapsIndex) (GpuP2PStatus, Return) { - return DeviceGetP2PStatus(Device1, Device2, P2pIndex) -} - -// nvml.DeviceGetUUID() -func DeviceGetUUID(Device Device) (string, Return) { - Uuid := make([]byte, DEVICE_UUID_V2_BUFFER_SIZE) - ret := nvmlDeviceGetUUID(Device, &Uuid[0], DEVICE_UUID_V2_BUFFER_SIZE) - return string(Uuid[:clen(Uuid)]), ret -} - -func (Device Device) GetUUID() (string, Return) { - return DeviceGetUUID(Device) -} - -// nvml.DeviceGetMinorNumber() -func DeviceGetMinorNumber(Device Device) (int, Return) { - var MinorNumber uint32 - ret := nvmlDeviceGetMinorNumber(Device, &MinorNumber) - return int(MinorNumber), ret -} - -func (Device Device) GetMinorNumber() (int, Return) { - return DeviceGetMinorNumber(Device) -} - -// nvml.DeviceGetBoardPartNumber() -func DeviceGetBoardPartNumber(Device Device) (string, Return) { - PartNumber := make([]byte, DEVICE_PART_NUMBER_BUFFER_SIZE) - ret := nvmlDeviceGetBoardPartNumber(Device, &PartNumber[0], DEVICE_PART_NUMBER_BUFFER_SIZE) - return string(PartNumber[:clen(PartNumber)]), ret -} - -func (Device Device) GetBoardPartNumber() (string, Return) { - return DeviceGetBoardPartNumber(Device) -} - -// nvml.DeviceGetInforomVersion() -func DeviceGetInforomVersion(Device Device, Object InforomObject) (string, Return) { - Version := make([]byte, DEVICE_INFOROM_VERSION_BUFFER_SIZE) - ret := nvmlDeviceGetInforomVersion(Device, Object, &Version[0], DEVICE_INFOROM_VERSION_BUFFER_SIZE) - return string(Version[:clen(Version)]), ret -} - -func (Device Device) GetInforomVersion(Object InforomObject) (string, Return) { - return DeviceGetInforomVersion(Device, Object) -} - -// nvml.DeviceGetInforomImageVersion() -func DeviceGetInforomImageVersion(Device Device) (string, Return) { - Version := make([]byte, DEVICE_INFOROM_VERSION_BUFFER_SIZE) - ret := nvmlDeviceGetInforomImageVersion(Device, &Version[0], DEVICE_INFOROM_VERSION_BUFFER_SIZE) - return string(Version[:clen(Version)]), ret -} - -func (Device Device) GetInforomImageVersion() (string, Return) { - return DeviceGetInforomImageVersion(Device) -} - -// nvml.DeviceGetInforomConfigurationChecksum() -func DeviceGetInforomConfigurationChecksum(Device Device) (uint32, Return) { - var Checksum uint32 - ret := nvmlDeviceGetInforomConfigurationChecksum(Device, &Checksum) - return Checksum, ret -} - -func (Device Device) GetInforomConfigurationChecksum() (uint32, Return) { - return DeviceGetInforomConfigurationChecksum(Device) -} - -// nvml.DeviceValidateInforom() -func DeviceValidateInforom(Device Device) Return { - return nvmlDeviceValidateInforom(Device) -} - -func (Device Device) ValidateInforom() Return { - return DeviceValidateInforom(Device) -} - -// nvml.DeviceGetDisplayMode() -func DeviceGetDisplayMode(Device Device) (EnableState, Return) { - var Display EnableState - ret := nvmlDeviceGetDisplayMode(Device, &Display) - return Display, ret -} - -func (Device Device) GetDisplayMode() (EnableState, Return) { - return DeviceGetDisplayMode(Device) -} - -// nvml.DeviceGetDisplayActive() -func DeviceGetDisplayActive(Device Device) (EnableState, Return) { - var IsActive EnableState - ret := nvmlDeviceGetDisplayActive(Device, &IsActive) - return IsActive, ret -} - -func (Device Device) GetDisplayActive() (EnableState, Return) { - return DeviceGetDisplayActive(Device) -} - -// nvml.DeviceGetPersistenceMode() -func DeviceGetPersistenceMode(Device Device) (EnableState, Return) { - var Mode EnableState - ret := nvmlDeviceGetPersistenceMode(Device, &Mode) - return Mode, ret -} - -func (Device Device) GetPersistenceMode() (EnableState, Return) { - return DeviceGetPersistenceMode(Device) -} - -// nvml.DeviceGetPciInfo() -func DeviceGetPciInfo(Device Device) (PciInfo, Return) { - var Pci PciInfo - ret := nvmlDeviceGetPciInfo(Device, &Pci) - return Pci, ret -} - -func (Device Device) GetPciInfo() (PciInfo, Return) { - return DeviceGetPciInfo(Device) -} - -// nvml.DeviceGetMaxPcieLinkGeneration() -func DeviceGetMaxPcieLinkGeneration(Device Device) (int, Return) { - var MaxLinkGen uint32 - ret := nvmlDeviceGetMaxPcieLinkGeneration(Device, &MaxLinkGen) - return int(MaxLinkGen), ret -} - -func (Device Device) GetMaxPcieLinkGeneration() (int, Return) { - return DeviceGetMaxPcieLinkGeneration(Device) -} - -// nvml.DeviceGetMaxPcieLinkWidth() -func DeviceGetMaxPcieLinkWidth(Device Device) (int, Return) { - var MaxLinkWidth uint32 - ret := nvmlDeviceGetMaxPcieLinkWidth(Device, &MaxLinkWidth) - return int(MaxLinkWidth), ret -} - -func (Device Device) GetMaxPcieLinkWidth() (int, Return) { - return DeviceGetMaxPcieLinkWidth(Device) -} - -// nvml.DeviceGetCurrPcieLinkGeneration() -func DeviceGetCurrPcieLinkGeneration(Device Device) (int, Return) { - var CurrLinkGen uint32 - ret := nvmlDeviceGetCurrPcieLinkGeneration(Device, &CurrLinkGen) - return int(CurrLinkGen), ret -} - -func (Device Device) GetCurrPcieLinkGeneration() (int, Return) { - return DeviceGetCurrPcieLinkGeneration(Device) -} - -// nvml.DeviceGetCurrPcieLinkWidth() -func DeviceGetCurrPcieLinkWidth(Device Device) (int, Return) { - var CurrLinkWidth uint32 - ret := nvmlDeviceGetCurrPcieLinkWidth(Device, &CurrLinkWidth) - return int(CurrLinkWidth), ret -} - -func (Device Device) GetCurrPcieLinkWidth() (int, Return) { - return DeviceGetCurrPcieLinkWidth(Device) -} - -// nvml.DeviceGetPcieThroughput() -func DeviceGetPcieThroughput(Device Device, Counter PcieUtilCounter) (uint32, Return) { - var Value uint32 - ret := nvmlDeviceGetPcieThroughput(Device, Counter, &Value) - return Value, ret -} - -func (Device Device) GetPcieThroughput(Counter PcieUtilCounter) (uint32, Return) { - return DeviceGetPcieThroughput(Device, Counter) -} - -// nvml.DeviceGetPcieReplayCounter() -func DeviceGetPcieReplayCounter(Device Device) (int, Return) { - var Value uint32 - ret := nvmlDeviceGetPcieReplayCounter(Device, &Value) - return int(Value), ret -} - -func (Device Device) GetPcieReplayCounter() (int, Return) { - return DeviceGetPcieReplayCounter(Device) -} - -// nvml.nvmlDeviceGetClockInfo() -func DeviceGetClockInfo(Device Device, _type ClockType) (uint32, Return) { - var Clock uint32 - ret := nvmlDeviceGetClockInfo(Device, _type, &Clock) - return Clock, ret -} - -func (Device Device) GetClockInfo(_type ClockType) (uint32, Return) { - return DeviceGetClockInfo(Device, _type) -} - -// nvml.DeviceGetMaxClockInfo() -func DeviceGetMaxClockInfo(Device Device, _type ClockType) (uint32, Return) { - var Clock uint32 - ret := nvmlDeviceGetMaxClockInfo(Device, _type, &Clock) - return Clock, ret -} - -func (Device Device) GetMaxClockInfo(_type ClockType) (uint32, Return) { - return DeviceGetMaxClockInfo(Device, _type) -} - -// nvml.DeviceGetApplicationsClock() -func DeviceGetApplicationsClock(Device Device, ClockType ClockType) (uint32, Return) { - var ClockMHz uint32 - ret := nvmlDeviceGetApplicationsClock(Device, ClockType, &ClockMHz) - return ClockMHz, ret -} - -func (Device Device) GetApplicationsClock(ClockType ClockType) (uint32, Return) { - return DeviceGetApplicationsClock(Device, ClockType) -} - -// nvml.DeviceGetDefaultApplicationsClock() -func DeviceGetDefaultApplicationsClock(Device Device, ClockType ClockType) (uint32, Return) { - var ClockMHz uint32 - ret := nvmlDeviceGetDefaultApplicationsClock(Device, ClockType, &ClockMHz) - return ClockMHz, ret -} - -func (Device Device) GetDefaultApplicationsClock(ClockType ClockType) (uint32, Return) { - return DeviceGetDefaultApplicationsClock(Device, ClockType) -} - -// nvml.DeviceResetApplicationsClocks() -func DeviceResetApplicationsClocks(Device Device) Return { - return nvmlDeviceResetApplicationsClocks(Device) -} - -func (Device Device) ResetApplicationsClocks() Return { - return DeviceResetApplicationsClocks(Device) -} - -// nvml.DeviceGetClock() -func DeviceGetClock(Device Device, ClockType ClockType, ClockId ClockId) (uint32, Return) { - var ClockMHz uint32 - ret := nvmlDeviceGetClock(Device, ClockType, ClockId, &ClockMHz) - return ClockMHz, ret -} - -func (Device Device) GetClock(ClockType ClockType, ClockId ClockId) (uint32, Return) { - return DeviceGetClock(Device, ClockType, ClockId) -} - -// nvml.DeviceGetMaxCustomerBoostClock() -func DeviceGetMaxCustomerBoostClock(Device Device, ClockType ClockType) (uint32, Return) { - var ClockMHz uint32 - ret := nvmlDeviceGetMaxCustomerBoostClock(Device, ClockType, &ClockMHz) - return ClockMHz, ret -} - -func (Device Device) GetMaxCustomerBoostClock(ClockType ClockType) (uint32, Return) { - return DeviceGetMaxCustomerBoostClock(Device, ClockType) -} - -// nvml.DeviceGetSupportedMemoryClocks() -func DeviceGetSupportedMemoryClocks(Device Device) (int, uint32, Return) { - var Count, ClocksMHz uint32 - ret := nvmlDeviceGetSupportedMemoryClocks(Device, &Count, &ClocksMHz) - return int(Count), ClocksMHz, ret -} - -func (Device Device) GetSupportedMemoryClocks() (int, uint32, Return) { - return DeviceGetSupportedMemoryClocks(Device) -} - -// nvml.DeviceGetSupportedGraphicsClocks() -func DeviceGetSupportedGraphicsClocks(Device Device, MemoryClockMHz int) (int, uint32, Return) { - var Count, ClocksMHz uint32 - ret := nvmlDeviceGetSupportedGraphicsClocks(Device, uint32(MemoryClockMHz), &Count, &ClocksMHz) - return int(Count), ClocksMHz, ret -} - -func (Device Device) GetSupportedGraphicsClocks(MemoryClockMHz int) (int, uint32, Return) { - return DeviceGetSupportedGraphicsClocks(Device, MemoryClockMHz) -} - -// nvml.DeviceGetAutoBoostedClocksEnabled() -func DeviceGetAutoBoostedClocksEnabled(Device Device) (EnableState, EnableState, Return) { - var IsEnabled, DefaultIsEnabled EnableState - ret := nvmlDeviceGetAutoBoostedClocksEnabled(Device, &IsEnabled, &DefaultIsEnabled) - return IsEnabled, DefaultIsEnabled, ret -} - -func (Device Device) GetAutoBoostedClocksEnabled() (EnableState, EnableState, Return) { - return DeviceGetAutoBoostedClocksEnabled(Device) -} - -// nvml.DeviceSetAutoBoostedClocksEnabled() -func DeviceSetAutoBoostedClocksEnabled(Device Device, Enabled EnableState) Return { - return nvmlDeviceSetAutoBoostedClocksEnabled(Device, Enabled) -} - -func (Device Device) SetAutoBoostedClocksEnabled(Enabled EnableState) Return { - return DeviceSetAutoBoostedClocksEnabled(Device, Enabled) -} - -// nvml.DeviceSetDefaultAutoBoostedClocksEnabled() -func DeviceSetDefaultAutoBoostedClocksEnabled(Device Device, Enabled EnableState, Flags uint32) Return { - return nvmlDeviceSetDefaultAutoBoostedClocksEnabled(Device, Enabled, Flags) -} - -func (Device Device) SetDefaultAutoBoostedClocksEnabled(Enabled EnableState, Flags uint32) Return { - return DeviceSetDefaultAutoBoostedClocksEnabled(Device, Enabled, Flags) -} - -// nvml.DeviceGetFanSpeed() -func DeviceGetFanSpeed(Device Device) (uint32, Return) { - var Speed uint32 - ret := nvmlDeviceGetFanSpeed(Device, &Speed) - return Speed, ret -} - -func (Device Device) GetFanSpeed() (uint32, Return) { - return DeviceGetFanSpeed(Device) -} - -// nvml.DeviceGetFanSpeed_v2() -func DeviceGetFanSpeed_v2(Device Device, Fan int) (uint32, Return) { - var Speed uint32 - ret := nvmlDeviceGetFanSpeed_v2(Device, uint32(Fan), &Speed) - return Speed, ret -} - -func (Device Device) GetFanSpeed_v2(Fan int) (uint32, Return) { - return DeviceGetFanSpeed_v2(Device, Fan) -} - -// nvml.DeviceGetNumFans() -func DeviceGetNumFans(Device Device) (int, Return) { - var NumFans uint32 - ret := nvmlDeviceGetNumFans(Device, &NumFans) - return int(NumFans), ret -} - -func (Device Device) GetNumFans() (int, Return) { - return DeviceGetNumFans(Device) -} - -// nvml.DeviceGetTemperature() -func DeviceGetTemperature(Device Device, SensorType TemperatureSensors) (uint32, Return) { - var Temp uint32 - ret := nvmlDeviceGetTemperature(Device, SensorType, &Temp) - return Temp, ret -} - -func (Device Device) GetTemperature(SensorType TemperatureSensors) (uint32, Return) { - return DeviceGetTemperature(Device, SensorType) -} - -// nvml.DeviceGetTemperatureThreshold() -func DeviceGetTemperatureThreshold(Device Device, ThresholdType TemperatureThresholds) (uint32, Return) { - var Temp uint32 - ret := nvmlDeviceGetTemperatureThreshold(Device, ThresholdType, &Temp) - return Temp, ret -} - -func (Device Device) GetTemperatureThreshold(ThresholdType TemperatureThresholds) (uint32, Return) { - return DeviceGetTemperatureThreshold(Device, ThresholdType) -} - -// nvml.DeviceSetTemperatureThreshold() -func DeviceSetTemperatureThreshold(Device Device, ThresholdType TemperatureThresholds, Temp int) Return { - t := int32(Temp) - ret := nvmlDeviceSetTemperatureThreshold(Device, ThresholdType, &t) - return ret -} - -func (Device Device) SetTemperatureThreshold(ThresholdType TemperatureThresholds, Temp int) Return { - return DeviceSetTemperatureThreshold(Device, ThresholdType, Temp) -} - -// nvml.DeviceGetPerformanceState() -func DeviceGetPerformanceState(Device Device) (Pstates, Return) { - var PState Pstates - ret := nvmlDeviceGetPerformanceState(Device, &PState) - return PState, ret -} - -func (Device Device) GetPerformanceState() (Pstates, Return) { - return DeviceGetPerformanceState(Device) -} - -// nvml.DeviceGetCurrentClocksThrottleReasons() -func DeviceGetCurrentClocksThrottleReasons(Device Device) (uint64, Return) { - var ClocksThrottleReasons uint64 - ret := nvmlDeviceGetCurrentClocksThrottleReasons(Device, &ClocksThrottleReasons) - return ClocksThrottleReasons, ret -} - -func (Device Device) GetCurrentClocksThrottleReasons() (uint64, Return) { - return DeviceGetCurrentClocksThrottleReasons(Device) -} - -// nvml.DeviceGetSupportedClocksThrottleReasons() -func DeviceGetSupportedClocksThrottleReasons(Device Device) (uint64, Return) { - var SupportedClocksThrottleReasons uint64 - ret := nvmlDeviceGetSupportedClocksThrottleReasons(Device, &SupportedClocksThrottleReasons) - return SupportedClocksThrottleReasons, ret -} - -func (Device Device) GetSupportedClocksThrottleReasons() (uint64, Return) { - return DeviceGetSupportedClocksThrottleReasons(Device) -} - -// nvml.DeviceGetPowerState() -func DeviceGetPowerState(Device Device) (Pstates, Return) { - var PState Pstates - ret := nvmlDeviceGetPowerState(Device, &PState) - return PState, ret -} - -func (Device Device) GetPowerState() (Pstates, Return) { - return DeviceGetPowerState(Device) -} - -// nvml.DeviceGetPowerManagementMode() -func DeviceGetPowerManagementMode(Device Device) (EnableState, Return) { - var Mode EnableState - ret := nvmlDeviceGetPowerManagementMode(Device, &Mode) - return Mode, ret -} - -func (Device Device) GetPowerManagementMode() (EnableState, Return) { - return DeviceGetPowerManagementMode(Device) -} - -// nvml.DeviceGetPowerManagementLimit() -func DeviceGetPowerManagementLimit(Device Device) (uint32, Return) { - var Limit uint32 - ret := nvmlDeviceGetPowerManagementLimit(Device, &Limit) - return Limit, ret -} - -func (Device Device) GetPowerManagementLimit() (uint32, Return) { - return DeviceGetPowerManagementLimit(Device) -} - -// nvml.DeviceGetPowerManagementLimitConstraints() -func DeviceGetPowerManagementLimitConstraints(Device Device) (uint32, uint32, Return) { - var MinLimit, MaxLimit uint32 - ret := nvmlDeviceGetPowerManagementLimitConstraints(Device, &MinLimit, &MaxLimit) - return MinLimit, MaxLimit, ret -} - -func (Device Device) GetPowerManagementLimitConstraints() (uint32, uint32, Return) { - return DeviceGetPowerManagementLimitConstraints(Device) -} - -// nvml.DeviceGetPowerManagementDefaultLimit() -func DeviceGetPowerManagementDefaultLimit(Device Device) (uint32, Return) { - var DefaultLimit uint32 - ret := nvmlDeviceGetPowerManagementDefaultLimit(Device, &DefaultLimit) - return DefaultLimit, ret -} - -func (Device Device) GetPowerManagementDefaultLimit() (uint32, Return) { - return DeviceGetPowerManagementDefaultLimit(Device) -} - -// nvml.DeviceGetPowerUsage() -func DeviceGetPowerUsage(Device Device) (uint32, Return) { - var Power uint32 - ret := nvmlDeviceGetPowerUsage(Device, &Power) - return Power, ret -} - -func (Device Device) GetPowerUsage() (uint32, Return) { - return DeviceGetPowerUsage(Device) -} - -// nvml.DeviceGetTotalEnergyConsumption() -func DeviceGetTotalEnergyConsumption(Device Device) (uint64, Return) { - var Energy uint64 - ret := nvmlDeviceGetTotalEnergyConsumption(Device, &Energy) - return Energy, ret -} - -func (Device Device) GetTotalEnergyConsumption() (uint64, Return) { - return DeviceGetTotalEnergyConsumption(Device) -} - -// nvml.DeviceGetEnforcedPowerLimit() -func DeviceGetEnforcedPowerLimit(Device Device) (uint32, Return) { - var Limit uint32 - ret := nvmlDeviceGetEnforcedPowerLimit(Device, &Limit) - return Limit, ret -} - -func (Device Device) GetEnforcedPowerLimit() (uint32, Return) { - return DeviceGetEnforcedPowerLimit(Device) -} - -// nvml.DeviceGetGpuOperationMode() -func DeviceGetGpuOperationMode(Device Device) (GpuOperationMode, GpuOperationMode, Return) { - var Current, Pending GpuOperationMode - ret := nvmlDeviceGetGpuOperationMode(Device, &Current, &Pending) - return Current, Pending, ret -} - -func (Device Device) GetGpuOperationMode() (GpuOperationMode, GpuOperationMode, Return) { - return DeviceGetGpuOperationMode(Device) -} - -// nvml.DeviceGetMemoryInfo() -func DeviceGetMemoryInfo(Device Device) (Memory, Return) { - var Memory Memory - ret := nvmlDeviceGetMemoryInfo(Device, &Memory) - return Memory, ret -} - -func (Device Device) GetMemoryInfo() (Memory, Return) { - return DeviceGetMemoryInfo(Device) -} - -// nvml.DeviceGetMemoryInfo_v2() -func DeviceGetMemoryInfo_v2(Device Device) (Memory_v2, Return) { - var Memory Memory_v2 - Memory.Version = STRUCT_VERSION(Memory, 2) - ret := nvmlDeviceGetMemoryInfo_v2(Device, &Memory) - return Memory, ret -} - -func (Device Device) GetMemoryInfo_v2() (Memory_v2, Return) { - return DeviceGetMemoryInfo_v2(Device) -} - -// nvml.DeviceGetComputeMode() -func DeviceGetComputeMode(Device Device) (ComputeMode, Return) { - var Mode ComputeMode - ret := nvmlDeviceGetComputeMode(Device, &Mode) - return Mode, ret -} - -func (Device Device) GetComputeMode() (ComputeMode, Return) { - return DeviceGetComputeMode(Device) -} - -// nvml.DeviceGetCudaComputeCapability() -func DeviceGetCudaComputeCapability(Device Device) (int, int, Return) { - var Major, Minor int32 - ret := nvmlDeviceGetCudaComputeCapability(Device, &Major, &Minor) - return int(Major), int(Minor), ret -} - -func (Device Device) GetCudaComputeCapability() (int, int, Return) { - return DeviceGetCudaComputeCapability(Device) -} - -// nvml.DeviceGetEccMode() -func DeviceGetEccMode(Device Device) (EnableState, EnableState, Return) { - var Current, Pending EnableState - ret := nvmlDeviceGetEccMode(Device, &Current, &Pending) - return Current, Pending, ret -} - -func (Device Device) GetEccMode() (EnableState, EnableState, Return) { - return DeviceGetEccMode(Device) -} - -// nvml.DeviceGetBoardId() -func DeviceGetBoardId(Device Device) (uint32, Return) { - var BoardId uint32 - ret := nvmlDeviceGetBoardId(Device, &BoardId) - return BoardId, ret -} - -func (Device Device) GetBoardId() (uint32, Return) { - return DeviceGetBoardId(Device) -} - -// nvml.DeviceGetMultiGpuBoard() -func DeviceGetMultiGpuBoard(Device Device) (int, Return) { - var MultiGpuBool uint32 - ret := nvmlDeviceGetMultiGpuBoard(Device, &MultiGpuBool) - return int(MultiGpuBool), ret -} - -func (Device Device) GetMultiGpuBoard() (int, Return) { - return DeviceGetMultiGpuBoard(Device) -} - -// nvml.DeviceGetTotalEccErrors() -func DeviceGetTotalEccErrors(Device Device, ErrorType MemoryErrorType, CounterType EccCounterType) (uint64, Return) { - var EccCounts uint64 - ret := nvmlDeviceGetTotalEccErrors(Device, ErrorType, CounterType, &EccCounts) - return EccCounts, ret -} - -func (Device Device) GetTotalEccErrors(ErrorType MemoryErrorType, CounterType EccCounterType) (uint64, Return) { - return DeviceGetTotalEccErrors(Device, ErrorType, CounterType) -} - -// nvml.DeviceGetDetailedEccErrors() -func DeviceGetDetailedEccErrors(Device Device, ErrorType MemoryErrorType, CounterType EccCounterType) (EccErrorCounts, Return) { - var EccCounts EccErrorCounts - ret := nvmlDeviceGetDetailedEccErrors(Device, ErrorType, CounterType, &EccCounts) - return EccCounts, ret -} - -func (Device Device) GetDetailedEccErrors(ErrorType MemoryErrorType, CounterType EccCounterType) (EccErrorCounts, Return) { - return DeviceGetDetailedEccErrors(Device, ErrorType, CounterType) -} - -// nvml.DeviceGetMemoryErrorCounter() -func DeviceGetMemoryErrorCounter(Device Device, ErrorType MemoryErrorType, CounterType EccCounterType, LocationType MemoryLocation) (uint64, Return) { - var Count uint64 - ret := nvmlDeviceGetMemoryErrorCounter(Device, ErrorType, CounterType, LocationType, &Count) - return Count, ret -} - -func (Device Device) GetMemoryErrorCounter(ErrorType MemoryErrorType, CounterType EccCounterType, LocationType MemoryLocation) (uint64, Return) { - return DeviceGetMemoryErrorCounter(Device, ErrorType, CounterType, LocationType) -} - -// nvml.DeviceGetUtilizationRates() -func DeviceGetUtilizationRates(Device Device) (Utilization, Return) { - var Utilization Utilization - ret := nvmlDeviceGetUtilizationRates(Device, &Utilization) - return Utilization, ret -} - -func (Device Device) GetUtilizationRates() (Utilization, Return) { - return DeviceGetUtilizationRates(Device) -} - -// nvml.DeviceGetEncoderUtilization() -func DeviceGetEncoderUtilization(Device Device) (uint32, uint32, Return) { - var Utilization, SamplingPeriodUs uint32 - ret := nvmlDeviceGetEncoderUtilization(Device, &Utilization, &SamplingPeriodUs) - return Utilization, SamplingPeriodUs, ret -} - -func (Device Device) GetEncoderUtilization() (uint32, uint32, Return) { - return DeviceGetEncoderUtilization(Device) -} - -// nvml.DeviceGetEncoderCapacity() -func DeviceGetEncoderCapacity(Device Device, EncoderQueryType EncoderType) (int, Return) { - var EncoderCapacity uint32 - ret := nvmlDeviceGetEncoderCapacity(Device, EncoderQueryType, &EncoderCapacity) - return int(EncoderCapacity), ret -} - -func (Device Device) GetEncoderCapacity(EncoderQueryType EncoderType) (int, Return) { - return DeviceGetEncoderCapacity(Device, EncoderQueryType) -} - -// nvml.DeviceGetEncoderStats() -func DeviceGetEncoderStats(Device Device) (int, uint32, uint32, Return) { - var SessionCount, AverageFps, AverageLatency uint32 - ret := nvmlDeviceGetEncoderStats(Device, &SessionCount, &AverageFps, &AverageLatency) - return int(SessionCount), AverageFps, AverageLatency, ret -} - -func (Device Device) GetEncoderStats() (int, uint32, uint32, Return) { - return DeviceGetEncoderStats(Device) -} - -// nvml.DeviceGetEncoderSessions() -func DeviceGetEncoderSessions(Device Device) ([]EncoderSessionInfo, Return) { - var SessionCount uint32 = 1 // Will be reduced upon returning - for { - SessionInfos := make([]EncoderSessionInfo, SessionCount) - ret := nvmlDeviceGetEncoderSessions(Device, &SessionCount, &SessionInfos[0]) - if ret == SUCCESS { - return SessionInfos[:SessionCount], ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - SessionCount *= 2 - } -} - -func (Device Device) GetEncoderSessions() ([]EncoderSessionInfo, Return) { - return DeviceGetEncoderSessions(Device) -} - -// nvml.DeviceGetDecoderUtilization() -func DeviceGetDecoderUtilization(Device Device) (uint32, uint32, Return) { - var Utilization, SamplingPeriodUs uint32 - ret := nvmlDeviceGetDecoderUtilization(Device, &Utilization, &SamplingPeriodUs) - return Utilization, SamplingPeriodUs, ret -} - -func (Device Device) GetDecoderUtilization() (uint32, uint32, Return) { - return DeviceGetDecoderUtilization(Device) -} - -// nvml.DeviceGetFBCStats() -func DeviceGetFBCStats(Device Device) (FBCStats, Return) { - var FbcStats FBCStats - ret := nvmlDeviceGetFBCStats(Device, &FbcStats) - return FbcStats, ret -} - -func (Device Device) GetFBCStats() (FBCStats, Return) { - return DeviceGetFBCStats(Device) -} - -// nvml.DeviceGetFBCSessions() -func DeviceGetFBCSessions(Device Device) ([]FBCSessionInfo, Return) { - var SessionCount uint32 = 1 // Will be reduced upon returning - for { - SessionInfo := make([]FBCSessionInfo, SessionCount) - ret := nvmlDeviceGetFBCSessions(Device, &SessionCount, &SessionInfo[0]) - if ret == SUCCESS { - return SessionInfo[:SessionCount], ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - SessionCount *= 2 - } -} - -func (Device Device) GetFBCSessions() ([]FBCSessionInfo, Return) { - return DeviceGetFBCSessions(Device) -} - -// nvml.DeviceGetDriverModel() -func DeviceGetDriverModel(Device Device) (DriverModel, DriverModel, Return) { - var Current, Pending DriverModel - ret := nvmlDeviceGetDriverModel(Device, &Current, &Pending) - return Current, Pending, ret -} - -func (Device Device) GetDriverModel() (DriverModel, DriverModel, Return) { - return DeviceGetDriverModel(Device) -} - -// nvml.DeviceGetVbiosVersion() -func DeviceGetVbiosVersion(Device Device) (string, Return) { - Version := make([]byte, DEVICE_VBIOS_VERSION_BUFFER_SIZE) - ret := nvmlDeviceGetVbiosVersion(Device, &Version[0], DEVICE_VBIOS_VERSION_BUFFER_SIZE) - return string(Version[:clen(Version)]), ret -} - -func (Device Device) GetVbiosVersion() (string, Return) { - return DeviceGetVbiosVersion(Device) -} - -// nvml.DeviceGetBridgeChipInfo() -func DeviceGetBridgeChipInfo(Device Device) (BridgeChipHierarchy, Return) { - var BridgeHierarchy BridgeChipHierarchy - ret := nvmlDeviceGetBridgeChipInfo(Device, &BridgeHierarchy) - return BridgeHierarchy, ret -} - -func (Device Device) GetBridgeChipInfo() (BridgeChipHierarchy, Return) { - return DeviceGetBridgeChipInfo(Device) -} - -// nvml.DeviceGetComputeRunningProcesses() -func deviceGetComputeRunningProcesses_v1(Device Device) ([]ProcessInfo, Return) { - var InfoCount uint32 = 1 // Will be reduced upon returning - for { - Infos := make([]ProcessInfo_v1, InfoCount) - ret := nvmlDeviceGetComputeRunningProcesses_v1(Device, &InfoCount, &Infos[0]) - if ret == SUCCESS { - return ProcessInfo_v1Slice(Infos[:InfoCount]).ToProcessInfoSlice(), ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - InfoCount *= 2 - } -} - -func deviceGetComputeRunningProcesses_v2(Device Device) ([]ProcessInfo, Return) { - var InfoCount uint32 = 1 // Will be reduced upon returning - for { - Infos := make([]ProcessInfo_v2, InfoCount) - ret := nvmlDeviceGetComputeRunningProcesses_v2(Device, &InfoCount, &Infos[0]) - if ret == SUCCESS { - return ProcessInfo_v2Slice(Infos[:InfoCount]).ToProcessInfoSlice(), ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - InfoCount *= 2 - } -} - -func deviceGetComputeRunningProcesses_v3(Device Device) ([]ProcessInfo, Return) { - var InfoCount uint32 = 1 // Will be reduced upon returning - for { - Infos := make([]ProcessInfo, InfoCount) - ret := nvmlDeviceGetComputeRunningProcesses_v3(Device, &InfoCount, &Infos[0]) - if ret == SUCCESS { - return Infos[:InfoCount], ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - InfoCount *= 2 - } -} - -func (Device Device) GetComputeRunningProcesses() ([]ProcessInfo, Return) { - return DeviceGetComputeRunningProcesses(Device) -} - -// nvml.DeviceGetGraphicsRunningProcesses() -func deviceGetGraphicsRunningProcesses_v1(Device Device) ([]ProcessInfo, Return) { - var InfoCount uint32 = 1 // Will be reduced upon returning - for { - Infos := make([]ProcessInfo_v1, InfoCount) - ret := nvmlDeviceGetGraphicsRunningProcesses_v1(Device, &InfoCount, &Infos[0]) - if ret == SUCCESS { - return ProcessInfo_v1Slice(Infos[:InfoCount]).ToProcessInfoSlice(), ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - InfoCount *= 2 - } -} - -func deviceGetGraphicsRunningProcesses_v2(Device Device) ([]ProcessInfo, Return) { - var InfoCount uint32 = 1 // Will be reduced upon returning - for { - Infos := make([]ProcessInfo_v2, InfoCount) - ret := nvmlDeviceGetGraphicsRunningProcesses_v2(Device, &InfoCount, &Infos[0]) - if ret == SUCCESS { - return ProcessInfo_v2Slice(Infos[:InfoCount]).ToProcessInfoSlice(), ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - InfoCount *= 2 - } -} - -func deviceGetGraphicsRunningProcesses_v3(Device Device) ([]ProcessInfo, Return) { - var InfoCount uint32 = 1 // Will be reduced upon returning - for { - Infos := make([]ProcessInfo, InfoCount) - ret := nvmlDeviceGetGraphicsRunningProcesses_v3(Device, &InfoCount, &Infos[0]) - if ret == SUCCESS { - return Infos[:InfoCount], ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - InfoCount *= 2 - } -} - -func (Device Device) GetGraphicsRunningProcesses() ([]ProcessInfo, Return) { - return DeviceGetGraphicsRunningProcesses(Device) -} - -// nvml.DeviceGetMPSComputeRunningProcesses() -func deviceGetMPSComputeRunningProcesses_v1(Device Device) ([]ProcessInfo, Return) { - var InfoCount uint32 = 1 // Will be reduced upon returning - for { - Infos := make([]ProcessInfo_v1, InfoCount) - ret := nvmlDeviceGetMPSComputeRunningProcesses_v1(Device, &InfoCount, &Infos[0]) - if ret == SUCCESS { - return ProcessInfo_v1Slice(Infos[:InfoCount]).ToProcessInfoSlice(), ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - InfoCount *= 2 - } -} - -func deviceGetMPSComputeRunningProcesses_v2(Device Device) ([]ProcessInfo, Return) { - var InfoCount uint32 = 1 // Will be reduced upon returning - for { - Infos := make([]ProcessInfo_v2, InfoCount) - ret := nvmlDeviceGetMPSComputeRunningProcesses_v2(Device, &InfoCount, &Infos[0]) - if ret == SUCCESS { - return ProcessInfo_v2Slice(Infos[:InfoCount]).ToProcessInfoSlice(), ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - InfoCount *= 2 - } -} - -func deviceGetMPSComputeRunningProcesses_v3(Device Device) ([]ProcessInfo, Return) { - var InfoCount uint32 = 1 // Will be reduced upon returning - for { - Infos := make([]ProcessInfo, InfoCount) - ret := nvmlDeviceGetMPSComputeRunningProcesses_v3(Device, &InfoCount, &Infos[0]) - if ret == SUCCESS { - return Infos[:InfoCount], ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - InfoCount *= 2 - } -} - -func (Device Device) GetMPSComputeRunningProcesses() ([]ProcessInfo, Return) { - return DeviceGetMPSComputeRunningProcesses(Device) -} - -// nvml.DeviceOnSameBoard() -func DeviceOnSameBoard(Device1 Device, Device2 Device) (int, Return) { - var OnSameBoard int32 - ret := nvmlDeviceOnSameBoard(Device1, Device2, &OnSameBoard) - return int(OnSameBoard), ret -} - -func (Device1 Device) OnSameBoard(Device2 Device) (int, Return) { - return DeviceOnSameBoard(Device1, Device2) -} - -// nvml.DeviceGetAPIRestriction() -func DeviceGetAPIRestriction(Device Device, ApiType RestrictedAPI) (EnableState, Return) { - var IsRestricted EnableState - ret := nvmlDeviceGetAPIRestriction(Device, ApiType, &IsRestricted) - return IsRestricted, ret -} - -func (Device Device) GetAPIRestriction(ApiType RestrictedAPI) (EnableState, Return) { - return DeviceGetAPIRestriction(Device, ApiType) -} - -// nvml.DeviceGetSamples() -func DeviceGetSamples(Device Device, _type SamplingType, LastSeenTimeStamp uint64) (ValueType, []Sample, Return) { - var SampleValType ValueType - var SampleCount uint32 - ret := nvmlDeviceGetSamples(Device, _type, LastSeenTimeStamp, &SampleValType, &SampleCount, nil) - if ret != SUCCESS { - return SampleValType, nil, ret - } - if SampleCount == 0 { - return SampleValType, []Sample{}, ret - } - Samples := make([]Sample, SampleCount) - ret = nvmlDeviceGetSamples(Device, _type, LastSeenTimeStamp, &SampleValType, &SampleCount, &Samples[0]) - return SampleValType, Samples, ret -} - -func (Device Device) GetSamples(_type SamplingType, LastSeenTimeStamp uint64) (ValueType, []Sample, Return) { - return DeviceGetSamples(Device, _type, LastSeenTimeStamp) -} - -// nvml.DeviceGetBAR1MemoryInfo() -func DeviceGetBAR1MemoryInfo(Device Device) (BAR1Memory, Return) { - var Bar1Memory BAR1Memory - ret := nvmlDeviceGetBAR1MemoryInfo(Device, &Bar1Memory) - return Bar1Memory, ret -} - -func (Device Device) GetBAR1MemoryInfo() (BAR1Memory, Return) { - return DeviceGetBAR1MemoryInfo(Device) -} - -// nvml.DeviceGetViolationStatus() -func DeviceGetViolationStatus(Device Device, PerfPolicyType PerfPolicyType) (ViolationTime, Return) { - var ViolTime ViolationTime - ret := nvmlDeviceGetViolationStatus(Device, PerfPolicyType, &ViolTime) - return ViolTime, ret -} - -func (Device Device) GetViolationStatus(PerfPolicyType PerfPolicyType) (ViolationTime, Return) { - return DeviceGetViolationStatus(Device, PerfPolicyType) -} - -// nvml.DeviceGetIrqNum() -func DeviceGetIrqNum(Device Device) (int, Return) { - var IrqNum uint32 - ret := nvmlDeviceGetIrqNum(Device, &IrqNum) - return int(IrqNum), ret -} - -func (Device Device) GetIrqNum() (int, Return) { - return DeviceGetIrqNum(Device) -} - -// nvml.DeviceGetNumGpuCores() -func DeviceGetNumGpuCores(Device Device) (int, Return) { - var NumCores uint32 - ret := nvmlDeviceGetNumGpuCores(Device, &NumCores) - return int(NumCores), ret -} - -func (Device Device) GetNumGpuCores() (int, Return) { - return DeviceGetNumGpuCores(Device) -} - -// nvml.DeviceGetPowerSource() -func DeviceGetPowerSource(Device Device) (PowerSource, Return) { - var PowerSource PowerSource - ret := nvmlDeviceGetPowerSource(Device, &PowerSource) - return PowerSource, ret -} - -func (Device Device) GetPowerSource() (PowerSource, Return) { - return DeviceGetPowerSource(Device) -} - -// nvml.DeviceGetMemoryBusWidth() -func DeviceGetMemoryBusWidth(Device Device) (uint32, Return) { - var BusWidth uint32 - ret := nvmlDeviceGetMemoryBusWidth(Device, &BusWidth) - return BusWidth, ret -} - -func (Device Device) GetMemoryBusWidth() (uint32, Return) { - return DeviceGetMemoryBusWidth(Device) -} - -// nvml.DeviceGetPcieLinkMaxSpeed() -func DeviceGetPcieLinkMaxSpeed(Device Device) (uint32, Return) { - var MaxSpeed uint32 - ret := nvmlDeviceGetPcieLinkMaxSpeed(Device, &MaxSpeed) - return MaxSpeed, ret -} - -func (Device Device) GetPcieLinkMaxSpeed() (uint32, Return) { - return DeviceGetPcieLinkMaxSpeed(Device) -} - -// nvml.DeviceGetAdaptiveClockInfoStatus() -func DeviceGetAdaptiveClockInfoStatus(Device Device) (uint32, Return) { - var AdaptiveClockStatus uint32 - ret := nvmlDeviceGetAdaptiveClockInfoStatus(Device, &AdaptiveClockStatus) - return AdaptiveClockStatus, ret -} - -func (Device Device) GetAdaptiveClockInfoStatus() (uint32, Return) { - return DeviceGetAdaptiveClockInfoStatus(Device) -} - -// nvml.DeviceGetAccountingMode() -func DeviceGetAccountingMode(Device Device) (EnableState, Return) { - var Mode EnableState - ret := nvmlDeviceGetAccountingMode(Device, &Mode) - return Mode, ret -} - -func (Device Device) GetAccountingMode() (EnableState, Return) { - return DeviceGetAccountingMode(Device) -} - -// nvml.DeviceGetAccountingStats() -func DeviceGetAccountingStats(Device Device, Pid uint32) (AccountingStats, Return) { - var Stats AccountingStats - ret := nvmlDeviceGetAccountingStats(Device, Pid, &Stats) - return Stats, ret -} - -func (Device Device) GetAccountingStats(Pid uint32) (AccountingStats, Return) { - return DeviceGetAccountingStats(Device, Pid) -} - -// nvml.DeviceGetAccountingPids() -func DeviceGetAccountingPids(Device Device) ([]int, Return) { - var Count uint32 = 1 // Will be reduced upon returning - for { - Pids := make([]uint32, Count) - ret := nvmlDeviceGetAccountingPids(Device, &Count, &Pids[0]) - if ret == SUCCESS { - return uint32SliceToIntSlice(Pids[:Count]), ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - Count *= 2 - } -} - -func (Device Device) GetAccountingPids() ([]int, Return) { - return DeviceGetAccountingPids(Device) -} - -// nvml.DeviceGetAccountingBufferSize() -func DeviceGetAccountingBufferSize(Device Device) (int, Return) { - var BufferSize uint32 - ret := nvmlDeviceGetAccountingBufferSize(Device, &BufferSize) - return int(BufferSize), ret -} - -func (Device Device) GetAccountingBufferSize() (int, Return) { - return DeviceGetAccountingBufferSize(Device) -} - -// nvml.DeviceGetRetiredPages() -func DeviceGetRetiredPages(Device Device, Cause PageRetirementCause) ([]uint64, Return) { - var PageCount uint32 = 1 // Will be reduced upon returning - for { - Addresses := make([]uint64, PageCount) - ret := nvmlDeviceGetRetiredPages(Device, Cause, &PageCount, &Addresses[0]) - if ret == SUCCESS { - return Addresses[:PageCount], ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - PageCount *= 2 - } -} - -func (Device Device) GetRetiredPages(Cause PageRetirementCause) ([]uint64, Return) { - return DeviceGetRetiredPages(Device, Cause) -} - -// nvml.DeviceGetRetiredPages_v2() -func DeviceGetRetiredPages_v2(Device Device, Cause PageRetirementCause) ([]uint64, []uint64, Return) { - var PageCount uint32 = 1 // Will be reduced upon returning - for { - Addresses := make([]uint64, PageCount) - Timestamps := make([]uint64, PageCount) - ret := nvmlDeviceGetRetiredPages_v2(Device, Cause, &PageCount, &Addresses[0], &Timestamps[0]) - if ret == SUCCESS { - return Addresses[:PageCount], Timestamps[:PageCount], ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, nil, ret - } - PageCount *= 2 - } -} - -func (Device Device) GetRetiredPages_v2(Cause PageRetirementCause) ([]uint64, []uint64, Return) { - return DeviceGetRetiredPages_v2(Device, Cause) -} - -// nvml.DeviceGetRetiredPagesPendingStatus() -func DeviceGetRetiredPagesPendingStatus(Device Device) (EnableState, Return) { - var IsPending EnableState - ret := nvmlDeviceGetRetiredPagesPendingStatus(Device, &IsPending) - return IsPending, ret -} - -func (Device Device) GetRetiredPagesPendingStatus() (EnableState, Return) { - return DeviceGetRetiredPagesPendingStatus(Device) -} - -// nvml.DeviceSetPersistenceMode() -func DeviceSetPersistenceMode(Device Device, Mode EnableState) Return { - return nvmlDeviceSetPersistenceMode(Device, Mode) -} - -func (Device Device) SetPersistenceMode(Mode EnableState) Return { - return DeviceSetPersistenceMode(Device, Mode) -} - -// nvml.DeviceSetComputeMode() -func DeviceSetComputeMode(Device Device, Mode ComputeMode) Return { - return nvmlDeviceSetComputeMode(Device, Mode) -} - -func (Device Device) SetComputeMode(Mode ComputeMode) Return { - return DeviceSetComputeMode(Device, Mode) -} - -// nvml.DeviceSetEccMode() -func DeviceSetEccMode(Device Device, Ecc EnableState) Return { - return nvmlDeviceSetEccMode(Device, Ecc) -} - -func (Device Device) SetEccMode(Ecc EnableState) Return { - return DeviceSetEccMode(Device, Ecc) -} - -// nvml.DeviceClearEccErrorCounts() -func DeviceClearEccErrorCounts(Device Device, CounterType EccCounterType) Return { - return nvmlDeviceClearEccErrorCounts(Device, CounterType) -} - -func (Device Device) ClearEccErrorCounts(CounterType EccCounterType) Return { - return DeviceClearEccErrorCounts(Device, CounterType) -} - -// nvml.DeviceSetDriverModel() -func DeviceSetDriverModel(Device Device, DriverModel DriverModel, Flags uint32) Return { - return nvmlDeviceSetDriverModel(Device, DriverModel, Flags) -} - -func (Device Device) SetDriverModel(DriverModel DriverModel, Flags uint32) Return { - return DeviceSetDriverModel(Device, DriverModel, Flags) -} - -// nvml.DeviceSetGpuLockedClocks() -func DeviceSetGpuLockedClocks(Device Device, MinGpuClockMHz uint32, MaxGpuClockMHz uint32) Return { - return nvmlDeviceSetGpuLockedClocks(Device, MinGpuClockMHz, MaxGpuClockMHz) -} - -func (Device Device) SetGpuLockedClocks(MinGpuClockMHz uint32, MaxGpuClockMHz uint32) Return { - return DeviceSetGpuLockedClocks(Device, MinGpuClockMHz, MaxGpuClockMHz) -} - -// nvml.DeviceResetGpuLockedClocks() -func DeviceResetGpuLockedClocks(Device Device) Return { - return nvmlDeviceResetGpuLockedClocks(Device) -} - -func (Device Device) ResetGpuLockedClocks() Return { - return DeviceResetGpuLockedClocks(Device) -} - -// nvmlDeviceSetMemoryLockedClocks() -func DeviceSetMemoryLockedClocks(Device Device, MinMemClockMHz uint32, MaxMemClockMHz uint32) Return { - return nvmlDeviceSetMemoryLockedClocks(Device, MinMemClockMHz, MaxMemClockMHz) -} - -func (Device Device) SetMemoryLockedClocks(NinMemClockMHz uint32, MaxMemClockMHz uint32) Return { - return DeviceSetMemoryLockedClocks(Device, NinMemClockMHz, MaxMemClockMHz) -} - -// nvmlDeviceResetMemoryLockedClocks() -func DeviceResetMemoryLockedClocks(Device Device) Return { - return nvmlDeviceResetMemoryLockedClocks(Device) -} - -func (Device Device) ResetMemoryLockedClocks() Return { - return DeviceResetMemoryLockedClocks(Device) -} - -// nvml.DeviceGetClkMonStatus() -func DeviceGetClkMonStatus(Device Device) (ClkMonStatus, Return) { - var Status ClkMonStatus - ret := nvmlDeviceGetClkMonStatus(Device, &Status) - return Status, ret -} - -func (Device Device) GetClkMonStatus() (ClkMonStatus, Return) { - return DeviceGetClkMonStatus(Device) -} - -// nvml.DeviceSetApplicationsClocks() -func DeviceSetApplicationsClocks(Device Device, MemClockMHz uint32, GraphicsClockMHz uint32) Return { - return nvmlDeviceSetApplicationsClocks(Device, MemClockMHz, GraphicsClockMHz) -} - -func (Device Device) SetApplicationsClocks(MemClockMHz uint32, GraphicsClockMHz uint32) Return { - return DeviceSetApplicationsClocks(Device, MemClockMHz, GraphicsClockMHz) -} - -// nvml.DeviceSetPowerManagementLimit() -func DeviceSetPowerManagementLimit(Device Device, Limit uint32) Return { - return nvmlDeviceSetPowerManagementLimit(Device, Limit) -} - -func (Device Device) SetPowerManagementLimit(Limit uint32) Return { - return DeviceSetPowerManagementLimit(Device, Limit) -} - -// nvml.DeviceSetGpuOperationMode() -func DeviceSetGpuOperationMode(Device Device, Mode GpuOperationMode) Return { - return nvmlDeviceSetGpuOperationMode(Device, Mode) -} - -func (Device Device) SetGpuOperationMode(Mode GpuOperationMode) Return { - return DeviceSetGpuOperationMode(Device, Mode) -} - -// nvml.DeviceSetAPIRestriction() -func DeviceSetAPIRestriction(Device Device, ApiType RestrictedAPI, IsRestricted EnableState) Return { - return nvmlDeviceSetAPIRestriction(Device, ApiType, IsRestricted) -} - -func (Device Device) SetAPIRestriction(ApiType RestrictedAPI, IsRestricted EnableState) Return { - return DeviceSetAPIRestriction(Device, ApiType, IsRestricted) -} - -// nvml.DeviceSetAccountingMode() -func DeviceSetAccountingMode(Device Device, Mode EnableState) Return { - return nvmlDeviceSetAccountingMode(Device, Mode) -} - -func (Device Device) SetAccountingMode(Mode EnableState) Return { - return DeviceSetAccountingMode(Device, Mode) -} - -// nvml.DeviceClearAccountingPids() -func DeviceClearAccountingPids(Device Device) Return { - return nvmlDeviceClearAccountingPids(Device) -} - -func (Device Device) ClearAccountingPids() Return { - return DeviceClearAccountingPids(Device) -} - -// nvml.DeviceGetNvLinkState() -func DeviceGetNvLinkState(Device Device, Link int) (EnableState, Return) { - var IsActive EnableState - ret := nvmlDeviceGetNvLinkState(Device, uint32(Link), &IsActive) - return IsActive, ret -} - -func (Device Device) GetNvLinkState(Link int) (EnableState, Return) { - return DeviceGetNvLinkState(Device, Link) -} - -// nvml.DeviceGetNvLinkVersion() -func DeviceGetNvLinkVersion(Device Device, Link int) (uint32, Return) { - var Version uint32 - ret := nvmlDeviceGetNvLinkVersion(Device, uint32(Link), &Version) - return Version, ret -} - -func (Device Device) GetNvLinkVersion(Link int) (uint32, Return) { - return DeviceGetNvLinkVersion(Device, Link) -} - -// nvml.DeviceGetNvLinkCapability() -func DeviceGetNvLinkCapability(Device Device, Link int, Capability NvLinkCapability) (uint32, Return) { - var CapResult uint32 - ret := nvmlDeviceGetNvLinkCapability(Device, uint32(Link), Capability, &CapResult) - return CapResult, ret -} - -func (Device Device) GetNvLinkCapability(Link int, Capability NvLinkCapability) (uint32, Return) { - return DeviceGetNvLinkCapability(Device, Link, Capability) -} - -// nvml.DeviceGetNvLinkRemotePciInfo() -func DeviceGetNvLinkRemotePciInfo(Device Device, Link int) (PciInfo, Return) { - var Pci PciInfo - ret := nvmlDeviceGetNvLinkRemotePciInfo(Device, uint32(Link), &Pci) - return Pci, ret -} - -func (Device Device) GetNvLinkRemotePciInfo(Link int) (PciInfo, Return) { - return DeviceGetNvLinkRemotePciInfo(Device, Link) -} - -// nvml.DeviceGetNvLinkErrorCounter() -func DeviceGetNvLinkErrorCounter(Device Device, Link int, Counter NvLinkErrorCounter) (uint64, Return) { - var CounterValue uint64 - ret := nvmlDeviceGetNvLinkErrorCounter(Device, uint32(Link), Counter, &CounterValue) - return CounterValue, ret -} - -func (Device Device) GetNvLinkErrorCounter(Link int, Counter NvLinkErrorCounter) (uint64, Return) { - return DeviceGetNvLinkErrorCounter(Device, Link, Counter) -} - -// nvml.DeviceResetNvLinkErrorCounters() -func DeviceResetNvLinkErrorCounters(Device Device, Link int) Return { - return nvmlDeviceResetNvLinkErrorCounters(Device, uint32(Link)) -} - -func (Device Device) ResetNvLinkErrorCounters(Link int) Return { - return DeviceResetNvLinkErrorCounters(Device, Link) -} - -// nvml.DeviceSetNvLinkUtilizationControl() -func DeviceSetNvLinkUtilizationControl(Device Device, Link int, Counter int, Control *NvLinkUtilizationControl, Reset bool) Return { - reset := uint32(0) - if Reset { - reset = 1 - } - return nvmlDeviceSetNvLinkUtilizationControl(Device, uint32(Link), uint32(Counter), Control, reset) -} - -func (Device Device) SetNvLinkUtilizationControl(Link int, Counter int, Control *NvLinkUtilizationControl, Reset bool) Return { - return DeviceSetNvLinkUtilizationControl(Device, Link, Counter, Control, Reset) -} - -// nvml.DeviceGetNvLinkUtilizationControl() -func DeviceGetNvLinkUtilizationControl(Device Device, Link int, Counter int) (NvLinkUtilizationControl, Return) { - var Control NvLinkUtilizationControl - ret := nvmlDeviceGetNvLinkUtilizationControl(Device, uint32(Link), uint32(Counter), &Control) - return Control, ret -} - -func (Device Device) GetNvLinkUtilizationControl(Link int, Counter int) (NvLinkUtilizationControl, Return) { - return DeviceGetNvLinkUtilizationControl(Device, Link, Counter) -} - -// nvml.DeviceGetNvLinkUtilizationCounter() -func DeviceGetNvLinkUtilizationCounter(Device Device, Link int, Counter int) (uint64, uint64, Return) { - var Rxcounter, Txcounter uint64 - ret := nvmlDeviceGetNvLinkUtilizationCounter(Device, uint32(Link), uint32(Counter), &Rxcounter, &Txcounter) - return Rxcounter, Txcounter, ret -} - -func (Device Device) GetNvLinkUtilizationCounter(Link int, Counter int) (uint64, uint64, Return) { - return DeviceGetNvLinkUtilizationCounter(Device, Link, Counter) -} - -// nvml.DeviceFreezeNvLinkUtilizationCounter() -func DeviceFreezeNvLinkUtilizationCounter(Device Device, Link int, Counter int, Freeze EnableState) Return { - return nvmlDeviceFreezeNvLinkUtilizationCounter(Device, uint32(Link), uint32(Counter), Freeze) -} - -func (Device Device) FreezeNvLinkUtilizationCounter(Link int, Counter int, Freeze EnableState) Return { - return DeviceFreezeNvLinkUtilizationCounter(Device, Link, Counter, Freeze) -} - -// nvml.DeviceResetNvLinkUtilizationCounter() -func DeviceResetNvLinkUtilizationCounter(Device Device, Link int, Counter int) Return { - return nvmlDeviceResetNvLinkUtilizationCounter(Device, uint32(Link), uint32(Counter)) -} - -func (Device Device) ResetNvLinkUtilizationCounter(Link int, Counter int) Return { - return DeviceResetNvLinkUtilizationCounter(Device, Link, Counter) -} - -// nvml.DeviceGetNvLinkRemoteDeviceType() -func DeviceGetNvLinkRemoteDeviceType(Device Device, Link int) (IntNvLinkDeviceType, Return) { - var NvLinkDeviceType IntNvLinkDeviceType - ret := nvmlDeviceGetNvLinkRemoteDeviceType(Device, uint32(Link), &NvLinkDeviceType) - return NvLinkDeviceType, ret -} - -func (Device Device) GetNvLinkRemoteDeviceType(Link int) (IntNvLinkDeviceType, Return) { - return DeviceGetNvLinkRemoteDeviceType(Device, Link) -} - -// nvml.DeviceRegisterEvents() -func DeviceRegisterEvents(Device Device, EventTypes uint64, Set EventSet) Return { - return nvmlDeviceRegisterEvents(Device, EventTypes, Set) -} - -func (Device Device) RegisterEvents(EventTypes uint64, Set EventSet) Return { - return DeviceRegisterEvents(Device, EventTypes, Set) -} - -// nvmlDeviceGetSupportedEventTypes() -func DeviceGetSupportedEventTypes(Device Device) (uint64, Return) { - var EventTypes uint64 - ret := nvmlDeviceGetSupportedEventTypes(Device, &EventTypes) - return EventTypes, ret -} - -func (Device Device) GetSupportedEventTypes() (uint64, Return) { - return DeviceGetSupportedEventTypes(Device) -} - -// nvml.DeviceModifyDrainState() -func DeviceModifyDrainState(PciInfo *PciInfo, NewState EnableState) Return { - return nvmlDeviceModifyDrainState(PciInfo, NewState) -} - -// nvml.DeviceQueryDrainState() -func DeviceQueryDrainState(PciInfo *PciInfo) (EnableState, Return) { - var CurrentState EnableState - ret := nvmlDeviceQueryDrainState(PciInfo, &CurrentState) - return CurrentState, ret -} - -// nvml.DeviceRemoveGpu() -func DeviceRemoveGpu(PciInfo *PciInfo) Return { - return nvmlDeviceRemoveGpu(PciInfo) -} - -// nvml.DeviceRemoveGpu_v2() -func DeviceRemoveGpu_v2(PciInfo *PciInfo, GpuState DetachGpuState, LinkState PcieLinkState) Return { - return nvmlDeviceRemoveGpu_v2(PciInfo, GpuState, LinkState) -} - -// nvml.DeviceDiscoverGpus() -func DeviceDiscoverGpus() (PciInfo, Return) { - var PciInfo PciInfo - ret := nvmlDeviceDiscoverGpus(&PciInfo) - return PciInfo, ret -} - -// nvml.DeviceGetFieldValues() -func DeviceGetFieldValues(Device Device, Values []FieldValue) Return { - ValuesCount := len(Values) - return nvmlDeviceGetFieldValues(Device, int32(ValuesCount), &Values[0]) -} - -func (Device Device) GetFieldValues(Values []FieldValue) Return { - return DeviceGetFieldValues(Device, Values) -} - -// nvml.DeviceGetVirtualizationMode() -func DeviceGetVirtualizationMode(Device Device) (GpuVirtualizationMode, Return) { - var PVirtualMode GpuVirtualizationMode - ret := nvmlDeviceGetVirtualizationMode(Device, &PVirtualMode) - return PVirtualMode, ret -} - -func (Device Device) GetVirtualizationMode() (GpuVirtualizationMode, Return) { - return DeviceGetVirtualizationMode(Device) -} - -// nvml.DeviceGetHostVgpuMode() -func DeviceGetHostVgpuMode(Device Device) (HostVgpuMode, Return) { - var PHostVgpuMode HostVgpuMode - ret := nvmlDeviceGetHostVgpuMode(Device, &PHostVgpuMode) - return PHostVgpuMode, ret -} - -func (Device Device) GetHostVgpuMode() (HostVgpuMode, Return) { - return DeviceGetHostVgpuMode(Device) -} - -// nvml.DeviceSetVirtualizationMode() -func DeviceSetVirtualizationMode(Device Device, VirtualMode GpuVirtualizationMode) Return { - return nvmlDeviceSetVirtualizationMode(Device, VirtualMode) -} - -func (Device Device) SetVirtualizationMode(VirtualMode GpuVirtualizationMode) Return { - return DeviceSetVirtualizationMode(Device, VirtualMode) -} - -// nvml.DeviceGetGridLicensableFeatures() -func DeviceGetGridLicensableFeatures(Device Device) (GridLicensableFeatures, Return) { - var PGridLicensableFeatures GridLicensableFeatures - ret := nvmlDeviceGetGridLicensableFeatures(Device, &PGridLicensableFeatures) - return PGridLicensableFeatures, ret -} - -func (Device Device) GetGridLicensableFeatures() (GridLicensableFeatures, Return) { - return DeviceGetGridLicensableFeatures(Device) -} - -// nvml.DeviceGetProcessUtilization() -func DeviceGetProcessUtilization(Device Device, LastSeenTimeStamp uint64) ([]ProcessUtilizationSample, Return) { - var ProcessSamplesCount uint32 - ret := nvmlDeviceGetProcessUtilization(Device, nil, &ProcessSamplesCount, LastSeenTimeStamp) - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - if ProcessSamplesCount == 0 { - return []ProcessUtilizationSample{}, ret - } - Utilization := make([]ProcessUtilizationSample, ProcessSamplesCount) - ret = nvmlDeviceGetProcessUtilization(Device, &Utilization[0], &ProcessSamplesCount, LastSeenTimeStamp) - return Utilization[:ProcessSamplesCount], ret -} - -func (Device Device) GetProcessUtilization(LastSeenTimeStamp uint64) ([]ProcessUtilizationSample, Return) { - return DeviceGetProcessUtilization(Device, LastSeenTimeStamp) -} - -// nvml.DeviceGetSupportedVgpus() -func DeviceGetSupportedVgpus(Device Device) ([]VgpuTypeId, Return) { - var VgpuCount uint32 = 1 // Will be reduced upon returning - for { - VgpuTypeIds := make([]VgpuTypeId, VgpuCount) - ret := nvmlDeviceGetSupportedVgpus(Device, &VgpuCount, &VgpuTypeIds[0]) - if ret == SUCCESS { - return VgpuTypeIds[:VgpuCount], ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - VgpuCount *= 2 - } -} - -func (Device Device) GetSupportedVgpus() ([]VgpuTypeId, Return) { - return DeviceGetSupportedVgpus(Device) -} - -// nvml.DeviceGetCreatableVgpus() -func DeviceGetCreatableVgpus(Device Device) ([]VgpuTypeId, Return) { - var VgpuCount uint32 = 1 // Will be reduced upon returning - for { - VgpuTypeIds := make([]VgpuTypeId, VgpuCount) - ret := nvmlDeviceGetCreatableVgpus(Device, &VgpuCount, &VgpuTypeIds[0]) - if ret == SUCCESS { - return VgpuTypeIds[:VgpuCount], ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - VgpuCount *= 2 - } -} - -func (Device Device) GetCreatableVgpus() ([]VgpuTypeId, Return) { - return DeviceGetCreatableVgpus(Device) -} - -// nvml.DeviceGetActiveVgpus() -func DeviceGetActiveVgpus(Device Device) ([]VgpuInstance, Return) { - var VgpuCount uint32 = 1 // Will be reduced upon returning - for { - VgpuInstances := make([]VgpuInstance, VgpuCount) - ret := nvmlDeviceGetActiveVgpus(Device, &VgpuCount, &VgpuInstances[0]) - if ret == SUCCESS { - return VgpuInstances[:VgpuCount], ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - VgpuCount *= 2 - } -} - -func (Device Device) GetActiveVgpus() ([]VgpuInstance, Return) { - return DeviceGetActiveVgpus(Device) -} - -// nvml.DeviceGetVgpuMetadata() -func DeviceGetVgpuMetadata(Device Device) (VgpuPgpuMetadata, Return) { - var VgpuPgpuMetadata VgpuPgpuMetadata - OpaqueDataSize := unsafe.Sizeof(VgpuPgpuMetadata.nvmlVgpuPgpuMetadata.OpaqueData) - VgpuPgpuMetadataSize := unsafe.Sizeof(VgpuPgpuMetadata.nvmlVgpuPgpuMetadata) - OpaqueDataSize - for { - BufferSize := uint32(VgpuPgpuMetadataSize + OpaqueDataSize) - Buffer := make([]byte, BufferSize) - nvmlVgpuPgpuMetadataPtr := (*nvmlVgpuPgpuMetadata)(unsafe.Pointer(&Buffer[0])) - ret := nvmlDeviceGetVgpuMetadata(Device, nvmlVgpuPgpuMetadataPtr, &BufferSize) - if ret == SUCCESS { - VgpuPgpuMetadata.nvmlVgpuPgpuMetadata = *nvmlVgpuPgpuMetadataPtr - VgpuPgpuMetadata.OpaqueData = Buffer[VgpuPgpuMetadataSize:BufferSize] - return VgpuPgpuMetadata, ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return VgpuPgpuMetadata, ret - } - OpaqueDataSize = 2 * OpaqueDataSize - } -} - -func (Device Device) GetVgpuMetadata() (VgpuPgpuMetadata, Return) { - return DeviceGetVgpuMetadata(Device) -} - -// nvml.DeviceGetPgpuMetadataString() -func DeviceGetPgpuMetadataString(Device Device) (string, Return) { - var BufferSize uint32 = 1 // Will be reduced upon returning - for { - PgpuMetadata := make([]byte, BufferSize) - ret := nvmlDeviceGetPgpuMetadataString(Device, &PgpuMetadata[0], &BufferSize) - if ret == SUCCESS { - return string(PgpuMetadata[:clen(PgpuMetadata)]), ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return "", ret - } - BufferSize *= 2 - } -} - -func (Device Device) GetPgpuMetadataString() (string, Return) { - return DeviceGetPgpuMetadataString(Device) -} - -// nvml.DeviceGetVgpuUtilization() -func DeviceGetVgpuUtilization(Device Device, LastSeenTimeStamp uint64) (ValueType, []VgpuInstanceUtilizationSample, Return) { - var SampleValType ValueType - var VgpuInstanceSamplesCount uint32 = 1 // Will be reduced upon returning - for { - UtilizationSamples := make([]VgpuInstanceUtilizationSample, VgpuInstanceSamplesCount) - ret := nvmlDeviceGetVgpuUtilization(Device, LastSeenTimeStamp, &SampleValType, &VgpuInstanceSamplesCount, &UtilizationSamples[0]) - if ret == SUCCESS { - return SampleValType, UtilizationSamples[:VgpuInstanceSamplesCount], ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return SampleValType, nil, ret - } - VgpuInstanceSamplesCount *= 2 - } -} - -func (Device Device) GetVgpuUtilization(LastSeenTimeStamp uint64) (ValueType, []VgpuInstanceUtilizationSample, Return) { - return DeviceGetVgpuUtilization(Device, LastSeenTimeStamp) -} - -// nvml.DeviceGetAttributes() -func DeviceGetAttributes(Device Device) (DeviceAttributes, Return) { - var Attributes DeviceAttributes - ret := nvmlDeviceGetAttributes(Device, &Attributes) - return Attributes, ret -} - -func (Device Device) GetAttributes() (DeviceAttributes, Return) { - return DeviceGetAttributes(Device) -} - -// nvml.DeviceGetRemappedRows() -func DeviceGetRemappedRows(Device Device) (int, int, bool, bool, Return) { - var CorrRows, UncRows, IsPending, FailureOccured uint32 - ret := nvmlDeviceGetRemappedRows(Device, &CorrRows, &UncRows, &IsPending, &FailureOccured) - return int(CorrRows), int(UncRows), (IsPending != 0), (FailureOccured != 0), ret -} - -func (Device Device) GetRemappedRows() (int, int, bool, bool, Return) { - return DeviceGetRemappedRows(Device) -} - -// nvml.DeviceGetRowRemapperHistogram() -func DeviceGetRowRemapperHistogram(Device Device) (RowRemapperHistogramValues, Return) { - var Values RowRemapperHistogramValues - ret := nvmlDeviceGetRowRemapperHistogram(Device, &Values) - return Values, ret -} - -func (Device Device) GetRowRemapperHistogram() (RowRemapperHistogramValues, Return) { - return DeviceGetRowRemapperHistogram(Device) -} - -// nvml.DeviceGetArchitecture() -func DeviceGetArchitecture(Device Device) (DeviceArchitecture, Return) { - var Arch DeviceArchitecture - ret := nvmlDeviceGetArchitecture(Device, &Arch) - return Arch, ret -} - -func (Device Device) GetArchitecture() (DeviceArchitecture, Return) { - return DeviceGetArchitecture(Device) -} - -// nvml.DeviceGetVgpuProcessUtilization() -func DeviceGetVgpuProcessUtilization(Device Device, LastSeenTimeStamp uint64) ([]VgpuProcessUtilizationSample, Return) { - var VgpuProcessSamplesCount uint32 = 1 // Will be reduced upon returning - for { - UtilizationSamples := make([]VgpuProcessUtilizationSample, VgpuProcessSamplesCount) - ret := nvmlDeviceGetVgpuProcessUtilization(Device, LastSeenTimeStamp, &VgpuProcessSamplesCount, &UtilizationSamples[0]) - if ret == SUCCESS { - return UtilizationSamples[:VgpuProcessSamplesCount], ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - VgpuProcessSamplesCount *= 2 - } -} - -func (Device Device) GetVgpuProcessUtilization(LastSeenTimeStamp uint64) ([]VgpuProcessUtilizationSample, Return) { - return DeviceGetVgpuProcessUtilization(Device, LastSeenTimeStamp) -} - -// nvml.GetExcludedDeviceCount() -func GetExcludedDeviceCount() (int, Return) { - var DeviceCount uint32 - ret := nvmlGetExcludedDeviceCount(&DeviceCount) - return int(DeviceCount), ret -} - -// nvml.GetExcludedDeviceInfoByIndex() -func GetExcludedDeviceInfoByIndex(Index int) (ExcludedDeviceInfo, Return) { - var Info ExcludedDeviceInfo - ret := nvmlGetExcludedDeviceInfoByIndex(uint32(Index), &Info) - return Info, ret -} - -// nvml.DeviceSetMigMode() -func DeviceSetMigMode(Device Device, Mode int) (Return, Return) { - var ActivationStatus Return - ret := nvmlDeviceSetMigMode(Device, uint32(Mode), &ActivationStatus) - return ActivationStatus, ret -} - -func (Device Device) SetMigMode(Mode int) (Return, Return) { - return DeviceSetMigMode(Device, Mode) -} - -// nvml.DeviceGetMigMode() -func DeviceGetMigMode(Device Device) (int, int, Return) { - var CurrentMode, PendingMode uint32 - ret := nvmlDeviceGetMigMode(Device, &CurrentMode, &PendingMode) - return int(CurrentMode), int(PendingMode), ret -} - -func (Device Device) GetMigMode() (int, int, Return) { - return DeviceGetMigMode(Device) -} - -// nvml.DeviceGetGpuInstanceProfileInfo() -func DeviceGetGpuInstanceProfileInfo(Device Device, Profile int) (GpuInstanceProfileInfo, Return) { - var Info GpuInstanceProfileInfo - ret := nvmlDeviceGetGpuInstanceProfileInfo(Device, uint32(Profile), &Info) - return Info, ret -} - -func (Device Device) GetGpuInstanceProfileInfo(Profile int) (GpuInstanceProfileInfo, Return) { - return DeviceGetGpuInstanceProfileInfo(Device, Profile) -} - -// nvml.DeviceGetGpuInstanceProfileInfoV() -type GpuInstanceProfileInfoV struct { - device Device - profile int -} - -func (InfoV GpuInstanceProfileInfoV) V1() (GpuInstanceProfileInfo, Return) { - return DeviceGetGpuInstanceProfileInfo(InfoV.device, InfoV.profile) -} - -func (InfoV GpuInstanceProfileInfoV) V2() (GpuInstanceProfileInfo_v2, Return) { - var Info GpuInstanceProfileInfo_v2 - Info.Version = STRUCT_VERSION(Info, 2) - ret := nvmlDeviceGetGpuInstanceProfileInfoV(InfoV.device, uint32(InfoV.profile), &Info) - return Info, ret -} - -func DeviceGetGpuInstanceProfileInfoV(Device Device, Profile int) GpuInstanceProfileInfoV { - return GpuInstanceProfileInfoV{Device, Profile} -} - -func (Device Device) GetGpuInstanceProfileInfoV(Profile int) GpuInstanceProfileInfoV { - return DeviceGetGpuInstanceProfileInfoV(Device, Profile) -} - -// nvml.DeviceGetGpuInstancePossiblePlacements() -func DeviceGetGpuInstancePossiblePlacements(Device Device, Info *GpuInstanceProfileInfo) ([]GpuInstancePlacement, Return) { - if Info == nil { - return nil, ERROR_INVALID_ARGUMENT - } - var Count uint32 - ret := nvmlDeviceGetGpuInstancePossiblePlacements(Device, Info.Id, nil, &Count) - if ret != SUCCESS { - return nil, ret - } - if Count == 0 { - return []GpuInstancePlacement{}, ret - } - Placements := make([]GpuInstancePlacement, Count) - ret = nvmlDeviceGetGpuInstancePossiblePlacements(Device, Info.Id, &Placements[0], &Count) - return Placements[:Count], ret -} - -func (Device Device) GetGpuInstancePossiblePlacements(Info *GpuInstanceProfileInfo) ([]GpuInstancePlacement, Return) { - return DeviceGetGpuInstancePossiblePlacements(Device, Info) -} - -// nvml.DeviceGetGpuInstanceRemainingCapacity() -func DeviceGetGpuInstanceRemainingCapacity(Device Device, Info *GpuInstanceProfileInfo) (int, Return) { - if Info == nil { - return 0, ERROR_INVALID_ARGUMENT - } - var Count uint32 - ret := nvmlDeviceGetGpuInstanceRemainingCapacity(Device, Info.Id, &Count) - return int(Count), ret -} - -func (Device Device) GetGpuInstanceRemainingCapacity(Info *GpuInstanceProfileInfo) (int, Return) { - return DeviceGetGpuInstanceRemainingCapacity(Device, Info) -} - -// nvml.DeviceCreateGpuInstance() -func DeviceCreateGpuInstance(Device Device, Info *GpuInstanceProfileInfo) (GpuInstance, Return) { - if Info == nil { - return GpuInstance{}, ERROR_INVALID_ARGUMENT - } - var GpuInstance GpuInstance - ret := nvmlDeviceCreateGpuInstance(Device, Info.Id, &GpuInstance) - return GpuInstance, ret -} - -func (Device Device) CreateGpuInstance(Info *GpuInstanceProfileInfo) (GpuInstance, Return) { - return DeviceCreateGpuInstance(Device, Info) -} - -// nvml.DeviceCreateGpuInstanceWithPlacement() -func DeviceCreateGpuInstanceWithPlacement(Device Device, Info *GpuInstanceProfileInfo, Placement *GpuInstancePlacement) (GpuInstance, Return) { - if Info == nil { - return GpuInstance{}, ERROR_INVALID_ARGUMENT - } - var GpuInstance GpuInstance - ret := nvmlDeviceCreateGpuInstanceWithPlacement(Device, Info.Id, Placement, &GpuInstance) - return GpuInstance, ret -} - -func (Device Device) CreateGpuInstanceWithPlacement(Info *GpuInstanceProfileInfo, Placement *GpuInstancePlacement) (GpuInstance, Return) { - return DeviceCreateGpuInstanceWithPlacement(Device, Info, Placement) -} - -// nvml.GpuInstanceDestroy() -func GpuInstanceDestroy(GpuInstance GpuInstance) Return { - return nvmlGpuInstanceDestroy(GpuInstance) -} - -func (GpuInstance GpuInstance) Destroy() Return { - return GpuInstanceDestroy(GpuInstance) -} - -// nvml.DeviceGetGpuInstances() -func DeviceGetGpuInstances(Device Device, Info *GpuInstanceProfileInfo) ([]GpuInstance, Return) { - if Info == nil { - return nil, ERROR_INVALID_ARGUMENT - } - var Count uint32 = Info.InstanceCount - GpuInstances := make([]GpuInstance, Count) - ret := nvmlDeviceGetGpuInstances(Device, Info.Id, &GpuInstances[0], &Count) - return GpuInstances[:Count], ret -} - -func (Device Device) GetGpuInstances(Info *GpuInstanceProfileInfo) ([]GpuInstance, Return) { - return DeviceGetGpuInstances(Device, Info) -} - -// nvml.DeviceGetGpuInstanceById() -func DeviceGetGpuInstanceById(Device Device, Id int) (GpuInstance, Return) { - var GpuInstance GpuInstance - ret := nvmlDeviceGetGpuInstanceById(Device, uint32(Id), &GpuInstance) - return GpuInstance, ret -} - -func (Device Device) GetGpuInstanceById(Id int) (GpuInstance, Return) { - return DeviceGetGpuInstanceById(Device, Id) -} - -// nvml.GpuInstanceGetInfo() -func GpuInstanceGetInfo(GpuInstance GpuInstance) (GpuInstanceInfo, Return) { - var Info GpuInstanceInfo - ret := nvmlGpuInstanceGetInfo(GpuInstance, &Info) - return Info, ret -} - -func (GpuInstance GpuInstance) GetInfo() (GpuInstanceInfo, Return) { - return GpuInstanceGetInfo(GpuInstance) -} - -// nvml.GpuInstanceGetComputeInstanceProfileInfo() -func GpuInstanceGetComputeInstanceProfileInfo(GpuInstance GpuInstance, Profile int, EngProfile int) (ComputeInstanceProfileInfo, Return) { - var Info ComputeInstanceProfileInfo - ret := nvmlGpuInstanceGetComputeInstanceProfileInfo(GpuInstance, uint32(Profile), uint32(EngProfile), &Info) - return Info, ret -} - -func (GpuInstance GpuInstance) GetComputeInstanceProfileInfo(Profile int, EngProfile int) (ComputeInstanceProfileInfo, Return) { - return GpuInstanceGetComputeInstanceProfileInfo(GpuInstance, Profile, EngProfile) -} - -// nvml.GpuInstanceGetComputeInstanceProfileInfoV() -type ComputeInstanceProfileInfoV struct { - gpuInstance GpuInstance - profile int - engProfile int -} - -func (InfoV ComputeInstanceProfileInfoV) V1() (ComputeInstanceProfileInfo, Return) { - return GpuInstanceGetComputeInstanceProfileInfo(InfoV.gpuInstance, InfoV.profile, InfoV.engProfile) -} - -func (InfoV ComputeInstanceProfileInfoV) V2() (ComputeInstanceProfileInfo_v2, Return) { - var Info ComputeInstanceProfileInfo_v2 - Info.Version = STRUCT_VERSION(Info, 2) - ret := nvmlGpuInstanceGetComputeInstanceProfileInfoV(InfoV.gpuInstance, uint32(InfoV.profile), uint32(InfoV.engProfile), &Info) - return Info, ret -} - -func GpuInstanceGetComputeInstanceProfileInfoV(GpuInstance GpuInstance, Profile int, EngProfile int) ComputeInstanceProfileInfoV { - return ComputeInstanceProfileInfoV{GpuInstance, Profile, EngProfile} -} - -func (GpuInstance GpuInstance) GetComputeInstanceProfileInfoV(Profile int, EngProfile int) ComputeInstanceProfileInfoV { - return GpuInstanceGetComputeInstanceProfileInfoV(GpuInstance, Profile, EngProfile) -} - -// nvml.GpuInstanceGetComputeInstanceRemainingCapacity() -func GpuInstanceGetComputeInstanceRemainingCapacity(GpuInstance GpuInstance, Info *ComputeInstanceProfileInfo) (int, Return) { - if Info == nil { - return 0, ERROR_INVALID_ARGUMENT - } - var Count uint32 - ret := nvmlGpuInstanceGetComputeInstanceRemainingCapacity(GpuInstance, Info.Id, &Count) - return int(Count), ret -} - -func (GpuInstance GpuInstance) GetComputeInstanceRemainingCapacity(Info *ComputeInstanceProfileInfo) (int, Return) { - return GpuInstanceGetComputeInstanceRemainingCapacity(GpuInstance, Info) -} - -// nvml.GpuInstanceCreateComputeInstance() -func GpuInstanceCreateComputeInstance(GpuInstance GpuInstance, Info *ComputeInstanceProfileInfo) (ComputeInstance, Return) { - if Info == nil { - return ComputeInstance{}, ERROR_INVALID_ARGUMENT - } - var ComputeInstance ComputeInstance - ret := nvmlGpuInstanceCreateComputeInstance(GpuInstance, Info.Id, &ComputeInstance) - return ComputeInstance, ret -} - -func (GpuInstance GpuInstance) CreateComputeInstance(Info *ComputeInstanceProfileInfo) (ComputeInstance, Return) { - return GpuInstanceCreateComputeInstance(GpuInstance, Info) -} - -// nvml.ComputeInstanceDestroy() -func ComputeInstanceDestroy(ComputeInstance ComputeInstance) Return { - return nvmlComputeInstanceDestroy(ComputeInstance) -} - -func (ComputeInstance ComputeInstance) Destroy() Return { - return ComputeInstanceDestroy(ComputeInstance) -} - -// nvml.GpuInstanceGetComputeInstances() -func GpuInstanceGetComputeInstances(GpuInstance GpuInstance, Info *ComputeInstanceProfileInfo) ([]ComputeInstance, Return) { - if Info == nil { - return nil, ERROR_INVALID_ARGUMENT - } - var Count uint32 = Info.InstanceCount - ComputeInstances := make([]ComputeInstance, Count) - ret := nvmlGpuInstanceGetComputeInstances(GpuInstance, Info.Id, &ComputeInstances[0], &Count) - return ComputeInstances[:Count], ret -} - -func (GpuInstance GpuInstance) GetComputeInstances(Info *ComputeInstanceProfileInfo) ([]ComputeInstance, Return) { - return GpuInstanceGetComputeInstances(GpuInstance, Info) -} - -// nvml.GpuInstanceGetComputeInstanceById() -func GpuInstanceGetComputeInstanceById(GpuInstance GpuInstance, Id int) (ComputeInstance, Return) { - var ComputeInstance ComputeInstance - ret := nvmlGpuInstanceGetComputeInstanceById(GpuInstance, uint32(Id), &ComputeInstance) - return ComputeInstance, ret -} - -func (GpuInstance GpuInstance) GetComputeInstanceById(Id int) (ComputeInstance, Return) { - return GpuInstanceGetComputeInstanceById(GpuInstance, Id) -} - -// nvml.ComputeInstanceGetInfo() -func ComputeInstanceGetInfo(ComputeInstance ComputeInstance) (ComputeInstanceInfo, Return) { - var Info ComputeInstanceInfo - ret := nvmlComputeInstanceGetInfo(ComputeInstance, &Info) - return Info, ret -} - -func (ComputeInstance ComputeInstance) GetInfo() (ComputeInstanceInfo, Return) { - return ComputeInstanceGetInfo(ComputeInstance) -} - -// nvml.DeviceIsMigDeviceHandle() -func DeviceIsMigDeviceHandle(Device Device) (bool, Return) { - var IsMigDevice uint32 - ret := nvmlDeviceIsMigDeviceHandle(Device, &IsMigDevice) - return (IsMigDevice != 0), ret -} - -func (Device Device) IsMigDeviceHandle() (bool, Return) { - return DeviceIsMigDeviceHandle(Device) -} - -// nvml DeviceGetGpuInstanceId() -func DeviceGetGpuInstanceId(Device Device) (int, Return) { - var Id uint32 - ret := nvmlDeviceGetGpuInstanceId(Device, &Id) - return int(Id), ret -} - -func (Device Device) GetGpuInstanceId() (int, Return) { - return DeviceGetGpuInstanceId(Device) -} - -// nvml.DeviceGetComputeInstanceId() -func DeviceGetComputeInstanceId(Device Device) (int, Return) { - var Id uint32 - ret := nvmlDeviceGetComputeInstanceId(Device, &Id) - return int(Id), ret -} - -func (Device Device) GetComputeInstanceId() (int, Return) { - return DeviceGetComputeInstanceId(Device) -} - -// nvml.DeviceGetMaxMigDeviceCount() -func DeviceGetMaxMigDeviceCount(Device Device) (int, Return) { - var Count uint32 - ret := nvmlDeviceGetMaxMigDeviceCount(Device, &Count) - return int(Count), ret -} - -func (Device Device) GetMaxMigDeviceCount() (int, Return) { - return DeviceGetMaxMigDeviceCount(Device) -} - -// nvml.DeviceGetMigDeviceHandleByIndex() -func DeviceGetMigDeviceHandleByIndex(device Device, Index int) (Device, Return) { - var MigDevice Device - ret := nvmlDeviceGetMigDeviceHandleByIndex(device, uint32(Index), &MigDevice) - return MigDevice, ret -} - -func (Device Device) GetMigDeviceHandleByIndex(Index int) (Device, Return) { - return DeviceGetMigDeviceHandleByIndex(Device, Index) -} - -// nvml.DeviceGetDeviceHandleFromMigDeviceHandle() -func DeviceGetDeviceHandleFromMigDeviceHandle(MigDevice Device) (Device, Return) { - var Device Device - ret := nvmlDeviceGetDeviceHandleFromMigDeviceHandle(MigDevice, &Device) - return Device, ret -} - -func (MigDevice Device) GetDeviceHandleFromMigDeviceHandle() (Device, Return) { - return DeviceGetDeviceHandleFromMigDeviceHandle(MigDevice) -} - -// nvml.DeviceGetBusType() -func DeviceGetBusType(Device Device) (BusType, Return) { - var Type BusType - ret := nvmlDeviceGetBusType(Device, &Type) - return Type, ret -} - -func (Device Device) GetBusType() (BusType, Return) { - return DeviceGetBusType(Device) -} - -// nvml.DeviceSetDefaultFanSpeed_v2() -func DeviceSetDefaultFanSpeed_v2(Device Device, Fan int) Return { - return nvmlDeviceSetDefaultFanSpeed_v2(Device, uint32(Fan)) -} - -func (Device Device) SetDefaultFanSpeed_v2(Fan int) Return { - return DeviceSetDefaultFanSpeed_v2(Device, Fan) -} - -// nvml.DeviceGetMinMaxFanSpeed() -func DeviceGetMinMaxFanSpeed(Device Device) (int, int, Return) { - var MinSpeed, MaxSpeed uint32 - ret := nvmlDeviceGetMinMaxFanSpeed(Device, &MinSpeed, &MaxSpeed) - return int(MinSpeed), int(MaxSpeed), ret -} - -func (Device Device) GetMinMaxFanSpeed() (int, int, Return) { - return DeviceGetMinMaxFanSpeed(Device) -} - -// nvml.DeviceGetThermalSettings() -func DeviceGetThermalSettings(Device Device, SensorIndex uint32) (GpuThermalSettings, Return) { - var PThermalSettings GpuThermalSettings - ret := nvmlDeviceGetThermalSettings(Device, SensorIndex, &PThermalSettings) - return PThermalSettings, ret -} - -func (Device Device) GetThermalSettings(SensorIndex uint32) (GpuThermalSettings, Return) { - return DeviceGetThermalSettings(Device, SensorIndex) -} - -// nvml.DeviceGetDefaultEccMode() -func DeviceGetDefaultEccMode(Device Device) (EnableState, Return) { - var DefaultMode EnableState - ret := nvmlDeviceGetDefaultEccMode(Device, &DefaultMode) - return DefaultMode, ret -} - -func (Device Device) GetDefaultEccMode() (EnableState, Return) { - return DeviceGetDefaultEccMode(Device) -} - -// nvml.DeviceGetPcieSpeed() -func DeviceGetPcieSpeed(Device Device) (int, Return) { - var PcieSpeed uint32 - ret := nvmlDeviceGetPcieSpeed(Device, &PcieSpeed) - return int(PcieSpeed), ret -} - -func (Device Device) GetPcieSpeed() (int, Return) { - return DeviceGetPcieSpeed(Device) -} - -// nvml.DeviceGetGspFirmwareVersion() -func DeviceGetGspFirmwareVersion(Device Device) (string, Return) { - Version := make([]byte, GSP_FIRMWARE_VERSION_BUF_SIZE) - ret := nvmlDeviceGetGspFirmwareVersion(Device, &Version[0]) - return string(Version[:clen(Version)]), ret -} - -func (Device Device) GetGspFirmwareVersion() (string, Return) { - return DeviceGetGspFirmwareVersion(Device) -} - -// nvml.DeviceGetGspFirmwareMode() -func DeviceGetGspFirmwareMode(Device Device) (bool, bool, Return) { - var IsEnabled, DefaultMode uint32 - ret := nvmlDeviceGetGspFirmwareMode(Device, &IsEnabled, &DefaultMode) - return (IsEnabled != 0), (DefaultMode != 0), ret -} - -func (Device Device) GetGspFirmwareMode() (bool, bool, Return) { - return DeviceGetGspFirmwareMode(Device) -} - -// nvml.DeviceGetDynamicPstatesInfo() -func DeviceGetDynamicPstatesInfo(Device Device) (GpuDynamicPstatesInfo, Return) { - var PDynamicPstatesInfo GpuDynamicPstatesInfo - ret := nvmlDeviceGetDynamicPstatesInfo(Device, &PDynamicPstatesInfo) - return PDynamicPstatesInfo, ret -} - -func (Device Device) GetDynamicPstatesInfo() (GpuDynamicPstatesInfo, Return) { - return DeviceGetDynamicPstatesInfo(Device) -} - -// nvml.DeviceSetFanSpeed_v2() -func DeviceSetFanSpeed_v2(Device Device, Fan int, Speed int) Return { - return nvmlDeviceSetFanSpeed_v2(Device, uint32(Fan), uint32(Speed)) -} - -func (Device Device) SetFanSpeed_v2(Fan int, Speed int) Return { - return DeviceSetFanSpeed_v2(Device, Fan, Speed) -} - -// nvml.DeviceGetGpcClkVfOffset() -func DeviceGetGpcClkVfOffset(Device Device) (int, Return) { - var Offset int32 - ret := nvmlDeviceGetGpcClkVfOffset(Device, &Offset) - return int(Offset), ret -} - -func (Device Device) GetGpcClkVfOffset() (int, Return) { - return DeviceGetGpcClkVfOffset(Device) -} - -// nvml.DeviceSetGpcClkVfOffset() -func DeviceSetGpcClkVfOffset(Device Device, Offset int) Return { - return nvmlDeviceSetGpcClkVfOffset(Device, int32(Offset)) -} - -func (Device Device) SetGpcClkVfOffset(Offset int) Return { - return DeviceSetGpcClkVfOffset(Device, Offset) -} - -// nvml.DeviceGetMinMaxClockOfPState() -func DeviceGetMinMaxClockOfPState(Device Device, _type ClockType, Pstate Pstates) (uint32, uint32, Return) { - var MinClockMHz, MaxClockMHz uint32 - ret := nvmlDeviceGetMinMaxClockOfPState(Device, _type, Pstate, &MinClockMHz, &MaxClockMHz) - return MinClockMHz, MaxClockMHz, ret -} - -func (Device Device) GetMinMaxClockOfPState(_type ClockType, Pstate Pstates) (uint32, uint32, Return) { - return DeviceGetMinMaxClockOfPState(Device, _type, Pstate) -} - -// nvml.DeviceGetSupportedPerformanceStates() -func DeviceGetSupportedPerformanceStates(Device Device) ([]Pstates, Return) { - Pstates := make([]Pstates, MAX_GPU_PERF_PSTATES) - ret := nvmlDeviceGetSupportedPerformanceStates(Device, &Pstates[0], MAX_GPU_PERF_PSTATES) - for i := 0; i < MAX_GPU_PERF_PSTATES; i++ { - if Pstates[i] == PSTATE_UNKNOWN { - return Pstates[0:i], ret - } - } - return Pstates, ret -} - -func (Device Device) GetSupportedPerformanceStates() ([]Pstates, Return) { - return DeviceGetSupportedPerformanceStates(Device) -} - -// nvml.DeviceGetTargetFanSpeed() -func DeviceGetTargetFanSpeed(Device Device, Fan int) (int, Return) { - var TargetSpeed uint32 - ret := nvmlDeviceGetTargetFanSpeed(Device, uint32(Fan), &TargetSpeed) - return int(TargetSpeed), ret -} - -func (Device Device) GetTargetFanSpeed(Fan int) (int, Return) { - return DeviceGetTargetFanSpeed(Device, Fan) -} - -// nvml.DeviceGetMemClkVfOffset() -func DeviceGetMemClkVfOffset(Device Device) (int, Return) { - var Offset int32 - ret := nvmlDeviceGetMemClkVfOffset(Device, &Offset) - return int(Offset), ret -} - -func (Device Device) GetMemClkVfOffset() (int, Return) { - return DeviceGetMemClkVfOffset(Device) -} - -// nvml.DeviceSetMemClkVfOffset() -func DeviceSetMemClkVfOffset(Device Device, Offset int) Return { - return nvmlDeviceSetMemClkVfOffset(Device, int32(Offset)) -} - -func (Device Device) SetMemClkVfOffset(Offset int) Return { - return DeviceSetMemClkVfOffset(Device, Offset) -} - -// nvml.DeviceGetGpcClkMinMaxVfOffset() -func DeviceGetGpcClkMinMaxVfOffset(Device Device) (int, int, Return) { - var MinOffset, MaxOffset int32 - ret := nvmlDeviceGetGpcClkMinMaxVfOffset(Device, &MinOffset, &MaxOffset) - return int(MinOffset), int(MaxOffset), ret -} - -func (Device Device) GetGpcClkMinMaxVfOffset() (int, int, Return) { - return DeviceGetGpcClkMinMaxVfOffset(Device) -} - -// nvml.DeviceGetMemClkMinMaxVfOffset() -func DeviceGetMemClkMinMaxVfOffset(Device Device) (int, int, Return) { - var MinOffset, MaxOffset int32 - ret := nvmlDeviceGetMemClkMinMaxVfOffset(Device, &MinOffset, &MaxOffset) - return int(MinOffset), int(MaxOffset), ret -} - -func (Device Device) GetMemClkMinMaxVfOffset() (int, int, Return) { - return DeviceGetMemClkMinMaxVfOffset(Device) -} - -// nvml.DeviceGetGpuMaxPcieLinkGeneration() -func DeviceGetGpuMaxPcieLinkGeneration(Device Device) (int, Return) { - var MaxLinkGenDevice uint32 - ret := nvmlDeviceGetGpuMaxPcieLinkGeneration(Device, &MaxLinkGenDevice) - return int(MaxLinkGenDevice), ret -} - -func (Device Device) GetGpuMaxPcieLinkGeneration() (int, Return) { - return DeviceGetGpuMaxPcieLinkGeneration(Device) -} - -// nvml.DeviceGetFanControlPolicy_v2() -func DeviceGetFanControlPolicy_v2(Device Device, Fan int) (FanControlPolicy, Return) { - var Policy FanControlPolicy - ret := nvmlDeviceGetFanControlPolicy_v2(Device, uint32(Fan), &Policy) - return Policy, ret -} - -func (Device Device) GetFanControlPolicy_v2(Fan int) (FanControlPolicy, Return) { - return DeviceGetFanControlPolicy_v2(Device, Fan) -} - -// nvml.DeviceSetFanControlPolicy() -func DeviceSetFanControlPolicy(Device Device, Fan int, Policy FanControlPolicy) Return { - return nvmlDeviceSetFanControlPolicy(Device, uint32(Fan), Policy) -} - -func (Device Device) SetFanControlPolicy(Fan int, Policy FanControlPolicy) Return { - return DeviceSetFanControlPolicy(Device, Fan, Policy) -} - -// nvml.DeviceClearFieldValues() -func DeviceClearFieldValues(Device Device, Values []FieldValue) Return { - ValuesCount := len(Values) - return nvmlDeviceClearFieldValues(Device, int32(ValuesCount), &Values[0]) -} - -func (Device Device) ClearFieldValues(Values []FieldValue) Return { - return DeviceClearFieldValues(Device, Values) -} - -// nvml.DeviceGetVgpuCapabilities() -func DeviceGetVgpuCapabilities(Device Device, Capability DeviceVgpuCapability) (bool, Return) { - var CapResult uint32 - ret := nvmlDeviceGetVgpuCapabilities(Device, Capability, &CapResult) - return (CapResult != 0), ret -} - -func (Device Device) GetVgpuCapabilities(Capability DeviceVgpuCapability) (bool, Return) { - return DeviceGetVgpuCapabilities(Device, Capability) -} - -// nvml.DeviceGetVgpuSchedulerLog() -func DeviceGetVgpuSchedulerLog(Device Device) (VgpuSchedulerLog, Return) { - var PSchedulerLog VgpuSchedulerLog - ret := nvmlDeviceGetVgpuSchedulerLog(Device, &PSchedulerLog) - return PSchedulerLog, ret -} - -func (Device Device) GetVgpuSchedulerLog() (VgpuSchedulerLog, Return) { - return DeviceGetVgpuSchedulerLog(Device) -} - -// nvml.DeviceGetVgpuSchedulerState() -func DeviceGetVgpuSchedulerState(Device Device) (VgpuSchedulerGetState, Return) { - var PSchedulerState VgpuSchedulerGetState - ret := nvmlDeviceGetVgpuSchedulerState(Device, &PSchedulerState) - return PSchedulerState, ret -} - -func (Device Device) GetVgpuSchedulerState() (VgpuSchedulerGetState, Return) { - return DeviceGetVgpuSchedulerState(Device) -} - -// nvml.DeviceSetVgpuSchedulerState() -func DeviceSetVgpuSchedulerState(Device Device, PSchedulerState *VgpuSchedulerSetState) Return { - return nvmlDeviceSetVgpuSchedulerState(Device, PSchedulerState) -} - -func (Device Device) SetVgpuSchedulerState(PSchedulerState *VgpuSchedulerSetState) Return { - return DeviceSetVgpuSchedulerState(Device, PSchedulerState) -} - -// nvml.DeviceGetVgpuSchedulerCapabilities() -func DeviceGetVgpuSchedulerCapabilities(Device Device) (VgpuSchedulerCapabilities, Return) { - var PCapabilities VgpuSchedulerCapabilities - ret := nvmlDeviceGetVgpuSchedulerCapabilities(Device, &PCapabilities) - return PCapabilities, ret -} - -func (Device Device) GetVgpuSchedulerCapabilities() (VgpuSchedulerCapabilities, Return) { - return DeviceGetVgpuSchedulerCapabilities(Device) -} - -// nvml.GpuInstanceGetComputeInstancePossiblePlacements() -func GpuInstanceGetComputeInstancePossiblePlacements(GpuInstance GpuInstance, Info *ComputeInstanceProfileInfo) ([]ComputeInstancePlacement, Return) { - var Count uint32 - ret := nvmlGpuInstanceGetComputeInstancePossiblePlacements(GpuInstance, Info.Id, nil, &Count) - if ret != SUCCESS { - return nil, ret - } - if Count == 0 { - return []ComputeInstancePlacement{}, ret - } - PlacementArray := make([]ComputeInstancePlacement, Count) - ret = nvmlGpuInstanceGetComputeInstancePossiblePlacements(GpuInstance, Info.Id, &PlacementArray[0], &Count) - return PlacementArray, ret -} - -func (GpuInstance GpuInstance) GetComputeInstancePossiblePlacements(Info *ComputeInstanceProfileInfo) ([]ComputeInstancePlacement, Return) { - return GpuInstanceGetComputeInstancePossiblePlacements(GpuInstance, Info) -} - -// nvml.GpuInstanceCreateComputeInstanceWithPlacement() -func GpuInstanceCreateComputeInstanceWithPlacement(GpuInstance GpuInstance, Info *ComputeInstanceProfileInfo, Placement *ComputeInstancePlacement, ComputeInstance *ComputeInstance) Return { - return nvmlGpuInstanceCreateComputeInstanceWithPlacement(GpuInstance, Info.Id, Placement, ComputeInstance) -} - -func (GpuInstance GpuInstance) CreateComputeInstanceWithPlacement(Info *ComputeInstanceProfileInfo, Placement *ComputeInstancePlacement, ComputeInstance *ComputeInstance) Return { - return GpuInstanceCreateComputeInstanceWithPlacement(GpuInstance, Info, Placement, ComputeInstance) -} - -// nvml.DeviceGetGpuFabricInfo() -func DeviceGetGpuFabricInfo(Device Device) (GpuFabricInfo, Return) { - var GpuFabricInfo GpuFabricInfo - ret := nvmlDeviceGetGpuFabricInfo(Device, &GpuFabricInfo) - return GpuFabricInfo, ret -} - -func (Device Device) GetGpuFabricInfo() (GpuFabricInfo, Return) { - return DeviceGetGpuFabricInfo(Device) -} - -// nvml.DeviceCcuGetStreamState() -func DeviceCcuGetStreamState(Device Device) (int, Return) { - var State uint32 - ret := nvmlDeviceCcuGetStreamState(Device, &State) - return int(State), ret -} - -func (Device Device) CcuGetStreamState() (int, Return) { - return DeviceCcuGetStreamState(Device) -} - -// nvml.DeviceCcuSetStreamState() -func DeviceCcuSetStreamState(Device Device, State int) Return { - return nvmlDeviceCcuSetStreamState(Device, uint32(State)) -} - -func (Device Device) CcuSetStreamState(State int) Return { - return DeviceCcuSetStreamState(Device, State) -} - -// nvml.DeviceSetNvLinkDeviceLowPowerThreshold() -func DeviceSetNvLinkDeviceLowPowerThreshold(Device Device, Info *NvLinkPowerThres) Return { - return nvmlDeviceSetNvLinkDeviceLowPowerThreshold(Device, Info) -} - -func (Device Device) SetNvLinkDeviceLowPowerThreshold(Info *NvLinkPowerThres) Return { - return DeviceSetNvLinkDeviceLowPowerThreshold(Device, Info) -} diff --git a/gen/nvml/event_set.go b/gen/nvml/event_set.go deleted file mode 100644 index c6315f5..0000000 --- a/gen/nvml/event_set.go +++ /dev/null @@ -1,42 +0,0 @@ -// 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.EventSetCreate() -func EventSetCreate() (EventSet, Return) { - var Set EventSet - ret := nvmlEventSetCreate(&Set) - return Set, ret -} - -// nvml.EventSetWait() -func EventSetWait(Set EventSet, Timeoutms uint32) (EventData, Return) { - var Data EventData - ret := nvmlEventSetWait(Set, &Data, Timeoutms) - return Data, ret -} - -func (Set EventSet) Wait(Timeoutms uint32) (EventData, Return) { - return EventSetWait(Set, Timeoutms) -} - -// nvml.EventSetFree() -func EventSetFree(Set EventSet) Return { - return nvmlEventSetFree(Set) -} - -func (Set EventSet) Free() Return { - return EventSetFree(Set) -} diff --git a/gen/nvml/gpm.go b/gen/nvml/gpm.go deleted file mode 100644 index c46c5d7..0000000 --- a/gen/nvml/gpm.go +++ /dev/null @@ -1,93 +0,0 @@ -// 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 - -// nvml.GpmMetricsGet() -type GpmMetricsGetVType struct { - metricsGet *GpmMetricsGetType -} - -func GpmMetricsGetV(MetricsGet *GpmMetricsGetType) GpmMetricsGetVType { - return GpmMetricsGetVType{MetricsGet} -} - -func (MetricsGetV GpmMetricsGetVType) V1() Return { - MetricsGetV.metricsGet.Version = 1 - return nvmlGpmMetricsGet(MetricsGetV.metricsGet) -} - -func GpmMetricsGet(MetricsGet *GpmMetricsGetType) Return { - MetricsGet.Version = GPM_METRICS_GET_VERSION - return nvmlGpmMetricsGet(MetricsGet) -} - -// nvml.GpmSampleFree() -func GpmSampleFree(GpmSample GpmSample) Return { - return nvmlGpmSampleFree(GpmSample) -} - -// nvml.GpmSampleAlloc() -func GpmSampleAlloc(GpmSample *GpmSample) Return { - return nvmlGpmSampleAlloc(GpmSample) -} - -// nvml.GpmSampleGet() -func GpmSampleGet(Device Device, GpmSample GpmSample) Return { - return nvmlGpmSampleGet(Device, GpmSample) -} - -func (Device Device) GpmSampleGet(GpmSample GpmSample) Return { - return GpmSampleGet(Device, GpmSample) -} - -// nvml.GpmQueryDeviceSupport() -type GpmSupportV struct { - device Device -} - -func GpmQueryDeviceSupportV(Device Device) GpmSupportV { - return GpmSupportV{Device} -} - -func (Device Device) GpmQueryDeviceSupportV() GpmSupportV { - return GpmSupportV{Device} -} - -func (GpmSupportV GpmSupportV) V1() (GpmSupport, Return) { - var GpmSupport GpmSupport - GpmSupport.Version = 1 - ret := nvmlGpmQueryDeviceSupport(GpmSupportV.device, &GpmSupport) - return GpmSupport, ret -} - -func GpmQueryDeviceSupport(Device Device) (GpmSupport, Return) { - var GpmSupport GpmSupport - GpmSupport.Version = GPM_SUPPORT_VERSION - ret := nvmlGpmQueryDeviceSupport(Device, &GpmSupport) - return GpmSupport, ret -} - -func (Device Device) GpmQueryDeviceSupport() (GpmSupport, Return) { - return GpmQueryDeviceSupport(Device) -} - -// nvml.GpmMigSampleGet() -func GpmMigSampleGet(Device Device, GpuInstanceId int, GpmSample GpmSample) Return { - return nvmlGpmMigSampleGet(Device, uint32(GpuInstanceId), GpmSample) -} - -func (Device Device) GpmMigSampleGet(GpuInstanceId int, GpmSample GpmSample) Return { - return GpmMigSampleGet(Device, GpuInstanceId, GpmSample) -} diff --git a/gen/nvml/init.go b/gen/nvml/init.go deleted file mode 100644 index e2bc943..0000000 --- a/gen/nvml/init.go +++ /dev/null @@ -1,48 +0,0 @@ -// 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 - -import "C" - -// nvml.Init() -func Init() Return { - if err := libnvml.load(); err != nil { - return ERROR_LIBRARY_NOT_FOUND - } - return nvmlInit() -} - -// nvml.InitWithFlags() -func InitWithFlags(Flags uint32) Return { - if err := libnvml.load(); err != nil { - return ERROR_LIBRARY_NOT_FOUND - } - return nvmlInitWithFlags(Flags) -} - -// nvml.Shutdown() -func Shutdown() Return { - ret := nvmlShutdown() - if ret != SUCCESS { - return ret - } - - err := libnvml.close() - if err != nil { - panic(err) - } - - return ret -} diff --git a/gen/nvml/lib.go b/gen/nvml/lib.go deleted file mode 100644 index be4b3fb..0000000 --- a/gen/nvml/lib.go +++ /dev/null @@ -1,299 +0,0 @@ -/** -# Copyright 2023 NVIDIA CORPORATION -# -# 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 - -import ( - "errors" - "fmt" - "sync" - - "github.com/NVIDIA/go-nvml/pkg/dl" -) - -import "C" - -const ( - defaultNvmlLibraryName = "libnvidia-ml.so.1" - defaultNvmlLibraryLoadFlags = dl.RTLD_LAZY | dl.RTLD_GLOBAL -) - -var errLibraryNotLoaded = errors.New("library not loaded") -var errLibraryAlreadyLoaded = errors.New("library already loaded") - -// library represents an nvml library. -// This includes a reference to the underlying DynamicLibrary -type library struct { - sync.Mutex - path string - flags int - refcount refcount - dl dynamicLibrary -} - -// libnvml is a global instance of the nvml library. -var libnvml = library{ - path: defaultNvmlLibraryName, - flags: defaultNvmlLibraryLoadFlags, -} - -var _ Interface = (*library)(nil) - -// GetLibrary returns a the library as a Library interface. -func (l *library) GetLibrary() Library { - return l -} - -// GetLibrary returns a representation of the underlying library that implements the Library interface. -func GetLibrary() Library { - return libnvml.GetLibrary() -} - -// Lookup checks whether the specified library symbol exists in the library. -// Note that this requires that the library be loaded. -func (l *library) Lookup(name string) error { - if l == nil || l.dl == nil { - return fmt.Errorf("error looking up %s: %w", name, errLibraryNotLoaded) - } - return l.dl.Lookup(name) -} - -// newDynamicLibrary is a function variable that can be overridden for testing. -var newDynamicLibrary = func(path string, flags int) dynamicLibrary { - return dl.New(path, flags) -} - -// load initializes the library and updates the versioned symbols. -// Multiple calls to an already loaded library will return without error. -func (l *library) load() (rerr error) { - l.Lock() - defer l.Unlock() - - defer func() { l.refcount.IncOnNoError(rerr) }() - if l.refcount > 0 { - return nil - } - - dl := newDynamicLibrary(l.path, l.flags) - if err := dl.Open(); err != nil { - return fmt.Errorf("error opening %s: %w", l.path, err) - } - - l.dl = dl - l.updateVersionedSymbols() - - return nil -} - -// close the underlying library and ensure that the global pointer to the -// library is set to nil to ensure that subsequent calls to open will reinitialize it. -// Multiple calls to an already closed nvml library will return without error. -func (l *library) close() (rerr error) { - l.Lock() - defer l.Unlock() - - defer func() { l.refcount.DecOnNoError(rerr) }() - if l.refcount != 1 { - return nil - } - - if err := l.dl.Close(); err != nil { - return fmt.Errorf("error closing %s: %w", l.path, err) - } - - l.dl = nil - - return nil -} - -// Default all versioned APIs to v1 (to infer the types) -var nvmlInit = nvmlInit_v1 -var nvmlDeviceGetPciInfo = nvmlDeviceGetPciInfo_v1 -var nvmlDeviceGetCount = nvmlDeviceGetCount_v1 -var nvmlDeviceGetHandleByIndex = nvmlDeviceGetHandleByIndex_v1 -var nvmlDeviceGetHandleByPciBusId = nvmlDeviceGetHandleByPciBusId_v1 -var nvmlDeviceGetNvLinkRemotePciInfo = nvmlDeviceGetNvLinkRemotePciInfo_v1 -var nvmlDeviceRemoveGpu = nvmlDeviceRemoveGpu_v1 -var nvmlDeviceGetGridLicensableFeatures = nvmlDeviceGetGridLicensableFeatures_v1 -var nvmlEventSetWait = nvmlEventSetWait_v1 -var nvmlDeviceGetAttributes = nvmlDeviceGetAttributes_v1 -var nvmlComputeInstanceGetInfo = nvmlComputeInstanceGetInfo_v1 -var DeviceGetComputeRunningProcesses = deviceGetComputeRunningProcesses_v1 -var DeviceGetGraphicsRunningProcesses = deviceGetGraphicsRunningProcesses_v1 -var DeviceGetMPSComputeRunningProcesses = deviceGetMPSComputeRunningProcesses_v1 -var GetBlacklistDeviceCount = GetExcludedDeviceCount -var GetBlacklistDeviceInfoByIndex = GetExcludedDeviceInfoByIndex -var nvmlDeviceGetGpuInstancePossiblePlacements = nvmlDeviceGetGpuInstancePossiblePlacements_v1 -var nvmlVgpuInstanceGetLicenseInfo = nvmlVgpuInstanceGetLicenseInfo_v1 - -// BlacklistDeviceInfo was replaced by ExcludedDeviceInfo -type BlacklistDeviceInfo = ExcludedDeviceInfo - -type ProcessInfo_v1Slice []ProcessInfo_v1 -type ProcessInfo_v2Slice []ProcessInfo_v2 - -func (pis ProcessInfo_v1Slice) ToProcessInfoSlice() []ProcessInfo { - var newInfos []ProcessInfo - for _, pi := range pis { - info := ProcessInfo{ - Pid: pi.Pid, - UsedGpuMemory: pi.UsedGpuMemory, - GpuInstanceId: 0xFFFFFFFF, // GPU instance ID is invalid in v1 - ComputeInstanceId: 0xFFFFFFFF, // Compute instance ID is invalid in v1 - } - newInfos = append(newInfos, info) - } - return newInfos -} - -func (pis ProcessInfo_v2Slice) ToProcessInfoSlice() []ProcessInfo { - var newInfos []ProcessInfo - for _, pi := range pis { - info := ProcessInfo(pi) - newInfos = append(newInfos, info) - } - return newInfos -} - -// updateVersionedSymbols checks for versioned symbols in the loaded dynamic library. -// If newer versioned symbols exist, these replace the default `v1` symbols initialized above. -// When new versioned symbols are added, these would have to be initialized above and have -// corresponding checks and subsequent assignments added below. -func (l *library) updateVersionedSymbols() { - err := l.Lookup("nvmlInit_v2") - if err == nil { - nvmlInit = nvmlInit_v2 - } - err = l.Lookup("nvmlDeviceGetPciInfo_v2") - if err == nil { - nvmlDeviceGetPciInfo = nvmlDeviceGetPciInfo_v2 - } - err = l.Lookup("nvmlDeviceGetPciInfo_v3") - if err == nil { - nvmlDeviceGetPciInfo = nvmlDeviceGetPciInfo_v3 - } - err = l.Lookup("nvmlDeviceGetCount_v2") - if err == nil { - nvmlDeviceGetCount = nvmlDeviceGetCount_v2 - } - err = l.Lookup("nvmlDeviceGetHandleByIndex_v2") - if err == nil { - nvmlDeviceGetHandleByIndex = nvmlDeviceGetHandleByIndex_v2 - } - err = l.Lookup("nvmlDeviceGetHandleByPciBusId_v2") - if err == nil { - nvmlDeviceGetHandleByPciBusId = nvmlDeviceGetHandleByPciBusId_v2 - } - err = l.Lookup("nvmlDeviceGetNvLinkRemotePciInfo_v2") - if err == nil { - nvmlDeviceGetNvLinkRemotePciInfo = nvmlDeviceGetNvLinkRemotePciInfo_v2 - } - // Unable to overwrite nvmlDeviceRemoveGpu() because the v2 function takes - // a different set of parameters than the v1 function. - //err = l.Lookup("nvmlDeviceRemoveGpu_v2") - //if err == nil { - // nvmlDeviceRemoveGpu = nvmlDeviceRemoveGpu_v2 - //} - err = l.Lookup("nvmlDeviceGetGridLicensableFeatures_v2") - if err == nil { - nvmlDeviceGetGridLicensableFeatures = nvmlDeviceGetGridLicensableFeatures_v2 - } - err = l.Lookup("nvmlDeviceGetGridLicensableFeatures_v3") - if err == nil { - nvmlDeviceGetGridLicensableFeatures = nvmlDeviceGetGridLicensableFeatures_v3 - } - err = l.Lookup("nvmlDeviceGetGridLicensableFeatures_v4") - if err == nil { - nvmlDeviceGetGridLicensableFeatures = nvmlDeviceGetGridLicensableFeatures_v4 - } - err = l.Lookup("nvmlEventSetWait_v2") - if err == nil { - nvmlEventSetWait = nvmlEventSetWait_v2 - } - err = l.Lookup("nvmlDeviceGetAttributes_v2") - if err == nil { - nvmlDeviceGetAttributes = nvmlDeviceGetAttributes_v2 - } - err = l.Lookup("nvmlComputeInstanceGetInfo_v2") - if err == nil { - nvmlComputeInstanceGetInfo = nvmlComputeInstanceGetInfo_v2 - } - err = l.Lookup("nvmlDeviceGetComputeRunningProcesses_v2") - if err == nil { - DeviceGetComputeRunningProcesses = deviceGetComputeRunningProcesses_v2 - } - err = l.Lookup("nvmlDeviceGetComputeRunningProcesses_v3") - if err == nil { - DeviceGetComputeRunningProcesses = deviceGetComputeRunningProcesses_v3 - } - err = l.Lookup("nvmlDeviceGetGraphicsRunningProcesses_v2") - if err == nil { - DeviceGetGraphicsRunningProcesses = deviceGetGraphicsRunningProcesses_v2 - } - err = l.Lookup("nvmlDeviceGetGraphicsRunningProcesses_v3") - if err == nil { - DeviceGetGraphicsRunningProcesses = deviceGetGraphicsRunningProcesses_v3 - } - err = l.Lookup("nvmlDeviceGetMPSComputeRunningProcesses_v2") - if err == nil { - DeviceGetMPSComputeRunningProcesses = deviceGetMPSComputeRunningProcesses_v2 - } - err = l.Lookup("nvmlDeviceGetMPSComputeRunningProcesses_v3") - if err == nil { - DeviceGetMPSComputeRunningProcesses = deviceGetMPSComputeRunningProcesses_v3 - } - err = l.Lookup("nvmlDeviceGetGpuInstancePossiblePlacements_v2") - if err == nil { - nvmlDeviceGetGpuInstancePossiblePlacements = nvmlDeviceGetGpuInstancePossiblePlacements_v2 - } - err = l.Lookup("nvmlVgpuInstanceGetLicenseInfo_v2") - if err == nil { - nvmlVgpuInstanceGetLicenseInfo = nvmlVgpuInstanceGetLicenseInfo_v2 - } -} - -// LibraryOption represents a functional option to configure the underlying NVML library -type LibraryOption func(*library) - -// WithLibraryPath provides an option to set the library name to be used by the NVML library. -func WithLibraryPath(path string) LibraryOption { - return func(l *library) { - l.path = path - } -} - -// SetLibraryOptions applies the specified options to the NVML library. -// If this is called when a library is already loaded, and error is raised. -func SetLibraryOptions(opts ...LibraryOption) error { - libnvml.Lock() - defer libnvml.Unlock() - if libnvml.dl != nil { - return errLibraryAlreadyLoaded - } - - for _, opt := range opts { - opt(&libnvml) - } - - if libnvml.path == "" { - libnvml.path = defaultNvmlLibraryName - } - if libnvml.flags == 0 { - libnvml.flags = defaultNvmlLibraryLoadFlags - } - - return nil -} diff --git a/gen/nvml/lib_test.go b/gen/nvml/lib_test.go deleted file mode 100644 index cfe8477..0000000 --- a/gen/nvml/lib_test.go +++ /dev/null @@ -1,264 +0,0 @@ -/** -# Copyright 2023 NVIDIA CORPORATION -# -# 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 - -import ( - "errors" - "fmt" - "testing" - - "github.com/stretchr/testify/require" -) - -func TestLookupFromDefault(t *testing.T) { - errClose := errors.New("close error") - errOpen := errors.New("open error") - errLookup := errors.New("lookup error") - - testCases := []struct { - description string - library dynamicLibrary - skipLoadLibrary bool - expectedLoadError error - expectedLookupErrror error - expectedCloseError error - }{ - { - description: "library not loaded yields error", - library: &dynamicLibraryMock{}, - skipLoadLibrary: true, - expectedLookupErrror: errLibraryNotLoaded, - }, - { - description: "open error is returned", - library: &dynamicLibraryMock{ - OpenFunc: func() error { - return errOpen - }, - }, - - expectedLoadError: errOpen, - expectedLookupErrror: errLibraryNotLoaded, - }, - { - description: "lookup error is returned", - library: &dynamicLibraryMock{ - OpenFunc: func() error { - return nil - }, - LookupFunc: func(s string) error { - return fmt.Errorf("%w: %s", errLookup, s) - }, - CloseFunc: func() error { - return nil - }, - }, - - expectedLookupErrror: errLookup, - }, - { - description: "lookup succeeds", - library: &dynamicLibraryMock{ - OpenFunc: func() error { - return nil - }, - LookupFunc: func(s string) error { - return nil - }, - CloseFunc: func() error { - return nil - }, - }, - }, - { - description: "lookup succeeds", - library: &dynamicLibraryMock{ - OpenFunc: func() error { - return nil - }, - LookupFunc: func(s string) error { - return nil - }, - CloseFunc: func() error { - return nil - }, - }, - }, - { - description: "close error is returned", - library: &dynamicLibraryMock{ - OpenFunc: func() error { - return nil - }, - LookupFunc: func(s string) error { - return nil - }, - CloseFunc: func() error { - return errClose - }, - }, - expectedCloseError: errClose, - }, - } - - for _, tc := range testCases { - t.Run(tc.description, func(t *testing.T) { - defer setNewDynamicLibraryDuringTest(tc.library)() - defer resetLibrary() - l := GetLibrary() - if !tc.skipLoadLibrary { - require.ErrorIs(t, libnvml.load(), tc.expectedLoadError) - } - require.ErrorIs(t, l.Lookup("symbol"), tc.expectedLookupErrror) - require.ErrorIs(t, libnvml.close(), tc.expectedCloseError) - if tc.expectedCloseError == nil { - require.Nil(t, libnvml.dl) - } else { - require.Equal(t, tc.library, libnvml.dl) - } - }) - } -} - -func TestLoadAndCloseNesting(t *testing.T) { - dl := &dynamicLibraryMock{ - OpenFunc: func() error { - return nil - }, - CloseFunc: func() error { - return nil - }, - } - - defer setNewDynamicLibraryDuringTest(dl)() - defer resetLibrary() - - // When calling close before opening the library nothing happens. - require.Equal(t, 0, len(dl.calls.Close)) - require.Nil(t, libnvml.close()) - require.Equal(t, 0, len(dl.calls.Close)) - - // When calling load twice, the library was only opened once - require.Equal(t, 0, len(dl.calls.Open)) - require.Nil(t, libnvml.load()) - require.Equal(t, 1, len(dl.calls.Open)) - require.Nil(t, libnvml.load()) - require.Equal(t, 1, len(dl.calls.Open)) - - // Only after calling close twice, was the library closed - require.Equal(t, 0, len(dl.calls.Close)) - require.Nil(t, libnvml.close()) - require.Equal(t, 0, len(dl.calls.Close)) - require.Nil(t, libnvml.close()) - require.Equal(t, 1, len(dl.calls.Close)) - - // Calling close again doesn't attempt to close the library again - require.Nil(t, libnvml.close()) - require.Equal(t, 1, len(dl.calls.Close)) -} - -func TestLoadAndCloseWithErrors(t *testing.T) { - testCases := []struct { - description string - dl dynamicLibrary - expectedLoadRefcount refcount - expectedCloseRefcount refcount - }{ - { - description: "regular flow", - dl: &dynamicLibraryMock{ - OpenFunc: func() error { - return nil - }, - CloseFunc: func() error { - return nil - }, - }, - expectedLoadRefcount: 1, - expectedCloseRefcount: 0, - }, - { - description: "open error", - dl: &dynamicLibraryMock{ - OpenFunc: func() error { - return errors.New("") - }, - CloseFunc: func() error { - return nil - }, - }, - expectedLoadRefcount: 0, - expectedCloseRefcount: 0, - }, - { - description: "close error", - dl: &dynamicLibraryMock{ - OpenFunc: func() error { - return nil - }, - CloseFunc: func() error { - return errors.New("") - }, - }, - expectedLoadRefcount: 1, - expectedCloseRefcount: 1, - }, - { - description: "open and close error", - dl: &dynamicLibraryMock{ - OpenFunc: func() error { - return errors.New("") - }, - CloseFunc: func() error { - return errors.New("") - }, - }, - expectedLoadRefcount: 0, - expectedCloseRefcount: 0, - }, - } - - for _, tc := range testCases { - t.Run(tc.description, func(t *testing.T) { - defer setNewDynamicLibraryDuringTest(tc.dl)() - defer resetLibrary() - - _ = libnvml.load() - require.Equal(t, tc.expectedLoadRefcount, libnvml.refcount) - _ = libnvml.close() - require.Equal(t, tc.expectedCloseRefcount, libnvml.refcount) - }) - } -} - -func setNewDynamicLibraryDuringTest(dl dynamicLibrary) func() { - original := newDynamicLibrary - newDynamicLibrary = func(string, int) dynamicLibrary { - return dl - } - - return func() { - newDynamicLibrary = original - } -} - -func resetLibrary() { - libnvml = library{ - path: defaultNvmlLibraryName, - flags: defaultNvmlLibraryLoadFlags, - } -} diff --git a/gen/nvml/nvml_test.go b/gen/nvml/nvml_test.go deleted file mode 100644 index 5e0f98f..0000000 --- a/gen/nvml/nvml_test.go +++ /dev/null @@ -1,305 +0,0 @@ -// 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 - -import ( - "testing" - - "github.com/NVIDIA/go-nvml/pkg/dl" -) - -func requireLibNvidiaML(t *testing.T) { - lib := dl.New(defaultNvmlLibraryName, defaultNvmlLibraryLoadFlags) - if err := lib.Open(); err != nil { - t.Skipf("This test requires %v", defaultNvmlLibraryName) - } - lib.Close() -} - -func TestInit(t *testing.T) { - requireLibNvidiaML(t) - - ret := Init() - if ret != SUCCESS { - t.Errorf("Init: %v", ret) - } else { - t.Logf("Init: %v", ret) - } - - ret = Shutdown() - if ret != SUCCESS { - t.Errorf("Shutdown: %v", ret) - } else { - t.Logf("Shutdown: %v", ret) - } -} - -func TestSystem(t *testing.T) { - requireLibNvidiaML(t) - - Init() - defer Shutdown() - - driverVersion, ret := SystemGetDriverVersion() - if ret != SUCCESS { - t.Errorf("SystemGetDriverVersion: %v", ret) - } else { - t.Logf("SystemGetDriverVersion: %v", ret) - t.Logf(" version: %v", driverVersion) - } - - nvmlVersion, ret := SystemGetNVMLVersion() - if ret != SUCCESS { - t.Errorf("SystemGetNVMLVersion: %v", ret) - } else { - t.Logf("SystemGetNVMLVersion: %v", ret) - t.Logf(" version: %v", nvmlVersion) - } - - cudaDriverVersion, ret := SystemGetCudaDriverVersion() - if ret != SUCCESS { - t.Errorf("SystemGetCudaDriverVersion: %v", ret) - } else { - t.Logf("SystemGetCudaDriverVersion: %v", ret) - t.Logf(" version: %v", cudaDriverVersion) - } - - cudaDriverVersionV2, ret := SystemGetCudaDriverVersion_v2() - if ret != SUCCESS { - t.Errorf("SystemGetCudaDriverVersion_v2: %v", ret) - } else { - t.Logf("SystemGetCudaDriverVersion_v2: %v", ret) - t.Logf(" version: %v", cudaDriverVersionV2) - } - - processName, ret := SystemGetProcessName(1) - if ret != SUCCESS { - t.Errorf("SystemGetProcessName: %v", ret) - } else { - t.Logf("SystemGetProcessName: %v", ret) - t.Logf(" name: %v", processName) - } - - hwbcEntries, ret := SystemGetHicVersion() - if ret != SUCCESS { - t.Errorf("SystemGetHicVersion: %v", ret) - } else { - t.Logf("SystemGetHicVersion: %v", ret) - t.Logf(" count: %v", len(hwbcEntries)) - for i, entry := range hwbcEntries { - t.Logf(" device[%v]: %v", i, entry) - } - } - - deviceArray, ret := SystemGetTopologyGpuSet(0) - if ret != SUCCESS { - t.Errorf("SystemGetTopologyGpuSet: %v", ret) - } else { - t.Logf("SystemGetTopologyGpuSet: %v", ret) - t.Logf(" count: %v", len(deviceArray)) - for i, device := range deviceArray { - t.Logf(" device[%v]: %v", i, device) - } - } -} - -func TestUnit(t *testing.T) { - requireLibNvidiaML(t) - - Init() - defer Shutdown() - - unitCount, ret := UnitGetCount() - if ret != SUCCESS { - t.Errorf("UnitGetCount: %v", ret) - } else { - t.Logf("UnitGetCount: %v", ret) - t.Logf(" count: %v", unitCount) - } - - if unitCount == 0 { - t.Skip("Skipping test with no Units.") - } - - unit, ret := UnitGetHandleByIndex(0) - if ret != SUCCESS { - t.Errorf("UnitGetHandleByIndex: %v", ret) - } else { - t.Logf("UnitGetHandleByIndex: %v", ret) - t.Logf(" unit: %v", unit) - } - - info, ret := UnitGetUnitInfo(unit) - if ret != SUCCESS { - t.Errorf("UnitGetUnitInfo: %v", ret) - } else { - t.Logf("UnitGetUnitInfo: %v", ret) - t.Logf(" info: %v", info) - } - - info, ret = unit.GetUnitInfo() - if ret != SUCCESS { - t.Errorf("Unit.GetUnitInfo: %v", ret) - } else { - t.Logf("Unit.GetUnitInfo: %v", ret) - t.Logf(" info: %v", info) - } - - state, ret := UnitGetLedState(unit) - if ret != SUCCESS { - t.Errorf("UnitGetLedState: %v", ret) - } else { - t.Logf("UnitGetLedState: %v", ret) - t.Logf(" state: %v", state) - } - - state, ret = unit.GetLedState() - if ret != SUCCESS { - t.Errorf("Unit.GetLedState: %v", ret) - } else { - t.Logf("Unit.GetLedState: %v", ret) - t.Logf(" state: %v", state) - } - - psu, ret := UnitGetPsuInfo(unit) - if ret != SUCCESS { - t.Errorf("UnitGetPsuInfo: %v", ret) - } else { - t.Logf("UnitGetPsuInfo: %v", ret) - t.Logf(" psu: %v", psu) - } - - psu, ret = unit.GetPsuInfo() - if ret != SUCCESS { - t.Errorf("Unit.GetPsuInfo: %v", ret) - } else { - t.Logf("Unit.GetPsuInfo: %v", ret) - t.Logf(" psu: %v", psu) - } - - temp, ret := UnitGetTemperature(unit, 0) - if ret != SUCCESS { - t.Errorf("UnitGetTemperature: %v", ret) - } else { - t.Logf("UnitGetTemperature: %v", ret) - t.Logf(" temp: %v", temp) - } - - temp, ret = unit.GetTemperature(0) - if ret != SUCCESS { - t.Errorf("Unit.GetTemperature: %v", ret) - } else { - t.Logf("Unit.GetTemperature: %v", ret) - t.Logf(" temp: %v", temp) - } - - speed, ret := UnitGetFanSpeedInfo(unit) - if ret != SUCCESS { - t.Errorf("UnitGetFanSpeedInfo: %v", ret) - } else { - t.Logf("UnitGetFanSpeedInfo: %v", ret) - t.Logf(" speed: %v", speed) - } - - speed, ret = unit.GetFanSpeedInfo() - if ret != SUCCESS { - t.Errorf("Unit.GetFanSpeedInfo: %v", ret) - } else { - t.Logf("Unit.GetFanSpeedInfo: %v", ret) - t.Logf(" speed: %v", speed) - } - - devices, ret := UnitGetDevices(unit) - if ret != SUCCESS { - t.Errorf("UnitGetDevices: %v", ret) - } else { - t.Logf("UnitGetDevices: %v", ret) - t.Logf(" count: %v", len(devices)) - for i, device := range devices { - t.Logf(" device[%v]: %v", i, device) - } - } - - devices, ret = unit.GetDevices() - if ret != SUCCESS { - t.Errorf("Unit.GetDevices: %v", ret) - } else { - t.Logf("Unit.GetDevices: %v", ret) - t.Logf(" count: %v", len(devices)) - for i, device := range devices { - t.Logf(" device[%v]: %v", i, device) - } - } - - ret = UnitSetLedState(unit, 0) - if ret != SUCCESS { - t.Errorf("UnitSetLedState: %v", ret) - } else { - t.Logf("UnitSetLedState: %v", ret) - } - - ret = unit.SetLedState(0) - if ret != SUCCESS { - t.Errorf("Unit.SetLedState: %v", ret) - } else { - t.Logf("Unit.SetLedState: %v", ret) - } -} - -func TestEventSet(t *testing.T) { - requireLibNvidiaML(t) - - Init() - defer Shutdown() - - set, ret := EventSetCreate() - if ret != SUCCESS { - t.Errorf("EventSetCreate: %v", ret) - } else { - t.Logf("EventSetCreate: %v", ret) - t.Logf(" set: %v", set) - } - - data, ret := EventSetWait(set, 0) - if ret != ERROR_TIMEOUT { - t.Errorf("EventSetWait: %v", ret) - } else { - t.Logf("EventSetWait: %v", ret) - t.Logf(" data: %v", data) - } - - data, ret = set.Wait(0) - if ret != ERROR_TIMEOUT { - t.Errorf("EventSet.Wait: %v", ret) - } else { - t.Logf("EventSet.Wait: %v", ret) - t.Logf(" data: %v", data) - } - - ret = EventSetFree(set) - if ret != SUCCESS { - t.Errorf("EventSetFree: %v", ret) - } else { - t.Logf("EventSetFree: %v", ret) - } - - set, _ = EventSetCreate() - ret = set.Free() - if ret != SUCCESS { - t.Errorf("EventSet.Free: %v", ret) - } else { - t.Logf("EventSet.Free: %v", ret) - } -} diff --git a/gen/nvml/refcount.go b/gen/nvml/refcount.go deleted file mode 100644 index 4d1e212..0000000 --- a/gen/nvml/refcount.go +++ /dev/null @@ -1,31 +0,0 @@ -/** -# Copyright 2024 NVIDIA CORPORATION -# -# 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 - -type refcount int - -func (r *refcount) IncOnNoError(err error) { - if err == nil { - (*r)++ - } -} - -func (r *refcount) DecOnNoError(err error) { - if err == nil && (*r) > 0 { - (*r)-- - } -} diff --git a/gen/nvml/refcount_test.go b/gen/nvml/refcount_test.go deleted file mode 100644 index 65001c2..0000000 --- a/gen/nvml/refcount_test.go +++ /dev/null @@ -1,139 +0,0 @@ -/** -# Copyright 2023 NVIDIA CORPORATION -# -# 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 - -import ( - "errors" - "testing" - - "github.com/stretchr/testify/require" -) - -func TestRefcount(t *testing.T) { - testCases := []struct { - description string - workload func(r *refcount) - expectedRefcount refcount - }{ - { - description: "No inc or dec", - workload: func(r *refcount) {}, - expectedRefcount: refcount(0), - }, - { - description: "Single inc, no error", - workload: func(r *refcount) { - r.IncOnNoError(nil) - }, - expectedRefcount: refcount(1), - }, - { - description: "Single inc, with error", - workload: func(r *refcount) { - r.IncOnNoError(errors.New("")) - }, - expectedRefcount: refcount(0), - }, - { - description: "Double inc, no error", - workload: func(r *refcount) { - r.IncOnNoError(nil) - r.IncOnNoError(nil) - }, - expectedRefcount: refcount(2), - }, - { - description: "Double inc, one with error", - workload: func(r *refcount) { - r.IncOnNoError(nil) - r.IncOnNoError(errors.New("")) - }, - expectedRefcount: refcount(1), - }, - { - description: "Single dec, no error", - workload: func(r *refcount) { - r.DecOnNoError(nil) - }, - expectedRefcount: refcount(0), - }, - { - description: "Single dec, with error", - workload: func(r *refcount) { - r.DecOnNoError(errors.New("")) - }, - expectedRefcount: refcount(0), - }, - { - description: "Single inc, single dec, no errors", - workload: func(r *refcount) { - r.IncOnNoError(nil) - r.DecOnNoError(nil) - }, - expectedRefcount: refcount(0), - }, - { - description: "Double inc, Double dec, no errors", - workload: func(r *refcount) { - r.IncOnNoError(nil) - r.IncOnNoError(nil) - r.DecOnNoError(nil) - r.DecOnNoError(nil) - }, - expectedRefcount: refcount(0), - }, - { - description: "Double inc, Double dec, one inc error", - workload: func(r *refcount) { - r.IncOnNoError(nil) - r.IncOnNoError(errors.New("")) - r.DecOnNoError(nil) - r.DecOnNoError(nil) - }, - expectedRefcount: refcount(0), - }, - { - description: "Double inc, Double dec, one dec error", - workload: func(r *refcount) { - r.IncOnNoError(nil) - r.IncOnNoError(nil) - r.DecOnNoError(nil) - r.DecOnNoError(errors.New("")) - }, - expectedRefcount: refcount(1), - }, - { - description: "Double inc, Tripple dec, one dec error early on", - workload: func(r *refcount) { - r.IncOnNoError(nil) - r.IncOnNoError(nil) - r.DecOnNoError(errors.New("")) - r.DecOnNoError(nil) - r.DecOnNoError(nil) - }, - expectedRefcount: refcount(0), - }, - } - - for _, tc := range testCases { - t.Run(tc.description, func(t *testing.T) { - var r refcount - tc.workload(&r) - require.Equal(t, tc.expectedRefcount, r) - }) - } -} diff --git a/gen/nvml/return.go b/gen/nvml/return.go deleted file mode 100644 index 0a0ccee..0000000 --- a/gen/nvml/return.go +++ /dev/null @@ -1,93 +0,0 @@ -// 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 - -import ( - "fmt" -) - -// nvml.ErrorString() -func ErrorString(r Return) string { - if err := GetLibrary().Lookup("nvmlErrorString"); err != nil { - return fallbackErrorStringFunc(r) - } - return nvmlErrorString(r) -} - -// fallbackErrorStringFunc provides a basic nvmlErrorString implementation. -// This allows the nvml.ErrorString function to be used even if the NVML library -// is not loaded. -var fallbackErrorStringFunc = func(r Return) string { - switch r { - case SUCCESS: - return "SUCCESS" - case ERROR_UNINITIALIZED: - return "ERROR_UNINITIALIZED" - case ERROR_INVALID_ARGUMENT: - return "ERROR_INVALID_ARGUMENT" - case ERROR_NOT_SUPPORTED: - return "ERROR_NOT_SUPPORTED" - case ERROR_NO_PERMISSION: - return "ERROR_NO_PERMISSION" - case ERROR_ALREADY_INITIALIZED: - return "ERROR_ALREADY_INITIALIZED" - case ERROR_NOT_FOUND: - return "ERROR_NOT_FOUND" - case ERROR_INSUFFICIENT_SIZE: - return "ERROR_INSUFFICIENT_SIZE" - case ERROR_INSUFFICIENT_POWER: - return "ERROR_INSUFFICIENT_POWER" - case ERROR_DRIVER_NOT_LOADED: - return "ERROR_DRIVER_NOT_LOADED" - case ERROR_TIMEOUT: - return "ERROR_TIMEOUT" - case ERROR_IRQ_ISSUE: - return "ERROR_IRQ_ISSUE" - case ERROR_LIBRARY_NOT_FOUND: - return "ERROR_LIBRARY_NOT_FOUND" - case ERROR_FUNCTION_NOT_FOUND: - return "ERROR_FUNCTION_NOT_FOUND" - case ERROR_CORRUPTED_INFOROM: - return "ERROR_CORRUPTED_INFOROM" - case ERROR_GPU_IS_LOST: - return "ERROR_GPU_IS_LOST" - case ERROR_RESET_REQUIRED: - return "ERROR_RESET_REQUIRED" - case ERROR_OPERATING_SYSTEM: - return "ERROR_OPERATING_SYSTEM" - case ERROR_LIB_RM_VERSION_MISMATCH: - return "ERROR_LIB_RM_VERSION_MISMATCH" - case ERROR_IN_USE: - return "ERROR_IN_USE" - case ERROR_MEMORY: - return "ERROR_MEMORY" - case ERROR_NO_DATA: - return "ERROR_NO_DATA" - case ERROR_VGPU_ECC_NOT_SUPPORTED: - return "ERROR_VGPU_ECC_NOT_SUPPORTED" - case ERROR_INSUFFICIENT_RESOURCES: - return "ERROR_INSUFFICIENT_RESOURCES" - case ERROR_FREQ_NOT_SUPPORTED: - return "ERROR_FREQ_NOT_SUPPORTED" - case ERROR_ARGUMENT_VERSION_MISMATCH: - return "ERROR_ARGUMENT_VERSION_MISMATCH" - case ERROR_DEPRECATED: - return "ERROR_DEPRECATED" - case ERROR_UNKNOWN: - return "ERROR_UNKNOWN" - default: - return fmt.Sprintf("unknown return value: %d", r) - } -} diff --git a/gen/nvml/system.go b/gen/nvml/system.go deleted file mode 100644 index 424f99b..0000000 --- a/gen/nvml/system.go +++ /dev/null @@ -1,81 +0,0 @@ -// 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.SystemGetDriverVersion() -func SystemGetDriverVersion() (string, Return) { - Version := make([]byte, SYSTEM_DRIVER_VERSION_BUFFER_SIZE) - ret := nvmlSystemGetDriverVersion(&Version[0], SYSTEM_DRIVER_VERSION_BUFFER_SIZE) - return string(Version[:clen(Version)]), ret -} - -// nvml.SystemGetNVMLVersion() -func SystemGetNVMLVersion() (string, Return) { - Version := make([]byte, SYSTEM_NVML_VERSION_BUFFER_SIZE) - ret := nvmlSystemGetNVMLVersion(&Version[0], SYSTEM_NVML_VERSION_BUFFER_SIZE) - return string(Version[:clen(Version)]), ret -} - -// nvml.SystemGetCudaDriverVersion() -func SystemGetCudaDriverVersion() (int, Return) { - var CudaDriverVersion int32 - ret := nvmlSystemGetCudaDriverVersion(&CudaDriverVersion) - return int(CudaDriverVersion), ret -} - -// nvml.SystemGetCudaDriverVersion_v2() -func SystemGetCudaDriverVersion_v2() (int, Return) { - var CudaDriverVersion int32 - ret := nvmlSystemGetCudaDriverVersion_v2(&CudaDriverVersion) - return int(CudaDriverVersion), ret -} - -// nvml.SystemGetProcessName() -func SystemGetProcessName(Pid int) (string, Return) { - Name := make([]byte, SYSTEM_PROCESS_NAME_BUFFER_SIZE) - ret := nvmlSystemGetProcessName(uint32(Pid), &Name[0], SYSTEM_PROCESS_NAME_BUFFER_SIZE) - return string(Name[:clen(Name)]), ret -} - -// nvml.SystemGetHicVersion() -func SystemGetHicVersion() ([]HwbcEntry, Return) { - var HwbcCount uint32 = 1 // Will be reduced upon returning - for { - HwbcEntries := make([]HwbcEntry, HwbcCount) - ret := nvmlSystemGetHicVersion(&HwbcCount, &HwbcEntries[0]) - if ret == SUCCESS { - return HwbcEntries[:HwbcCount], ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - HwbcCount *= 2 - } -} - -// nvml.SystemGetTopologyGpuSet() -func SystemGetTopologyGpuSet(CpuNumber int) ([]Device, Return) { - var Count uint32 - ret := nvmlSystemGetTopologyGpuSet(uint32(CpuNumber), &Count, nil) - if ret != SUCCESS { - return nil, ret - } - if Count == 0 { - return []Device{}, ret - } - DeviceArray := make([]Device, Count) - ret = nvmlSystemGetTopologyGpuSet(uint32(CpuNumber), &Count, &DeviceArray[0]) - return DeviceArray, ret -} diff --git a/gen/nvml/unit.go b/gen/nvml/unit.go deleted file mode 100644 index aba916a..0000000 --- a/gen/nvml/unit.go +++ /dev/null @@ -1,113 +0,0 @@ -// 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() -func UnitGetCount() (int, Return) { - var UnitCount uint32 - ret := nvmlUnitGetCount(&UnitCount) - return int(UnitCount), ret -} - -// nvml.UnitGetHandleByIndex() -func UnitGetHandleByIndex(Index int) (Unit, Return) { - var Unit Unit - ret := nvmlUnitGetHandleByIndex(uint32(Index), &Unit) - return Unit, ret -} - -// nvml.UnitGetUnitInfo() -func UnitGetUnitInfo(Unit Unit) (UnitInfo, Return) { - var Info UnitInfo - ret := nvmlUnitGetUnitInfo(Unit, &Info) - return Info, ret -} - -func (Unit Unit) GetUnitInfo() (UnitInfo, Return) { - return UnitGetUnitInfo(Unit) -} - -// nvml.UnitGetLedState() -func UnitGetLedState(Unit Unit) (LedState, Return) { - var State LedState - ret := nvmlUnitGetLedState(Unit, &State) - return State, ret -} - -func (Unit Unit) GetLedState() (LedState, Return) { - return UnitGetLedState(Unit) -} - -// nvml.UnitGetPsuInfo() -func UnitGetPsuInfo(Unit Unit) (PSUInfo, Return) { - var Psu PSUInfo - ret := nvmlUnitGetPsuInfo(Unit, &Psu) - return Psu, ret -} - -func (Unit Unit) GetPsuInfo() (PSUInfo, Return) { - return UnitGetPsuInfo(Unit) -} - -// nvml.UnitGetTemperature() -func UnitGetTemperature(Unit Unit, Type int) (uint32, Return) { - var Temp uint32 - ret := nvmlUnitGetTemperature(Unit, uint32(Type), &Temp) - return Temp, ret -} - -func (Unit Unit) GetTemperature(Type int) (uint32, Return) { - return UnitGetTemperature(Unit, Type) -} - -// nvml.UnitGetFanSpeedInfo() -func UnitGetFanSpeedInfo(Unit Unit) (UnitFanSpeeds, Return) { - var FanSpeeds UnitFanSpeeds - ret := nvmlUnitGetFanSpeedInfo(Unit, &FanSpeeds) - return FanSpeeds, ret -} - -func (Unit Unit) GetFanSpeedInfo() (UnitFanSpeeds, Return) { - return UnitGetFanSpeedInfo(Unit) -} - -// nvml.UnitGetDevices() -func UnitGetDevices(Unit Unit) ([]Device, Return) { - var DeviceCount uint32 = 1 // Will be reduced upon returning - for { - Devices := make([]Device, DeviceCount) - ret := nvmlUnitGetDevices(Unit, &DeviceCount, &Devices[0]) - if ret == SUCCESS { - return Devices[:DeviceCount], ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - DeviceCount *= 2 - } -} - -func (Unit Unit) GetDevices() ([]Device, Return) { - return UnitGetDevices(Unit) -} - -// nvml.UnitSetLedState() -func UnitSetLedState(Unit Unit, Color LedColor) Return { - return nvmlUnitSetLedState(Unit, Color) -} - -func (Unit Unit) SetLedState(Color LedColor) Return { - return UnitSetLedState(Unit, Color) -} diff --git a/gen/nvml/vgpu.go b/gen/nvml/vgpu.go deleted file mode 100644 index 2366fb7..0000000 --- a/gen/nvml/vgpu.go +++ /dev/null @@ -1,480 +0,0 @@ -// 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 - -import ( - "unsafe" -) - -// nvml.VgpuMetadata -type VgpuMetadata struct { - nvmlVgpuMetadata - OpaqueData []byte -} - -// nvml.VgpuPgpuMetadata -type VgpuPgpuMetadata struct { - nvmlVgpuPgpuMetadata - OpaqueData []byte -} - -// nvml.VgpuTypeGetClass() -func VgpuTypeGetClass(VgpuTypeId VgpuTypeId) (string, Return) { - var Size uint32 = DEVICE_NAME_BUFFER_SIZE - VgpuTypeClass := make([]byte, DEVICE_NAME_BUFFER_SIZE) - ret := nvmlVgpuTypeGetClass(VgpuTypeId, &VgpuTypeClass[0], &Size) - return string(VgpuTypeClass[:clen(VgpuTypeClass)]), ret -} - -func (VgpuTypeId VgpuTypeId) GetClass() (string, Return) { - return VgpuTypeGetClass(VgpuTypeId) -} - -// nvml.VgpuTypeGetName() -func VgpuTypeGetName(VgpuTypeId VgpuTypeId) (string, Return) { - var Size uint32 = DEVICE_NAME_BUFFER_SIZE - VgpuTypeName := make([]byte, DEVICE_NAME_BUFFER_SIZE) - ret := nvmlVgpuTypeGetName(VgpuTypeId, &VgpuTypeName[0], &Size) - return string(VgpuTypeName[:clen(VgpuTypeName)]), ret -} - -func (VgpuTypeId VgpuTypeId) GetName() (string, Return) { - return VgpuTypeGetName(VgpuTypeId) -} - -// nvml.VgpuTypeGetGpuInstanceProfileId() -func VgpuTypeGetGpuInstanceProfileId(VgpuTypeId VgpuTypeId) (uint32, Return) { - var Size uint32 - ret := nvmlVgpuTypeGetGpuInstanceProfileId(VgpuTypeId, &Size) - return Size, ret -} - -func (VgpuTypeId VgpuTypeId) GetGpuInstanceProfileId() (uint32, Return) { - return VgpuTypeGetGpuInstanceProfileId(VgpuTypeId) -} - -// nvml.VgpuTypeGetDeviceID() -func VgpuTypeGetDeviceID(VgpuTypeId VgpuTypeId) (uint64, uint64, Return) { - var DeviceID, SubsystemID uint64 - ret := nvmlVgpuTypeGetDeviceID(VgpuTypeId, &DeviceID, &SubsystemID) - return DeviceID, SubsystemID, ret -} - -func (VgpuTypeId VgpuTypeId) GetDeviceID() (uint64, uint64, Return) { - return VgpuTypeGetDeviceID(VgpuTypeId) -} - -// nvml.VgpuTypeGetFramebufferSize() -func VgpuTypeGetFramebufferSize(VgpuTypeId VgpuTypeId) (uint64, Return) { - var FbSize uint64 - ret := nvmlVgpuTypeGetFramebufferSize(VgpuTypeId, &FbSize) - return FbSize, ret -} - -func (VgpuTypeId VgpuTypeId) GetFramebufferSize() (uint64, Return) { - return VgpuTypeGetFramebufferSize(VgpuTypeId) -} - -// nvml.VgpuTypeGetNumDisplayHeads() -func VgpuTypeGetNumDisplayHeads(VgpuTypeId VgpuTypeId) (int, Return) { - var NumDisplayHeads uint32 - ret := nvmlVgpuTypeGetNumDisplayHeads(VgpuTypeId, &NumDisplayHeads) - return int(NumDisplayHeads), ret -} - -func (VgpuTypeId VgpuTypeId) GetNumDisplayHeads() (int, Return) { - return VgpuTypeGetNumDisplayHeads(VgpuTypeId) -} - -// nvml.VgpuTypeGetResolution() -func VgpuTypeGetResolution(VgpuTypeId VgpuTypeId, DisplayIndex int) (uint32, uint32, Return) { - var Xdim, Ydim uint32 - ret := nvmlVgpuTypeGetResolution(VgpuTypeId, uint32(DisplayIndex), &Xdim, &Ydim) - return Xdim, Ydim, ret -} - -func (VgpuTypeId VgpuTypeId) GetResolution(DisplayIndex int) (uint32, uint32, Return) { - return VgpuTypeGetResolution(VgpuTypeId, DisplayIndex) -} - -// nvml.VgpuTypeGetLicense() -func VgpuTypeGetLicense(VgpuTypeId VgpuTypeId) (string, Return) { - VgpuTypeLicenseString := make([]byte, GRID_LICENSE_BUFFER_SIZE) - ret := nvmlVgpuTypeGetLicense(VgpuTypeId, &VgpuTypeLicenseString[0], GRID_LICENSE_BUFFER_SIZE) - return string(VgpuTypeLicenseString[:clen(VgpuTypeLicenseString)]), ret -} - -func (VgpuTypeId VgpuTypeId) GetLicense() (string, Return) { - return VgpuTypeGetLicense(VgpuTypeId) -} - -// nvml.VgpuTypeGetFrameRateLimit() -func VgpuTypeGetFrameRateLimit(VgpuTypeId VgpuTypeId) (uint32, Return) { - var FrameRateLimit uint32 - ret := nvmlVgpuTypeGetFrameRateLimit(VgpuTypeId, &FrameRateLimit) - return FrameRateLimit, ret -} - -func (VgpuTypeId VgpuTypeId) GetFrameRateLimit() (uint32, Return) { - return VgpuTypeGetFrameRateLimit(VgpuTypeId) -} - -// nvml.VgpuTypeGetMaxInstances() -func VgpuTypeGetMaxInstances(Device Device, VgpuTypeId VgpuTypeId) (int, Return) { - var VgpuInstanceCount uint32 - ret := nvmlVgpuTypeGetMaxInstances(Device, VgpuTypeId, &VgpuInstanceCount) - return int(VgpuInstanceCount), ret -} - -func (Device Device) VgpuTypeGetMaxInstances(VgpuTypeId VgpuTypeId) (int, Return) { - return VgpuTypeGetMaxInstances(Device, VgpuTypeId) -} - -func (VgpuTypeId VgpuTypeId) GetMaxInstances(Device Device) (int, Return) { - return VgpuTypeGetMaxInstances(Device, VgpuTypeId) -} - -// nvml.VgpuTypeGetMaxInstancesPerVm() -func VgpuTypeGetMaxInstancesPerVm(VgpuTypeId VgpuTypeId) (int, Return) { - var VgpuInstanceCountPerVm uint32 - ret := nvmlVgpuTypeGetMaxInstancesPerVm(VgpuTypeId, &VgpuInstanceCountPerVm) - return int(VgpuInstanceCountPerVm), ret -} - -func (VgpuTypeId VgpuTypeId) GetMaxInstancesPerVm() (int, Return) { - return VgpuTypeGetMaxInstancesPerVm(VgpuTypeId) -} - -// nvml.VgpuInstanceGetVmID() -func VgpuInstanceGetVmID(VgpuInstance VgpuInstance) (string, VgpuVmIdType, Return) { - var VmIdType VgpuVmIdType - VmId := make([]byte, DEVICE_UUID_BUFFER_SIZE) - ret := nvmlVgpuInstanceGetVmID(VgpuInstance, &VmId[0], DEVICE_UUID_BUFFER_SIZE, &VmIdType) - return string(VmId[:clen(VmId)]), VmIdType, ret -} - -func (VgpuInstance VgpuInstance) GetVmID() (string, VgpuVmIdType, Return) { - return VgpuInstanceGetVmID(VgpuInstance) -} - -// nvml.VgpuInstanceGetUUID() -func VgpuInstanceGetUUID(VgpuInstance VgpuInstance) (string, Return) { - Uuid := make([]byte, DEVICE_UUID_BUFFER_SIZE) - ret := nvmlVgpuInstanceGetUUID(VgpuInstance, &Uuid[0], DEVICE_UUID_BUFFER_SIZE) - return string(Uuid[:clen(Uuid)]), ret -} - -func (VgpuInstance VgpuInstance) GetUUID() (string, Return) { - return VgpuInstanceGetUUID(VgpuInstance) -} - -// nvml.VgpuInstanceGetVmDriverVersion() -func VgpuInstanceGetVmDriverVersion(VgpuInstance VgpuInstance) (string, Return) { - Version := make([]byte, SYSTEM_DRIVER_VERSION_BUFFER_SIZE) - ret := nvmlVgpuInstanceGetVmDriverVersion(VgpuInstance, &Version[0], SYSTEM_DRIVER_VERSION_BUFFER_SIZE) - return string(Version[:clen(Version)]), ret -} - -func (VgpuInstance VgpuInstance) GetVmDriverVersion() (string, Return) { - return VgpuInstanceGetVmDriverVersion(VgpuInstance) -} - -// nvml.VgpuInstanceGetFbUsage() -func VgpuInstanceGetFbUsage(VgpuInstance VgpuInstance) (uint64, Return) { - var FbUsage uint64 - ret := nvmlVgpuInstanceGetFbUsage(VgpuInstance, &FbUsage) - return FbUsage, ret -} - -func (VgpuInstance VgpuInstance) GetFbUsage() (uint64, Return) { - return VgpuInstanceGetFbUsage(VgpuInstance) -} - -// nvml.VgpuInstanceGetLicenseInfo() -func VgpuInstanceGetLicenseInfo(VgpuInstance VgpuInstance) (VgpuLicenseInfo, Return) { - var LicenseInfo VgpuLicenseInfo - ret := nvmlVgpuInstanceGetLicenseInfo(VgpuInstance, &LicenseInfo) - return LicenseInfo, ret -} - -func (VgpuInstance VgpuInstance) GetLicenseInfo() (VgpuLicenseInfo, Return) { - return VgpuInstanceGetLicenseInfo(VgpuInstance) -} - -// nvml.VgpuInstanceGetLicenseStatus() -func VgpuInstanceGetLicenseStatus(VgpuInstance VgpuInstance) (int, Return) { - var Licensed uint32 - ret := nvmlVgpuInstanceGetLicenseStatus(VgpuInstance, &Licensed) - return int(Licensed), ret -} - -func (VgpuInstance VgpuInstance) GetLicenseStatus() (int, Return) { - return VgpuInstanceGetLicenseStatus(VgpuInstance) -} - -// nvml.VgpuInstanceGetType() -func VgpuInstanceGetType(VgpuInstance VgpuInstance) (VgpuTypeId, Return) { - var VgpuTypeId VgpuTypeId - ret := nvmlVgpuInstanceGetType(VgpuInstance, &VgpuTypeId) - return VgpuTypeId, ret -} - -func (VgpuInstance VgpuInstance) GetType() (VgpuTypeId, Return) { - return VgpuInstanceGetType(VgpuInstance) -} - -// nvml.VgpuInstanceGetFrameRateLimit() -func VgpuInstanceGetFrameRateLimit(VgpuInstance VgpuInstance) (uint32, Return) { - var FrameRateLimit uint32 - ret := nvmlVgpuInstanceGetFrameRateLimit(VgpuInstance, &FrameRateLimit) - return FrameRateLimit, ret -} - -func (VgpuInstance VgpuInstance) GetFrameRateLimit() (uint32, Return) { - return VgpuInstanceGetFrameRateLimit(VgpuInstance) -} - -// nvml.VgpuInstanceGetEccMode() -func VgpuInstanceGetEccMode(VgpuInstance VgpuInstance) (EnableState, Return) { - var EccMode EnableState - ret := nvmlVgpuInstanceGetEccMode(VgpuInstance, &EccMode) - return EccMode, ret -} - -func (VgpuInstance VgpuInstance) GetEccMode() (EnableState, Return) { - return VgpuInstanceGetEccMode(VgpuInstance) -} - -// nvml.VgpuInstanceGetEncoderCapacity() -func VgpuInstanceGetEncoderCapacity(VgpuInstance VgpuInstance) (int, Return) { - var EncoderCapacity uint32 - ret := nvmlVgpuInstanceGetEncoderCapacity(VgpuInstance, &EncoderCapacity) - return int(EncoderCapacity), ret -} - -func (VgpuInstance VgpuInstance) GetEncoderCapacity() (int, Return) { - return VgpuInstanceGetEncoderCapacity(VgpuInstance) -} - -// nvml.VgpuInstanceSetEncoderCapacity() -func VgpuInstanceSetEncoderCapacity(VgpuInstance VgpuInstance, EncoderCapacity int) Return { - return nvmlVgpuInstanceSetEncoderCapacity(VgpuInstance, uint32(EncoderCapacity)) -} - -func (VgpuInstance VgpuInstance) SetEncoderCapacity(EncoderCapacity int) Return { - return VgpuInstanceSetEncoderCapacity(VgpuInstance, EncoderCapacity) -} - -// nvml.VgpuInstanceGetEncoderStats() -func VgpuInstanceGetEncoderStats(VgpuInstance VgpuInstance) (int, uint32, uint32, Return) { - var SessionCount, AverageFps, AverageLatency uint32 - ret := nvmlVgpuInstanceGetEncoderStats(VgpuInstance, &SessionCount, &AverageFps, &AverageLatency) - return int(SessionCount), AverageFps, AverageLatency, ret -} - -func (VgpuInstance VgpuInstance) GetEncoderStats() (int, uint32, uint32, Return) { - return VgpuInstanceGetEncoderStats(VgpuInstance) -} - -// nvml.VgpuInstanceGetEncoderSessions() -func VgpuInstanceGetEncoderSessions(VgpuInstance VgpuInstance) (int, EncoderSessionInfo, Return) { - var SessionCount uint32 - var SessionInfo EncoderSessionInfo - ret := nvmlVgpuInstanceGetEncoderSessions(VgpuInstance, &SessionCount, &SessionInfo) - return int(SessionCount), SessionInfo, ret -} - -func (VgpuInstance VgpuInstance) GetEncoderSessions() (int, EncoderSessionInfo, Return) { - return VgpuInstanceGetEncoderSessions(VgpuInstance) -} - -// nvml.VgpuInstanceGetFBCStats() -func VgpuInstanceGetFBCStats(VgpuInstance VgpuInstance) (FBCStats, Return) { - var FbcStats FBCStats - ret := nvmlVgpuInstanceGetFBCStats(VgpuInstance, &FbcStats) - return FbcStats, ret -} - -func (VgpuInstance VgpuInstance) GetFBCStats() (FBCStats, Return) { - return VgpuInstanceGetFBCStats(VgpuInstance) -} - -// nvml.VgpuInstanceGetFBCSessions() -func VgpuInstanceGetFBCSessions(VgpuInstance VgpuInstance) (int, FBCSessionInfo, Return) { - var SessionCount uint32 - var SessionInfo FBCSessionInfo - ret := nvmlVgpuInstanceGetFBCSessions(VgpuInstance, &SessionCount, &SessionInfo) - return int(SessionCount), SessionInfo, ret -} - -func (VgpuInstance VgpuInstance) GetFBCSessions() (int, FBCSessionInfo, Return) { - return VgpuInstanceGetFBCSessions(VgpuInstance) -} - -// nvml.VgpuInstanceGetGpuInstanceId() -func VgpuInstanceGetGpuInstanceId(VgpuInstance VgpuInstance) (int, Return) { - var gpuInstanceId uint32 - ret := nvmlVgpuInstanceGetGpuInstanceId(VgpuInstance, &gpuInstanceId) - return int(gpuInstanceId), ret -} - -func (VgpuInstance VgpuInstance) GetGpuInstanceId() (int, Return) { - return VgpuInstanceGetGpuInstanceId(VgpuInstance) -} - -// nvml.VgpuInstanceGetGpuPciId() -func VgpuInstanceGetGpuPciId(VgpuInstance VgpuInstance) (string, Return) { - var Length uint32 = 1 // Will be reduced upon returning - for { - VgpuPciId := make([]byte, Length) - ret := nvmlVgpuInstanceGetGpuPciId(VgpuInstance, &VgpuPciId[0], &Length) - if ret == SUCCESS { - return string(VgpuPciId[:clen(VgpuPciId)]), ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return "", ret - } - Length *= 2 - } -} - -func (VgpuInstance VgpuInstance) GetGpuPciId() (string, Return) { - return VgpuInstanceGetGpuPciId(VgpuInstance) -} - -// nvml.VgpuInstanceGetMetadata() -func VgpuInstanceGetMetadata(VgpuInstance VgpuInstance) (VgpuMetadata, Return) { - var VgpuMetadata VgpuMetadata - OpaqueDataSize := unsafe.Sizeof(VgpuMetadata.nvmlVgpuMetadata.OpaqueData) - VgpuMetadataSize := unsafe.Sizeof(VgpuMetadata.nvmlVgpuMetadata) - OpaqueDataSize - for { - BufferSize := uint32(VgpuMetadataSize + OpaqueDataSize) - Buffer := make([]byte, BufferSize) - nvmlVgpuMetadataPtr := (*nvmlVgpuMetadata)(unsafe.Pointer(&Buffer[0])) - ret := nvmlVgpuInstanceGetMetadata(VgpuInstance, nvmlVgpuMetadataPtr, &BufferSize) - if ret == SUCCESS { - VgpuMetadata.nvmlVgpuMetadata = *nvmlVgpuMetadataPtr - VgpuMetadata.OpaqueData = Buffer[VgpuMetadataSize:BufferSize] - return VgpuMetadata, ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return VgpuMetadata, ret - } - OpaqueDataSize = 2 * OpaqueDataSize - } -} - -func (VgpuInstance VgpuInstance) GetMetadata() (VgpuMetadata, Return) { - return VgpuInstanceGetMetadata(VgpuInstance) -} - -// nvml.VgpuInstanceGetAccountingMode() -func VgpuInstanceGetAccountingMode(VgpuInstance VgpuInstance) (EnableState, Return) { - var Mode EnableState - ret := nvmlVgpuInstanceGetAccountingMode(VgpuInstance, &Mode) - return Mode, ret -} - -func (VgpuInstance VgpuInstance) GetAccountingMode() (EnableState, Return) { - return VgpuInstanceGetAccountingMode(VgpuInstance) -} - -// nvml.VgpuInstanceGetAccountingPids() -func VgpuInstanceGetAccountingPids(VgpuInstance VgpuInstance) ([]int, Return) { - var Count uint32 = 1 // Will be reduced upon returning - for { - Pids := make([]uint32, Count) - ret := nvmlVgpuInstanceGetAccountingPids(VgpuInstance, &Count, &Pids[0]) - if ret == SUCCESS { - return uint32SliceToIntSlice(Pids[:Count]), ret - } - if ret != ERROR_INSUFFICIENT_SIZE { - return nil, ret - } - Count *= 2 - } -} - -func (VgpuInstance VgpuInstance) GetAccountingPids() ([]int, Return) { - return VgpuInstanceGetAccountingPids(VgpuInstance) -} - -// nvml.VgpuInstanceGetAccountingStats() -func VgpuInstanceGetAccountingStats(VgpuInstance VgpuInstance, Pid int) (AccountingStats, Return) { - var Stats AccountingStats - ret := nvmlVgpuInstanceGetAccountingStats(VgpuInstance, uint32(Pid), &Stats) - return Stats, ret -} - -func (VgpuInstance VgpuInstance) GetAccountingStats(Pid int) (AccountingStats, Return) { - return VgpuInstanceGetAccountingStats(VgpuInstance, Pid) -} - -// nvml.GetVgpuCompatibility() -func GetVgpuCompatibility(nvmlVgpuMetadata *nvmlVgpuMetadata, PgpuMetadata *nvmlVgpuPgpuMetadata) (VgpuPgpuCompatibility, Return) { - var CompatibilityInfo VgpuPgpuCompatibility - ret := nvmlGetVgpuCompatibility(nvmlVgpuMetadata, PgpuMetadata, &CompatibilityInfo) - return CompatibilityInfo, ret -} - -// nvml.GetVgpuVersion() -func GetVgpuVersion() (VgpuVersion, VgpuVersion, Return) { - var Supported, Current VgpuVersion - ret := nvmlGetVgpuVersion(&Supported, &Current) - return Supported, Current, ret -} - -// nvml.SetVgpuVersion() -func SetVgpuVersion(VgpuVersion *VgpuVersion) Return { - return nvmlSetVgpuVersion(VgpuVersion) -} - -// nvml.VgpuInstanceClearAccountingPids() -func VgpuInstanceClearAccountingPids(VgpuInstance VgpuInstance) Return { - return nvmlVgpuInstanceClearAccountingPids(VgpuInstance) -} - -func (VgpuInstance VgpuInstance) ClearAccountingPids() Return { - return VgpuInstanceClearAccountingPids(VgpuInstance) -} - -// nvml.VgpuInstanceGetMdevUUID() -func VgpuInstanceGetMdevUUID(VgpuInstance VgpuInstance) (string, Return) { - MdevUuid := make([]byte, DEVICE_UUID_BUFFER_SIZE) - ret := nvmlVgpuInstanceGetMdevUUID(VgpuInstance, &MdevUuid[0], DEVICE_UUID_BUFFER_SIZE) - return string(MdevUuid[:clen(MdevUuid)]), ret -} - -func (VgpuInstance VgpuInstance) GetMdevUUID() (string, Return) { - return VgpuInstanceGetMdevUUID(VgpuInstance) -} - -// nvml.VgpuTypeGetCapabilities() -func VgpuTypeGetCapabilities(VgpuTypeId VgpuTypeId, Capability VgpuCapability) (bool, Return) { - var CapResult uint32 - ret := nvmlVgpuTypeGetCapabilities(VgpuTypeId, Capability, &CapResult) - return (CapResult != 0), ret -} - -func (VgpuTypeId VgpuTypeId) GetCapabilities(Capability VgpuCapability) (bool, Return) { - return VgpuTypeGetCapabilities(VgpuTypeId, Capability) -} - -// nvml.GetVgpuDriverCapabilities() -func GetVgpuDriverCapabilities(Capability VgpuDriverCapability) (bool, Return) { - var CapResult uint32 - ret := nvmlGetVgpuDriverCapabilities(Capability, &CapResult) - return (CapResult != 0), ret -} diff --git a/pkg/nvml/cgo_helpers.go b/pkg/nvml/cgo_helpers.go deleted file mode 100644 index b04f366..0000000 --- a/pkg/nvml/cgo_helpers.go +++ /dev/null @@ -1,64 +0,0 @@ -// 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 - -import ( - "unsafe" -) - -import "C" - -var cgoAllocsUnknown = new(struct{}) - -type stringHeader struct { - Data unsafe.Pointer - Len int -} - -func clen(n []byte) int { - for i := 0; i < len(n); i++ { - if n[i] == 0 { - return i - } - } - return len(n) -} - -func uint32SliceToIntSlice(s []uint32) []int { - ret := make([]int, len(s)) - for i := range s { - ret[i] = int(s[i]) - } - return ret -} - -// packPCharString creates a Go string backed by *C.char and avoids copying. -func packPCharString(p *C.char) (raw string) { - if p != nil && *p != 0 { - h := (*stringHeader)(unsafe.Pointer(&raw)) - h.Data = unsafe.Pointer(p) - for *p != 0 { - p = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(p)) + 1)) // p++ - } - h.Len = int(uintptr(unsafe.Pointer(p)) - uintptr(h.Data)) - } - return -} - -// unpackPCharString represents the data from Go string as *C.char and avoids copying. -func unpackPCharString(str string) (*C.char, *struct{}) { - h := (*stringHeader)(unsafe.Pointer(&str)) - return (*C.char)(h.Data), cgoAllocsUnknown -} diff --git a/gen/nvml/cgo_helpers.go b/pkg/nvml/cgo_helpers_static.go similarity index 100% rename from gen/nvml/cgo_helpers.go rename to pkg/nvml/cgo_helpers_static.go diff --git a/pkg/nvml/const_gen.go b/pkg/nvml/const_gen.go deleted file mode 100644 index 9038b31..0000000 --- a/pkg/nvml/const_gen.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2021, 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 - -import ( - "reflect" -) - -const ( - SYSTEM_PROCESS_NAME_BUFFER_SIZE = 256 -) - -func STRUCT_VERSION(data interface{}, version uint32) uint32 { - return uint32(uint32(reflect.Indirect(reflect.ValueOf(data)).Type().Size()) | (version << uint32(24))) -} diff --git a/gen/nvml/const_gen.go b/pkg/nvml/const_static.go similarity index 100% rename from gen/nvml/const_gen.go rename to pkg/nvml/const_static.go