Skip to content

Commit c74fe5d

Browse files
Port kernel_bundle to new properties
1 parent 2508ba0 commit c74fe5d

File tree

8 files changed

+106
-90
lines changed

8 files changed

+106
-90
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <string_view>
1515

1616
#include <sycl/detail/defines_elementary.hpp>
17-
17+
#include <sycl/detail/type_traits.hpp>
1818

1919
// For old properties:
2020
#include <sycl/detail/is_device_copyable.hpp>
@@ -171,6 +171,7 @@ inline constexpr bool is_property_v =
171171

172172
// Empty property list.
173173
template <> class __SYCL_EBO properties<detail::properties_type_list<>, void> {
174+
public:
174175
template <typename> static constexpr bool has_property() { return false; }
175176
};
176177

@@ -312,7 +313,20 @@ properties(properties<detail::properties_type_list<other_property_list_tys...>>,
312313

313314
using empty_properties_t = decltype(properties{});
314315

315-
template <typename, typename> struct is_property_of : std::false_type {};
316+
template <typename property_list_ty, typename... allowed_property_keys>
317+
struct all_properties_in : std::false_type{};
318+
template <typename... property_tys, typename... allowed_property_keys>
319+
struct all_properties_in<
320+
properties<detail::properties_type_list<property_tys...>>,
321+
allowed_property_keys...>
322+
: std::bool_constant<((sycl::detail::check_type_in_v<
323+
property_tys, allowed_property_keys...> &&
324+
...))> {};
325+
326+
template <typename property_list_ty, typename... allowed_property_keys>
327+
inline constexpr bool all_properties_in_v =
328+
all_properties_in<std::remove_const_t<property_list_ty>,
329+
allowed_property_keys...>::value;
316330
} // namespace new_properties
317331
} // namespace ext::oneapi::experimental
318332
} // namespace _V1

sycl/include/sycl/kernel_bundle.hpp

