Skip to content

Commit cea5abd

Browse files
early continue for "if (deviceMatch)"
1 parent 0913045 commit cea5abd

File tree

1 file changed

+76
-81
lines changed

1 file changed

+76
-81
lines changed

sycl/source/detail/platform_impl.cpp

Lines changed: 76 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -403,102 +403,97 @@ static std::vector<device> amendDeviceAndSubDevices(
403403
deviceMatch = (target.DeviceNum.value() == original_indices[i]);
404404
}
405405

406-
if (deviceMatch) {
407-
// Top level matches. Do we add it, or subdevices, or sub-sub-devices?
408-
bool wantSubDevice =
409-
target.SubDeviceNum || target.HasSubDeviceWildCard;
410-
bool supportsSubPartitioning =
411-
(supportsPartitionProperty(dev, partitionProperty) &&
412-
supportsAffinityDomain(dev, partitionProperty, affinityDomain));
413-
bool wantSubSubDevice =
414-
target.SubSubDeviceNum || target.HasSubSubDeviceWildCard;
415-
416-
// -- Add top level device.
417-
if (!wantSubDevice) {
418-
if (!deviceAdded) {
419-
FinalResult.push_back(dev);
420-
deviceAdded = true;
406+
if (!deviceMatch)
407+
continue;
408+
// Top level matches. Do we add it, or subdevices, or sub-sub-devices?
409+
bool wantSubDevice = target.SubDeviceNum || target.HasSubDeviceWildCard;
410+
bool supportsSubPartitioning =
411+
(supportsPartitionProperty(dev, partitionProperty) &&
412+
supportsAffinityDomain(dev, partitionProperty, affinityDomain));
413+
bool wantSubSubDevice =
414+
target.SubSubDeviceNum || target.HasSubSubDeviceWildCard;
415+
416+
// -- Add top level device.
417+
if (!wantSubDevice) {
418+
if (!deviceAdded) {
419+
FinalResult.push_back(dev);
420+
deviceAdded = true;
421+
}
422+
} else {
423+
if (!supportsSubPartitioning) {
424+
if (target.DeviceNum ||
425+
(target.DeviceType &&
426+
(target.DeviceType.value() != info::device_type::all))) {
427+
// This device was specifically requested and yet is not
428+
// partitionable.
429+
std::cout << "device is not partitionable: " << target
430+
<< std::endl;
421431
}
422-
} else {
423-
if (!supportsSubPartitioning) {
424-
if (target.DeviceNum ||
425-
(target.DeviceType &&
426-
(target.DeviceType.value() != info::device_type::all))) {
427-
// This device was specifically requested and yet is not
428-
// partitionable.
429-
std::cout << "device is not partitionable: " << target
432+
continue;
433+
}
434+
// -- Add sub sub device.
435+
if (wantSubSubDevice) {
436+
437+
auto subDevicesToPartition =
438+
dev.create_sub_devices<partitionProperty>(affinityDomain);
439+
if (target.SubDeviceNum) {
440+
if (subDevicesToPartition.size() > target.SubDeviceNum.value()) {
441+
subDevicesToPartition[0] =
442+
subDevicesToPartition[target.SubDeviceNum.value()];
443+
subDevicesToPartition.resize(1);
444+
} else {
445+
std::cout << "subdevice index out of bounds: " << target
430446
<< std::endl;
447+
continue;
431448
}
432-
continue;
433449
}
434-
// -- Add sub sub device.
435-
if (wantSubSubDevice) {
436-
437-
auto subDevicesToPartition =
438-
dev.create_sub_devices<partitionProperty>(affinityDomain);
439-
if (target.SubDeviceNum) {
440-
if (subDevicesToPartition.size() >
441-
target.SubDeviceNum.value()) {
442-
subDevicesToPartition[0] =
443-
subDevicesToPartition[target.SubDeviceNum.value()];
444-
subDevicesToPartition.resize(1);
445-
} else {
446-
std::cout << "subdevice index out of bounds: " << target
450+
for (device subDev : subDevicesToPartition) {
451+
bool supportsSubSubPartitioning =
452+
(supportsPartitionProperty(subDev, partitionProperty) &&
453+
supportsAffinityDomain(subDev, partitionProperty,
454+
affinityDomain));
455+
if (!supportsSubSubPartitioning) {
456+
if (target.SubDeviceNum) {
457+
// Parent subdevice was specifically requested, yet is not
458+
// partitionable.
459+
std::cout << "sub-device is not partitionable: " << target
447460
<< std::endl;
448-
continue;
449-
}
450-
}
451-
for (device subDev : subDevicesToPartition) {
452-
bool supportsSubSubPartitioning =
453-
(supportsPartitionProperty(subDev, partitionProperty) &&
454-
supportsAffinityDomain(subDev, partitionProperty,
455-
affinityDomain));
456-
if (!supportsSubSubPartitioning) {
457-
if (target.SubDeviceNum) {
458-
// Parent subdevice was specifically requested, yet is not
459-
// partitionable.
460-
std::cout << "sub-device is not partitionable: " << target
461-
<< std::endl;
462-
}
463-
continue;
464-
}
465-
// Allright, lets get them sub-sub-devices.
466-
auto subSubDevices =
467-
subDev.create_sub_devices<partitionProperty>(
468-
affinityDomain);
469-
if (target.HasSubSubDeviceWildCard) {
470-
FinalResult.insert(FinalResult.end(), subSubDevices.begin(),
471-
subSubDevices.end());
472-
} else {
473-
if (subSubDevices.size() > target.SubSubDeviceNum.value()) {
474-
FinalResult.push_back(
475-
subSubDevices[target.SubSubDeviceNum.value()]);
476-
} else {
477-
std::cout
478-
<< "sub-sub-device index out of bounds: " << target
479-
<< std::endl;
480-
}
481461
}
462+
continue;
482463
}
483-
} else if (wantSubDevice) {
484-
auto subDevices = dev.create_sub_devices<
485-
info::partition_property::partition_by_affinity_domain>(
486-
affinityDomain);
487-
if (target.HasSubDeviceWildCard) {
488-
FinalResult.insert(FinalResult.end(), subDevices.begin(),
489-
subDevices.end());
464+
// Allright, lets get them sub-sub-devices.
465+
auto subSubDevices =
466+
subDev.create_sub_devices<partitionProperty>(affinityDomain);
467+
if (target.HasSubSubDeviceWildCard) {
468+
FinalResult.insert(FinalResult.end(), subSubDevices.begin(),
469+
subSubDevices.end());
490470
} else {
491-
if (subDevices.size() > target.SubDeviceNum.value()) {
471+
if (subSubDevices.size() > target.SubSubDeviceNum.value()) {
492472
FinalResult.push_back(
493-
subDevices[target.SubDeviceNum.value()]);
473+
subSubDevices[target.SubSubDeviceNum.value()]);
494474
} else {
495-
std::cout << "subdevice index out of bounds: " << target
475+
std::cout << "sub-sub-device index out of bounds: " << target
496476
<< std::endl;
497477
}
498478
}
499479
}
480+
} else if (wantSubDevice) {
481+
auto subDevices = dev.create_sub_devices<
482+
info::partition_property::partition_by_affinity_domain>(
483+
affinityDomain);
484+
if (target.HasSubDeviceWildCard) {
485+
FinalResult.insert(FinalResult.end(), subDevices.begin(),
486+
subDevices.end());
487+
} else {
488+
if (subDevices.size() > target.SubDeviceNum.value()) {
489+
FinalResult.push_back(subDevices[target.SubDeviceNum.value()]);
490+
} else {
491+
std::cout << "subdevice index out of bounds: " << target
492+
<< std::endl;
493+
}
494+
}
500495
}
501-
} // /if deviceMatch
496+
}
502497
}
503498
} // /for
504499
} // /for

0 commit comments

Comments
 (0)