🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.debian.bugs.dist
Article #5172

Bug#1154528: amdsmi: Do not complain loudly when no device is found

#5172
From: Samuel Thibault
Date: Fri, 20 Nov 2026 00:00
152 lines
7878 bytes
--Nz+zXh2r04Jxh5DQ
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

Source: amdsmi
Version: 10.1-1
Severity: normal
Tags: patch upstream
Forwarded: https://github.com/ROCm/rocm-systems/pull/7251

Hello,

When librocm-smi is pulled through a dependency, we may end up on a
system without actual hardware supported by ROCM, and rsmi_init()
failing is actually expected, we do want to frighten the user in such a
case.

The situation that triggered this is that I was considering to enable
ROCm support by default in hwloc shipped by Debian. On all systems
that don't have rocm-supported hardware, we would always get Exception
caught: rsmi_init. without any way for hwloc to avoid it. We really
cannot have this by default in Debian, so unless we have a way to avoid
this warning, I cannot enable ROCm by default in hwloc in Debian.

The proposed patch was applied upstream, could you apply it in the
Debian package (I have attached it), so I can enable ROCm support in
hwloc without having to wait for 10.3.0?

Thanks,
Samuel

-- System Information:
Debian Release: forky/sid
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable-debug'), (500, 'testing-debug'), (500, 'stable-security'), (500, 'stable-debug'), (500, 'proposed-updates'), (500, 'oldstable-debug'), (500, 'oldoldstable'), (500, 'buildd-unstable'), (500, 'unstable'), (500, 'stable'), (500, 'oldstable'), (1, 'experimental-debug'), (1, 'buildd-experimental'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386, arm64

Kernel: Linux 7.3.0 (SMP w/22 CPU threads; PREEMPT)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

-- 
Samuel
<N> M.  MIMRAM  Samuel Antonin
<N> en voila un qui etait predestiné
 -+- #ens-mim - Quelles gueules qu'ils ont les ptits nouveaux ? -+-

--Nz+zXh2r04Jxh5DQ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=patch

commit 9fc1a20805beada90d912aac13e8a0535cf8f885
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Mon Jun 15 13:23:56 2026 +0200

    fix(rsmi_init): Do not complain loudly when no device is found
    
    This is a follow-up for ROCm/amdsmi#74, to generalize to various
    initialization cases which show the stack or device is simply not available.
    
    Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

