-
Notifications
You must be signed in to change notification settings - Fork 9
/
system.go
45 lines (36 loc) · 1.49 KB
/
system.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package nvml
import (
"C"
"unsafe"
)
// SystemGetCudaDriverVersion retrieves the version of the CUDA driver.
// The returned CUDA driver version is the same as the CUDA API cuDriverGetVersion() would return on the system.
func (a API) SystemGetCudaDriverVersion() (cudaDriverVersion int32, err error) {
err = a.call(a.nvmlSystemGetCudaDriverVersion, uintptr(unsafe.Pointer(&cudaDriverVersion)))
return
}
// SystemGetDriverVersion retrieves the version of the system's graphics driver.
func (a API) SystemGetDriverVersion() (string, error) {
buffer := [systemDriverVersionBufferSize]C.char{}
if err := a.call(a.nvmlSystemGetDriverVersion, uintptr(unsafe.Pointer(&buffer[0])), systemDriverVersionBufferSize); err != nil {
return "", err
}
return C.GoString(&buffer[0]), nil
}
// SystemGetNVMLVersion retrieves the version of the NVML library.
func (a API) SystemGetNVMLVersion() (string, error) {
buffer := [systemDriverVersionBufferSize]C.char{}
if err := a.call(a.nvmlSystemGetNVMLVersion, uintptr(unsafe.Pointer(&buffer[0])), systemDriverVersionBufferSize); err != nil {
return "", err
}
return C.GoString(&buffer[0]), nil
}
// SystemGetProcessName gets name of the process with provided process id
func (a API) SystemGetProcessName(pid uint) (string, error) {
const maxLength = 256
buffer := [maxLength]C.char{}
if err := a.call(a.nvmlSystemGetProcessName, uintptr(pid), uintptr(unsafe.Pointer(&buffer[0])), maxLength); err != nil {
return "", err
}
return C.GoString(&buffer[0]), nil
}