Skip to content

Commit 8aafb3b

Browse files
committed
WIP
1 parent 0ce7118 commit 8aafb3b

File tree

8 files changed

+77
-34
lines changed

8 files changed

+77
-34
lines changed

sycl/include/sycl/backend.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <sycl/feature_test.hpp> // for SYCL_BACKEND_OP...
2626
#include <sycl/image.hpp> // for image, image_al...
2727
#include <sycl/kernel.hpp> // for kernel, get_native
28-
#include <sycl/kernel_bundle.hpp>
2928
#include <sycl/kernel_bundle_enums.hpp> // for bundle_state
3029
#include <sycl/platform.hpp> // for platform, get_n...
3130
#include <sycl/property_list.hpp> // for property_list
@@ -46,7 +45,7 @@
4645
#include <sycl/detail/backend_traits_hip.hpp>
4746
#endif
4847
#if SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
49-
#include <sycl/detail/backend_traits_level_zero.hpp> // for _ze_command_lis...
48+
// #include <sycl/detail/backend_traits_level_zero.hpp> // for _ze_command_lis...
5049
#endif
5150

5251
#include <sycl/detail/ur.hpp>
@@ -59,6 +58,9 @@
5958
namespace sycl {
6059
inline namespace _V1 {
6160

61+
template<bundle_state State>
62+
class kernel_bundle;
63+
6264
namespace detail {
6365
// TODO each backend can have its own custom errc enumeration
6466
// but the details for this are not fully specified yet
@@ -150,13 +152,15 @@ auto get_native(const queue &Obj) -> backend_return_t<BackendName, queue> {
150152
int32_t IsImmCmdList;
151153
ur_native_handle_t Handle = Obj.getNative(IsImmCmdList);
152154
backend_return_t<BackendName, queue> RetVal;
155+
#if 0 && SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
153156
if constexpr (BackendName == backend::ext_oneapi_level_zero)
154157
RetVal = IsImmCmdList
155158
? backend_return_t<BackendName, queue>{reinterpret_cast<
156159
ze_command_list_handle_t>(Handle)}
157160
: backend_return_t<BackendName, queue>{
158161
reinterpret_cast<ze_command_queue_handle_t>(Handle)};
159162
else
163+
#endif
160164
RetVal = reinterpret_cast<backend_return_t<BackendName, queue>>(Handle);
161165

162166
return RetVal;

sycl/include/sycl/ext/oneapi/get_kernel_info.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,21 @@
1111
#include <sycl/detail/export.hpp>
1212
#include <sycl/detail/info_desc_helpers.hpp>
1313
#include <sycl/device.hpp>
14+
#include <sycl/kernel_bundle_enums.hpp>
1415
#include <sycl/queue.hpp>
1516

17+
#include <vector>
18+
1619
namespace sycl {
1720
inline namespace _V1 {
21+
22+
template<bundle_state State>
23+
class kernel_bundle;
24+
25+
template <typename KernelName, bundle_state State>
26+
kernel_bundle<State> get_kernel_bundle(const context &,
27+
const std::vector<device> &);
28+
1829
namespace ext::oneapi {
1930

2031
template <typename KernelName, typename Param>

sycl/include/sycl/ext/oneapi/owner_less.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ namespace ext::oneapi {
2929
class kernel_id;
3030
template<bundle_state State>
3131
class kernel_bundle;
32+
template<bundle_state State>
33+
class device_image;
3234

3335
namespace detail {
3436
template <typename SyclObject> struct owner_less_base {

sycl/include/sycl/handler.hpp

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include <sycl/id.hpp>
4444
#include <sycl/item.hpp>
4545
#include <sycl/kernel.hpp>
46-
#include <sycl/kernel_bundle.hpp>
4746
#include <sycl/kernel_bundle_enums.hpp>
4847
#include <sycl/kernel_handler.hpp>
4948
#include <sycl/nd_item.hpp>
@@ -1730,36 +1729,18 @@ class __SYCL_EXPORT handler {
17301729
handler &operator=(const handler &) = delete;
17311730
handler &operator=(handler &&) = delete;
17321731

1732+
// This is somewhat radical, but to make handler.hpp independtent from
1733+
// kernel_bundle.hpp, we define those methods within kernel_bundle.hpp
1734+
// header. Independence is needed in context of potential upcoming split of
1735+
// sycl.hpp so that users could do fine-grained include's, saving on
1736+
// compilation time by avoiding using headers for features they don't use.
17331737
template <auto &SpecName>
17341738
void set_specialization_constant(
1735-
typename std::remove_reference_t<decltype(SpecName)>::value_type Value) {
1736-
1737-
setStateSpecConstSet();
1738-
1739-
std::shared_ptr<detail::kernel_bundle_impl> KernelBundleImplPtr =
1740-
getOrInsertHandlerKernelBundle(/*Insert=*/true);
1741-
1742-
detail::createSyclObjFromImpl<kernel_bundle<bundle_state::input>>(
1743-
KernelBundleImplPtr)
1744-
.set_specialization_constant<SpecName>(Value);
1745-
}
1739+
typename std::remove_reference_t<decltype(SpecName)>::value_type Value);
17461740

17471741
template <auto &SpecName>
17481742
typename std::remove_reference_t<decltype(SpecName)>::value_type
1749-
get_specialization_constant() const {
1750-
1751-
if (isStateExplicitKernelBundle())
1752-
throw sycl::exception(make_error_code(errc::invalid),
1753-
"Specialization constants cannot be read after "
1754-
"explicitly setting the used kernel bundle");
1755-
1756-
std::shared_ptr<detail::kernel_bundle_impl> KernelBundleImplPtr =
1757-
getOrInsertHandlerKernelBundle(/*Insert=*/true);
1758-
1759-
return detail::createSyclObjFromImpl<kernel_bundle<bundle_state::input>>(
1760-
KernelBundleImplPtr)
1761-
.get_specialization_constant<SpecName>();
1762-
}
1743+
get_specialization_constant() const;
17631744

17641745
void
17651746
use_kernel_bundle(const kernel_bundle<bundle_state::executable> &ExecBundle);

sycl/include/sycl/kernel_bundle.hpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
#include <sycl/detail/kernel_desc.hpp> // for get_spec_constant_symboli...
1515
#include <sycl/detail/owner_less_base.hpp> // for OwnerLessBase
1616
#include <sycl/detail/string_view.hpp>
17-
#include <sycl/detail/ur.hpp> // for cast
18-
#include <sycl/device.hpp> // for device
17+
#include <sycl/detail/ur.hpp> // for cast
18+
#include <sycl/device.hpp> // for device
19+
#include <sycl/handler.hpp>
1920
#include <sycl/kernel.hpp> // for kernel, kernel_bundle
2021
#include <sycl/kernel_bundle_enums.hpp> // for bundle_state
2122
#include <sycl/property_list.hpp> // for property_list
@@ -1135,6 +1136,37 @@ build(kernel_bundle<bundle_state::ext_oneapi_source> &SourceKB,
11351136

11361137
} // namespace ext::oneapi::experimental
11371138

1139+
template <auto &SpecName>
1140+
void handler::set_specialization_constant(
1141+
typename std::remove_reference_t<decltype(SpecName)>::value_type Value) {
1142+
1143+
setStateSpecConstSet();
1144+
1145+
std::shared_ptr<detail::kernel_bundle_impl> KernelBundleImplPtr =
1146+
getOrInsertHandlerKernelBundle(/*Insert=*/true);
1147+
1148+
detail::createSyclObjFromImpl<kernel_bundle<bundle_state::input>>(
1149+
KernelBundleImplPtr)
1150+
.set_specialization_constant<SpecName>(Value);
1151+
}
1152+
1153+
template <auto &SpecName>
1154+
typename std::remove_reference_t<decltype(SpecName)>::value_type
1155+
handler::get_specialization_constant() const {
1156+
1157+
if (isStateExplicitKernelBundle())
1158+
throw sycl::exception(make_error_code(errc::invalid),
1159+
"Specialization constants cannot be read after "
1160+
"explicitly setting the used kernel bundle");
1161+
1162+
std::shared_ptr<detail::kernel_bundle_impl> KernelBundleImplPtr =
1163+
getOrInsertHandlerKernelBundle(/*Insert=*/true);
1164+
1165+
return detail::createSyclObjFromImpl<kernel_bundle<bundle_state::input>>(
1166+
KernelBundleImplPtr)
1167+
.get_specialization_constant<SpecName>();
1168+
}
1169+
11381170
} // namespace _V1
11391171
} // namespace sycl
11401172

sycl/source/detail/handler_proxy.cpp

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

99
#include <sycl/detail/handler_proxy.hpp>
1010

11-
// FIXME: that's a hack
12-
#include <sycl/kernel_bundle.hpp>
1311
#include <sycl/handler.hpp>
1412

1513
namespace sycl {

sycl/test/include_deps/sycl_detail_core.hpp.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@
159159
// CHECK-NEXT: ext/oneapi/experimental/virtual_functions.hpp
160160
// CHECK-NEXT: ext/oneapi/kernel_properties/properties.hpp
161161
// CHECK-NEXT: kernel.hpp
162-
// CHECK-NEXT: kernel_bundle.hpp
163-
// CHECK-NEXT: ext/oneapi/experimental/free_function_traits.hpp
164162
// CHECK-NEXT: sampler.hpp
165163
// CHECK-NEXT: feature_test.hpp
166164
// CHECK-EMPTY:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify %s
2+
// expected-no-diagnostics
3+
//
4+
// The purpose of this test is to ensure that the header containing
5+
// sycl::handler class definition is self-contained, i.e. we can use handler
6+
// and no extra headers are needed.
7+
//
8+
// TODO: the test should be expanded to use various methods of the class. Due
9+
// to their template nature we may not test all code paths until we trigger
10+
// instantiation of a corresponding method.
11+
// TODO: methods related to specialization constants were moved into
12+
// kernel_bundle.hpp and therefore handler.hpp is known *not* to be
13+
// self-contained.
14+
15+
#include <sycl/handler.hpp>
16+
17+
void foo(sycl::handler &h) {}

0 commit comments

Comments
 (0)