@@ -681,10 +681,10 @@ For example, if the kernel is defined like this in the source code string:
681
681
----
682
682
std::string source = R"""(
683
683
#include <sycl/sycl.hpp>
684
- namespace syclex = sycl::ext::oneapi::experimental;
684
+ namespace syclexp = sycl::ext::oneapi::experimental;
685
685
686
686
extern "C"
687
- SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclex::range_kernel <1>))
687
+ SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel <1>))
688
688
void foo(int *in, int *out) {/*...*/}
689
689
)""";
690
690
----
@@ -712,11 +712,11 @@ To illustrate, consider source code that defines a kernel like this:
712
712
----
713
713
std::string source = R"""(
714
714
#include <sycl/sycl.hpp>
715
- namespace syclex = sycl::ext::oneapi::experimental;
715
+ namespace syclexp = sycl::ext::oneapi::experimental;
716
716
717
717
namespace mykernels {
718
718
719
- SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclex::range_kernel <1>))
719
+ SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel <1>))
720
720
void bar(int *in, int *out) {/*...*/}
721
721
722
722
} // namespace mykernels
@@ -729,8 +729,8 @@ The host code can compile this and get the kernel's `kernel` object like so:
729
729
----
730
730
sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source> kb_src = /*...*/;
731
731
732
- sycl::kernel_bundle<sycl::bundle_state::executable> kb = syclex ::build(kb_src,
733
- syclex ::properties{syclex ::registered_kernel_names{"mykernels::bar"}});
732
+ sycl::kernel_bundle<sycl::bundle_state::executable> kb = syclexp ::build(kb_src,
733
+ syclexp ::properties{syclexp ::registered_kernel_names{"mykernels::bar"}});
734
734
735
735
sycl::kernel k = kb.ext_oneapi_get_kernel("mykernels::bar");
736
736
----
@@ -749,8 +749,8 @@ the kernel by calling `ext_oneapi_get_raw_kernel_name` like this:
749
749
----
750
750
sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source> kb_src = /*...*/;
751
751
752
- sycl::kernel_bundle<sycl::bundle_state::executable> kb = syclex ::build(kb_src,
753
- syclex ::properties{syclex ::registered_kernel_names{"mykernels::bar"}});
752
+ sycl::kernel_bundle<sycl::bundle_state::executable> kb = syclexp ::build(kb_src,
753
+ syclexp ::properties{syclexp ::registered_kernel_names{"mykernels::bar"}});
754
754
755
755
std::string mangled_name = kb.ext_oneapi_get_raw_kernel_name("mykernels::bar");
756
756
----
@@ -772,10 +772,10 @@ this:
772
772
----
773
773
std::string source = R"""(
774
774
#include <sycl/sycl.hpp>
775
- namespace syclex = sycl::ext::oneapi::experimental;
775
+ namespace syclexp = sycl::ext::oneapi::experimental;
776
776
777
777
template<typename T>
778
- SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclex::range_kernel <1>))
778
+ SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel <1>))
779
779
void bartmpl(T *in, T *out) {/*...*/}
780
780
)""";
781
781
----
@@ -789,8 +789,8 @@ object for each instantiation:
789
789
----
790
790
sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source> kb_src = /*...*/;
791
791
792
- sycl::kernel_bundle<sycl::bundle_state::executable> kb = syclex ::build(kb_src,
793
- syclex ::properties{syclex ::registered_kernel_names{{"bartmpl<float>", "bartmpl<int>"}});
792
+ sycl::kernel_bundle<sycl::bundle_state::executable> kb = syclexp ::build(kb_src,
793
+ syclexp ::properties{syclexp ::registered_kernel_names{{"bartmpl<float>", "bartmpl<int>"}});
794
794
795
795
sycl::kernel k_float = kb.ext_oneapi_get_kernel("bartmpl<float>");
796
796
sycl::kernel k_int = kb.ext_oneapi_get_kernel("bartmpl<int>");
@@ -807,36 +807,39 @@ as a string and then compile and launch it.
807
807
[source,c++]
808
808
----
809
809
#include <sycl/sycl.hpp>
810
- namespace syclex = sycl::ext::oneapi::experimental;
810
+ namespace syclexp = sycl::ext::oneapi::experimental;
811
+
811
812
static constexpr size_t NUM = 1024;
813
+ static constexpr size_t WGSIZE = 16;
812
814
813
815
int main() {
814
816
sycl::queue q;
815
817
816
818
// The source code for a kernel, defined as a SYCL "free function kernel".
817
819
std::string source = R"""(
818
820
#include <sycl/sycl.hpp>
819
- namespace syclex = sycl::ext::oneapi::experimental;
821
+ namespace syclext = sycl::ext::oneapi;
822
+ namespace syclexp = sycl::ext::oneapi::experimental;
820
823
821
824
extern "C"
822
- SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclex::range_kernel <1>))
825
+ SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel <1>))
823
826
void iota(float start, float *ptr) {
824
- size_t id = syclex::this_kernel::get_id ();
827
+ size_t id = syclext::this_work_item::get_nd_item().get_global_linear_id ();
825
828
ptr[id] = start + static_cast<float>(id);
826
829
}
827
830
)""";
828
831
829
832
// Create a kernel bundle in "source" state.
830
833
sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source> kb_src =
831
- syclex ::create_kernel_bundle_from_source(
834
+ syclexp ::create_kernel_bundle_from_source(
832
835
q.get_context(),
833
- syclex ::source_language::sycl,
836
+ syclexp ::source_language::sycl,
834
837
source);
835
838
836
839
// Compile the kernel. There is no need to use the "registered_kernel_names"
837
840
// property because the kernel is declared extern "C".
838
841
sycl::kernel_bundle<sycl::bundle_state::executable> kb_exe =
839
- syclex ::build(kb_src);
842
+ syclexp ::build(kb_src);
840
843
841
844
// Get the kernel via its compiler-generated name.
842
845
sycl::kernel iota = kb_exe.ext_oneapi_get_kernel("iota");
@@ -846,9 +849,9 @@ int main() {
846
849
// Set the values of the kernel arguments.
847
850
cgh.set_args(3.14f, ptr);
848
851
849
- // Launch the kernel according to its type, in this case a simple
850
- // "range" kernel.
851
- cgh.parallel_for({NUM} , iota);
852
+ // Launch the kernel according to its type, in this case an nd-range kernel.
853
+ sycl::nd_range ndr{{NUM}, {WGSIZE}};
854
+ cgh.parallel_for(ndr , iota);
852
855
}).wait();
853
856
}
854
857
----
@@ -861,43 +864,46 @@ disambiguate a kernel function that has several overloads.
861
864
[source,c++]
862
865
----
863
866
#include <sycl/sycl.hpp>
864
- namespace syclex = sycl::ext::oneapi::experimental;
867
+ namespace syclexp = sycl::ext::oneapi::experimental;
868
+
865
869
static constexpr size_t NUM = 1024;
870
+ static constexpr size_t WGSIZE = 16;
866
871
867
872
int main() {
868
873
sycl::queue q;
869
874
870
875
// The source code for two kernels defined as overloaded functions.
871
876
std::string source = R"""(
872
877
#include <sycl/sycl.hpp>
873
- namespace syclex = sycl::ext::oneapi::experimental;
878
+ namespace syclext = sycl::ext::oneapi;
879
+ namespace syclexp = sycl::ext::oneapi::experimental;
874
880
875
- SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclex::range_kernel <1>))
881
+ SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel <1>))
876
882
void iota(float start, float *ptr) {
877
- size_t id = syclex::this_kernel::get_id ();
883
+ size_t id = syclext::this_work_item::get_nd_item().get_global_linear_id ();
878
884
ptr[id] = start + static_cast<float>(id);
879
885
}
880
886
881
- SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclex ::range_kernel<1>))
887
+ SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp ::range_kernel<1>))
882
888
void iota(int start, int *ptr) {
883
- size_t id = syclex::this_kernel::get_id ();
889
+ size_t id = syclext::this_work_item::get_nd_item().get_global_linear_id ();
884
890
ptr[id] = start + static_cast<int>(id);
885
891
}
886
892
)""";
887
893
888
894
// Create a kernel bundle in "source" state.
889
895
sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source> kb_src =
890
- syclex ::create_kernel_bundle_from_source(
896
+ syclexp ::create_kernel_bundle_from_source(
891
897
q.get_context(),
892
- syclex ::source_language::sycl,
898
+ syclexp ::source_language::sycl,
893
899
source);
894
900
895
901
// Compile the kernel. Because there are two overloads of "iota", we need to
896
902
// use a C++ cast to disambiguate between them. Here, we are selecting the
897
903
// "int" overload.
898
904
std::string iota_name{"(void(*)(int, int*))iota"};
899
- sycl::kernel_bundle<sycl::bundle_state::executable> kb_exe = syclex ::build(kb_src,
900
- syclex ::properties{syclex ::registered_kernel_names{iota_name}});
905
+ sycl::kernel_bundle<sycl::bundle_state::executable> kb_exe = syclexp ::build(kb_src,
906
+ syclexp ::properties{syclexp ::registered_kernel_names{iota_name}});
901
907
902
908
// Get the kernel by passing the same string we used to construct the
903
909
// "registered_kernel_names" property.
@@ -908,9 +914,9 @@ int main() {
908
914
// Set the values of the kernel arguments.
909
915
cgh.set_args(3, ptr);
910
916
911
- // Launch the kernel according to its type, in this case a simple
912
- // "range" kernel.
913
- cgh.parallel_for({NUM} , iota);
917
+ // Launch the kernel according to its type, in this case an nd-range kernel.
918
+ sycl::nd_range ndr{{NUM}, {WGSIZE}};
919
+ cgh.parallel_for(ndr , iota);
914
920
}).wait();
915
921
}
916
922
----
0 commit comments