NVIDIA GPU loadable plugin
Source
// - `pendingEnabled` (bool): `true` if ECC will be enabled on the next reboot, `false` if it will be disabled.
/*
** Zabbix
** Copyright (C) 2001-2024 Zabbix SIA
**
** 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
/*
#cgo CFLAGS: -I${SRCDIR}/nvml-sdk/include
#cgo CFLAGS: -DNVML_NO_UNVERSIONED_FUNC_DEFS=1
#include "nvml.h"
*/
import "C" //nolint:gocritic,gci
import (
"errors"
"sync"
"syscall"
"unsafe" //nolint:gocritic
"golang.org/x/sys/windows"
"golang.zabbix.com/sdk/errs"
)
var (
_ Device = (*NVMLDevice)(nil)
_ Runner = (*NVMLRunner)(nil)
)
// NVMLRunner manages the loading and retrieval of functions from a Windows DLL.
// It is responsible for ensuring thread-safe access to the list of loaded
// procedures and facilitates dynamic function calls from the DLL.
type NVMLRunner struct {
dll *windows.DLL
procListMux *sync.Mutex
procList map[string]*windows.Proc
}
// NVMLDevice represents an NVML GPU device, identified by a unique handle.
type NVMLDevice struct {
handle uintptr
runner *NVMLRunner // Reference to the Runner (formerly NVMLRunner)
}
// NewNVMLRunner creates a new NVML Runner instance, loading the NVML library.
func NewNVMLRunner() (*NVMLRunner, error) {
dll, err := windows.LoadDLL("nvml.dll")
if err != nil {
return nil, errs.WrapConst(err, ErrLibraryNotFound) //nolint:wrapcheck
}