Skip to content

Commit 042b307

Browse files
authored
[SYCL][RTC] Rename property to registered_names (#17266)
Renames the `registered_kernel_names` property to just `registered_names`. The rationale is to prepare the `kernel_compiler` extension to support device globals in the future, for which we'll need help from the frontend to resolve source code names to mangled symbol names, in the same way we currently handle kernel names. Note: This PR only changes the user-facing property, whereas the implementation continues to use the similarly-named but independent `__sycl_detail__::__registered_kernels__` attribute, `!sycl_registered_kernels` named metdata and `[SYCL/registered kernels]` property set internally. --------- Signed-off-by: Julian Oppermann <[email protected]>
1 parent d8b064a commit 042b307

File tree

6 files changed

+63
-66
lines changed

6 files changed

+63
-66
lines changed

Diff for: sycl/doc/extensions/experimental/sycl_ext_oneapi_kernel_compiler.asciidoc

+42-44
Original file line numberDiff line numberDiff line change
@@ -485,53 +485,52 @@ a!
485485
----
486486
namespace sycl::ext::oneapi::experimental {
487487
488-
struct registered_kernel_names {
489-
registered_kernel_names(); (1)
490-
registered_kernel_names(const std::string &name); (2)
491-
registered_kernel_names(const std::vector<std::string> &names); (3)
492-
void add(const std::string &name); (4)
488+
struct registered_names {
489+
registered_names(); (1)
490+
registered_names(const std::string &name); (2)
491+
registered_names(const std::vector<std::string> &names); (3)
492+
void add(const std::string &name); (4)
493493
};
494-
using registered_kernel_names_key = registered_kernel_names;
494+
using registered_names_key = registered_names;
495495
496496
template<>
497-
struct is_property_key<registered_kernel_names_key> : std::true_type {};
497+
struct is_property_key<registered_names_key> : std::true_type {};
498498
499499
} // namespace sycl::ext::oneapi::experimental
500500
----
501501
!====
502502

503-
This property is useful when the source language represents kernel names
504-
differently in the source code and the generated code.
505-
For example, {cpp} function names in the generated code are "mangled" in an
506-
implementation-defined way.
503+
This property is useful when the source language represents names differently in
504+
the source code and the generated code.
505+
For example, {cpp} function names and the names of static variables at global
506+
scope are "mangled" in an implementation-defined way in the generated code.
507507
The precise meaning of this property is defined by each source language, but in
508-
general it allows the application to supply a list of kernel names as they
509-
appear in the source code.
508+
general it allows the application to supply a list of names as they appear in
509+
the source code.
510510
The application can then get the corresponding raw (i.e. mangled) names after
511511
the code is compiled.
512512
See the section below "Obtaining a kernel when the language is ``sycl``" for a
513513
description of how this property is used with the `source_language::sycl`
514514
language.
515515

516-
_Effects (1):_ Creates a new `registered_kernel_names` property with no
517-
registered kernel names.
516+
_Effects (1):_ Creates a new `registered_names` property with no registered
517+
names.
518518

519-
_Effects (2):_ Creates a new `registered_kernel_names` property with a single
520-
registered kernel name.
519+
_Effects (2):_ Creates a new `registered_names` property with a single
520+
registered name.
521521

522-
_Effects (3):_ Creates a new `registered_kernel_names` property from a vector
523-
of kernel names.
522+
_Effects (3):_ Creates a new `registered_names` property from a vector of names.
524523

525-
_Effects (4):_ Adds `name` to the property's list of registered kernel names.
524+
_Effects (4):_ Adds `name` to the property's list of registered names.
526525

527-
_Preconditions (2-4):_ Each source language defines its own requirements for
528-
the registered kernel names.
526+
_Preconditions (2-4):_ Each source language defines its own requirements for the
527+
registered names.
529528
For the language `source_language::sycl`, each name must be a {cpp} expression
530529
for a pointer to a kernel function as defined below under "Obtaining a kernel
531530
when the language is ``sycl``".
532531

533-
[_Note:_ It is not an error to have duplicate names in a
534-
`registered_kernel_names` property, but the duplicates have no effect.
532+
[_Note:_ It is not an error to have duplicate names in a `registered_names`
533+
property, but the duplicates have no effect.
535534
_{endnote}_]
536535
|====
537536

@@ -643,8 +642,8 @@ _Constraints:_ This function is not available when `State` is
643642

644643
_Returns:_ If the kernel bundle was created from a bundle of state
645644
`bundle_state::ext_oneapi_source` and `name` was registered via
646-
`registered_kernel_names`, returns the compiler-generated (e.g. mangled) name
647-
for this kernel function.
645+
`registered_names`, returns the compiler-generated (e.g. mangled) name for this
646+
kernel function.
648647
If the kernel bundle was created from a bundle of state
649648
`bundle_state::ext_oneapi_source` and `name` is the same as a
650649
compiler-generated name for a kernel defined in that bundle, that same
@@ -661,7 +660,7 @@ _Throws:_
661660
When the kernel is defined in the language `source_language::sycl`, the host
662661
code may query for the kernel or obtain the `kernel` object using either the
663662
kernel's name as it is generated by the compiler (i.e. the {cpp} mangled name)
664-
or by using the `registered_kernel_names` property.
663+
or by using the `registered_names` property.
665664

666665
==== Using the compiler-generated name
667666

@@ -691,11 +690,10 @@ sycl::kernel_bundle<sycl::bundle_state::executable> kb = /*...*/;
691690
sycl::kernel k = kb.ext_oneapi_get_kernel("foo");
692691
----
693692

694-
==== Using the `registered_kernel_names` property
693+
==== Using the `registered_names` property
695694

696695
When the kernel is not declared as `extern "C"`, the compiler generates a
697-
mangled name, so it is more convenient to use the `registered_kernel_names`
698-
property.
696+
mangled name, so it is more convenient to use the `registered_names` property.
699697
Each string in the property must be the {cpp} expression for a pointer to a
700698
kernel function.
701699
These expression strings are conceptually compiled at the bottom of source
@@ -724,7 +722,7 @@ The host code can compile this and get the kernel's `kernel` object like so:
724722
sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source> kb_src = /*...*/;
725723
726724
sycl::kernel_bundle<sycl::bundle_state::executable> kb = syclexp::build(kb_src,
727-
syclexp::properties{syclexp::registered_kernel_names{"mykernels::bar"}});
725+
syclexp::properties{syclexp::registered_names{"mykernels::bar"}});
728726
729727
sycl::kernel k = kb.ext_oneapi_get_kernel("mykernels::bar");
730728
----
@@ -744,21 +742,21 @@ the kernel by calling `ext_oneapi_get_raw_kernel_name` like this:
744742
sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source> kb_src = /*...*/;
745743
746744
sycl::kernel_bundle<sycl::bundle_state::executable> kb = syclexp::build(kb_src,
747-
syclexp::properties{syclexp::registered_kernel_names{"mykernels::bar"}});
745+
syclexp::properties{syclexp::registered_names{"mykernels::bar"}});
748746
749747
std::string mangled_name = kb.ext_oneapi_get_raw_kernel_name("mykernels::bar");
750748
----
751749

752750
Again, the string passed to `ext_oneapi_get_raw_kernel_name` must have exactly
753-
the same content as the string that was used to construct the
754-
`registered_kernel_names` property.
751+
the same content as the string that was used to construct the `registered_names`
752+
property.
755753
The application may also pass this compiler-generated (i.e. mangled) name to
756754
`ext_oneapi_get_kernel` in order to get the `kernel` object.
757755

758756
==== Instantiating templated kernel functions
759757

760-
The `registered_kernel_names` property can also be used to instantiate a
761-
kernel that is defined as a function template.
758+
The `registered_names` property can also be used to instantiate a kernel that is
759+
defined as a function template.
762760
For example, consider source code that defines a kernel function template like
763761
this:
764762

@@ -774,8 +772,8 @@ std::string source = R"""(
774772
)""";
775773
----
776774

777-
The application can use the `registered_kernel_names` property to instantiate
778-
the template for specific template arguments.
775+
The application can use the `registered_names` property to instantiate the
776+
template for specific template arguments.
779777
For example, this host code instantiates the template twice and gets a `kernel`
780778
object for each instantiation:
781779

@@ -784,7 +782,7 @@ object for each instantiation:
784782
sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source> kb_src = /*...*/;
785783
786784
sycl::kernel_bundle<sycl::bundle_state::executable> kb = syclexp::build(kb_src,
787-
syclexp::properties{syclexp::registered_kernel_names{{"bartmpl<float>", "bartmpl<int>"}});
785+
syclexp::properties{syclexp::registered_names{{"bartmpl<float>", "bartmpl<int>"}});
788786
789787
sycl::kernel k_float = kb.ext_oneapi_get_kernel("bartmpl<float>");
790788
sycl::kernel k_int = kb.ext_oneapi_get_kernel("bartmpl<int>");
@@ -830,7 +828,7 @@ int main() {
830828
syclexp::source_language::sycl,
831829
source);
832830
833-
// Compile the kernel. There is no need to use the "registered_kernel_names"
831+
// Compile the kernel. There is no need to use the "registered_names"
834832
// property because the kernel is declared extern "C".
835833
sycl::kernel_bundle<sycl::bundle_state::executable> kb_exe =
836834
syclexp::build(kb_src);
@@ -852,7 +850,7 @@ int main() {
852850

853851
=== Disambiguating overloaded kernel functions
854852

855-
This example demonstrates how to use the `registered_kernel_names` property to
853+
This example demonstrates how to use the `registered_names` property to
856854
disambiguate a kernel function that has several overloads.
857855

858856
[source,c++]
@@ -896,11 +894,11 @@ int main() {
896894
// use a C++ cast to disambiguate between them. Here, we are selecting the
897895
// "int" overload.
898896
std::string iota_name{"(void(*)(int, int*))iota"};
899-
sycl::kernel_bundle<sycl::bundle_state::executable> kb_exe = syclexp::build(kb_src,
900-
syclexp::properties{syclexp::registered_kernel_names{iota_name}});
897+
sycl::kernel_bundle<sycl::bundle_state::executable> kb_exe =
898+
syclexp::build(kb_src, syclexp::properties{syclexp::registered_names{iota_name}});
901899
902900
// Get the kernel by passing the same string we used to construct the
903-
// "registered_kernel_names" property.
901+
// "registered_names" property.
904902
sycl::kernel iota = kb_exe.ext_oneapi_get_kernel(iota_name);
905903
906904
int *ptr = sycl::malloc_shared<int>(NUM, q);

Diff for: sycl/include/sycl/ext/oneapi/properties/property.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ enum PropKind : uint32_t {
210210
InputDataPlacement = 65,
211211
OutputDataPlacement = 66,
212212
IncludeFiles = 67,
213-
RegisteredKernelNames = 68,
213+
RegisteredNames = 68,
214214
ClusterLaunch = 69,
215215
FPGACluster = 70,
216216
Balanced = 71,

Diff for: sycl/include/sycl/kernel_bundle.hpp

+13-14
Original file line numberDiff line numberDiff line change
@@ -1001,22 +1001,21 @@ struct is_property_key_of<save_log_key, detail::build_source_bundle_props>
10011001
: std::true_type {};
10021002

10031003
/////////////////////////
1004-
// PropertyT syclex::registered_kernel_names
1004+
// PropertyT syclex::registered_names
10051005
/////////////////////////
1006-
struct registered_kernel_names
1007-
: detail::run_time_property_key<registered_kernel_names,
1008-
detail::PropKind::RegisteredKernelNames> {
1009-
std::vector<std::string> kernel_names;
1010-
registered_kernel_names() {}
1011-
registered_kernel_names(const std::string &knArg) : kernel_names{knArg} {}
1012-
registered_kernel_names(const std::vector<std::string> &knsArg)
1013-
: kernel_names(knsArg) {}
1014-
void add(const std::string &name) { kernel_names.push_back(name); }
1006+
struct registered_names
1007+
: detail::run_time_property_key<registered_names,
1008+
detail::PropKind::RegisteredNames> {
1009+
std::vector<std::string> names;
1010+
registered_names() {}
1011+
registered_names(const std::string &name) : names{name} {}
1012+
registered_names(const std::vector<std::string> &names) : names{names} {}
1013+
void add(const std::string &name) { names.push_back(name); }
10151014
};
1016-
using registered_kernel_names_key = registered_kernel_names;
1015+
using registered_names_key = registered_names;
10171016

10181017
template <>
1019-
struct is_property_key_of<registered_kernel_names_key,
1018+
struct is_property_key_of<registered_names_key,
10201019
detail::build_source_bundle_props> : std::true_type {
10211020
};
10221021

@@ -1161,9 +1160,9 @@ build(kernel_bundle<bundle_state::ext_oneapi_source> &SourceKB,
11611160
if constexpr (props.template has_property<save_log>()) {
11621161
LogPtr = props.template get_property<save_log>().log;
11631162
}
1164-
if constexpr (props.template has_property<registered_kernel_names>()) {
1163+
if constexpr (props.template has_property<registered_names>()) {
11651164
RegisteredKernelNamesVec =
1166-
props.template get_property<registered_kernel_names>().kernel_names;
1165+
props.template get_property<registered_names>().names;
11671166
}
11681167
return detail::build_from_source(SourceKB, Devices, BuildOptionsVec, LogPtr,
11691168
RegisteredKernelNamesVec);

Diff for: sycl/test-e2e/KernelCompiler/kernel_compiler_sycl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void test_build_and_run() {
166166
exe_kb kbExe2 = syclex::build(
167167
kbSrc, devs,
168168
syclex::properties{syclex::build_options{flags}, syclex::save_log{&log},
169-
syclex::registered_kernel_names{"ff_templated<int>"}});
169+
syclex::registered_names{"ff_templated<int>"}});
170170

171171
assert(log.find("warning: 'this_nd_item<1>' is deprecated") !=
172172
std::string::npos);

Diff for: sycl/test-e2e/KernelCompiler/kernel_compiler_sycl_jit.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ int test_build_and_run() {
236236
exe_kb kbExe2 = syclex::build(
237237
kbSrc, devs,
238238
syclex::properties{syclex::build_options{flags}, syclex::save_log{&log},
239-
syclex::registered_kernel_names{"ff_templated<int>"}});
239+
syclex::registered_names{"ff_templated<int>"}});
240240

241241
// extern "C" was used, so the name "ff_cp" is implicitly known.
242242
sycl::kernel k = kbExe2.ext_oneapi_get_kernel("ff_cp");
@@ -355,7 +355,7 @@ int test_device_code_split() {
355355
auto build = [&](const std::string &mode) -> size_t {
356356
exe_kb kbExe = syclex::build(
357357
kbSrc, syclex::properties{
358-
syclex::registered_kernel_names{names},
358+
syclex::registered_names{names},
359359
syclex::build_options{"-fsycl-device-code-split=" + mode}});
360360
return std::distance(kbExe.begin(), kbExe.end());
361361
};
@@ -372,8 +372,8 @@ int test_device_code_split() {
372372

373373
// Test implicit device code split
374374
names = {"vec_add<float, 8>", "vec_add<float, 16>"};
375-
exe_kb kbDiffWorkGroupSizes = syclex::build(
376-
kbSrc, syclex::properties{syclex::registered_kernel_names{names}});
375+
exe_kb kbDiffWorkGroupSizes =
376+
syclex::build(kbSrc, syclex::properties{syclex::registered_names{names}});
377377
assert(std::distance(kbDiffWorkGroupSizes.begin(),
378378
kbDiffWorkGroupSizes.end()) == 2);
379379

Diff for: sycl/test/abi/sycl_classes_abi_neutral_test.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
// 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)
3434
// 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)}}
3535

36-
// CHECK: 0 | struct sycl::ext::oneapi::experimental::registered_kernel_names
36+
// CHECK: 0 | struct sycl::ext::oneapi::experimental::registered_names
3737
// CHECK-NEXT: 0 | struct sycl::ext::oneapi::experimental::detail::run_time_property_key
38-
// CHECK: 0 | class std::vector<class std::basic_string<char> > kernel_names
38+
// CHECK: 0 | class std::vector<class std::basic_string<char> > names
3939
// CHECK-NEXT: 0 | struct std::_Vector_base<class std::basic_string<char>, class std::allocator<class std::basic_string<char> > > (base)
4040
// CHECK-NEXT: 0 | struct std::_Vector_base<class std::basic_string<char>, class std::allocator<class std::basic_string<char> > >::_Vector_impl _M_impl
4141
// CHECK-NEXT: 0 | class std::allocator<class std::basic_string<char> > (base) (empty)

0 commit comments

Comments
 (0)