Skip to content

Commit 26184e2

Browse files
author
Erich Keane
authored
[SYCL] Fix warning in integration header about empty array. (#4490)
The kernel_signatures array represents the list of fields for the kernels. When no kernel has a field, this causes a warning about the array being empty. This patch adds a 'dummy' value at the end of the array that serves 2 purposes: 1- to suppress this warning. 2- to be obvious when the runtime ends up 1 past the end of the valid array.
1 parent c583a20 commit 26184e2

12 files changed

+49
-0
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4823,6 +4823,15 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
48234823
}
48244824
O << "\n";
48254825
}
4826+
4827+
// Sentinel in place for 2 reasons:
4828+
// 1- to make sure we don't get a warning because this collection is empty.
4829+
// 2- to provide an obvious value that we can use when debugging to see that
4830+
// we have left valid kernel information.
4831+
// integer-field values are negative, so they are obviously invalid, notable
4832+
// enough to 'stick out' and 'negative enough' to not be easily reachable by a
4833+
// mathematical error.
4834+
O << " { kernel_param_kind_t::kind_invalid, -987654321, -987654321 }, \n";
48264835
O << "};\n\n";
48274836

48284837
O << "// Specializations of KernelInfo for kernel function types:\n";
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -fsycl-int-header=%t.h %s -fsyntax-only
2+
// RUN: FileCheck -input-file=%t.h %s
3+
// This test validates that we don't generate an empty 'kernel_signatures' in
4+
// the case where there are no kernel fields. This is to avoid a warning in the
5+
// integration header.
6+
7+
// CHECK: static constexpr
8+
// CHECK-NEXT: const char* const kernel_names[] = {
9+
// CHECK-NEXT: "_ZTSZ4mainE1K"
10+
// CHECK-NEXT: };
11+
12+
// CHECK: static constexpr
13+
// CHECK-NEXT: const kernel_param_desc_t kernel_signatures[] = {
14+
// CHECK-NEXT: //--- _ZTSZ4mainE1K
15+
// CHECK-EMPTY:
16+
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
17+
// CHECK-NEXT: };
18+
19+
#include "Inputs/sycl.hpp"
20+
21+
using namespace cl::sycl;
22+
23+
int main() {
24+
// captureless kernel lambda results in no fields.
25+
kernel_single_task<class K>([]{});
26+
}

clang/test/CodeGenSYCL/integration_header.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
// CHECK-NEXT: { kernel_param_kind_t::kind_accessor, 4062, 40 },
4949
// CHECK-NEXT: { kernel_param_kind_t::kind_accessor, 4062, 52 },
5050
// CHECK-EMPTY:
51+
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
5152
// CHECK-NEXT: };
5253
//
5354
// CHECK: template <> struct KernelInfo<first_kernel> {

clang/test/CodeGenSYCL/kernel-param-acc-array-ih.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
// CHECK-NEXT: { kernel_param_kind_t::kind_accessor, 4062, 0 },
2424
// CHECK-NEXT: { kernel_param_kind_t::kind_accessor, 4062, 12 },
2525
// CHECK-EMPTY:
26+
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
2627
// CHECK-NEXT: };
2728

2829
// CHECK: template <> struct KernelInfo<kernel_A> {

clang/test/CodeGenSYCL/kernel-param-member-acc-array-ih.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
// CHECK-NEXT: { kernel_param_kind_t::kind_accessor, 4062, 0 },
2424
// CHECK-NEXT: { kernel_param_kind_t::kind_accessor, 4062, 12 },
2525
// CHECK-EMPTY:
26+
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
2627
// CHECK-NEXT: };
2728

2829
// CHECK: template <> struct KernelInfo<kernel_C> {

clang/test/CodeGenSYCL/kernel-param-pod-array-ih.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
// CHECK-NEXT: //--- _ZTSZ4mainE8kernel_D
3030
// CHECK-NEXT: { kernel_param_kind_t::kind_std_layout, 48, 0 },
3131
// CHECK-EMPTY:
32+
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
3233
// CHECK-NEXT: };
3334

3435
// CHECK: template <> struct KernelInfo<kernel_B> {

clang/test/CodeGenSYCL/struct_kernel_param.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// CHECK-NEXT: { kernel_param_kind_t::kind_std_layout, 8, 32 },
1515
// CHECK-NEXT: { kernel_param_kind_t::kind_std_layout, 12, 40 },
1616
// CHECK-EMPTY:
17+
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
1718
// CHECK-NEXT:};
1819

1920
// This test checks if compiler accepts structures as kernel parameters.

clang/test/CodeGenSYCL/union-kernel-param-ih.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// CHECK-NEXT: //--- _ZTSZ4mainE8kernel_A
2323
// CHECK-NEXT: { kernel_param_kind_t::kind_std_layout, 12, 0 },
2424
// CHECK-EMPTY:
25+
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
2526
// CHECK-NEXT:};
2627

2728
// CHECK: template <> struct KernelInfo<kernel_A> {

clang/test/CodeGenSYCL/wrapped-accessor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// CHECK-NEXT: //--- _ZTSZ4mainE14wrapped_access
2020
// CHECK-NEXT: { kernel_param_kind_t::kind_accessor, 4062, 0 },
2121
// CHECK-EMPTY:
22+
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
2223
// CHECK-NEXT: };
2324

2425
// CHECK: template <> struct KernelInfo<wrapped_access> {

sycl/include/CL/sycl/detail/kernel_desc.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ enum class kernel_param_kind_t {
2929
kind_pointer = 3,
3030
kind_specialization_constants_buffer = 4,
3131
kind_stream = 5,
32+
kind_invalid = 0xf, // not a valid kernel kind
3233
};
3334

3435
// describes a kernel parameter

sycl/source/detail/scheduler/commands.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,6 +1792,9 @@ pi_result ExecCGCommand::SetKernelParamsAndLaunch(
17921792
&SpecConstsBuffer);
17931793
break;
17941794
}
1795+
case kernel_param_kind_t::kind_invalid:
1796+
throw runtime_error("Invalid kernel param kind", PI_INVALID_VALUE);
1797+
break;
17951798
}
17961799
};
17971800

sycl/source/handler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ void handler::processArg(void *Ptr, const detail::kernel_param_kind_t &Kind,
404404
Index + IndexShift);
405405
break;
406406
}
407+
case kernel_param_kind_t::kind_invalid:
408+
throw runtime_error("Invalid kernel param kind", PI_INVALID_VALUE);
409+
break;
407410
}
408411
}
409412

0 commit comments

Comments
 (0)