Skip to content

Commit 47a78cc

Browse files
Early continue for "(PlatformBackend == TargetBackend || TargetBackend == backend::all)"
1 parent 2382d5b commit 47a78cc

File tree

1 file changed

+91
-92
lines changed

1 file changed

+91
-92
lines changed

sycl/source/detail/platform_impl.cpp

Lines changed: 91 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -392,114 +392,113 @@ static std::vector<device> amendDeviceAndSubDevices(
392392
bool deviceAdded = false;
393393
for (ods_target target : OdsTargetList->get()) {
394394
backend TargetBackend = target.Backend.value_or(backend::all);
395-
if (PlatformBackend == TargetBackend || TargetBackend == backend::all) {
396-
bool deviceMatch = target.HasDeviceWildCard; // opencl:*
397-
if (target.DeviceType) { // opencl:gpu
398-
deviceMatch = ((target.DeviceType == info::device_type::all) ||
399-
(dev.get_info<info::device::device_type>() ==
400-
target.DeviceType));
401-
402-
} else if (target.DeviceNum) { // opencl:0
403-
deviceMatch = (target.DeviceNum.value() == original_indices[i]);
404-
}
395+
if (PlatformBackend != TargetBackend && TargetBackend != backend::all)
396+
continue;
405397

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-
continue;
423-
}
398+
bool deviceMatch = target.HasDeviceWildCard; // opencl:*
399+
if (target.DeviceType) { // opencl:gpu
400+
deviceMatch =
401+
((target.DeviceType == info::device_type::all) ||
402+
(dev.get_info<info::device::device_type>() == target.DeviceType));
424403

425-
if (!supportsSubPartitioning) {
426-
if (target.DeviceNum ||
427-
(target.DeviceType &&
428-
(target.DeviceType.value() != info::device_type::all))) {
429-
// This device was specifically requested and yet is not
430-
// partitionable.
431-
std::cout << "device is not partitionable: " << target << std::endl;
432-
}
433-
continue;
404+
} else if (target.DeviceNum) { // opencl:0
405+
deviceMatch = (target.DeviceNum.value() == original_indices[i]);
406+
}
407+
408+
if (!deviceMatch)
409+
continue;
410+
// Top level matches. Do we add it, or subdevices, or sub-sub-devices?
411+
bool wantSubDevice = target.SubDeviceNum || target.HasSubDeviceWildCard;
412+
bool supportsSubPartitioning =
413+
(supportsPartitionProperty(dev, partitionProperty) &&
414+
supportsAffinityDomain(dev, partitionProperty, affinityDomain));
415+
bool wantSubSubDevice =
416+
target.SubSubDeviceNum || target.HasSubSubDeviceWildCard;
417+
418+
// -- Add top level device.
419+
if (!wantSubDevice) {
420+
if (!deviceAdded) {
421+
FinalResult.push_back(dev);
422+
deviceAdded = true;
434423
}
424+
continue;
425+
}
435426

436-
if (!wantSubSubDevice) {
437-
// -- Add sub device.
438-
auto subDevices = dev.create_sub_devices<
439-
info::partition_property::partition_by_affinity_domain>(
440-
affinityDomain);
441-
if (target.HasSubDeviceWildCard) {
442-
FinalResult.insert(FinalResult.end(), subDevices.begin(),
443-
subDevices.end());
444-
} else {
445-
if (subDevices.size() > target.SubDeviceNum.value()) {
446-
FinalResult.push_back(subDevices[target.SubDeviceNum.value()]);
447-
} else {
448-
std::cout << "subdevice index out of bounds: " << target
449-
<< std::endl;
450-
}
451-
}
452-
continue;
427+
if (!supportsSubPartitioning) {
428+
if (target.DeviceNum ||
429+
(target.DeviceType &&
430+
(target.DeviceType.value() != info::device_type::all))) {
431+
// This device was specifically requested and yet is not
432+
// partitionable.
433+
std::cout << "device is not partitionable: " << target << std::endl;
453434
}
435+
continue;
436+
}
454437

455-
// -- Add sub sub device.
456-
auto subDevicesToPartition =
457-
dev.create_sub_devices<partitionProperty>(affinityDomain);
458-
if (target.SubDeviceNum) {
459-
if (subDevicesToPartition.size() > target.SubDeviceNum.value()) {
460-
subDevicesToPartition[0] =
461-
subDevicesToPartition[target.SubDeviceNum.value()];
462-
subDevicesToPartition.resize(1);
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()]);
463449
} else {
464450
std::cout << "subdevice index out of bounds: " << target
465451
<< std::endl;
466-
continue;
467452
}
468453
}
469-
for (device subDev : subDevicesToPartition) {
470-
bool supportsSubSubPartitioning =
471-
(supportsPartitionProperty(subDev, partitionProperty) &&
472-
supportsAffinityDomain(subDev, partitionProperty,
473-
affinityDomain));
474-
if (!supportsSubSubPartitioning) {
475-
if (target.SubDeviceNum) {
476-
// Parent subdevice was specifically requested, yet is not
477-
// partitionable.
478-
std::cout << "sub-device is not partitionable: " << target
479-
<< std::endl;
480-
}
481-
continue;
454+
continue;
455+
}
456+
457+
// -- Add sub sub device.
458+
auto subDevicesToPartition =
459+
dev.create_sub_devices<partitionProperty>(affinityDomain);
460+
if (target.SubDeviceNum) {
461+
if (subDevicesToPartition.size() > target.SubDeviceNum.value()) {
462+
subDevicesToPartition[0] =
463+
subDevicesToPartition[target.SubDeviceNum.value()];
464+
subDevicesToPartition.resize(1);
465+
} else {
466+
std::cout << "subdevice index out of bounds: " << target << std::endl;
467+
continue;
468+
}
469+
}
470+
for (device subDev : subDevicesToPartition) {
471+
bool supportsSubSubPartitioning =
472+
(supportsPartitionProperty(subDev, partitionProperty) &&
473+
supportsAffinityDomain(subDev, partitionProperty, affinityDomain));
474+
if (!supportsSubSubPartitioning) {
475+
if (target.SubDeviceNum) {
476+
// Parent subdevice was specifically requested, yet is not
477+
// partitionable.
478+
std::cout << "sub-device is not partitionable: " << target
479+
<< std::endl;
482480
}
483-
// Allright, lets get them sub-sub-devices.
484-
auto subSubDevices =
485-
subDev.create_sub_devices<partitionProperty>(affinityDomain);
486-
if (target.HasSubSubDeviceWildCard) {
487-
FinalResult.insert(FinalResult.end(), subSubDevices.begin(),
488-
subSubDevices.end());
481+
continue;
482+
}
483+
// Allright, lets get them sub-sub-devices.
484+
auto subSubDevices =
485+
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()]);
489493
} else {
490-
if (subSubDevices.size() > target.SubSubDeviceNum.value()) {
491-
FinalResult.push_back(
492-
subSubDevices[target.SubSubDeviceNum.value()]);
493-
} else {
494-
std::cout << "sub-sub-device index out of bounds: " << target
495-
<< std::endl;
496-
}
494+
std::cout << "sub-sub-device index out of bounds: " << target
495+
<< std::endl;
497496
}
498497
}
499-
continue;
500498
}
501-
} // /for
502-
} // /for
499+
continue;
500+
}
501+
}
503502
return FinalResult;
504503
}
505504

0 commit comments

Comments
 (0)