Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions sycl/source/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,51 @@ vector_class<device> device::get_devices(info::device_type deviceType) {
}
}
}

// If SYCL_BE is set and there are multiple devices of the same type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused with meaning of SYCL_BE var. In another PR you are making so that SYCL_BE makes some preference towards specified BE in the selectors, but this patch removes all devices that do not match specified BE.
The documentation says that this var controls which BE will be used when a device is chosen using default selector only.
I think we should have consistent behavior and update documentation. Probably we need to introduce new env var if we need two different behaviors(force and preference).

// supported by different BE, and one of the devices is from SYCL_BE
// then only add that (and remove all others). This allows to force
// selection of a specific BE for a target, while running on other
// targets, unsupported by the SYCL_BE, with other BEs.
//
if (std::getenv("SYCL_BE")) {
vector_class<device> filtered_devices;
auto SyclBE = detail::pi::getPreferredBE();

// On the first pass see which device types are supported with SYCL_BE
pi_uint64 TypesSupportedBySyclBE = 0; // bit-set of info::device_type
for (const auto &dev : devices) {
if (dev.is_host())
continue;
auto BE = detail::getSyclObjImpl(dev)->getPlugin().getBackend();
if (BE == SyclBE) {
TypesSupportedBySyclBE |=
(pi_uint64)dev.get_info<info::device::device_type>();
}
}
// On the second pass only add devices that are from SYCL_BE or not
// supported there.
//
for (const auto &dev : devices) {
if (dev.is_host()) {
// TODO: decide if we really want to add the host here.
// The cons of doing so is that if SYCL_BE is set but that BE
// is unavailable for whatever reason, the execution would silently
// proceed to the host while people may think it is running
// with the SYCL_BE as they wanted.
//
filtered_devices.push_back(dev);
continue;
}

auto BE = detail::getSyclObjImpl(dev)->getPlugin().getBackend();
auto Type = (pi_uint64)dev.get_info<info::device::device_type>();
if (BE == SyclBE || (TypesSupportedBySyclBE & Type) == 0) {
filtered_devices.push_back(dev);
}
}
return filtered_devices;
}
return devices;
}

Expand Down