From cb1f02f4f7bd8dbd8721ca758495a00a5c0ce205 Mon Sep 17 00:00:00 2001 From: Rakesh Roy Date: Wed, 17 Apr 2024 14:38:48 +0530 Subject: [PATCH] SWDEV-453180 - Add UUID support for HIP_VISIBLE_DEVICES on Windows - UUID needs to be specified in the format GPU-, encodes UUID as a 16 chars - Convert set UUID in HIP_VISIBLE_DEVICES to device index internally - Then use existing device index logic for HIP_VISIBLE_DEVICES Change-Id: I654f492a49cd4d7a9b7339360ab558165240caa5 [ROCm/clr commit: fb217fa9e02139cc0f52d101a9ab8ad71deaea31] --- projects/clr/rocclr/device/pal/paldevice.cpp | 44 +++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/projects/clr/rocclr/device/pal/paldevice.cpp b/projects/clr/rocclr/device/pal/paldevice.cpp index 9601a8b15f..48ca8740d0 100644 --- a/projects/clr/rocclr/device/pal/paldevice.cpp +++ b/projects/clr/rocclr/device/pal/paldevice.cpp @@ -1290,10 +1290,50 @@ typedef std::unordered_map requestedDevices_t; //! Parses the requested list of devices to be exposed to the user. static void parseRequestedDeviceList(const char* requestedDeviceList, - requestedDevices_t& requestedDevices, uint32_t numDevices) { + requestedDevices_t& requestedDevices, uint32_t numDevices, + Pal::IDevice* deviceList[Pal::MaxDevices]) { char* pch = strtok(const_cast(requestedDeviceList), ","); while (pch != nullptr) { bool deviceIdValid = true; + // UUID needs to be specified in the format GPU-, encodes UUID as a 16 chars + char* deviceUuid = strstr(pch, "GPU-"); + // If Uuid is specified, then convert it to index + if (deviceUuid != nullptr) { + for (uint32_t i = 0; i < numDevices; i++) { + Pal::DeviceProperties properties; + // Retrieve device properties + Pal::Result result = deviceList[i]->GetProperties(&properties); + if (result != Pal::Result::Success) { + continue; + } + + // Retrieve uuid + char uuid[17] = {0}; + for (int j = 0; j < 4; j++) { + itoa((reinterpret_cast(&properties.pciProperties.domainNumber))[j], + &uuid[j], 10); + } + for (int j = 0; j < 4; j++) { + itoa((reinterpret_cast(&properties.pciProperties.busNumber))[j], + &uuid[j + 4], 10); + } + for (int j = 0; j < 4; j++) { + itoa((reinterpret_cast(&properties.pciProperties.deviceNumber))[j], + &uuid[j + 8], 10); + } + for (int j = 0; j < 4; j++) { + itoa((reinterpret_cast(&properties.pciProperties.functionNumber))[j], + &uuid[j + 12], 10); + } + + // Convert it to index + if (strcmp(pch + 4, uuid) == 0) { + snprintf(pch, strlen(pch), "%d", i); + break; + } + } + } + int currentDeviceIndex = atoi(pch); // Validate device index. for (size_t i = 0; i < strlen(pch); i++) { @@ -1378,7 +1418,7 @@ bool Device::init() { if (requestedDeviceList[0] != '\0') { useDeviceList = true; - parseRequestedDeviceList(requestedDeviceList, requestedDevices, gNumDevices); + parseRequestedDeviceList(requestedDeviceList, requestedDevices, gNumDevices, &gDeviceList[0]); } bool foundDevice = false;