diff --git amdsmi/rocm_smi/include/rocm_smi/rocm_smi.h amdsmi/rocm_smi/include/rocm_smi/rocm_smi.h
index 3e1fbf6410..42d4e72a04 100644
--- amdsmi/rocm_smi/include/rocm_smi/rocm_smi.h
+++ amdsmi/rocm_smi/include/rocm_smi/rocm_smi.h
@@ -1866,6 +1866,8 @@ typedef struct {
  *  to modify how RSMI initializes.
  *
  *  @retval ::RSMI_STATUS_SUCCESS is returned upon successful call.
+ *  @retval ::RSMI_STATUS_DRIVER_NOT_LOADED ROCm/KFD is not present on this system.
+ *  @retval ::RSMI_STATUS_INIT_ERROR initialization failed for other reasons.
  */
 rsmi_status_t rsmi_init(uint64_t init_flags);
 
diff --git amdsmi/rocm_smi/src/rocm_smi.cc amdsmi/rocm_smi/src/rocm_smi.cc
index b303990cd1..9ae4f39959 100644
--- amdsmi/rocm_smi/src/rocm_smi.cc
+++ amdsmi/rocm_smi/src/rocm_smi.cc
@@ -456,15 +456,14 @@ rsmi_status_t rsmi_init(uint64_t flags) {
       smi.Initialize(flags);
     } catch (const amd::smi::rsmi_exception& e) {
       smi.Cleanup();
-      if (e.error_code() == RSMI_INITIALIZATION_ERROR &&
-          !strcmp(e.what(), "Failed to initialize rocm_smi library (KFD node discovery).")) {
+      if (e.error_code() == RSMI_STATUS_DRIVER_NOT_LOADED) {
         // This system does not actually have ROCM drivers set up
         // We were probably just called through dependency, just report the
         // error and log without complaining loudly.
         std::ostringstream ss;
         ss << "Exception caught: " << e.what() << ".";
         LOG_INFO(ss);
-        return RSMI_STATUS_NOT_SUPPORTED;
+        return RSMI_STATUS_DRIVER_NOT_LOADED;
       }
       throw amd::smi::rsmi_exception(RSMI_STATUS_INIT_ERROR, __FUNCTION__);
     } catch (...) {
diff --git amdsmi/rocm_smi/src/rocm_smi_main.cc amdsmi/rocm_smi/src/rocm_smi_main.cc
index 0aa36cb7cf..7df18aab6f 100644
--- amdsmi/rocm_smi/src/rocm_smi_main.cc
+++ amdsmi/rocm_smi/src/rocm_smi_main.cc
@@ -285,6 +285,11 @@ void RocmSMI::Initialize(uint64_t flags) {
   // internal data structures.
   ret = DiscoverAmdgpuDevices();
   if (ret != 0) {
+    if (ret == 2) {
+      // DiscoverAmdgpuDevices returns 2 when GetLargestNodeNumber failed with ENOENT
+      throw amd::smi::rsmi_exception(RSMI_STATUS_DRIVER_NOT_LOADED,
+                                     "DiscoverAmdgpuDevices() did not detect a supported device.");
+    }
     throw amd::smi::rsmi_exception(RSMI_INITIALIZATION_ERROR, "DiscoverAmdgpuDevices() failed.");
   }
 
@@ -806,12 +811,16 @@ uint32_t GetLargestNodeNumber(const std::string& path = KFDNodesPathRoot()) {
   // Open the directory
   DIR* dir = opendir(path.c_str());
   if (!dir) {
+    int error = errno;
     // Return UINT32_MAX on error
-    ss << __PRETTY_FUNCTION__ << " | Failed to open directory: " << path << " | errno = " << errno
-       << " | error = " << strerror(errno);
+    ss << __PRETTY_FUNCTION__ << " | Failed to open directory: " << path << " | errno = " << error
+       << " | error = " << strerror(error);
     // std::cout << ss.str() << std::endl;
     LOG_ERROR(ss);
-    return UINT32_MAX;
+    if (error == ENOENT)
+      return UINT32_MAX - 1;
+    else
+      return UINT32_MAX;
   }
 
   struct dirent* entry;
@@ -854,6 +863,12 @@ uint32_t RocmSMI::DiscoverAmdgpuDevices(void) {
      << " kfd nodes";
   // std::cout << ss.str() << std::endl;
   LOG_DEBUG(ss);
+  if (max_nodes == UINT32_MAX - 1) {
+    ss << __PRETTY_FUNCTION__ << " | Failed to get kfd directory";
+    // std::cout << ss.str() << std::endl;
+    LOG_ERROR(ss);
+    return 2;
+  }
   if (max_nodes == UINT32_MAX) {
     ss << __PRETTY_FUNCTION__ << " | Failed to get largest node number";
     // std::cout << ss.str() << std::endl;

--Nz+zXh2r04Jxh5DQ--
Technical Details
Message-ID: <O1kcO-cYO7-3@gated-at.bofh.it>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!news-ams.pugleaf.net!srl.newsdeef.eu!news.corradoroberto.it!news.servidellagleba.it!bofh.it!news.nic.it!robomod

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!news-ams.pugleaf.net!srl.newsdeef.eu!news.corradoroberto.it!news.servidellagleba.it!bofh.it!news.nic.it!robomod
From: Samuel Thibault <sthibault@debian.org>
Newsgroups: linux.debian.bugs.dist
Subject: Bug#1154528: amdsmi: Do not complain loudly when no device is found
Date: Fri, 20 Nov 2026 01:00:02 +0100
Message-ID: <O1kcO-cYO7-3@gated-at.bofh.it>
X-Mailbox-Line: From debian-bugs-dist-request@lists.debian.org  Thu Nov 19 23:51:08 2026
Old-Return-Path: <debbugs@buxtehude.debian.org>
X-Spam-Flag: NO
X-Spam-Score: -1.7
Reply-To: Samuel Thibault <sthibault@debian.org>, 1154528@bugs.debian.org
Resent-To: debian-bugs-dist@lists.debian.org
Resent-Cc: debian-ai@lists.debian.org
X-Debian-Pr-Message: report 1154528
X-Debian-Pr-Package: src:amdsmi
X-Debian-Pr-Keywords: patch upstream
X-Debian-Pr-Source: amdsmi
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="Nz+zXh2r04Jxh5DQ"
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
X-Reportbug-Version: 13.2.0+nmu1
Organization: I am not organized
X-Debian-User: sthibault
X-Debian-Message: from BTS
X-Mailing-List: <debian-bugs-dist@lists.debian.org> archive/latest/2003649
List-ID: <debian-bugs-dist.lists.debian.org>
List-URL: <https://lists.debian.org/debian-bugs-dist/>
Approved: robomod@news.nic.it
Lines: 152
Sender: robomod@news.nic.it
X-Original-Date: Fri, 20 Nov 2026 00:48:44 +0100
X-Original-Message-ID: <av-K3MgvNG_gpbrj@end>