From 22b4ff7aae68d1eab63e1c19b506d369874e3bc6 Mon Sep 17 00:00:00 2001 From: Jatin Chaudhary <51944368+cjatin@users.noreply.github.com> Date: Thu, 9 Oct 2025 06:26:05 +0100 Subject: [PATCH] SWDEV-1 fix issues seen due to test sharding (#1134) --- .../multiproc/hipDeviceGetPCIBusIdMproc.cc | 23 ++++++++++++++ .../catch/unit/device/hipDeviceGetName.cc | 30 ++++++++++++++++++ .../catch/unit/device/hipDeviceGetUuid.cc | 31 +++++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/projects/hip-tests/catch/multiproc/hipDeviceGetPCIBusIdMproc.cc b/projects/hip-tests/catch/multiproc/hipDeviceGetPCIBusIdMproc.cc index cc97e7005a..136eb38272 100644 --- a/projects/hip-tests/catch/multiproc/hipDeviceGetPCIBusIdMproc.cc +++ b/projects/hip-tests/catch/multiproc/hipDeviceGetPCIBusIdMproc.cc @@ -172,7 +172,30 @@ TEST_CASE("Unit_hipDeviceGetPCIBusId_MaskedDevices") { /* Compare {pciDomainID, pciBusID, pciDeviceID} values * hipDeviceGetPCIBusId vs lspci */ + TEST_CASE("Unit_hipDeviceGetPCIBusId_CheckPciBusIDWithLspci") { + auto are_devices_hidden = []() -> bool { +#if HT_AMD + auto env_res = std::getenv("HIP_VISIBLE_DEVICES"); + if (env_res == nullptr) { + env_res = std::getenv("ROCR_VISIBLE_DEVICES"); + if (env_res == nullptr) { + return false; + } + } + return true; +#else + auto env_res = std::getenv("HIP_VISIBLE_DEVICES"); + return env_res != nullptr; +#endif + }(); + + if (are_devices_hidden) { + HipTest::HIP_SKIP_TEST( + "There are hidden devices, which means lscpi might report something different than what we " + "have here"); + } + FILE* fpipe; { // Check if lspci is installed, if not, don't proceed diff --git a/projects/hip-tests/catch/unit/device/hipDeviceGetName.cc b/projects/hip-tests/catch/unit/device/hipDeviceGetName.cc index 924717e654..028358bf66 100644 --- a/projects/hip-tests/catch/unit/device/hipDeviceGetName.cc +++ b/projects/hip-tests/catch/unit/device/hipDeviceGetName.cc @@ -179,6 +179,25 @@ TEST_CASE("Unit_hipDeviceGetName_PartialFill") { #if HT_AMD #define BUFFER_LEN 512 +static inline std::vector parseVisibleDevices() { + std::vector res; + auto env_res = std::getenv("HIP_VISIBLE_DEVICES"); + if (env_res == nullptr) { + env_res = std::getenv("ROCR_VISIBLE_DEVICES"); + if (env_res == nullptr) { + return res; + } + } + + std::stringstream ss(std::string{env_res}); + std::string item; + while (std::getline(ss, item, ',')) { + res.push_back(std::stoi(item)); + } + + return res; +} + /** * Test Description * ------------------------ @@ -223,6 +242,17 @@ TEST_CASE("Unit_hipDeviceName_gcnArchName_And_rocm_agent_enumerator") { j++; } + auto visible_devices = parseVisibleDevices(); + if (visible_devices.size() > 0) { + // We have visible devices set, basically parse the visible devices and remove the entries + size_t start = 0; // The devices will be reported from 0.. + std::map> dNameMapCopy; + for (auto device : visible_devices) { + dNameMapCopy[start] = dNameMap[device]; + } + dNameMap = dNameMapCopy; + } + for (const auto& i : dNameMap) { if (i.second.size() == 0) { continue; diff --git a/projects/hip-tests/catch/unit/device/hipDeviceGetUuid.cc b/projects/hip-tests/catch/unit/device/hipDeviceGetUuid.cc index e55f769212..551cc595ca 100644 --- a/projects/hip-tests/catch/unit/device/hipDeviceGetUuid.cc +++ b/projects/hip-tests/catch/unit/device/hipDeviceGetUuid.cc @@ -114,6 +114,26 @@ TEST_CASE("Unit_hipDeviceGetUuid_Negative") { } #ifdef __linux__ #if HT_AMD + +static inline std::vector parseVisibleDevices() { + std::vector res; + auto env_res = std::getenv("HIP_VISIBLE_DEVICES"); + if (env_res == nullptr) { + env_res = std::getenv("ROCR_VISIBLE_DEVICES"); + if (env_res == nullptr) { + return res; + } + } + + std::stringstream ss(std::string{env_res}); + std::string item; + while (std::getline(ss, item, ',')) { + res.push_back(std::stoi(item)); + } + + return res; +} + /** * Test Description * ------------------------ @@ -161,6 +181,17 @@ TEST_CASE("Unit_hipDeviceGetUuid_From_RocmInfo") { j++; } + auto visible_devices = parseVisibleDevices(); + if (visible_devices.size() > 0) { + // We have visible devices set, basically parse the visible devices and remove the entries + size_t start = 0; // The devices will be reported from 0.. + std::map> uuid_map_copy; + for (auto device : visible_devices) { + uuid_map_copy[start] = uuid_map[device]; + } + uuid_map = uuid_map_copy; + } + for (const auto& i : uuid_map) { if (i.second.size() == 0) { continue;