Skip to content

Commit a7d654c

Browse files
[SYCL] Add fast-link option for SYCLBIN (#20174)
This commit adds the ability for doing "fast linking" of kernel bundles. Fast linking lets the implementation use AOT binaries from the underlying SYCLBIN files to dynamically link the images in the kernel bundles. Extension PR: #20271 --------- Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 3d70234 commit a7d654c

File tree

15 files changed

+460
-93
lines changed

15 files changed

+460
-93
lines changed

sycl/include/sycl/ext/oneapi/experimental/syclbin_kernel_bundle.hpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#pragma once
1010

11+
#include <sycl/ext/oneapi/experimental/syclbin_properties.hpp>
1112
#include <sycl/ext/oneapi/properties/properties.hpp>
1213
#include <sycl/kernel_bundle.hpp>
1314

@@ -24,6 +25,39 @@
2425

2526
namespace sycl {
2627
inline namespace _V1 {
28+
29+
namespace detail {
30+
__SYCL_EXPORT std::shared_ptr<detail::kernel_bundle_impl>
31+
link_impl(const kernel_bundle<bundle_state::object> *ObjectBundles,
32+
size_t NumObjectBundles, const std::vector<device> &Devs,
33+
bool FastLink);
34+
35+
template <
36+
typename PropertyListT = ext::oneapi::experimental::empty_properties_t,
37+
typename = std::enable_if_t<
38+
ext::oneapi::experimental::detail::all_are_properties_of_v<
39+
ext::oneapi::experimental::detail::link_props, PropertyListT>>>
40+
kernel_bundle<bundle_state::executable>
41+
link_common(const kernel_bundle<bundle_state::object> *ObjectBundles,
42+
size_t NumObjectBundles, const std::vector<device> &Devs,
43+
PropertyListT Props = {}) {
44+
std::vector<device> UniqueDevices = removeDuplicateDevices(Devs);
45+
46+
bool UseFastLink = [&]() {
47+
if constexpr (Props.template has_property<
48+
ext::oneapi::experimental::fast_link>())
49+
return Props.template get_property<ext::oneapi::experimental::fast_link>()
50+
.value;
51+
return false;
52+
}();
53+
54+
KernelBundleImplPtr Impl =
55+
link_impl(ObjectBundles, NumObjectBundles, UniqueDevices, UseFastLink);
56+
return createSyclObjFromImpl<kernel_bundle<bundle_state::executable>>(
57+
std::move(Impl));
58+
}
59+
} // namespace detail
60+
2761
namespace ext::oneapi::experimental {
2862

2963
template <bundle_state State, typename PropertyListT = empty_properties_t>
@@ -77,6 +111,46 @@ get_kernel_bundle(const context &Ctxt, const std::filesystem::path &Filename,
77111
}
78112
#endif
79113

114+
template <typename PropertyListT = empty_properties_t,
115+
typename = std::enable_if_t<detail::all_are_properties_of_v<
116+
sycl::detail::link_props, PropertyListT>>>
117+
kernel_bundle<bundle_state::executable>
118+
link(const std::vector<kernel_bundle<bundle_state::object>> &ObjectBundles,
119+
const std::vector<device> &Devs, PropertyListT Props = {}) {
120+
return sycl::detail::link_common(ObjectBundles.data(), ObjectBundles.size(),
121+
Devs, Props);
122+
}
123+
124+
template <typename PropertyListT = empty_properties_t,
125+
typename = std::enable_if_t<detail::all_are_properties_of_v<
126+
sycl::detail::link_props, PropertyListT>>>
127+
kernel_bundle<bundle_state::executable>
128+
link(const kernel_bundle<bundle_state::object> &ObjectBundle,
129+
const std::vector<device> &Devs, PropertyListT Props = {}) {
130+
return sycl::detail::link_common(&ObjectBundle, 1, Devs, Props);
131+
}
132+
133+
template <typename PropertyListT = empty_properties_t,
134+
typename = std::enable_if_t<detail::all_are_properties_of_v<
135+
sycl::detail::link_props, PropertyListT>>>
136+
kernel_bundle<bundle_state::executable>
137+
link(const std::vector<kernel_bundle<bundle_state::object>> &ObjectBundles,
138+
PropertyListT Props = {}) {
139+
std::vector<sycl::device> IntersectDevices =
140+
sycl::detail::find_device_intersection(ObjectBundles);
141+
return link(ObjectBundles, IntersectDevices, Props);
142+
}
143+
144+
template <typename PropertyListT = empty_properties_t,
145+
typename = std::enable_if_t<detail::all_are_properties_of_v<
146+
sycl::detail::link_props, PropertyListT>>>
147+
kernel_bundle<bundle_state::executable>
148+
link(const kernel_bundle<bundle_state::object> &ObjectBundle,
149+
PropertyListT Props = {}) {
150+
return link(std::vector<kernel_bundle<bundle_state::object>>{ObjectBundle},
151+
ObjectBundle.get_devices(), Props);
152+
}
153+
80154
} // namespace ext::oneapi::experimental
81155
} // namespace _V1
82156
} // namespace sycl
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//==------------------------------------------------------------------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <sycl/ext/oneapi/properties/properties.hpp>
12+
#include <sycl/kernel_bundle.hpp>
13+
14+
namespace sycl {
15+
inline namespace _V1 {
16+
17+
namespace detail {
18+
struct link_props;
19+
} // namespace detail
20+
21+
namespace ext::oneapi::experimental {
22+
23+
/////////////////////////
24+
// PropertyT syclex::fast_link
25+
/////////////////////////
26+
struct fast_link
27+
: detail::run_time_property_key<fast_link, detail::PropKind::FastLink> {
28+
fast_link(bool DoFastLink = true) : value(DoFastLink) {}
29+
30+
bool value;
31+
};
32+
using fast_link_key = fast_link;
33+
34+
template <>
35+
struct is_property_key_of<fast_link_key, sycl::detail::link_props>
36+
: std::true_type {};
37+
} // namespace ext::oneapi::experimental
38+
} // namespace _V1
39+
} // namespace sycl

sycl/include/sycl/ext/oneapi/properties/property.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,9 @@ enum PropKind : uint32_t {
228228
InitialThreshold = 83,
229229
MaximumSize = 84,
230230
ZeroInit = 85,
231+
FastLink = 86,
231232
// PropKindSize must always be the last value.
232-
PropKindSize = 86,
233+
PropKindSize = 87,
233234
};
234235

235236
template <typename PropertyT> struct PropertyToKind {

sycl/include/sycl/sycl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ can be disabled by setting SYCL_DISABLE_FSYCL_SYCLHPP_WARNING macro.")
138138
#include <sycl/ext/oneapi/experimental/reduction_properties.hpp>
139139
#include <sycl/ext/oneapi/experimental/root_group.hpp>
140140
#include <sycl/ext/oneapi/experimental/syclbin_kernel_bundle.hpp>
141+
#include <sycl/ext/oneapi/experimental/syclbin_properties.hpp>
141142
#include <sycl/ext/oneapi/experimental/tangle.hpp>
142143
#include <sycl/ext/oneapi/experimental/work_group_memory.hpp>
143144
#include <sycl/ext/oneapi/filter_selector.hpp>

sycl/source/detail/helpers.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ template <typename iterator> class iterator_range {
108108
iterator_range(IterTy Begin, IterTy End, size_t Size)
109109
: Begin(Begin), End(End), Size(Size) {}
110110

111+
template <typename IterTy>
112+
iterator_range(IterTy Begin, IterTy End)
113+
: iterator_range(Begin, End, std::distance(Begin, End)) {}
114+
111115
iterator_range() : iterator_range(iterator{}, iterator{}, 0) {}
112116

113117
template <typename ContainerTy, typename = std::void_t<decltype(iterator{

0 commit comments

Comments
 (0)