Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get brand type func #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down