Skip to content

Commit b9a6aac

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web' (4 commits)
2 parents 91f11cb + 46b04db commit b9a6aac

File tree

12 files changed

+209
-90
lines changed

12 files changed

+209
-90
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/device_impl.hpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,24 +2282,10 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
22822282

22832283
}; // class device_impl
22842284

2285-
struct devices_deref_impl {
2286-
template <typename T> static device_impl &dereference(T &Elem) {
2287-
using Ty = std::decay_t<decltype(Elem)>;
2288-
if constexpr (std::is_same_v<Ty, device>) {
2289-
return *getSyclObjImpl(Elem);
2290-
} else if constexpr (std::is_same_v<Ty, device_impl>) {
2291-
return Elem;
2292-
} else {
2293-
return *Elem;
2294-
}
2295-
}
2296-
};
2297-
using devices_iterator =
2298-
variadic_iterator<devices_deref_impl, device,
2299-
std::vector<std::shared_ptr<device_impl>>::const_iterator,
2300-
std::vector<device>::const_iterator,
2301-
std::vector<device_impl *>::const_iterator,
2302-
device_impl *>;
2285+
using devices_iterator = variadic_iterator<
2286+
device, std::vector<std::shared_ptr<device_impl>>::const_iterator,
2287+
std::vector<device>::const_iterator,
2288+
std::vector<device_impl *>::const_iterator, device_impl *>;
23032289

23042290
class devices_range : public iterator_range<devices_iterator> {
23052291
private:

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/graph/node_impl.hpp

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -749,37 +749,13 @@ class node_impl : public std::enable_shared_from_this<node_impl> {
749749
}
750750
};
751751

752-
struct nodes_deref_impl {
753-
template <typename T> static node_impl &dereference(T &Elem) {
754-
using Ty = std::decay_t<decltype(Elem)>;
755-
if constexpr (std::is_same_v<Ty, std::weak_ptr<node_impl>>) {
756-
// This assumes that weak_ptr doesn't actually manage lifetime and
757-
// the object is guaranteed to be alive (which seems to be the
758-
// assumption across all graph code).
759-
return *Elem.lock();
760-
} else if constexpr (std::is_same_v<Ty, node>) {
761-
return *getSyclObjImpl(Elem);
762-
} else {
763-
return *Elem;
764-
}
765-
}
766-
};
767-
768752
template <typename... ContainerTy>
769753
using nodes_iterator_impl =
770-
variadic_iterator<nodes_deref_impl, node,
771-
typename ContainerTy::const_iterator...>;
754+
variadic_iterator<node, typename ContainerTy::const_iterator...>;
772755

773756
using nodes_iterator = nodes_iterator_impl<
774757
std::vector<std::shared_ptr<node_impl>>, std::vector<node_impl *>,
775-
// Next one is temporary. It looks like `weak_ptr`s aren't
776-
// used for the actual lifetime management and the objects are
777-
// always guaranteed to be alive. Once the code is cleaned
778-
// from `weak_ptr`s this alternative should be removed too.
779-
std::vector<std::weak_ptr<node_impl>>,
780-
//
781758
std::set<std::shared_ptr<node_impl>>, std::set<node_impl *>,
782-
//
783759
std::list<node_impl *>, std::vector<node>>;
784760

