nvml

package module
v0.0.0-...-83ad7cc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2017 License: MIT Imports: 5 Imported by: 0

README

NVIDIA Management Library (NVML) Go Bindings

GoDoc

There are multiple NVML Go bindings lying around GitHub. But they either are unmaintained or require configuring compiler flags. This package uses cgo and aims to be usable without any configuration.

Currently very few functionalities are exported from the underlying C library because those are what I need. But if you want more features, please submit an issue and I'll be happy to implement.

Example

Following is an easy example that displays processes information on all devices.

package main

import (
    "fmt"

    "github.com/hotpxl/nvml"
)

func main() {
    s, err := nvml.NewSession()
    if err != nil {
        panic(err)
    }
    defer s.Close()

    devices, err := s.GetAllDevices()
    if err != nil {
        panic(err)
    }
    for _, d := range devices {
        p, err := d.Processes()
        if err != nil {
            panic(err)
        }
        fmt.Printf("%+v\n", p)
    }
}

A second example cmd/nvml-monitor monitors device information and uploads to etcd.

Documentation

Overview

Package nvml is the NVIDIA Management Library (NVML) bindings for Go.

Following is an easy example that displays processes information on all devices.

package main

import (
	"fmt"

	"github.com/hotpxl/nvml"
)

func main() {
	s, err := nvml.NewSession()
	if err != nil {
		panic(err)
	}
	defer s.Close()

	devices, err := s.GetAllDevices()
	if err != nil {
		panic(err)
	}
	for _, d := range devices {
		p, err := d.Processes()
		if err != nil {
			panic(err)
		}
		fmt.Printf("%+v\n", p)
	}
}

Visit https://github.com/hotpxl/nvml for more information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device represents a single device.

func (*Device) MemoryInfo

func (d *Device) MemoryInfo() (MemoryInfo, error)

MemoryInfo returns memory consumption information from a device.

func (*Device) Processes

func (d *Device) Processes() ([]ProcessInfo, error)

Processes returns processes running on a device.

type MemoryInfo

type MemoryInfo struct {
	Free  uint64
	Used  uint64
	Total uint64
}

MemoryInfo holds memory consumption information for a device.

type ProcessInfo

type ProcessInfo struct {
	PID        int32  `json:"pid"`
	UsedMemory uint64 `json:"usedMemory"`
	Username   string `json:"username"`
}

ProcessInfo holds process information on a device.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session manages the initialization and shutdown of NVML context.

func NewSession

func NewSession() (*Session, error)

NewSession creates a new session.

func (*Session) Close

func (s *Session) Close()

Close frees existing session and underlying NVML context.

func (*Session) DeviceCount

func (s *Session) DeviceCount() (int, error)

DeviceCount returns the number of devices.

func (*Session) GetAllDevices

func (s *Session) GetAllDevices() ([]Device, error)

GetAllDevices returns all devices accessible.

func (*Session) GetDevice

func (s *Session) GetDevice(idx int) (*Device, error)

GetDevice returns a specific device given its index.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL