Files
TheRock/rocm-systems/projects/amdsmi/docs/how-to/amdsmi-go-lib.md
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

3.1 KiB

myst
myst
html_meta
description lang=en keywords
Get started with the AMD SMI Go interface. api, smi, lib, go, golang, system, management, interface, ROCm

AMD SMI Go interface overview

The AMD SMI Go interface provides a convenient way to interact with AMD hardware through a simple and accessible API. The API is compatible with Go 1.20 and higher and requires the AMD driver to be loaded for initialization. Review the prerequisites.

Refer to the [Go library API reference](../reference/amdsmi-go-api.md).

(go_prereqs)=

Prerequisites

Before get started, make sure your environment satisfies the following prerequisites. See the requirements section for more information.

  1. Ensure amdgpu drivers are installed properly for initialization.

  2. Export LD_LIBRARY_PATH to the amdsmi installation directory.

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/rocm/lib:/opt/rocm/lib64:
    
  3. Install Go 1.20+.

    Download Go from https://go.dev/dl/ and follow the official installation documentation at Download and install.

    Alternatively, use a third-party utility like update-golang.

    git clone https://github.com/udhos/update-golang
    cd update-golang
    sudo ./update-golang.sh
    source /etc/profile.d/golang_path.sh
    go version
    

Get started

``hipcc`` and other compilers will not automatically link in the ``libamd_smi``
dynamic library. To compile code that uses the AMD SMI library API, ensure the
``libamd_smi.so`` can be located by setting the ``LD_LIBRARY_PATH`` environment
variable to the directory containing ``librocm_smi64.so`` (usually
``/opt/rocm/lib``) or by passing the ``-lamd_smi`` flag to the compiler.

A Go application using AMD SMI must call goamdsmi.GO_gpu_init() to initialize the AMI SMI library before all other calls. This call initializes the internal data structures required for subsequent AMD SMI operations.

goamdsmi.GO_gpu_shutdown() must be the last call to properly close connection to driver and make sure that any resources held by AMD SMI are released.

Usage

For an example on using the AMD SMI Go API, refer to this implementation https://github.com/amd/amd_smi_exporter/tree/master.

Refer to the [Go library API reference](../reference/amdsmi-go-api.md).

Add AMD SMI library to your project

To include the AMD SMI Go API in your project, update your Makefile or Go module configuration to fetch the appropriate version of the AMD SMI library.

# Add to go.mod
go get github.com/ROCm/rocm-systems/projects/amdsmi@develop

Then import it:

import "github.com/ROCm/rocm-systems/projects/amdsmi"

When using a Makefile, ensure you're fetching the latest AMD SMI repository with Go API support. See https://github.com/amd/amd_smi_exporter/blob/master/src/Makefile for an example implementation.