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 ? -+-
commit 9fc1a20805beada90d912aac13e8a0535cf8f885 Author: Samuel Thibault <[email protected]> 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 <[email protected]> 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;