Lines changed: 38 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -892,16 +892,14 @@ build(const kernel_bundle<bundle_state::input> &InputBundle,
892892

893893
namespace ext::oneapi::experimental {
894894

895-
namespace detail {
896-
struct create_bundle_from_source_props;
897-
struct build_source_bundle_props;
898-
} // namespace detail
899-
900895
/////////////////////////
901896
// PropertyT syclex::include_files
902897
/////////////////////////
903898
struct include_files
904-
: detail::run_time_property_key<detail::PropKind::IncludeFiles> {
899+
: new_properties::detail::property_base<include_files> {
900+
static constexpr std::string_view property_name{
901+
"sycl::ext::oneapi::experimental::include_files"};
902+
905903
include_files();
906904
include_files(const std::string &name, const std::string &content) {
907905
record.emplace_back(std::make_pair(name, content));
@@ -911,61 +909,53 @@ struct include_files
911909
}
912910
std::vector<std::pair<std::string, std::string>> record;
913911
};
914-
using include_files_key = include_files;
915-
916-
template <>
917-
struct is_property_key_of<include_files_key,
918-
detail::create_bundle_from_source_props>
919-
: std::true_type {};
920912

921913
/////////////////////////
922914
// PropertyT syclex::build_options
923915
/////////////////////////
924-
struct build_options
925-
: detail::run_time_property_key<detail::PropKind::BuildOptions> {
916+
struct build_options : new_properties::detail::property_base<build_options> {
917+
static constexpr std::string_view property_name{
918+
"sycl::ext::oneapi::experimental::build_options"};
926919
std::vector<std::string> opts;
927920
build_options(const std::string &optsArg) : opts{optsArg} {}
928921
build_options(const std::vector<std::string> &optsArg) : opts(optsArg) {}
929922
};
930-
using build_options_key = build_options;
931-
932-
template <>
933-
struct is_property_key_of<build_options_key, detail::build_source_bundle_props>
934-
: std::true_type {};
935923

936924
/////////////////////////
937925
// PropertyT syclex::save_log
938926
/////////////////////////
939-
struct save_log : detail::run_time_property_key<detail::PropKind::BuildLog> {
927+
struct save_log : new_properties::detail::property_base<save_log> {
928+
static constexpr std::string_view property_name{
929+
"sycl::ext::oneapi::experimental::save_log"};
940930
std::string *log;
941931
save_log(std::string *logArg) : log(logArg) {}
942932
};
943-
using save_log_key = save_log;
944-
945-
template <>
946-
struct is_property_key_of<save_log_key, detail::build_source_bundle_props>
947-
: std::true_type {};
948933

949934
/////////////////////////
950935
// PropertyT syclex::registered_kernel_names
951936
/////////////////////////
952937
struct registered_kernel_names
953-
: detail::run_time_property_key<detail::PropKind::RegisteredKernelNames> {
938+
: new_properties::detail::property_base<registered_kernel_names> {
939+
static constexpr std::string_view property_name{
940+
"sycl::ext::oneapi::experimental::registered_kernel_names"};
954941
std::vector<std::string> kernel_names;
955942
registered_kernel_names() {}
956943
registered_kernel_names(const std::string &knArg) : kernel_names{knArg} {}
957944
registered_kernel_names(const std::vector<std::string> &knsArg)
958945
: kernel_names(knsArg) {}
959946
void add(const std::string &name) { kernel_names.push_back(name); }
960947
};
961-
using registered_kernel_names_key = registered_kernel_names;
962-
963-
template <>
964-
struct is_property_key_of<registered_kernel_names_key,
965-
detail::build_source_bundle_props> : std::true_type {
966-
};
967948

968949
namespace detail {
950+
template <typename property_list_ty>
951+
inline constexpr bool are_properties_valid_for_create_bundle_from_source =
952+
new_properties::all_properties_in_v<property_list_ty, include_files>;
953+
954+
template <typename property_list_ty>
955+
inline constexpr bool are_properties_valid_for_build_source_bundle =
956+
new_properties::all_properties_in_v<property_list_ty, build_options,
957+
save_log, registered_kernel_names>;
958+
969959
// forward decls
970960
__SYCL_EXPORT bool is_source_kernel_bundle_supported(backend BE,
971961
source_language Language);
@@ -1054,12 +1044,10 @@ build_from_source(kernel_bundle<bundle_state::ext_oneapi_source> &SourceKB,
10541044
/////////////////////////
10551045
// syclex::create_kernel_bundle_from_source
10561046
/////////////////////////
1057-
template <
1058-
typename PropertyListT = empty_properties_t,
1059-
typename = std::enable_if_t<
1060-
is_property_list_v<PropertyListT> &&
1061-
detail::all_props_are_keys_of<detail::create_bundle_from_source_props,
1062-
PropertyListT>::value>>
1047+
template <typename PropertyListT = new_properties::empty_properties_t,
1048+
typename = std::enable_if_t<
1049+
detail::are_properties_valid_for_create_bundle_from_source<
1050+
PropertyListT>>>
10631051
kernel_bundle<bundle_state::ext_oneapi_source> create_kernel_bundle_from_source(
10641052
const context &SyclContext, source_language Language,
10651053
const std::string &Source, PropertyListT props = {}) {
@@ -1073,12 +1061,10 @@ kernel_bundle<bundle_state::ext_oneapi_source> create_kernel_bundle_from_source(
10731061
}
10741062

10751063
#if (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
1076-
template <
1077-
typename PropertyListT = empty_properties_t,
1078-
typename = std::enable_if_t<
1079-
is_property_list_v<PropertyListT> &&
1080-
detail::all_props_are_keys_of<detail::create_bundle_from_source_props,
1081-
PropertyListT>::value>>
1064+
template <typename PropertyListT = new_properties::empty_properties_t,
1065+
typename = std::enable_if_t<
1066+
detail::are_properties_valid_for_create_bundle_from_source<
1067+
PropertyListT>>>
10821068
kernel_bundle<bundle_state::ext_oneapi_source> create_kernel_bundle_from_source(
10831069
const context &SyclContext, source_language Language,
10841070
const std::vector<std::byte> &Bytes, PropertyListT props = {}) {
@@ -1096,12 +1082,10 @@ kernel_bundle<bundle_state::ext_oneapi_source> create_kernel_bundle_from_source(
10961082
// syclex::build(source_kb) => exe_kb
10971083
/////////////////////////
10981084

1099-
template <typename PropertyListT = empty_properties_t,
1100-
typename = std::enable_if_t<
1101-
is_property_list_v<PropertyListT> &&
1102-
detail::all_props_are_keys_of<detail::build_source_bundle_props,
1103-
PropertyListT>::value>>
1104-
1085+
template <
1086+
typename PropertyListT = new_properties::empty_properties_t,
1087+
typename = std::enable_if_t<
1088+
detail::are_properties_valid_for_build_source_bundle<PropertyListT>>>
11051089
kernel_bundle<bundle_state::executable>
11061090
build(kernel_bundle<bundle_state::ext_oneapi_source> &SourceKB,
11071091
const std::vector<device> &Devices, PropertyListT props = {}) {
@@ -1122,11 +1106,10 @@ build(kernel_bundle<bundle_state::ext_oneapi_source> &SourceKB,
11221106
RegisteredKernelNamesVec);
11231107
}
11241108

1125-
template <typename PropertyListT = empty_properties_t,
1126-
typename = std::enable_if_t<
1127-
is_property_list_v<PropertyListT> &&
1128-
detail::all_props_are_keys_of<detail::build_source_bundle_props,
1129-
PropertyListT>::value>>
1109+
template <
1110+
typename PropertyListT = new_properties::empty_properties_t,
1111+
typename = std::enable_if_t<
1112+
detail::are_properties_valid_for_build_source_bundle<PropertyListT>>>
11301113
kernel_bundle<bundle_state::executable>
11311114
build(kernel_bundle<bundle_state::ext_oneapi_source> &SourceKB,
11321115
PropertyListT props = {}) {

sycl/test-e2e/KernelCompiler/kernel_compiler_opencl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ void test_build_and_run() {
105105
sycl::backend beRes = kbSrc.get_backend();
106106
assert(beRes == ctx.get_backend());
107107

108-
exe_kb kbExe2 = syclex::build(
109-
kbSrc, devs,
110-
syclex::properties{syclex::build_options{flags}, syclex::save_log{&log}});
108+
exe_kb kbExe2 =
109+
syclex::build(kbSrc, devs,
110+
syclex::new_properties::properties{
111+
syclex::build_options{flags}, syclex::save_log{&log}});
111112

112113
bool hasMyKernel = kbExe2.ext_oneapi_has_kernel("my_kernel");
113114
bool hasHerKernel = kbExe2.ext_oneapi_has_kernel("her_kernel");

sycl/test-e2e/KernelCompiler/kernel_compiler_sycl.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void test_build_and_run() {
138138
incFiles.add("intermediate/PlusEm.h", PlusEmH);
139139
source_kb kbSrc = syclex::create_kernel_bundle_from_source(
140140
ctx, syclex::source_language::sycl, SYCLSource,
141-
syclex::properties{incFiles});
141+
syclex::new_properties::properties{incFiles});
142142

143143
// Double check kernel_bundle.get_source() / get_backend().
144144
sycl::context ctxRes = kbSrc.get_context();
@@ -153,10 +153,11 @@ void test_build_and_run() {
153153
std::string log;
154154
std::vector<std::string> flags{"-g", "-fno-fast-math"};
155155
std::vector<sycl::device> devs = kbSrc.get_devices();
156-
exe_kb kbExe2 = syclex::build(
157-
kbSrc, devs,
158-
syclex::properties{syclex::build_options{flags}, syclex::save_log{&log},
159-
syclex::registered_kernel_names{"ff_templated<int>"}});
156+
exe_kb kbExe2 =
157+
syclex::build(kbSrc, devs,
158+
syclex::new_properties::properties{
159+
syclex::build_options{flags}, syclex::save_log{&log},
160+
syclex::registered_kernel_names{"ff_templated<int>"}});
160161
assert(log.find("warning: 'this_nd_item<1>' is deprecated") !=
161162
std::string::npos);
162163

@@ -231,8 +232,8 @@ void test_esimd() {
231232

232233
source_kb kbSrc = syclex::create_kernel_bundle_from_source(
233234
ctx, syclex::source_language::sycl, ESIMDSource);
234-
exe_kb kbExe =
235-
syclex::build(kbSrc, syclex::properties{syclex::save_log{&log}});
235+
exe_kb kbExe = syclex::build(
236+
kbSrc, syclex::new_properties::properties{syclex::save_log{&log}});
236237

237238
// extern "C" was used, so the name "vector_add_esimd" is not mangled and can
238239
// be used directly.

sycl/test-e2e/KernelCompiler/sycl_device_flags.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ int main(int argc, char *argv[]) {
129129
// Flags with and without space, inner quotes.
130130
std::vector<std::string> flags{"-Xs '-doubleGRF'",
131131
"-Xs'-Xfinalizer \"-printregusage\"'"};
132-
exe_kb kbExe =
133-
syclex::build(kbSrc, syclex::properties{syclex::build_options{flags}});
132+
exe_kb kbExe = syclex::build(
133+
kbSrc, syclex::new_properties::properties{syclex::build_options{flags}});
134134

135135
sycl::kernel k = kbExe.ext_oneapi_get_kernel("add_thirty");
136136

sycl/test/abi/sycl_classes_abi_neutral_test.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,32 @@
1515
// New exclusions are NOT ALLOWED to this file unless it is guaranteed that data
1616
// member is not crossing ABI boundary. All current exclusions are listed below.
1717

18-
// CHECK: 0 | struct sycl::ext::oneapi::experimental::build_options
19-
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::detail::run_time_property_key<sycl::ext::oneapi::experimental::detail::BuildOptions> (base) (empty)
20-
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::detail::property_key_base_tag (base) (empty)
18+
// CHECK: 0 | struct sycl::ext::oneapi::experimental::build_options
19+
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::new_properties::detail::property_base<struct sycl::ext::oneapi::experimental::build_options> (base) (empty)
20+
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::new_properties::detail::property_key_tag<struct sycl::ext::oneapi::experimental::build_options> (base) (empty)
21+
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::new_properties::detail::property_key_tag_base (base) (empty)
2122
// CHECK-NEXT: 0 | class std::vector<class std::basic_string<char> > opts
2223
// CHECK-NEXT: 0 | struct std::_Vector_base<class std::basic_string<char>, class std::allocator<class std::basic_string<char> > > (base)
2324
// CHECK-NEXT: 0 | struct std::_Vector_base<class std::basic_string<char>, class std::allocator<class std::basic_string<char> > >::_Vector_impl _M_impl
2425
// CHECK-NEXT: 0 | class std::allocator<class std::basic_string<char> > (base) (empty)
2526
// CHECK-NEXT: 0 | class {{(std::__new_allocator|__gnu_cxx::new_allocator)}}<class std::basic_string<char> > (base) (empty)
2627
// CHECK-NEXT: 0 | {{(struct std::_Vector_base<class std::basic_string<char>, class std::allocator<class std::basic_string<char> > >::_Vector_impl_data \(base\)|pointer _M_start)}}
2728

28-
// CHECK: 0 | struct sycl::ext::oneapi::experimental::include_files
29-
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::detail::run_time_property_key<sycl::ext::oneapi::experimental::detail::IncludeFiles> (base) (empty)
30-
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::detail::property_key_base_tag (base) (empty)
29+
// CHECK: 0 | struct sycl::ext::oneapi::experimental::include_files
30+
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::new_properties::detail::property_base<struct sycl::ext::oneapi::experimental::include_files> (base) (empty)
31+
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::new_properties::detail::property_key_tag<struct sycl::ext::oneapi::experimental::include_files> (base) (empty)
32+
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::new_properties::detail::property_key_tag_base (base) (empty)
3133
// CHECK-NEXT: 0 | class std::vector<struct std::pair<class std::basic_string<char>, class std::basic_string<char> > > record
3234
// CHECK-NEXT: 0 | struct std::_Vector_base<struct std::pair<class std::basic_string<char>, class std::basic_string<char> >, class std::allocator<struct std::pair<class std::basic_string<char>, class std::basic_string<char> > > > (base)
3335
// CHECK-NEXT: 0 | struct std::_Vector_base<struct std::pair<class std::basic_string<char>, class std::basic_string<char> >, class std::allocator<struct std::pair<class std::basic_string<char>, class std::basic_string<char> > > >::_Vector_impl _M_impl
3436
// CHECK-NEXT: 0 | class std::allocator<struct std::pair<class std::basic_string<char>, class std::basic_string<char> > > (base) (empty)
3537
// CHECK-NEXT: 0 | class {{(std::__new_allocator|__gnu_cxx::new_allocator)}}<struct std::pair<class std::basic_string<char>, class std::basic_string<char> > > (base) (empty)
3638
// CHECK-NEXT: 0 | {{(struct std::_Vector_base<struct std::pair<class std::basic_string<char>, class std::basic_string<char> >, class std::allocator<struct std::pair<class std::basic_string<char>, class std::basic_string<char> > > >::_Vector_impl_data \(base\)|pointer _M_start)}}
3739

38-
// CHECK: 0 | struct sycl::ext::oneapi::experimental::registered_kernel_names
39-
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::detail::run_time_property_key<sycl::ext::oneapi::experimental::detail::RegisteredKernelNames> (base) (empty)
40-
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::detail::property_key_base_tag (base) (empty)
40+
// CHECK: 0 | struct sycl::ext::oneapi::experimental::registered_kernel_names
41+
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::new_properties::detail::property_base<struct sycl::ext::oneapi::experimental::registered_kernel_names> (base) (empty)
42+
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::new_properties::detail::property_key_tag<struct sycl::ext::oneapi::experimental::registered_kernel_names> (base) (empty)
43+
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::new_properties::detail::property_key_tag_base (base) (empty)
4144
// CHECK-NEXT: 0 | class std::vector<class std::basic_string<char> > kernel_names
4245
// CHECK-NEXT: 0 | struct std::_Vector_base<class std::basic_string<char>, class std::allocator<class std::basic_string<char> > > (base)
4346
// CHECK-NEXT: 0 | struct std::_Vector_base<class std::basic_string<char>, class std::allocator<class std::basic_string<char> > >::_Vector_impl _M_impl

sycl/test/extensions/kernel_compiler_constraints.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@
88

99
// RUN: %clangxx -fsyntax-only -fsycl -Xclang -verify -Xclang -verify-ignore-unexpected=note %s
1010

11-
// kernel_bundles sporting the new bundle_state::ext_oneapi_source should NOT
11+
// kernel_bundles supporting the new bundle_state::ext_oneapi_source should NOT
1212
// support several member functions. This test confirms that.
1313

1414
#include <sycl/sycl.hpp>
1515

16+
namespace syclex = sycl::ext::oneapi::experimental;
17+
18+
struct some_property : syclex::new_properties::detail::property_base<some_property> {
19+
static constexpr std::string_view property_name{"::some_property"};
20+
};
21+
1622
int main() {
1723
#ifdef SYCL_EXT_ONEAPI_KERNEL_COMPILER
1824

19-
namespace syclex = sycl::ext::oneapi::experimental;
2025
using source_kb = sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source>;
2126

2227
sycl::queue q;
@@ -75,34 +80,33 @@ int main() {
7580
syclex::build(kbSrc);
7681

7782
// expected-error@+1 {{no matching function for call to 'build'}}
78-
syclex::build(kbSrc,
79-
syclex::properties{syclex::usm_kind<sycl::usm::alloc::host>});
83+
syclex::build(kbSrc, syclex::new_properties::properties{some_property{}});
8084

8185
// OK
82-
syclex::build(kbSrc, syclex::properties{syclex::build_options{flags},
86+
syclex::build(kbSrc, syclex::new_properties::properties{syclex::build_options{flags},
8387
syclex::save_log{&log}});
8488

8589
// expected-error@+1 {{no matching function for call to 'build'}}
86-
syclex::build(kbSrc, syclex::properties{
90+
syclex::build(kbSrc, syclex::new_properties::properties{
8791
syclex::build_options{flags}, syclex::save_log{&log},
88-
syclex::usm_kind<sycl::usm::alloc::host>});
92+
some_property{}});
8993
// OK
9094
syclex::build(kbSrc, devices);
9195

9296
// expected-error@+1 {{no matching function for call to 'build'}}
9397
syclex::build(kbSrc, devices,
94-
syclex::properties{syclex::usm_kind<sycl::usm::alloc::host>});
98+
syclex::new_properties::properties{some_property{}});
9599

96100
// OK
97101
syclex::build(
98102
kbSrc, devices,
99-
syclex::properties{syclex::build_options{flags}, syclex::save_log{&log}});
103+
syclex::new_properties::properties{syclex::build_options{flags}, syclex::save_log{&log}});
100104

101105
// expected-error@+1 {{no matching function for call to 'build'}}
102106
syclex::build(kbSrc, devices,
103-
syclex::properties{syclex::build_options{flags},
104-
syclex::save_log{&log},
105-
syclex::usm_kind<sycl::usm::alloc::host>});
107+
syclex::new_properties::properties{syclex::build_options{flags},
108+
syclex::save_log{&log},
109+
some_property{}});
106110

107111
#endif
108112
}

0 commit comments

Comments
 (0)