CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/golang-github-com-rocm-amdsmi

AMD System Management Interface Go library for monitoring and managing AMD GPUs and EPYC CPUs

Pending
Overview
Eval results
Files

gpu-management.mddocs/

GPU Management

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

import "github.com/ROCm/amdsmi"

Initialization and Shutdown

GO_gpu_init

Initializes the GPU subsystem. Must be called before using any other GPU functions.

func GO_gpu_init() bool

Returns: bool

  • true on successful initialization
  • false on failure

Example:

if !goamdsmi.GO_gpu_init() {
    log.Fatal("Failed to initialize GPU subsystem")
}
defer goamdsmi.GO_gpu_shutdown()

GO_gpu_shutdown

Shuts down the GPU subsystem and releases resources.

func GO_gpu_shutdown() bool

Returns: bool

  • true on successful shutdown
  • false on failure

Device Enumeration

GO_gpu_num_monitor_devices

Returns the number of GPU monitor devices available on the system.

func GO_gpu_num_monitor_devices() uint

Returns: uint

  • Number of GPU monitor devices on success
  • 0 on failure

Example:

numGPUs := goamdsmi.GO_gpu_num_monitor_devices()
fmt.Printf("Found %d GPU(s)\n", numGPUs)

Device Information

GO_gpu_dev_name_get

Returns the name of the GPU device at the specified index.

func GO_gpu_dev_name_get(i int) *C.char

Parameters:

  • i (int): GPU index (0-based)

Returns: *C.char

  • GPU device name on success
  • "NA" on failure

Example:

name := C.GoString(goamdsmi.GO_gpu_dev_name_get(0))
fmt.Printf("GPU 0: %s\n", name)

GO_gpu_dev_id_get

Returns the device ID of the GPU at the specified index.

func GO_gpu_dev_id_get(i int) C.uint16_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint16_t

  • GPU device ID on success
  • 0xFFFF on failure

Example:

deviceID := uint16(goamdsmi.GO_gpu_dev_id_get(0))
if deviceID == 0xFFFF {
    fmt.Println("Failed to get device ID")
}

GO_gpu_dev_pci_id_get

Returns the PCI ID of the GPU device at the specified index.

func GO_gpu_dev_pci_id_get(i int) C.uint64_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint64_t

  • GPU PCI ID on success
  • 0xFFFFFFFFFFFFFFFF on failure

Example:

pciID := uint64(goamdsmi.GO_gpu_dev_pci_id_get(0))
fmt.Printf("PCI ID: 0x%x\n", pciID)

GO_gpu_dev_vbios_version_get

Returns the VBIOS version of the GPU at the specified index.

func GO_gpu_dev_vbios_version_get(i int) *C.char

Parameters:

  • i (int): GPU index (0-based)

Returns: *C.char

  • VBIOS version string on success
  • "NA" on failure

Example:

vbios := C.GoString(goamdsmi.GO_gpu_dev_vbios_version_get(0))
fmt.Printf("VBIOS: %s\n", vbios)

GO_gpu_dev_vendor_name_get

Returns the vendor name of the GPU device at the specified index.

func GO_gpu_dev_vendor_name_get(i int) *C.char

Parameters:

  • i (int): GPU index (0-based)

Returns: *C.char

  • Vendor name on success
  • "NA" on failure

Example:

vendor := C.GoString(goamdsmi.GO_gpu_dev_vendor_name_get(0))
fmt.Printf("Vendor: %s\n", vendor)

Power Management

GO_gpu_dev_power_cap_get

Returns the power cap of the GPU at the specified index.

func GO_gpu_dev_power_cap_get(i int) C.uint64_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint64_t

  • Power cap value on success (units depend on hardware)
  • 0xFFFFFFFFFFFFFFFF on failure

Example:

powerCap := uint64(goamdsmi.GO_gpu_dev_power_cap_get(0))
if powerCap != 0xFFFFFFFFFFFFFFFF {
    fmt.Printf("Power cap: %d\n", powerCap)
}

GO_gpu_dev_power_get

Returns the current power consumption of the GPU at the specified index.

func GO_gpu_dev_power_get(i int) C.uint64_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint64_t

  • Current power value on success (units depend on hardware)
  • 0xFFFFFFFFFFFFFFFF on failure

Example:

power := uint64(goamdsmi.GO_gpu_dev_power_get(0))
fmt.Printf("Current power: %d\n", power)

Temperature Monitoring

GO_gpu_dev_temp_metric_get

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_t

Parameters:

  • i (int): GPU index (0-based)
  • sensor (int): Sensor number
  • metric (int): Metric number

Returns: C.uint64_t

  • Temperature value on success (units depend on hardware)
  • 0xFFFFFFFFFFFFFFFF on failure

Example:

// Query sensor 1, metric 0
temp := uint64(goamdsmi.GO_gpu_dev_temp_metric_get(0, 1, 0))
fmt.Printf("Temperature: %d\n", temp)

