Skip to content

[NFC][SYCL] Add [all|any|none]_of hidden friends to iterator_range #19523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 2 additions & 3 deletions sycl/source/detail/device_image_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,8 @@ class device_image_impl
const device &DeviceCand) const noexcept {
// If the device is in the device list and the kernel ID is in the kernel
// bundle, return true.
for (device_impl &Device : get_devices())
if (&Device == &*getSyclObjImpl(DeviceCand))
return has_kernel(KernelIDCand);
if (get_devices().contains(*getSyclObjImpl(DeviceCand)))
return has_kernel(KernelIDCand);

// Otherwise, if the device candidate is a sub-device it is also valid if
// its parent is valid.
Expand Down
20 changes: 7 additions & 13 deletions sycl/source/detail/graph/graph_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,19 +376,13 @@ std::set<node_impl *> graph_impl::getCGEdges(
for (auto &Req : Requirements) {
// Look through the graph for nodes which share this requirement
for (node_impl &Node : nodes()) {
if (Node.hasRequirementDependency(Req)) {
bool ShouldAddDep = true;
// If any of this node's successors have this requirement then we skip
// adding the current node as a dependency.
for (node_impl &Succ : Node.successors()) {
if (Succ.hasRequirementDependency(Req)) {
ShouldAddDep = false;
break;
}
}
if (ShouldAddDep) {
UniqueDeps.insert(&Node);
}
if (Node.hasRequirementDependency(Req) &&
// If any of this node's successors have this requirement then we skip
// adding the current node as a dependency.
none_of(Node.successors(), [&](node_impl &Succ) {
return Succ.hasRequirementDependency(Req);
})) {
UniqueDeps.insert(&Node);
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions sycl/source/detail/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ template <typename iterator> class iterator_range {
iterator Begin;
iterator End;
const size_t Size;

template <class Pred> friend bool all_of(iterator_range R, Pred &&P) {
return std::all_of(R.begin(), R.end(), std::forward<Pred>(P));
}

template <class Pred> friend bool any_of(iterator_range R, Pred &&P) {
return std::any_of(R.begin(), R.end(), std::forward<Pred>(P));
}

template <class Pred> friend bool none_of(iterator_range R, Pred &&P) {
return std::none_of(R.begin(), R.end(), std::forward<Pred>(P));
}
};
} // namespace detail
} // namespace _V1
Expand Down
28 changes: 11 additions & 17 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,33 +125,27 @@ static bool isDeviceBinaryTypeSupported(context_impl &ContextImpl,
devices_range Devices = ContextImpl.getDevices();

// Program type is SPIR-V, so we need a device compiler to do JIT.
for (device_impl &D : Devices) {
if (!D.get_info<info::device::is_compiler_available>())
return false;
}
if (!all_of(Devices, [](device_impl &D) {
return D.get_info<info::device::is_compiler_available>();
}))
return false;

// OpenCL 2.1 and greater require clCreateProgramWithIL
if (ContextBackend == backend::opencl) {
std::string ver = ContextImpl.get_info<info::context::platform>()
.get_info<info::platform::version>();
std::string ver =
ContextImpl.getPlatformImpl().get_info<info::platform::version>();
if (ver.find("OpenCL 1.0") == std::string::npos &&
ver.find("OpenCL 1.1") == std::string::npos &&
ver.find("OpenCL 1.2") == std::string::npos &&
ver.find("OpenCL 2.0") == std::string::npos)
return true;
}

for (device_impl &D : Devices) {
// We need cl_khr_il_program extension to be present
// and we can call clCreateProgramWithILKHR using the extension
std::vector<std::string> Extensions =
D.get_info<info::device::extensions>();
if (Extensions.end() ==
std::find(Extensions.begin(), Extensions.end(), "cl_khr_il_program"))
return false;
}

return true;
// We need cl_khr_il_program extension to be present
// and we can call clCreateProgramWithILKHR using the extension
return all_of(Devices, [](device_impl &D) {
return D.has_extension("cl_khr_il_program");
});
}

// getFormatStr is used for debug-printing, so it may be unused.
Expand Down
8 changes: 3 additions & 5 deletions sycl/source/detail/scheduler/graph_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,11 +674,9 @@ static bool checkHostUnifiedMemory(context_impl *Ctx) {
if (Ctx == nullptr)
return true;

for (device_impl &Device : Ctx->getDevices()) {
if (!Device.get_info<info::device::host_unified_memory>())
return false;
}
return true;
return all_of(Ctx->getDevices(), [](device_impl &Device) {
return Device.get_info<info::device::host_unified_memory>();
});
}

// The function searches for the alloca command matching context and
Expand Down