From 23a1d7e03c453e55f96d45e669b1da72fd51486c Mon Sep 17 00:00:00 2001 From: Aryan Salmanpour Date: Tue, 28 Jan 2025 16:22:52 -0500 Subject: [PATCH] Eliminate the use of std::fs (#115) --- CMakeLists.txt | 3 -- src/rocjpeg_vaapi_decoder.cpp | 95 +++++++++++++++++------------------ src/rocjpeg_vaapi_decoder.h | 9 +--- 3 files changed, 47 insertions(+), 60 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bd27b50c9..b8233cfaa5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -146,9 +146,6 @@ if(HIP_FOUND AND Libva_FOUND) set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${LIBVA_LIBRARY}) set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${LIBVA_DRM_LIBRARY}) - # std filesystem - set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} stdc++fs) - # rocprofiler if(rocprofiler-register_FOUND) set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} rocprofiler-register::rocprofiler-register) diff --git a/src/rocjpeg_vaapi_decoder.cpp b/src/rocjpeg_vaapi_decoder.cpp index a8688afc68..14cf5d2756 100644 --- a/src/rocjpeg_vaapi_decoder.cpp +++ b/src/rocjpeg_vaapi_decoder.cpp @@ -1001,61 +1001,56 @@ RocJpegStatus RocJpegVappiDecoder::SetSurfaceAsIdle(VASurfaceID surface_id) { */ void RocJpegVappiDecoder::GetGpuUuids() { std::string dri_path = "/dev/dri"; - // Iterate through all render nodes - if (fs::exists(dri_path)) { - for (const auto& entry : fs::directory_iterator(dri_path, fs::directory_options::skip_permission_denied)) { - try { - std::string filename = entry.path().filename().string(); - // Check if the file name starts with "renderD" - if (filename.find("renderD") == 0) { - // Extract the integer part from the render node name (e.g., 128 from renderD128) - int render_id = std::stoi(filename.substr(7)); - std::string sys_device_path = "/sys/class/drm/" + filename + "/device"; - if (fs::exists(sys_device_path)) { - std::string unique_id_path = sys_device_path + "/unique_id"; - std::string unique_id; - if (fs::exists(unique_id_path)) { - std::ifstream unique_id_file(unique_id_path); - if (unique_id_file.is_open() && std::getline(unique_id_file, unique_id)) { - if (!unique_id.empty()) { - // Map the unique GPU UUID to the render node ID - gpu_uuids_to_render_nodes_map_[unique_id] = render_id; - } - } - unique_id_file.close(); - } + DIR* dir = opendir(dri_path.c_str()); + if (dir) { + struct dirent* entry; + // Iterate through all render nodes + while ((entry = readdir(dir)) != nullptr) { + std::string filename = entry->d_name; + // Check if the file name starts with "renderD" + if (filename.find("renderD") == 0) { + // Extract the integer part from the render node name (e.g., 128 from renderD128) + int render_id = std::stoi(filename.substr(7)); + std::string sys_device_path = "/sys/class/drm/" + filename + "/device"; + struct stat info; + if (stat(sys_device_path.c_str(), &info) == 0) { + std::string unique_id_path = sys_device_path + "/unique_id"; + std::ifstream unique_id_file(unique_id_path); + std::string unique_id; + if (unique_id_file.is_open() && std::getline(unique_id_file, unique_id)) { if (!unique_id.empty()) { - unique_id_path = sys_device_path + "/current_compute_partition"; - if (fs::exists(unique_id_path)) { - std::ifstream unique_id_file(unique_id_path); - std::string partition; - ComputePartition current_compute_partition = kSpx; - if (unique_id_file.is_open() && std::getline(unique_id_file, partition)) { - if (!partition.empty()) { - if (partition.compare("SPX") == 0 || partition.compare("spx") == 0) { - current_compute_partition = kSpx; - } else if (partition.compare("DPX") == 0 || partition.compare("dpx") == 0) { - current_compute_partition = kDpx; - } else if (partition.compare("TPX") == 0 || partition.compare("tpx") == 0) { - current_compute_partition = kTpx; - } else if (partition.compare("QPX") == 0 || partition.compare("qpx") == 0) { - current_compute_partition = kQpx; - } else if (partition.compare("CPX") == 0 || partition.compare("cpx") == 0) { - current_compute_partition = kCpx; - } - // Map the unique GPU UUID to the compute partition - gpu_uuids_to_compute_partition_map_[unique_id] = current_compute_partition; - } - unique_id_file.close(); - } - } + // Map the unique GPU UUID to the render node ID + gpu_uuids_to_render_nodes_map_[unique_id] = render_id; } } + unique_id_file.close(); + if (!unique_id.empty()) { + unique_id_path = sys_device_path + "/current_compute_partition"; + std::ifstream partition_file(unique_id_path); + std::string partition; + ComputePartition current_compute_partition = kSpx; + if (partition_file.is_open() && std::getline(partition_file, partition)) { + if (!partition.empty()) { + if (partition.compare("SPX") == 0 || partition.compare("spx") == 0) { + current_compute_partition = kSpx; + } else if (partition.compare("DPX") == 0 || partition.compare("dpx") == 0) { + current_compute_partition = kDpx; + } else if (partition.compare("TPX") == 0 || partition.compare("tpx") == 0) { + current_compute_partition = kTpx; + } else if (partition.compare("QPX") == 0 || partition.compare("qpx") == 0) { + current_compute_partition = kQpx; + } else if (partition.compare("CPX") == 0 || partition.compare("cpx") == 0) { + current_compute_partition = kCpx; + } + // Map the unique GPU UUID to the compute partition + gpu_uuids_to_compute_partition_map_[unique_id] = current_compute_partition; + } + } + partition_file.close(); + } } - } catch (const std::exception& e) { - // If an exception occurs, continue with the next entry - continue; } } + closedir(dir); } } \ No newline at end of file diff --git a/src/rocjpeg_vaapi_decoder.h b/src/rocjpeg_vaapi_decoder.h index c0272867b4..030f1cc86e 100644 --- a/src/rocjpeg_vaapi_decoder.h +++ b/src/rocjpeg_vaapi_decoder.h @@ -31,13 +31,8 @@ THE SOFTWARE. #include #include #include -#if __cplusplus >= 201703L && __has_include() - #include - namespace fs = std::filesystem; -#else - #include - namespace fs = std::experimental::filesystem; -#endif +#include +#include #include #include #include