Skip to content

Commit 46b04db

Browse files
[NFC][SYCL] Add [all|any|none]_of hidden friends to iterator_range (#19523)
1 parent 4608d74 commit 46b04db

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
@@ -393,9 +393,8 @@ class device_image_impl
393393
const device &DeviceCand) const noexcept {
394394
// If the device is in the device list and the kernel ID is in the kernel
395395
// bundle, return true.
396-
for (device_impl &Device : get_devices())
397-
if (&Device == &*getSyclObjImpl(DeviceCand))
398-
return has_kernel(KernelIDCand);
396+
if (get_devices().contains(*getSyclObjImpl(DeviceCand)))
397+
return has_kernel(KernelIDCand);
399398

400399
// Otherwise, if the device candidate is a sub-device it is also valid if
401400
// 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
@@ -179,6 +179,18 @@ template <typename iterator> class iterator_range {
179179
iterator Begin;
180180
iterator End;
181181
const size_t Size;
182+
183+
template <class Pred> friend bool all_of(iterator_range R, Pred &&P) {
184+
return std::all_of(R.begin(), R.end(), std::forward<Pred>(P));
185+
}
186+
187+
template <class Pred> friend bool any_of(iterator_range R, Pred &&P) {
188+
return std::any_of(R.begin(), R.end(), std::forward<Pred>(P));
189+
}
190+
191+
template <class Pred> friend bool none_of(iterator_range R, Pred &&P) {
192+
return std::none_of(R.begin(), R.end(), std::forward<Pred>(P));
193+
}
182194
};
183195
} // namespace detail
184196
} // namespace _V1

sycl/source/detail/program_manager/program_manager.cpp

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

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

126126
// OpenCL 2.1 and greater require clCreateProgramWithIL
127127
if (ContextBackend == backend::opencl) {
128-
std::string ver = ContextImpl.get_info<info::context::platform>()
129-
.get_info<info::platform::version>();
128+
std::string ver =
129+
ContextImpl.getPlatformImpl().get_info<info::platform::version>();
130130
if (ver.find("OpenCL 1.0") == std::string::npos &&
131131
ver.find("OpenCL 1.1") == std::string::npos &&
132132
ver.find("OpenCL 1.2") == std::string::npos &&
133133
ver.find("OpenCL 2.0") == std::string::npos)
134134
return true;
135135
}
136136

137-
for (device_impl &D : Devices) {
138-
// We need cl_khr_il_program extension to be present
139-
// and we can call clCreateProgramWithILKHR using the extension
140-
std::vector<std::string> Extensions =
141-
D.get_info<info::device::extensions>();
142-
if (Extensions.end() ==
143-
std::find(Extensions.begin(), Extensions.end(), "cl_khr_il_program"))
144-
return false;
145-
}
146-
147-
return true;
137+
// We need cl_khr_il_program extension to be present
138+
// and we can call clCreateProgramWithILKHR using the extension
139+
return all_of(Devices, [](device_impl &D) {
140+
return D.has_extension("cl_khr_il_program");
141+
});
148142
}
149143

150144
// 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)