@@ -109,7 +109,8 @@ supports.
109
109
This extension adds the `ext_oneapi_source` enumerator to `sycl::bundle_state`
110
110
to identify a kernel bundle that is represented as a source code string.
111
111
112
- ```
112
+ [source,c++]
113
+ ----
113
114
namespace sycl {
114
115
115
116
enum class bundle_state : /*unspecified*/ {
@@ -118,22 +119,23 @@ enum class bundle_state : /*unspecified*/ {
118
119
};
119
120
120
121
} // namespace sycl
121
- ```
122
+ ----
122
123
123
124
=== New enumerator of kernel source languages
124
125
125
126
This extension adds the `source_language` enumeration, which identifies
126
127
possible languages for a kernel bundle that is in `ext_oneapi_source` state:
127
128
128
- ```
129
+ [source,c++]
130
+ ----
129
131
namespace sycl::ext::oneapi::experimental {
130
132
131
133
enum class source_language : /*unspecified*/ {
132
134
sycl
133
135
};
134
136
135
137
} // namespace sycl::ext::oneapi::experimental
136
- ```
138
+ ----
137
139
138
140
The only enumerator defined by this extension is `sycl`, which indicates that
139
141
the kernel is written in SYCL using the "free function kernel" syntax defined
151
153
[frame=all,grid=none]
152
154
!====
153
155
a!
154
- [source]
156
+ [source,c++ ]
155
157
----
156
158
class device {
157
159
175
177
[frame=all,grid=none]
176
178
!====
177
179
a!
178
- [source]
180
+ [source,c++ ]
179
181
----
180
182
namespace sycl::ext::oneapi::experimental {
181
183
246
248
[frame=all,grid=none]
247
249
!====
248
250
a!
249
- [source]
251
+ [source,c++ ]
250
252
----
251
253
namespace sycl::ext::oneapi::experimental {
252
254
322
324
[frame=all,grid=none]
323
325
!====
324
326
a!
325
- [source]
327
+ [source,c++ ]
326
328
----
327
329
namespace sycl::ext::oneapi::experimental {
328
330
396
398
[frame=all,grid=none]
397
399
!====
398
400
a!
399
- [source]
401
+ [source,c++ ]
400
402
----
401
403
namespace sycl::ext::oneapi::experimental {
402
404
438
440
[frame=all,grid=none]
439
441
!====
440
442
a!
441
- [source]
443
+ [source,c++ ]
442
444
----
443
445
namespace sycl::ext::oneapi::experimental {
444
446
480
482
[frame=all,grid=none]
481
483
!====
482
484
a!
483
- [source]
485
+ [source,c++ ]
484
486
----
485
487
namespace sycl::ext::oneapi::experimental {
486
488
@@ -570,7 +572,8 @@ of `kernel_id` objects if the kernel bundle was created from a bundle of state
570
572
571
573
This extensions adds the following new `kernel_bundle` member functions:
572
574
573
- ```
575
+ [source,c++]
576
+ ----
574
577
namespace sycl {
575
578
576
579
template <bundle_state State>
@@ -583,14 +586,14 @@ class kernel_bundle {
583
586
};
584
587
585
588
} // namespace sycl
586
- ```
589
+ ----
587
590
588
591
|====
589
592
a|
590
593
[frame=all,grid=none]
591
594
!====
592
595
a!
593
- [source]
596
+ [source,c++ ]
594
597
----
595
598
bool ext_oneapi_has_kernel(const std::string &name)
596
599
----
609
612
[frame=all,grid=none]
610
613
!====
611
614
a!
612
- [source]
615
+ [source,c++ ]
613
616
----
614
617
kernel ext_oneapi_get_kernel(const std::string &name)
615
618
----
630
633
[frame=all,grid=none]
631
634
!====
632
635
a!
633
- [source]
636
+ [source,c++ ]
634
637
----
635
638
std::string ext_oneapi_get_raw_kernel_name(const std::string &name)
636
639
----
@@ -669,7 +672,8 @@ Therefore, it is easy to query for the kernel by using the compiler-generated
669
672
name.
670
673
For example, if the kernel is defined like this in the source code string:
671
674
672
- ```
675
+ [source,c++]
676
+ ----
673
677
std::string source = R"""(
674
678
#include <sycl/sycl.hpp>
675
679
namespace syclex = sycl::ext::oneapi::experimental;
@@ -678,14 +682,15 @@ std::string source = R"""(
678
682
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclex::range_kernel<1>))
679
683
void foo(int *in, int *out) {/*...*/}
680
684
)""";
681
- ```
685
+ ----
682
686
683
687
Then the application's host code can query for the kernel like this:
684
688
685
- ```
689
+ [source,c++]
690
+ ----
686
691
sycl::kernel_bundle<sycl::bundle_state::executable> kb = /*...*/;
687
692
sycl::kernel k = kb.ext_oneapi_get_kernel("foo");
688
- ```
693
+ ----
689
694
690
695
==== Using the `registered_kernel_names` property
691
696
@@ -698,7 +703,8 @@ These expression strings are conceptually compiled at the bottom of source
698
703
code.
699
704
To illustrate, consider source code that defines a kernel like this:
700
705
701
- ```
706
+ [source,c++]
707
+ ----
702
708
std::string source = R"""(
703
709
#include <sycl/sycl.hpp>
704
710
namespace syclex = sycl::ext::oneapi::experimental;
@@ -710,18 +716,19 @@ std::string source = R"""(
710
716
711
717
} // namespace mykernels
712
718
)""";
713
- ```
719
+ ----
714
720
715
721
The host code can compile this and get the kernel's `kernel` object like so:
716
722
717
- ```
723
+ [source,c++]
724
+ ----
718
725
sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source> kb_src = /*...*/;
719
726
720
727
sycl::kernel_bundle<sycl::bundle_state::executable> kb = syclex::build(kb_src,
721
728
syclex::properties{syclex::registered_kernel_names{"mykernels::bar"}});
722
729
723
730
sycl::kernel k = kb.ext_oneapi_get_kernel("mykernels::bar");
724
- ```
731
+ ----
725
732
726
733
The {cpp} expression `"mykernels::bar"` computes the address of the kernel
727
734
function `bar`.
@@ -733,14 +740,15 @@ construct the property, without even any whitespace differences.
733
740
The application can also obtain the compiler-generated (i.e. mangled) name for
734
741
the kernel by calling `ext_oneapi_get_raw_kernel_name` like this:
735
742
736
- ```
743
+ [source,c++]
744
+ ----
737
745
sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source> kb_src = /*...*/;
738
746
739
747
sycl::kernel_bundle<sycl::bundle_state::executable> kb = syclex::build(kb_src,
740
748
syclex::properties{syclex::registered_kernel_names{"mykernels::bar"}});
741
749
742
750
std::string mangled_name = kb.ext_oneapi_get_raw_kernel_name("mykernels::bar");
743
- ```
751
+ ----
744
752
745
753
Again, the string passed to `ext_oneapi_get_raw_kernel_name` must have exactly
746
754
the same content as the string that was used to construct the
@@ -755,7 +763,8 @@ kernel that is defined as a function template.
755
763
For example, consider source code that defines a kernel function template like
756
764
this:
757
765
758
- ```
766
+ [source,c++]
767
+ ----
759
768
std::string source = R"""(
760
769
#include <sycl/sycl.hpp>
761
770
namespace syclex = sycl::ext::oneapi::experimental;
@@ -764,22 +773,23 @@ std::string source = R"""(
764
773
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclex::range_kernel<1>))
765
774
void bartmpl(T *in, T *out) {/*...*/}
766
775
)""";
767
- ```
776
+ ----
768
777
769
778
The application can use the `registered_kernel_names` property to instantiate
770
779
the template for specific template arguments.
771
780
For example, this host code instantiates the template twice and gets a `kernel`
772
781
object for each instantiation:
773
782
774
- ```
783
+ [source,c++]
784
+ ----
775
785
sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source> kb_src = /*...*/;
776
786
777
787
sycl::kernel_bundle<sycl::bundle_state::executable> kb = syclex::build(kb_src,
778
788
syclex::properties{syclex::registered_kernel_names{{"bartmpl<float>", "bartmpl<int>"}});
779
789
780
790
sycl::kernel k_float = kb.ext_oneapi_get_kernel("bartmpl<float>");
781
791
sycl::kernel k_int = kb.ext_oneapi_get_kernel("bartmpl<int>");
782
- ```
792
+ ----
783
793
784
794
785
795
== Examples
@@ -789,7 +799,8 @@ sycl::kernel k_int = kb.ext_oneapi_get_kernel("bartmpl<int>");
789
799
The following example demonstrates how a SYCL application can define a kernel
790
800
as a string and then compile and launch it.
791
801
792
- ```
802
+ [source,c++]
803
+ ----
793
804
#include <sycl/sycl.hpp>
794
805
namespace syclex = sycl::ext::oneapi::experimental;
795
806
static constexpr size_t NUM = 1024;
@@ -835,14 +846,15 @@ int main() {
835
846
cgh.parallel_for({NUM}, iota);
836
847
}).wait();
837
848
}
838
- ```
849
+ ----
839
850
840
851
=== Disambiguating overloaded kernel functions
841
852
842
853
This example demonstrates how to use the `registered_kernel_names` property to
843
854
disambiguate a kernel function that has several overloads.
844
855
845
- ```
856
+ [source,c++]
857
+ ----
846
858
#include <sycl/sycl.hpp>
847
859
namespace syclex = sycl::ext::oneapi::experimental;
848
860
static constexpr size_t NUM = 1024;
@@ -896,7 +908,7 @@ int main() {
896
908
cgh.parallel_for({NUM}, iota);
897
909
}).wait();
898
910
}
899
- ```
911
+ ----
900
912
901
913
902
914
== Issues
0 commit comments