AMD System Management Interface Go library for monitoring and managing AMD GPUs and EPYC CPUs
—
This document describes all GPU management functions in the goamdsmi package. These functions enable monitoring and querying AMD GPU devices for hardware information, performance metrics, power consumption, temperature, clock frequencies, and memory usage.
import "github.com/ROCm/amdsmi"Initializes the GPU subsystem. Must be called before using any other GPU functions.
func GO_gpu_init() boolReturns: bool
true on successful initializationfalse on failureExample:
if !goamdsmi.GO_gpu_init() {
log.Fatal("Failed to initialize GPU subsystem")
}
defer goamdsmi.GO_gpu_shutdown()Shuts down the GPU subsystem and releases resources.
func GO_gpu_shutdown() boolReturns: bool
true on successful shutdownfalse on failureReturns the number of GPU monitor devices available on the system.
func GO_gpu_num_monitor_devices() uintReturns: uint
0 on failureExample:
numGPUs := goamdsmi.GO_gpu_num_monitor_devices()
fmt.Printf("Found %d GPU(s)\n", numGPUs)Returns the name of the GPU device at the specified index.
func GO_gpu_dev_name_get(i int) *C.charParameters:
i (int): GPU index (0-based)Returns: *C.char
"NA" on failureExample:
name := C.GoString(goamdsmi.GO_gpu_dev_name_get(0))
fmt.Printf("GPU 0: %s\n", name)Returns the device ID of the GPU at the specified index.
func GO_gpu_dev_id_get(i int) C.uint16_tParameters:
i (int): GPU index (0-based)Returns: C.uint16_t
0xFFFF on failureExample:
deviceID := uint16(goamdsmi.GO_gpu_dev_id_get(0))
if deviceID == 0xFFFF {
fmt.Println("Failed to get device ID")
}Returns the PCI ID of the GPU device at the specified index.
func GO_gpu_dev_pci_id_get(i int) C.uint64_tParameters:
i (int): GPU index (0-based)Returns: C.uint64_t
0xFFFFFFFFFFFFFFFF on failureExample:
pciID := uint64(goamdsmi.GO_gpu_dev_pci_id_get(0))
fmt.Printf("PCI ID: 0x%x\n", pciID)Returns the VBIOS version of the GPU at the specified index.
func GO_gpu_dev_vbios_version_get(i int) *C.charParameters:
i (int): GPU index (0-based)Returns: *C.char
"NA" on failureExample:
vbios := C.GoString(goamdsmi.GO_gpu_dev_vbios_version_get(0))
fmt.Printf("VBIOS: %s\n", vbios)Returns the vendor name of the GPU device at the specified index.
func GO_gpu_dev_vendor_name_get(i int) *C.charParameters:
i (int): GPU index (0-based)Returns: *C.char
"NA" on failureExample:
vendor := C.GoString(goamdsmi.GO_gpu_dev_vendor_name_get(0))
fmt.Printf("Vendor: %s\n", vendor)Returns the power cap of the GPU at the specified index.
func GO_gpu_dev_power_cap_get(i int) C.uint64_tParameters:
i (int): GPU index (0-based)Returns: C.uint64_t
0xFFFFFFFFFFFFFFFF on failureExample:
powerCap := uint64(goamdsmi.GO_gpu_dev_power_cap_get(0))
if powerCap != 0xFFFFFFFFFFFFFFFF {
fmt.Printf("Power cap: %d\n", powerCap)
}Returns the current power consumption of the GPU at the specified index.
func GO_gpu_dev_power_get(i int) C.uint64_tParameters:
i (int): GPU index (0-based)Returns: C.uint64_t
0xFFFFFFFFFFFFFFFF on failureExample:
power := uint64(goamdsmi.GO_gpu_dev_power_get(0))
fmt.Printf("Current power: %d\n", power)Returns the temperature of the GPU at the specified index, sensor, and metric.
func GO_gpu_dev_temp_metric_get(i int, sensor int, metric int) C.uint64_tParameters:
i (int): GPU index (0-based)sensor (int): Sensor numbermetric (int): Metric numberReturns: C.uint64_t
0xFFFFFFFFFFFFFFFF on failureExample:
// Query sensor 1, metric 0
temp := uint64(goamdsmi.GO_gpu_dev_temp_metric_get(0, 1, 0))
fmt.Printf("Temperature: %d\n", temp)Returns the performance level of the GPU at the specified index.
func GO_gpu_dev_perf_level_get(i int) C.uint32_tParameters:
i (int): GPU index (0-based)Returns: C.uint32_t
0xFFFFFFFF on failureExample:
perfLevel := uint32(goamdsmi.GO_gpu_dev_perf_level_get(0))
fmt.Printf("Performance level: %d\n", perfLevel)Returns the overdrive level of the GPU at the specified index.
func GO_gpu_dev_overdrive_level_get(i int) C.uint32_tParameters:
i (int): GPU index (0-based)Returns: C.uint32_t
0xFFFFFFFF on failureExample:
overdrive := uint32(goamdsmi.GO_gpu_dev_overdrive_level_get(0))
fmt.Printf("Overdrive level: %d\n", overdrive)Returns the memory overdrive level of the GPU at the specified index.
func GO_gpu_dev_mem_overdrive_level_get(i int) C.uint32_tParameters:
i (int): GPU index (0-based)Returns: C.uint32_t
0xFFFFFFFF on failureExample:
memOverdrive := uint32(goamdsmi.GO_gpu_dev_mem_overdrive_level_get(0))
fmt.Printf("Memory overdrive level: %d\n", memOverdrive)Returns the system clock (SCLK) frequency of the GPU at the specified index.
func GO_gpu_dev_gpu_clk_freq_get_sclk(i int) C.uint64_tParameters:
i (int): GPU index (0-based)Returns: C.uint64_t
0xFFFFFFFFFFFFFFFF on failureExample:
sclk := uint64(goamdsmi.GO_gpu_dev_gpu_clk_freq_get_sclk(0))
fmt.Printf("System clock: %d\n", sclk)Returns the memory clock (MCLK) frequency of the GPU at the specified index.
func GO_gpu_dev_gpu_clk_freq_get_mclk(i int) C.uint64_tParameters:
i (int): GPU index (0-based)Returns: C.uint64_t
0xFFFFFFFFFFFFFFFF on failureExample:
mclk := uint64(goamdsmi.GO_gpu_dev_gpu_clk_freq_get_mclk(0))
fmt.Printf("Memory clock: %d\n", mclk)Returns the minimum system clock (SCLK) frequency of the GPU at the specified index.
func GO_gpu_od_volt_freq_range_min_get_sclk(i int) C.uint64_tParameters:
i (int): GPU index (0-based)Returns: C.uint64_t
0xFFFFFFFFFFFFFFFF on failureReturns the minimum memory clock (MCLK) frequency of the GPU at the specified index.
func GO_gpu_od_volt_freq_range_min_get_mclk(i int) C.uint64_tParameters:
i (int): GPU index (0-based)Returns: C.uint64_t
0xFFFFFFFFFFFFFFFF on failureReturns the maximum system clock (SCLK) frequency of the GPU at the specified index.
func GO_gpu_od_volt_freq_range_max_get_sclk(i int) C.uint64_tParameters:
i (int): GPU index (0-based)Returns: C.uint64_t
0xFFFFFFFFFFFFFFFF on failureReturns the maximum memory clock (MCLK) frequency of the GPU at the specified index.
func GO_gpu_od_volt_freq_range_max_get_mclk(i int) C.uint64_tParameters:
i (int): GPU index (0-based)Returns: C.uint64_t
0xFFFFFFFFFFFFFFFF on failureExample:
minSclk := uint64(goamdsmi.GO_gpu_od_volt_freq_range_min_get_sclk(0))
maxSclk := uint64(goamdsmi.GO_gpu_od_volt_freq_range_max_get_sclk(0))
fmt.Printf("SCLK range: %d - %d\n", minSclk, maxSclk)Returns the busy percentage of the GPU at the specified index.
func GO_gpu_dev_gpu_busy_percent_get(i int) C.uint32_tParameters:
i (int): GPU index (0-based)Returns: C.uint32_t
0xFFFFFFFF on failureExample:
busyPercent := uint32(goamdsmi.GO_gpu_dev_gpu_busy_percent_get(0))
fmt.Printf("GPU utilization: %d%%\n", busyPercent)Returns the memory busy percentage of the GPU at the specified index.
func GO_gpu_dev_gpu_memory_busy_percent_get(i int) C.uint64_tParameters:
i (int): GPU index (0-based)Returns: C.uint64_t
0xFFFFFFFFFFFFFFFF on failureExample:
memBusy := uint64(goamdsmi.GO_gpu_dev_gpu_memory_busy_percent_get(0))
fmt.Printf("Memory utilization: %d%%\n", memBusy)Returns the memory usage of the GPU at the specified index.
func GO_gpu_dev_gpu_memory_usage_get(i int) C.uint64_tParameters:
i (int): GPU index (0-based)Returns: C.uint64_t
0xFFFFFFFFFFFFFFFF on failureExample:
memUsage := uint64(goamdsmi.GO_gpu_dev_gpu_memory_usage_get(0))
fmt.Printf("Memory usage: %d\n", memUsage)Returns the total memory of the GPU at the specified index.
func GO_gpu_dev_gpu_memory_total_get(i int) C.uint64_tParameters:
i (int): GPU index (0-based)Returns: C.uint64_t
0xFFFFFFFFFFFFFFFF on failureExample:
memTotal := uint64(goamdsmi.GO_gpu_dev_gpu_memory_total_get(0))
memUsage := uint64(goamdsmi.GO_gpu_dev_gpu_memory_usage_get(0))
fmt.Printf("Memory: %d / %d\n", memUsage, memTotal)package main
import (
"fmt"
"github.com/ROCm/amdsmi"
)
func main() {
// Initialize GPU subsystem
if !goamdsmi.GO_gpu_init() {
fmt.Println("Failed to initialize GPU")
return
}
defer goamdsmi.GO_gpu_shutdown()
// Get GPU count
numGPUs := int(goamdsmi.GO_gpu_num_monitor_devices())
fmt.Printf("Found %d GPU(s)\n", numGPUs)
// Query each GPU
for i := 0; i < numGPUs; i++ {
fmt.Printf("\n=== GPU %d ===\n", i)
// Device information
name := C.GoString(goamdsmi.GO_gpu_dev_name_get(i))
vendor := C.GoString(goamdsmi.GO_gpu_dev_vendor_name_get(i))
fmt.Printf("Name: %s\n", name)
fmt.Printf("Vendor: %s\n", vendor)
// Power metrics
power := uint64(goamdsmi.GO_gpu_dev_power_get(i))
powerCap := uint64(goamdsmi.GO_gpu_dev_power_cap_get(i))
fmt.Printf("Power: %d / %d\n", power, powerCap)
// Temperature
temp := uint64(goamdsmi.GO_gpu_dev_temp_metric_get(i, 1, 0))
fmt.Printf("Temperature: %d\n", temp)
// Clock frequencies
sclk := uint64(goamdsmi.GO_gpu_dev_gpu_clk_freq_get_sclk(i))
mclk := uint64(goamdsmi.GO_gpu_dev_gpu_clk_freq_get_mclk(i))
fmt.Printf("Clocks - SCLK: %d, MCLK: %d\n", sclk, mclk)
// Utilization
gpuBusy := uint32(goamdsmi.GO_gpu_dev_gpu_busy_percent_get(i))
memBusy := uint64(goamdsmi.GO_gpu_dev_gpu_memory_busy_percent_get(i))
fmt.Printf("Utilization - GPU: %d%%, Memory: %d%%\n", gpuBusy, memBusy)
// Memory
memUsage := uint64(goamdsmi.GO_gpu_dev_gpu_memory_usage_get(i))
memTotal := uint64(goamdsmi.GO_gpu_dev_gpu_memory_total_get(i))
fmt.Printf("Memory: %d / %d\n", memUsage, memTotal)
}
}Install with Tessl CLI
npx tessl i tessl/golang-github-com-rocm-amdsmi