Skip to content

Commit 56ed8f3

Browse files
[SYCL] Enable use of variadic templates in SYCL kernel names.
Added support for template parameters pack processing to the clang::TypeName::getFullyQualifiedTemplateArgument method. Signed-off-by: Alexey Voronov <alexey.voronov@intel.com>
1 parent 1a3a536 commit 56ed8f3

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

Diff for: clang/lib/AST/QualTypeNames.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ static bool getFullyQualifiedTemplateArgument(const ASTContext &Ctx,
109109
Arg = TemplateArgument(QTFQ);
110110
Changed = true;
111111
}
112+
} else if (Arg.getKind() == TemplateArgument::Pack) {
113+
for (const auto &It : Arg.pack_elements()) {
114+
Changed |= getFullyQualifiedTemplateArgument(
115+
Ctx, const_cast<TemplateArgument &>(It), WithGlobalNsPrefix);
116+
}
112117
}
113118
return Changed;
114119
}

Diff for: clang/test/CodeGenSYCL/int_header1.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// CHECK:template <> struct KernelInfo<::nm1::KernelName4< ::nm1::KernelName1>> {
1212
// CHECK:template <> struct KernelInfo<::nm1::KernelName3<KernelName5>> {
1313
// CHECK:template <> struct KernelInfo<::nm1::KernelName4<KernelName7>> {
14+
// CHECK:template <> struct KernelInfo<::nm1::KernelName8< ::nm1::nm2::C>> {
1415
// CHECK:template <> struct KernelInfo<class TmplClassInAnonNS<class ClassInAnonNS>> {
1516

1617
// This test checks if the SYCL device compiler is able to generate correct
@@ -34,6 +35,7 @@ namespace nm1 {
3435

3536
template <typename T> class KernelName3;
3637
template <typename T> class KernelName4;
38+
template <typename... T> class KernelName8;
3739

3840
template <> class KernelName3<nm1::nm2::KernelName0>;
3941
template <> class KernelName3<KernelName1>;
@@ -142,6 +144,12 @@ struct MyWrapper {
142144
kernel_single_task<nm1::KernelName4<class KernelName7>>(
143145
[=]() { acc.use(); });
144146

147+
// TPITD
148+
// a defined template pack specialization class with defined class
149+
// as argument declared in a namespace at translation unit scope
150+
kernel_single_task<nm1::KernelName8<nm1::nm2::C>>(
151+
[=]() { acc.use(); });
152+
145153
#ifdef TDLI
146154
// TODO unexpected compilation error when host code + integration header
147155
// is compiled TDLI a defined template specialization class with
@@ -202,6 +210,7 @@ int main() {
202210
KernelInfo<class nm1::KernelName4<class nm1::KernelName1>>::getName();
203211
KernelInfo<class nm1::KernelName3<class KernelName5>>::getName();
204212
KernelInfo<class nm1::KernelName4<class KernelName7>>::getName();
213+
KernelInfo<class nm1::KernelName8<nm1::nm2::C>>::getName();
205214
KernelInfo<class TmplClassInAnonNS<class ClassInAnonNS>>::getName();
206215
#endif //__SYCL_DEVICE_ONLY__
207216
}

Diff for: clang/test/CodeGenSYCL/integration_header.cpp

+24-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010
// CHECK-NEXT: struct X;
1111
// CHECK-NEXT: template <typename T> struct point;
1212
// CHECK-NEXT: template <int a, typename T1, typename T2> class third_kernel;
13+
// CHECK-NEXT: namespace template_arg_ns {
14+
// CHECK-NEXT: template <int DimX> struct namespaced_arg;
15+
// CHECK-NEXT: }
16+
// CHECK-NEXT: template <typename ...Ts> class fourth_kernel;
1317
//
1418
// CHECK: static constexpr
1519
// CHECK-NEXT: const char* const kernel_names[] = {
1620
// CHECK-NEXT: "_ZTSZ4mainE12first_kernel",
1721
// CHECK-NEXT: "_ZTSN16second_namespace13second_kernelIcEE",
1822
// CHECK-NEXT: "_ZTS12third_kernelILi1Ei5pointIZ4mainE1XEE"
23+
// CHECK-NEXT: "_ZTS13fourth_kernelIJN15template_arg_ns14namespaced_argILi1EEEEE"
1924
// CHECK-NEXT: };
2025
//
2126
// CHECK: static constexpr
@@ -36,12 +41,17 @@
3641
// CHECK-NEXT: { kernel_param_kind_t::kind_accessor, 6112, 4 },
3742
// CHECK-NEXT: { kernel_param_kind_t::kind_sampler, 8, 8 },
3843
// CHECK-EMPTY:
44+
// CHECK-NEXT: //--- _ZTS13fourth_kernelIJN15template_arg_ns14namespaced_argILi1EEEEE
45+
// CHECK-NEXT: { kernel_param_kind_t::kind_std_layout, 4, 0 },
46+
// CHECK-NEXT: { kernel_param_kind_t::kind_accessor, 6112, 4 },
47+
// CHECK-EMPTY:
3948
// CHECK-NEXT: };
4049
//
4150
// CHECK: template <class KernelNameType> struct KernelInfo;
4251
// CHECK: template <> struct KernelInfo<class first_kernel> {
4352
// CHECK: template <> struct KernelInfo<::second_namespace::second_kernel<char>> {
4453
// CHECK: template <> struct KernelInfo<::third_kernel<1, int, ::point<X> >> {
54+
// CHECK: template <> struct KernelInfo<::fourth_kernel< ::template_arg_ns::namespaced_arg<1> >> {
4555

4656
#include "sycl.hpp"
4757

@@ -60,6 +70,14 @@ class second_kernel;
6070
template <int a, typename T1, typename T2>
6171
class third_kernel;
6272

73+
namespace template_arg_ns {
74+
template <int DimX>
75+
struct namespaced_arg {};
76+
} // namespace template_arg_ns
77+
78+
template <typename... Ts>
79+
class fourth_kernel;
80+
6381
int main() {
6482

6583
cl::sycl::accessor<char, 1, cl::sycl::access::mode::read> acc1;
@@ -98,6 +116,11 @@ int main() {
98116
}
99117
});
100118

119+
kernel_single_task<class fourth_kernel<template_arg_ns::namespaced_arg<1>>>([=]() {
120+
if (i == 13) {
121+
acc2.use();
122+
}
123+
});
124+
101125
return 0;
102126
}
103-

