Skip to content

Commit 6858b0f

Browse files
SWDEV-521135 - Make common way to set/parse UUID bytes from PAL props. (#63)
1 parent c35e964 commit 6858b0f

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

rocclr/device/pal/paldevice.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,22 @@ device::Program* NullDevice::createProgram(amd::Program& owner, amd::option::Opt
323323
return program;
324324
}
325325

326+
void setUUID(Pal::DeviceProperties* devProps, char* uuid) {
327+
snprintf(uuid, 5, "%04d", devProps->pciProperties.domainNumber);
328+
snprintf(uuid + 4, 5, "%04d", devProps->pciProperties.busNumber);
329+
snprintf(uuid + 8, 5, "%04d", devProps->pciProperties.deviceNumber);
330+
snprintf(uuid + 12, 5, "%04d", devProps->pciProperties.functionNumber);
331+
}
332+
326333
void NullDevice::fillDeviceInfo(const Pal::DeviceProperties& palProp,
327334
const Pal::GpuMemoryHeapProperties heaps[Pal::GpuHeapCount],
328335
size_t maxTextureSize, uint numComputeRings,
329336
uint numExclusiveComputeRings, Pal::IDevice* pal_device) {
330337
info_.type_ = CL_DEVICE_TYPE_GPU;
331338
info_.vendorId_ = palProp.vendorId;
332339
// Set uuid
333-
memcpy(info_.uuid_, &palProp.pciProperties.domainNumber, sizeof(uint32_t));
334-
memcpy(info_.uuid_ + 4, &palProp.pciProperties.busNumber, sizeof(uint32_t));
335-
memcpy(info_.uuid_ + 8, &palProp.pciProperties.deviceNumber, sizeof(uint32_t));
336-
memcpy(info_.uuid_ + 12, &palProp.pciProperties.functionNumber, sizeof(uint32_t));
340+
Pal::DeviceProperties palPropTmp = palProp;
341+
setUUID(&palPropTmp, &info_.uuid_[0]);
337342

338343
info_.maxWorkItemDimensions_ = 3;
339344

@@ -1335,22 +1340,7 @@ static void parseRequestedDeviceList(const char* requestedDeviceList,
13351340

13361341
// Retrieve uuid
13371342
char uuid[17] = {0};
1338-
for (int j = 0; j < 4; j++) {
1339-
itoa((reinterpret_cast<char*>(&properties.pciProperties.domainNumber))[j],
1340-
&uuid[j], 10);
1341-
}
1342-
for (int j = 0; j < 4; j++) {
1343-
itoa((reinterpret_cast<char*>(&properties.pciProperties.busNumber))[j],
1344-
&uuid[j + 4], 10);
1345-
}
1346-
for (int j = 0; j < 4; j++) {
1347-
itoa((reinterpret_cast<char*>(&properties.pciProperties.deviceNumber))[j],
1348-
&uuid[j + 8], 10);
1349-
}
1350-
for (int j = 0; j < 4; j++) {
1351-
itoa((reinterpret_cast<char*>(&properties.pciProperties.functionNumber))[j],
1352-
&uuid[j + 12], 10);
1353-
}
1343+
setUUID(&properties, &uuid[0]);
13541344

13551345
// Convert it to index
13561346
if (strcmp(pch + 4, uuid) == 0) {

0 commit comments

Comments
 (0)