From 52db98edd95f618861f38cf14d348aaab1c18d33 Mon Sep 17 00:00:00 2001 From: Rakesh Roy Date: Mon, 8 Apr 2024 19:04:59 +0530 Subject: [PATCH] SWDEV-453180 - Add UUID support for HIP_VISIBLE_DEVICES on Linux - UUID is Ascii string with a maximum of 21 chars which uniquely identifies a GPU - Convert set UUID in HIP_VISIBLE_DEVICES to device index internally - Then use existing device index logic for HIP_VISIBLE_DEVICES Change-Id: I8cab4fe42459f8209b97f909300789e6e687b9ac --- rocclr/device/rocm/rocdevice.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/rocclr/device/rocm/rocdevice.cpp b/rocclr/device/rocm/rocdevice.cpp index 091f1814a5..ff5eebc005 100644 --- a/rocclr/device/rocm/rocdevice.cpp +++ b/rocclr/device/rocm/rocdevice.cpp @@ -503,11 +503,28 @@ bool Device::init() { if (end == std::string::npos) { end = ordinals.size(); } - std::string strIndex = ordinals.substr(pos, end - pos); - int index = atoi(strIndex.c_str()); + std::string str_id = ordinals.substr(pos, end - pos); + // If Uuid is specified, then convert it to index + // Uuid is an Ascii string with a maximum of 21 chars including NULL + // The string value is in the format GPU-, encodes UUID as a 16 chars hex + if (str_id.find("GPU-") != std::string::npos) { + for (int i = 0; i < gpu_agents_.size(); i++) { + auto agent = gpu_agents_[i]; + char unique_id[32] = {0}; + if (HSA_STATUS_SUCCESS == + hsa_agent_get_info(agent, static_cast(HSA_AMD_AGENT_INFO_UUID), + unique_id)) { + if (std::string(unique_id).find(str_id) != std::string::npos) { + str_id = std::to_string(i); + break; + } + } + } + } + int index = atoi(str_id.c_str()); if (index < 0 || static_cast(index) >= gpu_agents_.size() || - strIndex != std::to_string(index)) { + str_id != std::to_string(index)) { deviceIdValid = false; }