Skip to content

Commit 7cf81c6

Browse files
[SYCL] Free function host compilation bugfix (#19541)
The `KernelInfoData` struct is specialized in the integration header for free function kernels and results in compilation errors when using other host compilers to compile code for example while using `-fsycl-host-compiler=g++` . This PR removes its generation for free function kernels in the integration header altogether since it is not used anywhere. For more info about the bug tackled by this PR: `KernelInfoData` struct is specialized in the integration header for unnamed kernels such as free function kernels with the primary definition located in `kernel_desc.hpp`. The primary definition however seems to be conditional upon the fact that the unnamed lambda extension must be enabled which is not the case with other host compilers and we end up with an error of specialization without a primary template. Furthermore setting `-fsycl-unnamed-lambda` doesn't do the trick as apparently it is not allowed to be used together with `-fsycl-host-compiler`. Since it seems unreasonable to disallow using other host compilers with free function kernels, this seemed one of the easier solutions at the moment. Another approach would be to potentially remove the ifdefs in kernel_desc.hpp that conditionally include/exclude `KernelInfo `and `KernelInfoData` and have them both available unconditionally. Tagging @bader for some input about this alternative approach. --------- Co-authored-by: Tom Honermann <[email protected]>
1 parent a0d67c5 commit 7cf81c6

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6980,6 +6980,10 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
69806980

69816981
for (const KernelDesc &K : KernelDescs) {
69826982
const size_t N = K.Params.size();
6983+
if (S.isFreeFunction(K.SyclKernel)) {
6984+
CurStart += N;
6985+
continue;
6986+
}
69836987
PresumedLoc PLoc = S.getASTContext().getSourceManager().getPresumedLoc(
69846988
S.getASTContext()
69856989
.getSourceManager()

clang/test/CodeGenSYCL/free_function_int_header_rtc_mode.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ int main(){
4444
// CHECK-NEXT: "{{.*}}__sycl_kernel_free_function_nd_rangePiii",
4545
// CHECK-NEXT: "{{.*}}Kernel_Function",
4646

47-
48-
// CHECK: static constexpr const char* getName() { return "{{.*}}__sycl_kernel_free_function_singlePiii"; }
49-
// CHECK: static constexpr const char* getName() { return "{{.*}}__sycl_kernel_free_function_nd_rangePiii"; }
50-
// CHECK: static constexpr const char* getName() { return "{{.*}}Kernel_Function"; }
47+
// CHECK: _Z34__sycl_kernel_free_function_singlePiii
48+
// CHECK: _Z36__sycl_kernel_free_function_nd_rangePiii
49+
// CHECK: _ZTSZ4mainE15Kernel_Function
5150

5251
// CHECK-RTC-NOT: free_function_single_kernel
5352
// CHECK-RTC-NOT: free_function_nd_range
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %clangxx -fsycl %s
2+
// RUN: %clangxx -fsycl -fno-sycl-unnamed-lambda %s
3+
// RUN: %clangxx -fsycl -fsycl-host-compiler=g++ %s
4+
// REQUIRES: linux
5+
6+
// This test serves as a sanity check that compilation succeeds
7+
// for a simple free function kernel when using the host compiler
8+
// flag with unnamed lambda extension enabled(default) and disabled.
9+
10+
#include <sycl/detail/core.hpp>
11+
#include <sycl/ext/oneapi/experimental/free_function_traits.hpp>
12+
#include <sycl/kernel_bundle.hpp>
13+
14+
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY(
15+
(sycl::ext::oneapi::experimental::nd_range_kernel<1>))
16+
void kernel() {}
17+
18+
int main() {
19+
sycl::queue q;
20+
21+
sycl::kernel_bundle bundle =
22+
sycl::get_kernel_bundle<sycl::bundle_state::executable>(q.get_context());
23+
sycl::kernel_id kID =
24+
sycl::ext::oneapi::experimental::get_kernel_id<kernel>();
25+
sycl::kernel krn = bundle.get_kernel(kID);
26+
27+
q.submit([&](sycl::handler &cgh) {
28+
sycl::nd_range<1> ndr;
29+
cgh.parallel_for(ndr, krn);
30+
});
31+
return 0;
32+
}

0 commit comments

Comments
 (0)