Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions onnxruntime/core/platform/linux/device_discovery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <iterator>
#include <optional>
#include <regex>
#include <string>
#include <string_view>

#include "core/common/common.h"
Expand All @@ -21,14 +22,17 @@ namespace onnxruntime {

namespace {

Status ErrorCodeToStatus(const std::error_code& ec) {
Status ErrorCodeToStatus(const std::error_code& ec, const fs::path& path, std::string_view context) {
Copy link
Contributor Author

@theHamsta theHamsta Feb 9, 2026

Choose a reason for hiding this comment

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

the string "context" could be overkill. I thought it would provide useful context, why we accessed the file. But I would at least include the filesystem path that caused the error code. Otherwise, debugging the error code could be difficult

if (!ec) {
return Status::OK();
}

return Status{common::StatusCategory::ONNXRUNTIME, common::StatusCode::FAIL,
MakeString("Error: std::error_code with category name: ", ec.category().name(),
", value: ", ec.value(), ", message: ", ec.message())};
", value: ", ec.value(),
", message: ", ec.message(),
", filesystem path: ", path,
", context: ", context)};
}

struct GpuSysfsPathInfo {
Expand All @@ -40,7 +44,7 @@ Status DetectGpuSysfsPaths(std::vector<GpuSysfsPathInfo>& gpu_sysfs_paths_out) {
std::error_code error_code{};
const fs::path sysfs_class_drm_path = "/sys/class/drm";
const bool sysfs_class_drm_path_exists = fs::exists(sysfs_class_drm_path, error_code);
ORT_RETURN_IF_ERROR(ErrorCodeToStatus(error_code));
ORT_RETURN_IF_ERROR(ErrorCodeToStatus(error_code, sysfs_class_drm_path, "Checking existance of DRM sysfs path"));

if (!sysfs_class_drm_path_exists) {
gpu_sysfs_paths_out = std::vector<GpuSysfsPathInfo>{};
Expand Down Expand Up @@ -69,7 +73,7 @@ Status DetectGpuSysfsPaths(std::vector<GpuSysfsPathInfo>& gpu_sysfs_paths_out) {
std::vector<GpuSysfsPathInfo> gpu_sysfs_paths{};

auto dir_iterator = fs::directory_iterator{sysfs_class_drm_path, error_code};
ORT_RETURN_IF_ERROR(ErrorCodeToStatus(error_code));
ORT_RETURN_IF_ERROR(ErrorCodeToStatus(error_code, sysfs_class_drm_path, "Iterating over DRM sysfs devices"));

for (const auto& dir_item : dir_iterator) {
const auto& dir_item_path = dir_item.path();
Expand Down Expand Up @@ -121,7 +125,7 @@ Status GetPciBusId(const std::filesystem::path& sysfs_path, std::optional<std::s

std::error_code error_code;
auto pci_bus_id_path = std::filesystem::canonical(sysfs_path / "device", error_code); // resolves symlink to PCI bus id, e.g. 0000:65:00.0
ORT_RETURN_IF_ERROR(ErrorCodeToStatus(error_code));
ORT_RETURN_IF_ERROR(ErrorCodeToStatus(error_code, sysfs_path / "device", "Getting PCI bus id from DRM device by resolving symlink"));

auto pci_bus_id_filename = pci_bus_id_path.filename();
if (std::regex_match(pci_bus_id_filename.string(), pci_bus_id_regex)) {
Expand All @@ -130,9 +134,9 @@ Status GetPciBusId(const std::filesystem::path& sysfs_path, std::optional<std::s
pci_bus_id = {};
LOGS_DEFAULT(WARNING) << MakeString("Skipping pci_bus_id for PCI path at \"",
pci_bus_id_path.string(),
"\" because filename \"", pci_bus_id_filename, "\" dit not match expected pattern of ",
"\" because filename \"", pci_bus_id_filename, "\" did not match expected pattern of ",
regex_pattern);
};
}

return Status::OK();
}
Expand Down