Skip to content

Comments

Amd smi#45

Closed
djwoun wants to merge 166 commits intomasterfrom
amd-smi
Closed

Amd smi#45
djwoun wants to merge 166 commits intomasterfrom
amd-smi

Conversation

@djwoun
Copy link
Owner

@djwoun djwoun commented Sep 15, 2025

Pull Request Description

AMD SMI PAPI Component

Overview

This component adds AMD SMI to PAPI. It discovers GPUs at runtime and exposes AMD SMI-reported metrics (temperatures, power, fans, PCIe, RAS/ECC, cache/VRAM info, utilization, counters, etc.) as PAPI native events.

Targeted for ROCm 6.4.0 (AMD SMI ~25.3) and expected to work with ROCm(6.3.4 ~ 6.4.3) releases as well.
Tested on a combination of MI210 & MI300 for ROCm:

  • 6.4.0
  • 6.3.4

Usage

# point to your ROCm install (tested with 6.4.0)
export PAPI_AMDSMI_ROOT=/opt/rocm-6.4.0

# configure PAPI
./configure --prefix=${INSTDIR} --with-components="amd_smi"

How it fits together (high-level)

  • linux-amd-smi.c: implements the PAPI vector (init/start/stop/read/reset/etc.) and delegates to the internal amds_* APIs.
  • amds.c: dlopen AMD SMI, discover devices, build the native event table, and wire up accessors.
  • amds_accessors.c: one function per metric — actually calls AMD SMI library to read and write values.
  • amds_ctx.c: per-eventset lifecycle — open/close/start/stop/read/write/reset groups of events and enforce device usage.
  • amds_evtapi.c: native event enumeration — code↔name↔description helpers for PAPI.
  • amds_priv.h: internal types (e.g., native_event_t), globals, and AMD SMI function-pointer declarations.
  • amds_funcs.h: list of AMD SMI API calls used (generates the function-pointer declarations/definitions).
  • htable.h: lightweight string→event lookup (for fast name→code mapping).
  • amds.h: public “component-internal” API used across the above files.
  • Rules.amd_smi: build glue to include this component in PAPI.

File-by-file (concise)

  • linux-amd-smi.c
    Declares the papi_vector_t for this component; initializes on first use; hands off work to amds_* for device/event management; implements PAPI hooks (init_component, update_control_state, start, read, stop, reset, shutdown, and native-event queries).

  • amds.c
    Dynamically loads libamd_smi.so, resolves AMD SMI symbols, discovers sockets/devices, and builds the native event table. Defines helpers to add simple and counter-based events. Manages global teardown (destroy event table, close library).

  • amds_accessors.c
    Implements the accessors that read/write individual metrics (e.g., temperatures, fans, PCIe, energy, power caps, RAS/ECC, clocks, VRAM, link topology, XGMI/PCIe metrics, firmware/board info, etc.). Each accessor maps an event’s (variant, subvariant) to the right SMI call and returns the value.

  • amds_ctx.c
    Provides the per-eventset context:

    • amds_ctx_open/close — acquire/release devices, run per-event open/close hooks.
    • amds_ctx_start/stop — start/stop counters where needed.
    • amds_ctx_read/write/reset — read current values, optionally write supported controls (e.g., power cap), zero software view.
  • amds_evtapi.c
    Implements native-event enumeration for PAPI (enum, code_to_name, name_to_code, code_to_descr) using the in-memory event table and a small hash map for fast lookups.

  • amds_priv.h
    Internal definitions: native_event_t (name/descr/device/mode/value + open/close/start/stop/access callbacks), global getters, and the AMD SMI function-pointer declarations (via amds_funcs.h).

  • amds_funcs.h
    Centralized macro list of AMD SMI APIs used by the component; generates function-pointer declarations/definitions so amds.c can dlsym() them at runtime. Conditional entries handle newer SMI features.

  • htable.h
    Minimal chained hash table for name→event mapping; used by amds_evtapi.c to resolve native event names quickly.

  • amds.h
    Public, component-internal API across files: init/shutdown, native-event queries, context ops, and error-string retrieval.

  • Rules.amd_smi
    Build integration for PAPI’s make system; compiles this component and sets include/library paths for AMD SMI.


Author Checklist

  • Description
    Why this PR exists. Reference all relevant information, including background, issues, test failures, etc
  • Commits
    Commits are self contained and only do one thing
    Commits have a header of the form: module: short description
    Commits have a body (whenever relevant) containing a detailed description of the addressed problem and its solution
  • Tests
    The PR needs to pass all the tests

@djwoun djwoun closed this Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant