Skip to content

Commit 9e04fbf

Browse files
More refactoring + comments adjustments
1 parent 47a78cc commit 9e04fbf

File tree

1 file changed

+26
-38
lines changed

1 file changed

+26
-38
lines changed

sycl/source/detail/platform_impl.cpp

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ static std::vector<device> amendDeviceAndSubDevices(
407407

408408
if (!deviceMatch)
409409
continue;
410+
410411
// Top level matches. Do we add it, or subdevices, or sub-sub-devices?
411412
bool wantSubDevice = target.SubDeviceNum || target.HasSubDeviceWildCard;
412413
bool supportsSubPartitioning =
@@ -415,8 +416,8 @@ static std::vector<device> amendDeviceAndSubDevices(
415416
bool wantSubSubDevice =
416417
target.SubSubDeviceNum || target.HasSubSubDeviceWildCard;
417418

418-
// -- Add top level device.
419419
if (!wantSubDevice) {
420+
// -- Add top level device only.
420421
if (!deviceAdded) {
421422
FinalResult.push_back(dev);
422423
deviceAdded = true;
@@ -435,39 +436,27 @@ static std::vector<device> amendDeviceAndSubDevices(
435436
continue;
436437
}
437438

438-
if (!wantSubSubDevice) {
439-
// -- Add sub device.
440-
auto subDevices = dev.create_sub_devices<
441-
info::partition_property::partition_by_affinity_domain>(
442-
affinityDomain);
443-
if (target.HasSubDeviceWildCard) {
444-
FinalResult.insert(FinalResult.end(), subDevices.begin(),
445-
subDevices.end());
446-
} else {
447-
if (subDevices.size() > target.SubDeviceNum.value()) {
448-
FinalResult.push_back(subDevices[target.SubDeviceNum.value()]);
449-
} else {
450-
std::cout << "subdevice index out of bounds: " << target
451-
<< std::endl;
452-
}
453-
}
454-
continue;
455-
}
456-
457-
// -- Add sub sub device.
458-
auto subDevicesToPartition =
459-
dev.create_sub_devices<partitionProperty>(affinityDomain);
439+
auto subDevices = dev.create_sub_devices<
440+
info::partition_property::partition_by_affinity_domain>(
441+
affinityDomain);
460442
if (target.SubDeviceNum) {
461-
if (subDevicesToPartition.size() > target.SubDeviceNum.value()) {
462-
subDevicesToPartition[0] =
463-
subDevicesToPartition[target.SubDeviceNum.value()];
464-
subDevicesToPartition.resize(1);
465-
} else {
443+
if (subDevices.size() <= target.SubDeviceNum.value()) {
466444
std::cout << "subdevice index out of bounds: " << target << std::endl;
467445
continue;
468446
}
447+
subDevices[0] = subDevices[target.SubDeviceNum.value()];
448+
subDevices.resize(1);
469449
}
470-
for (device subDev : subDevicesToPartition) {
450+
451+
if (!wantSubSubDevice) {
452+
// -- Add sub device(s) only.
453+
FinalResult.insert(FinalResult.end(), subDevices.begin(),
454+
subDevices.end());
455+
continue;
456+
}
457+
458+
// -- Add sub sub device(s).
459+
for (device subDev : subDevices) {
471460
bool supportsSubSubPartitioning =
472461
(supportsPartitionProperty(subDev, partitionProperty) &&
473462
supportsAffinityDomain(subDev, partitionProperty, affinityDomain));
@@ -480,23 +469,22 @@ static std::vector<device> amendDeviceAndSubDevices(
480469
}
481470
continue;
482471
}
472+
483473
// Allright, lets get them sub-sub-devices.
484474
auto subSubDevices =
485475
subDev.create_sub_devices<partitionProperty>(affinityDomain);
486-
if (target.HasSubSubDeviceWildCard) {
487-
FinalResult.insert(FinalResult.end(), subSubDevices.begin(),
488-
subSubDevices.end());
489-
} else {
490-
if (subSubDevices.size() > target.SubSubDeviceNum.value()) {
491-
FinalResult.push_back(
492-
subSubDevices[target.SubSubDeviceNum.value()]);
493-
} else {
476+
if (target.SubSubDeviceNum) {
477+
if (subSubDevices.size() <= target.SubSubDeviceNum.value()) {
494478
std::cout << "sub-sub-device index out of bounds: " << target
495479
<< std::endl;
480+
continue;
496481
}
482+
subSubDevices[0] = subSubDevices[target.SubSubDeviceNum.value()];
483+
subSubDevices.resize(1);
497484
}
485+
FinalResult.insert(FinalResult.end(), subSubDevices.begin(),
486+
subSubDevices.end());
498487
}
499-
continue;
500488
}
501489
}
502490
return FinalResult;

0 commit comments

Comments
 (0)