Performance Levels

GO_gpu_dev_perf_level_get

Returns the performance level of the GPU at the specified index.

func GO_gpu_dev_perf_level_get(i int) C.uint32_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint32_t

  • Performance level on success
  • 0xFFFFFFFF on failure

Example:

perfLevel := uint32(goamdsmi.GO_gpu_dev_perf_level_get(0))
fmt.Printf("Performance level: %d\n", perfLevel)

GO_gpu_dev_overdrive_level_get

Returns the overdrive level of the GPU at the specified index.

func GO_gpu_dev_overdrive_level_get(i int) C.uint32_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint32_t

  • Overdrive level on success
  • 0xFFFFFFFF on failure

Example:

overdrive := uint32(goamdsmi.GO_gpu_dev_overdrive_level_get(0))
fmt.Printf("Overdrive level: %d\n", overdrive)

GO_gpu_dev_mem_overdrive_level_get

Returns the memory overdrive level of the GPU at the specified index.

func GO_gpu_dev_mem_overdrive_level_get(i int) C.uint32_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint32_t

  • Memory overdrive level on success
  • 0xFFFFFFFF on failure

Example:

memOverdrive := uint32(goamdsmi.GO_gpu_dev_mem_overdrive_level_get(0))
fmt.Printf("Memory overdrive level: %d\n", memOverdrive)

Clock Frequencies

GO_gpu_dev_gpu_clk_freq_get_sclk

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_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint64_t

  • System clock frequency on success
  • 0xFFFFFFFFFFFFFFFF on failure

Example:

sclk := uint64(goamdsmi.GO_gpu_dev_gpu_clk_freq_get_sclk(0))
fmt.Printf("System clock: %d\n", sclk)

GO_gpu_dev_gpu_clk_freq_get_mclk

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_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint64_t

  • Memory clock frequency on success
  • 0xFFFFFFFFFFFFFFFF on failure

Example:

mclk := uint64(goamdsmi.GO_gpu_dev_gpu_clk_freq_get_mclk(0))
fmt.Printf("Memory clock: %d\n", mclk)

Voltage and Frequency Ranges

GO_gpu_od_volt_freq_range_min_get_sclk

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_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint64_t

  • Minimum SCLK frequency on success
  • 0xFFFFFFFFFFFFFFFF on failure

GO_gpu_od_volt_freq_range_min_get_mclk

Returns 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_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint64_t

  • Minimum MCLK frequency on success
  • 0xFFFFFFFFFFFFFFFF on failure

GO_gpu_od_volt_freq_range_max_get_sclk

Returns 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_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint64_t

  • Maximum SCLK frequency on success
  • 0xFFFFFFFFFFFFFFFF on failure

GO_gpu_od_volt_freq_range_max_get_mclk

Returns 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_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint64_t

  • Maximum MCLK frequency on success
  • 0xFFFFFFFFFFFFFFFF on failure

Example:

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)

Utilization Metrics

GO_gpu_dev_gpu_busy_percent_get

Returns the busy percentage of the GPU at the specified index.

func GO_gpu_dev_gpu_busy_percent_get(i int) C.uint32_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint32_t

  • GPU busy percentage (0-100) on success
  • 0xFFFFFFFF on failure

Example:

busyPercent := uint32(goamdsmi.GO_gpu_dev_gpu_busy_percent_get(0))
fmt.Printf("GPU utilization: %d%%\n", busyPercent)

GO_gpu_dev_gpu_memory_busy_percent_get

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_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint64_t

  • Memory busy percentage on success
  • 0xFFFFFFFFFFFFFFFF on failure

Example:

memBusy := uint64(goamdsmi.GO_gpu_dev_gpu_memory_busy_percent_get(0))
fmt.Printf("Memory utilization: %d%%\n", memBusy)

Memory Information

GO_gpu_dev_gpu_memory_usage_get

Returns the memory usage of the GPU at the specified index.

func GO_gpu_dev_gpu_memory_usage_get(i int) C.uint64_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint64_t

  • Memory usage on success (units depend on hardware)
  • 0xFFFFFFFFFFFFFFFF on failure

Example:

memUsage := uint64(goamdsmi.GO_gpu_dev_gpu_memory_usage_get(0))
fmt.Printf("Memory usage: %d\n", memUsage)

GO_gpu_dev_gpu_memory_total_get

Returns the total memory of the GPU at the specified index.

func GO_gpu_dev_gpu_memory_total_get(i int) C.uint64_t

Parameters:

  • i (int): GPU index (0-based)

Returns: C.uint64_t

  • Total memory on success (units depend on hardware)
  • 0xFFFFFFFFFFFFFFFF on failure

Example:

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)

Complete Example

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

docs

cpu-management.md

gpu-management.md

index.md

tile.json