Diff for: sycl/test/regression/kernel_name_class.cpp

+27-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace nm1 {
2121
namespace nm2 {
2222
class C {};
2323
class KernelName0 : public C {};
24+
25+
template <int X> class KernelName11 {};
2426
} // namespace nm2
2527

2628
class KernelName1;
@@ -34,8 +36,12 @@ template <> class KernelName3<KernelName1>;
3436
template <> class KernelName4<nm1::nm2::KernelName0> {};
3537
template <> class KernelName4<KernelName1> {};
3638

39+
template <typename... Ts> class KernelName10;
40+
3741
} // namespace nm1
3842

43+
template <typename... Ts> class KernelName12;
44+
3945
static int NumTestCases = 0;
4046

4147
namespace nm3 {
@@ -233,6 +239,27 @@ struct Wrapper {
233239
});
234240
++NumTestCases;
235241
#endif
242+
// TPITD
243+
// an incomplete vatiadic template specialization class in a namespace at
244+
// translation unit scope with a defined class as argument declared in
245+
// a namespace at translation unit scope
246+
deviceQueue.submit([&](cl::sycl::handler &cgh) {
247+
auto acc = buf.get_access<cl::sycl::access::mode::read_write>(cgh);
248+
cgh.single_task<nm1::KernelName10<nm1::nm2::KernelName11<10>>>(
249+
[=]() { acc[0] += GOLD; });
250+
});
251+
++NumTestCases;
252+
253+
// TPITD
254+
// an incomplete vatiadic template specialization class in the global
255+
// namespace at translation unit scope with a defined class as argument
256+
// declared in a namespace at translation unit scope
257+
deviceQueue.submit([&](cl::sycl::handler &cgh) {
258+
auto acc = buf.get_access<cl::sycl::access::mode::read_write>(cgh);
259+
cgh.single_task<KernelName12<nm1::nm2::KernelName11<10>>>(
260+
[=]() { acc[0] += GOLD; });
261+
});
262+
++NumTestCases;
236263
}
237264
return arr[0];
238265
}
@@ -246,4 +273,3 @@ int main() {
246273
std::cout << (pass ? "pass" : "FAIL") << "\n";
247274
return pass ? 0 : 1;
248275
}
249-

0 commit comments

Comments
 (0)