Skip to content

Commit c688ce2

Browse files
[NFC][SYCL] Add [all|any|none]_of hidden friends to iterator_range
1 parent e7edd49 commit c688ce2

File tree

5 files changed

+35
-38
lines changed

5 files changed

+35
-38
lines changed

sycl/source/detail/device_image_impl.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,8 @@ class device_image_impl
397397
const device &DeviceCand) const noexcept {
398398
// If the device is in the device list and the kernel ID is in the kernel
399399
// bundle, return true.
400-
for (device_impl &Device : get_devices())
401-
if (&Device == &*getSyclObjImpl(DeviceCand))
402-
return has_kernel(KernelIDCand);
400+
if (get_devices().contains(*getSyclObjImpl(DeviceCand)))
401+
return has_kernel(KernelIDCand);
403402

404403
// Otherwise, if the device candidate is a sub-device it is also valid if
405404
// its parent is valid.

sycl/source/detail/graph/graph_impl.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -376,19 +376,13 @@ std::set<node_impl *> graph_impl::getCGEdges(
376376
for (auto &Req : Requirements) {
377377
// Look through the graph for nodes which share this requirement
378378
for (node_impl &Node : nodes()) {
379-
if (Node.hasRequirementDependency(Req)) {
380-
bool ShouldAddDep = true;
381-
// If any of this node's successors have this requirement then we skip
382-
// adding the current node as a dependency.
383-
for (node_impl &Succ : Node.successors()) {
384-
if (Succ.hasRequirementDependency(Req)) {
385-
ShouldAddDep = false;
386-
break;
387-
}
388-
}
389-
if (ShouldAddDep) {
390-
UniqueDeps.insert(&Node);
391-
}
379+
if (Node.hasRequirementDependency(Req) &&
380+
// If any of this node's successors have this requirement then we skip
381+
// adding the current node as a dependency.
382+
none_of(Node.successors(), [&](node_impl &Succ) {
383+
return Succ.hasRequirementDependency(Req);
384+
})) {
385+
UniqueDeps.insert(&Node);
392386
}
393387
}
394388
}

sycl/source/detail/helpers.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ template <typename iterator> class iterator_range {
167167
iterator Begin;
168168
iterator End;
169169
const size_t Size;
170+
171+
template <class Pred> friend bool all_of(iterator_range R, Pred &&P) {
172+
return std::all_of(R.begin(), R.end(), std::forward<Pred>(P));
173+
}
174+
175+
template <class Pred> friend bool any_of(iterator_range R, Pred &&P) {
176+
return std::any_of(R.begin(), R.end(), std::forward<Pred>(P));
177+
}
178+
179+
template <class Pred> friend bool none_of(iterator_range R, Pred &&P) {
180+
return std::none_of(R.begin(), R.end(), std::forward<Pred>(P));
181+
}
170182
};
171183
} // namespace detail
172184
} // namespace _V1

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -125,33 +125,27 @@ static bool isDeviceBinaryTypeSupported(context_impl &ContextImpl,
125125
devices_range Devices = ContextImpl.getDevices();
126126

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

133133
// OpenCL 2.1 and greater require clCreateProgramWithIL
134134
if (ContextBackend == backend::opencl) {
135-
std::string ver = ContextImpl.get_info<info::context::platform>()
136-
.get_info<info::platform::version>();
135+
std::string ver =
136+
ContextImpl.getPlatformImpl().get_info<info::platform::version>();
137137
if (ver.find("OpenCL 1.0") == std::string::npos &&
138138
ver.find("OpenCL 1.1") == std::string::npos &&
139139
ver.find("OpenCL 1.2") == std::string::npos &&
140140
ver.find("OpenCL 2.0") == std::string::npos)
141141
return true;
142142
}
143143

144-
for (device_impl &D : Devices) {
145-
// We need cl_khr_il_program extension to be present
146-
// and we can call clCreateProgramWithILKHR using the extension
147-
std::vector<std::string> Extensions =
148-
D.get_info<info::device::extensions>();
149-
if (Extensions.end() ==
150-
std::find(Extensions.begin(), Extensions.end(), "cl_khr_il_program"))
151-
return false;
152-
}
153-
154-
return true;
144+
// We need cl_khr_il_program extension to be present
145+
// and we can call clCreateProgramWithILKHR using the extension
146+
return all_of(Devices, [](device_impl &D) {
147+
return D.has_extension("cl_khr_il_program");
148+
});
155149
}
156150

157151
// getFormatStr is used for debug-printing, so it may be unused.

sycl/source/detail/scheduler/graph_builder.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,11 +674,9 @@ static bool checkHostUnifiedMemory(context_impl *Ctx) {
674674
if (Ctx == nullptr)
675675
return true;
676676

677-
for (device_impl &Device : Ctx->getDevices()) {
678-
if (!Device.get_info<info::device::host_unified_memory>())
679-
return false;
680-
}
681-
return true;
677+
return all_of(Ctx->getDevices(), [](device_impl &Device) {
678+
return Device.get_info<info::device::host_unified_memory>();
679+
});
682680
}
683681

684682
// The function searches for the alloca command matching context and

0 commit comments

Comments
 (0)