mindprince / gonvml Goto Github PK
View Code? Open in Web Editor NEWNVIDIA Management Library (NVML) bindings for Go
License: Apache License 2.0
NVIDIA Management Library (NVML) bindings for Go
License: Apache License 2.0
I updated to the latest nvidia drivers and there's an issue with running the example go file...
$ gonvml/cmd/example$ go run example.go
Initialize() took 668.203408ms
SystemDriverVersion(): 390.116
DeviceCount(): 1
minorNumber: 0
uuid: GPU-f4978516-fb34-9fff-a5ae-d7a5b7f8a33c
name: Quadro P2000
memory.total: 5304745984, memory.used: 0
utilization.gpu: 0, utilization.memory: 0
power.draw: 18850
average power.draw for last 10s: 18565
dev.AverageGPUUtilization() error: nvml: Not Found
Found the library on my system in these paths
/usr/lib/i386-linux-gnu/libnvidia-ml.so
/usr/lib/i386-linux-gnu/libnvidia-ml.so.1
/usr/lib/i386-linux-gnu/libnvidia-ml.so.390.116
/usr/lib/x86_64-linux-gnu/libnvidia-ml.so
/usr/lib/x86_64-linux-gnu/libnvidia-ml.so.1
/usr/lib/x86_64-linux-gnu/libnvidia-ml.so.390.116
I'd like to be able to query the current and maximum gpu clock speeds if possible:
Specifically, for my purposes:
nvmlDeviceGetMaxClockInfo
and
nvmlDeviceGetClockInfo with a clock type of NVML_CLOCK_SM = 1
example failed to query device count:
package main
// #cgo LDFLAGS: -ldl -lnvidia-ml
// #cgo CFLAGS: -I /usr/local/cuda-8.0/include
/*
#include <stdio.h>
#include "nvml.h"
void testNvml()
{
nvmlReturn_t result;
unsigned int device_count, i;
// First initialize NVML library
result = nvmlInit();
if (NVML_SUCCESS != result)
{
printf("Failed to initialize NVML: %s\n", nvmlErrorString(result));
return;
}
result = nvmlDeviceGetCount(&device_count);
if (NVML_SUCCESS != result)
{
printf("Failed to query device count: %s\n", nvmlErrorString(result));
return;
}
printf("Found %d device%s\n\n", device_count, device_count != 1 ? "s" : "");
}
*/
import "C"
import (
"fmt"
"github.com/mindprince/gonvml"
)
func testGoNvml() (value []string) {
err := gonvml.Initialize()
if err != nil {
return
}
defer func() { _ = gonvml.Shutdown() }()
n, err := gonvml.DeviceCount()
if err != nil {
panic(err)
}
fmt.Println("testGoNvml gpu num:", n)
return
}
func main() {
C.testNvml()
testGoNvml()
C.testNvml()
}
output:
Failed to query device count: nvmlErrorString Function Not Found
testGoNvml gpu num: 8
Found 8 devices
example ok
package main
// #cgo LDFLAGS: -ldl -lnvidia-ml
// #cgo CFLAGS: -I /usr/local/cuda-8.0/include
/*
#include <stdio.h>
#include "nvml.h"
void testNvml()
{
nvmlReturn_t result;
unsigned int device_count, i;
// First initialize NVML library
result = nvmlInit();
if (NVML_SUCCESS != result)
{
printf("Failed to initialize NVML: %s\n", nvmlErrorString(result));
return;
}
result = nvmlDeviceGetCount(&device_count);
if (NVML_SUCCESS != result)
{
printf("Failed to query device count: %s\n", nvmlErrorString(result));
return;
}
printf("Found %d device%s\n\n", device_count, device_count != 1 ? "s" : "");
}
*/
import "C"
func main() {
C.testNvml()
}
output:
Found 8 devices
This is a simple example, actually a possible situation:
a complex golang program import package a and b
package a import gonvml
package b call libnvidia-xxx use cgo
libnvidia-xxx dynamic link libnvidia-ml
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.