Skip to content

AMD SMI was initialized multiple times - #1244

Open
manoj-freyr wants to merge 2 commits into
masterfrom
smi-init-faultfix
Open

AMD SMI was initialized multiple times#1244
manoj-freyr wants to merge 2 commits into
masterfrom
smi-init-faultfix

Conversation

@manoj-freyr

Copy link
Copy Markdown
Collaborator

Motivation

Fix — centralized AMD SMI lifecycle. One ownership and idempotent cleanup API to work with both CLI run as well as API and ensure multi module loads are handled (ufor -r and -m cases)

Technical Details

amdsmi_init() called more than once in a process as of now and a single shutdoqwn() call at exit of a RVS module. This resulted in corrupted heap and causes a segfault. A mutex guard for amd smi as a resource ensures single init and cleanup path . This solves cases for :

  • Multi module call in a single process: like -m or -r runs and also a conf file with many modules in it.
  • Single action runs
  • API based calls.

Rootcause

Typical RVS run is :


- First init — gst module rvs_module_init() → gpulist::Initialize()
- Test runs and passes; action_destroy() cleans up rvs_blas
- Second init — end-of-run summary → systemOverview() → gpulist::Initialize() again 
- Single shutdown — module::terminate() → gst rvs_module_terminate() → amdsmi_shut_down()

This double init and single shutdown causes Clib heap corruption error.
WIth the current PR: we use guard to init and shutdown smi. We ensure gpulist::Initialize() calls smi init and gpulist::Terminate() calls smi shutdown. gpulist::Terminate() is called from module::terminate() after unloading modules.
For API cases, we add module::terminate() in rvs_terminate() but since this is idempotent and a no-op in case SMI already shutdown.
Retaubed existing behavior in unit tests as they run as standalone binaries.

Test Plan

Run rvs with a multi module conf on latest rocm,.

in RVS per run (module init, systemOverview(), get_gpu_name())
but shut down once — causing heap corruption and a post-summary
segfault

Fix — centralized AMD SMI lifecycle. One ownership and idempotent
cleanup API to work with both CLI run as well as API and ensure multi
module loads are handled (ufor -r and -m cases)
Comment thread rvs/src/rvs_interface.cpp Outdated

/* Ensure AMD SMI and loaded modules are torn down if the client skipped
* session destroy or exited without running module::terminate via exec. */
rvs::module::terminate();

@jkottiku jkottiku Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really required here ? As it would be called in run() function anyways.

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.

2 participants