diff --git a/sycl/source/detail/device_image_impl.hpp b/sycl/source/detail/device_image_impl.hpp index 38bcb19e240ae..6863ba219af1b 100644 --- a/sycl/source/detail/device_image_impl.hpp +++ b/sycl/source/detail/device_image_impl.hpp @@ -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. diff --git a/sycl/source/detail/graph/graph_impl.cpp b/sycl/source/detail/graph/graph_impl.cpp index 0026cadadb4c7..b72057cc30ae3 100644 --- a/sycl/source/detail/graph/graph_impl.cpp +++ b/sycl/source/detail/graph/graph_impl.cpp @@ -376,19 +376,13 @@ std::set 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); } } } diff --git a/sycl/source/detail/helpers.hpp b/sycl/source/detail/helpers.hpp index a1a49361e5755..b2482d9d34b0e 100644 --- a/sycl/source/detail/helpers.hpp +++ b/sycl/source/detail/helpers.hpp @@ -167,6 +167,18 @@ template class iterator_range { iterator Begin; iterator End; const size_t Size; + + template friend bool all_of(iterator_range R, Pred &&P) { + return std::all_of(R.begin(), R.end(), std::forward(P)); + } + + template friend bool any_of(iterator_range R, Pred &&P) { + return std::any_of(R.begin(), R.end(), std::forward(P)); + } + + template friend bool none_of(iterator_range R, Pred &&P) { + return std::none_of(R.begin(), R.end(), std::forward(P)); + } }; } // namespace detail } // namespace _V1 diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index a07c0f24ab3d4..3ef10c697d6ea 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -125,15 +125,15 @@ 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()) - return false; - } + if (!all_of(Devices, [](device_impl &D) { + return D.get_info(); + })) + return false; // OpenCL 2.1 and greater require clCreateProgramWithIL if (ContextBackend == backend::opencl) { - std::string ver = ContextImpl.get_info() - .get_info(); + std::string ver = + ContextImpl.getPlatformImpl().get_info(); 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 && @@ -141,17 +141,11 @@ static bool isDeviceBinaryTypeSupported(context_impl &ContextImpl, 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 Extensions = - D.get_info(); - 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. diff --git a/sycl/source/detail/scheduler/graph_builder.cpp b/sycl/source/detail/scheduler/graph_builder.cpp index 0423c0b29f52a..e4f2e77f1a6ac 100644 --- a/sycl/source/detail/scheduler/graph_builder.cpp +++ b/sycl/source/detail/scheduler/graph_builder.cpp @@ -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()) - return false; - } - return true; + return all_of(Ctx->getDevices(), [](device_impl &Device) { + return Device.get_info(); + }); } // The function searches for the alloca command matching context and