From ed76f9808311fe007ea312e94a6dac3c836a90b7 Mon Sep 17 00:00:00 2001 From: grapeVine Date: Thu, 9 Apr 2020 18:43:54 +0800 Subject: [PATCH] add get brand type func --- bindings.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bindings.go b/bindings.go index abefe83..7f42e4d 100644 --- a/bindings.go +++ b/bindings.go @@ -87,6 +87,14 @@ nvmlReturn_t nvmlDeviceGetName(nvmlDevice_t device, char *name, unsigned int len return nvmlDeviceGetNameFunc(device, name, length); } +nvmlReturn_t (*nvmlDeviceGetBrandFunc)(nvmlDevice_t device, nvmlBrandType_t *type); +nvmlReturn_t nvmlDeviceGetBrand(nvmlDevice_t device, nvmlBrandType_t *type) { + if (nvmlDeviceGetBrandFunc == NULL) { + return NVML_ERROR_FUNCTION_NOT_FOUND; + } + return nvmlDeviceGetBrandFunc(device, type); +} + nvmlReturn_t (*nvmlDeviceGetMemoryInfoFunc)(nvmlDevice_t device, nvmlMemory_t *memory); nvmlReturn_t nvmlDeviceGetMemoryInfo(nvmlDevice_t device, nvmlMemory_t *memory) { if (nvmlDeviceGetMemoryInfoFunc == NULL) { @@ -189,6 +197,10 @@ nvmlReturn_t nvmlInit_dl(void) { if (nvmlDeviceGetNameFunc == NULL) { return NVML_ERROR_FUNCTION_NOT_FOUND; } + nvmlDeviceGetBrandFunc = dlsym(nvmlHandle, "nvmlDeviceGetBrand"); + if (nvmlDeviceGetBrandFunc == NULL) { + return NVML_ERROR_FUNCTION_NOT_FOUND; + } nvmlDeviceGetMemoryInfoFunc = dlsym(nvmlHandle, "nvmlDeviceGetMemoryInfo"); if (nvmlDeviceGetMemoryInfoFunc == NULL) { return NVML_ERROR_FUNCTION_NOT_FOUND; @@ -420,6 +432,16 @@ func (d Device) Name() (string, error) { return C.GoString(&name[0]), errorString(r) } +// Brand returns the product Brand of the device. +func (d Device) Brand() (uint, error) { + if C.nvmlHandle == nil { + return 0, errLibraryNotLoaded + } + var brand C.nvmlBrandType_t + r := C.nvmlDeviceGetBrand(d.dev, &brand) + return uint(brand), errorString(r) +} + // MemoryInfo returns the total and used memory (in bytes) of the device. func (d Device) MemoryInfo() (uint64, uint64, error) { if C.nvmlHandle == nil {