785761
class nodes_range : public iterator_range<nodes_iterator> {

sycl/source/detail/helpers.hpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,19 @@ const RTDeviceBinaryImage *
3535
retrieveKernelBinary(queue_impl &Queue, KernelNameStrRefT KernelName,
3636
CGExecKernel *CGKernel = nullptr);
3737

38-
template <typename DereferenceImpl, typename SyclTy, typename... Iterators>
39-
class variadic_iterator {
38+
template <typename SyclTy, typename... Iterators> class variadic_iterator {
4039
using storage_iter = std::variant<Iterators...>;
4140

4241
storage_iter It;
4342

4443
public:
4544
using iterator_category = std::forward_iterator_tag;
4645
using difference_type = std::ptrdiff_t;
47-
using reference = decltype(DereferenceImpl::dereference(
48-
*std::declval<nth_type_t<0, Iterators...>>()));
49-
using value_type = std::remove_reference_t<reference>;
46+
using value_type = std::remove_reference_t<decltype(*getSyclObjImpl(
47+
std::declval<SyclTy>()))>;
5048
using sycl_type = SyclTy;
5149
using pointer = value_type *;
52-
static_assert(std::is_same_v<reference, value_type &>);
50+
using reference = value_type &;
5351

5452
variadic_iterator() = default;
5553
variadic_iterator(const variadic_iterator &) = default;
@@ -80,7 +78,16 @@ class variadic_iterator {
8078
decltype(auto) operator*() {
8179
return std::visit(
8280
[](auto &&It) -> decltype(auto) {
83-
return DereferenceImpl::dereference(*It);
81+
decltype(auto) Elem = *It;
82+
using Ty = std::decay_t<decltype(Elem)>;
83+
static_assert(!std::is_same_v<Ty, decltype(Elem)>);
84+
if constexpr (std::is_same_v<Ty, sycl_type>) {
85+
return *getSyclObjImpl(Elem);
86+
} else if constexpr (std::is_same_v<Ty, value_type>) {
87+
return Elem;
88+
} else {
89+
return *Elem;
90+
}
8491
},
8592
It);
8693
}
@@ -172,6 +179,18 @@ template <typename iterator> class iterator_range {
172179
iterator Begin;
173180
iterator End;
174181
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+
}
175194
};
176195
} // namespace detail
177196
} // 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
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// RUN: %{build} -o %t.out
2+
// RUN: %{run} %t.out
3+
4+
#include <iostream>
5+
#include <sycl/detail/core.hpp>
6+
#include <sycl/ext/oneapi/get_kernel_info.hpp>
7+
#include <sycl/kernel_bundle.hpp>
8+
9+
namespace syclext = sycl::ext::oneapi;
10+
namespace syclexp = sycl::ext::oneapi::experimental;
11+
12+
static constexpr size_t NUM = 1024;
13+
static constexpr size_t WGSIZE = 16;
14+
static constexpr auto FFTestMark = "Free function Kernel Test:";
15+
16+
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel<2>))
17+
void func_range(float start, float *ptr) {}
18+
19+
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::single_task_kernel))
20+
void func_single(float start, float *ptr) {}
21+
22+
template <auto *Func> int test_free_function_kernel_id(sycl::context &ctxt) {
23+
sycl::kernel_id id = syclexp::get_kernel_id<Func>();
24+
auto exe_bndl =
25+
syclexp::get_kernel_bundle<Func, sycl::bundle_state::executable>(ctxt);
26+
const auto kernel_ids = exe_bndl.get_kernel_ids();
27+
const bool res =
28+
std::find(kernel_ids.begin(), kernel_ids.end(), id) == kernel_ids.end();
29+
if (res)
30+
std::cout << FFTestMark << "test_kernel_id failed: kernel id is not found"
31+
<< std::endl;
32+
return res;
33+
}
34+
35+
template <auto *Func>
36+
int test_kernel_bundle_ctxt(sycl::context &ctxt, std::string_view fname) {
37+
sycl::kernel_id id = syclexp::get_kernel_id<Func>();
38+
auto exe_bndl =
39+
syclexp::get_kernel_bundle<Func, sycl::bundle_state::executable>(ctxt);
40+
const bool res =
41+
exe_bndl.has_kernel(id) &&
42+
exe_bndl.get_kernel(id)
43+
.template get_info<sycl::info::kernel::function_name>() == fname;
44+
if (!res)
45+
std::cout
46+
<< FFTestMark
47+
<< "test_kernel_bundle_ctxt failed: bundle does not contain kernel id "
48+
"or function name "
49+
<< fname << std::endl;
50+
return res;
51+
}
52+
53+
template <auto *Func>
54+
int test_kernel_bundle_ctxt_dev(sycl::context &ctxt, sycl::device &dev,
55+
std::string_view fname) {
56+
sycl::kernel_id id = syclexp::get_kernel_id<Func>();
57+
auto exe_bndl =
58+
syclexp::get_kernel_bundle<Func, sycl::bundle_state::executable>(ctxt,
59+
{dev});
60+
const bool res =
61+
exe_bndl.has_kernel(id) &&
62+
exe_bndl.get_kernel(id)
63+
.template get_info<sycl::info::kernel::function_name>() == fname;
64+
if (!res)
65+
std::cout << FFTestMark
66+
<< "test_kernel_bundle_ctxt_dev failed: bundle does not contain "
67+
"kernel id "
68+
"or function name "
69+
<< fname << std::endl;
70+
return res;
71+
}
72+
73+
int main() {
74+
sycl::queue q;
75+
sycl::context ctxt = q.get_context();
76+
sycl::device dev = q.get_device();
77+
78+
int ret = test_free_function_kernel_id<func_range>(ctxt);
79+
ret |= test_free_function_kernel_id<func_single>(ctxt);
80+
ret |= test_kernel_bundle_ctxt<func_range>(ctxt, "func_range");
81+
ret |= test_kernel_bundle_ctxt<func_single>(ctxt, "func_single");
82+
ret |= test_kernel_bundle_ctxt_dev<func_range>(ctxt, dev, "func_range");
83+
ret |= test_kernel_bundle_ctxt_dev<func_single>(ctxt, dev, "func_single");
84+
return ret;
85+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: %{build} -fsycl-device-code-split=per_kernel -o %t.out
2+
// RUN: %{run} %t.out
3+
4+
#include <iostream>
5+
#include <sycl/detail/core.hpp>
6+
#include <sycl/ext/oneapi/get_kernel_info.hpp>
7+
#include <sycl/kernel_bundle.hpp>
8+
9+
namespace syclexp = sycl::ext::oneapi::experimental;
10+
11+
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel<2>))
12+
void func_range(float start, float *ptr) {}
13+
14+
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::single_task_kernel))
15+
void func_single(float start, float *ptr) {}
16+
17+
int main() {
18+
sycl::queue q;
19+
auto bundle_range =
20+
syclexp::get_kernel_bundle<func_range, sycl::bundle_state::executable>(
21+
q.get_context());
22+
try {
23+
sycl::kernel k = bundle_range.ext_oneapi_get_kernel<func_single>();
24+
} catch (const sycl::exception &e) {
25+
assert(e.code() == sycl::errc::invalid);
26+
return 0;
27+
}
28+
auto bundle_single =
29+
syclexp::get_kernel_bundle<func_single, sycl::bundle_state::executable>(
30+
q.get_context());
31+
try {
32+
sycl::kernel k = bundle_single.ext_oneapi_get_kernel<func_range>();
33+
} catch (const sycl::exception &e) {
34+
assert(e.code() == sycl::errc::invalid);
35+
return 0;
36+
}
37+
return 1;
38+
}

0 commit comments

Comments
 (0)