Skip to content

mxpv/nvml-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

e07f8c2 · Feb 27, 2018

History

20 Commits
Jan 19, 2018
Jan 19, 2018
Jan 17, 2018
Jan 19, 2018
Feb 26, 2018
Jan 21, 2018
Feb 27, 2018
Feb 27, 2018
Feb 27, 2018
Feb 27, 2018
Feb 27, 2018
Feb 27, 2018
Jan 19, 2018
Jan 19, 2018
Jan 19, 2018
Jan 21, 2018
Jan 19, 2018

Repository files navigation

GoDoc Go Report Card MIT license

nvml-go

golang wrapper for NVIDIA Management Library (NVML)

Basic example

func ExampleNew() {
	nvml, err := New("")
	if err != nil {
		panic(err)
	}

	defer nvml.Shutdown()

	err = nvml.Init()
	if err != nil {
		panic(err)
	}

	driverVersion, err := nvml.SystemGetDriverVersion()
	if err != nil {
		panic(err)
	}

	log.Printf("Driver version:\t%s", driverVersion)

	nvmlVersion, err := nvml.SystemGetNVMLVersion()
	if err != nil {
		panic(err)
	}

	log.Printf("NVML version:\t%s", nvmlVersion)

	deviceCount, err := nvml.DeviceGetCount()
	if err != nil {
		panic(err)
	}

	for i := uint32(0); i < deviceCount; i++ {
		handle, err := nvml.DeviceGetHandleByIndex(i)
		if err != nil {
			panic(err)
		}

		name, err := nvml.DeviceGetName(handle)
		log.Printf("Product name:\t%s", name)

		brand, err := nvml.DeviceGetBrand(handle)
		if err != nil {
			panic(err)
		}

		log.Printf("Product Brand:\t%s", brand)

		uuid, err := nvml.DeviceGetUUID(handle)
		if err != nil {
			panic(err)
		}

		log.Printf("GPU UUID:\t\t%s", uuid)

		fan, err := nvml.DeviceGetFanSpeed(handle)
		if err != nil {
			panic(err)
		}

		log.Printf("Fan Speed:\t\t%d", fan)
	}
}

TODO