Skip to content

Commit 820d835

Browse files
ApurvMishra-amdammallya
authored andcommitted
rocr: Return path for XDNA devices as a string (#3212)
Return the Devnode and Sysfs paths for XDNA devices as a string to avoid C++ ABI issues with std::filesystem::path. Signed-off-by: Apurv Mishra <Apurv.Mishra@amd.com>
1 parent c69deca commit 820d835

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

runtime/hsa-runtime/core/driver/xdna/amd_xdna_driver.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
#include <unistd.h>
4949

5050
#include <array>
51-
#include <filesystem>
5251
#include <fstream>
5352
#include <map>
5453
#include <memory>
@@ -87,12 +86,11 @@ static const std::map<XDNADeviceId, XDNADeviceType> supported_xdna_devices = {
8786
{{0x17f0}, XDNADeviceType::Stx}, // Strix Halo / Krackan
8887
};
8988

90-
namespace fs = std::filesystem;
91-
89+
/// Returns the path as a string to avoid C++ ABI issues with std::filesystem::path.
9290
/// @brief Devnode path for XDNA devices.
93-
static const fs::path devnodes_path = "/dev/accel";
91+
static const std::string devnodes_path = "/dev/accel";
9492
/// @brief Sysfs path for XDNA devices.
95-
static const fs::path sysfs_path = "/sys/class/accel";
93+
static const std::string sysfs_path = "/sys/class/accel";
9694
/// @brief Devnode prefix for XDNA devices.
9795
static const std::string devnode_prefix = "accel";
9896
/// @brief Maximum devnode minor number for XDNA devices.
@@ -180,7 +178,7 @@ hsa_status_t XdnaDriver::QueryKernelModeDriver(core::DriverQuery query) {
180178
}
181179

182180
hsa_status_t XdnaDriver::Open() {
183-
const auto devnode_path = devnodes_path / devnode_name_;
181+
const std::string devnode_path = devnodes_path + "/" + devnode_name_;
184182
fd_ = open(devnode_path.c_str(), O_RDWR | O_CLOEXEC);
185183
if (fd_ < 0) {
186184
return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
@@ -216,19 +214,19 @@ hsa_status_t XdnaDriver::GetNodeProperties(HsaNodeProperties& node_props, uint32
216214
return HSA_STATUS_ERROR;
217215
}
218216

219-
const auto sysfs_device_path = sysfs_path / devnode_name_ / "device";
217+
const std::string sysfs_device_path = sysfs_path + "/" + devnode_name_ + "/device";
220218

221219
// Find device type.
222220
XDNADeviceType device_type = XDNADeviceType::Unknown;
223221
{
224-
const auto device_id_file = sysfs_device_path / "device";
225-
if (!fs::exists(device_id_file)) {
222+
const std::string device_id_file = sysfs_device_path + "/device";
223+
std::ifstream is(device_id_file);
224+
if (!is.good()) {
226225
assert(false && "Device file not found in sysfs.");
227226
return HSA_STATUS_ERROR;
228227
}
229228

230229
XDNADeviceId device_id = {};
231-
std::ifstream is(device_id_file);
232230
// Device ID is in hex.
233231
if (!(is >> std::hex >> device_id.device)) {
234232
assert(false && "Failed to read device ID from sysfs.");
@@ -268,13 +266,13 @@ hsa_status_t XdnaDriver::GetNodeProperties(HsaNodeProperties& node_props, uint32
268266

269267
// Read device name from sysfs.
270268
{
271-
const auto device_name_file = sysfs_device_path / "vbnv";
272-
if (!fs::exists(device_name_file)) {
269+
const std::string device_name_file = sysfs_device_path + "/vbnv";
270+
std::array<char, HSA_PUBLIC_NAME_SIZE> device_name = {};
271+
std::ifstream is(device_name_file);
272+
if (!is.good()) {
273273
assert(false && "Device file name not found in sysfs.");
274274
return HSA_STATUS_ERROR;
275275
}
276-
std::array<char, HSA_PUBLIC_NAME_SIZE> device_name = {};
277-
std::ifstream is(device_name_file);
278276
if (!is.getline(device_name.data(), device_name.size() - 1)) {
279277
assert(false && "Failed to read device name from sysfs.");
280278
return HSA_STATUS_ERROR;

0 commit comments

Comments
 (0)