Skip to content

[SYCL] Fix warning in integration header about empty array. #4490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4823,6 +4823,15 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
}
O << "\n";
}

// Sentinel in place for 2 reasons:
// 1- to make sure we don't get a warning because this collection is empty.
// 2- to provide an obvious value that we can use when debugging to see that
// we have left valid kernel information.
// integer-field values are negative, so they are obviously invalid, notable
// enough to 'stick out' and 'negative enough' to not be easily reachable by a
// mathematical error.
O << " { kernel_param_kind_t::kind_invalid, -987654321, -987654321 }, \n";
O << "};\n\n";

O << "// Specializations of KernelInfo for kernel function types:\n";
Expand Down
26 changes: 26 additions & 0 deletions clang/test/CodeGenSYCL/int-header-empty-signatures.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -fsycl-int-header=%t.h %s -fsyntax-only
// RUN: FileCheck -input-file=%t.h %s
// This test validates that we don't generate an empty 'kernel_signatures' in
// the case where there are no kernel fields. This is to avoid a warning in the
// integration header.

// CHECK: static constexpr
// CHECK-NEXT: const char* const kernel_names[] = {
// CHECK-NEXT: "_ZTSZ4mainE1K"
// CHECK-NEXT: };

// CHECK: static constexpr
// CHECK-NEXT: const kernel_param_desc_t kernel_signatures[] = {
// CHECK-NEXT: //--- _ZTSZ4mainE1K
// CHECK-EMPTY:
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
// CHECK-NEXT: };

#include "Inputs/sycl.hpp"

using namespace cl::sycl;

int main() {
// captureless kernel lambda results in no fields.
kernel_single_task<class K>([]{});
}
1 change: 1 addition & 0 deletions clang/test/CodeGenSYCL/integration_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
// CHECK-NEXT: { kernel_param_kind_t::kind_accessor, 4062, 40 },
// CHECK-NEXT: { kernel_param_kind_t::kind_accessor, 4062, 52 },
// CHECK-EMPTY:
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
// CHECK-NEXT: };
//
// CHECK: template <> struct KernelInfo<first_kernel> {
Expand Down
1 change: 1 addition & 0 deletions clang/test/CodeGenSYCL/kernel-param-acc-array-ih.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// CHECK-NEXT: { kernel_param_kind_t::kind_accessor, 4062, 0 },
// CHECK-NEXT: { kernel_param_kind_t::kind_accessor, 4062, 12 },
// CHECK-EMPTY:
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
// CHECK-NEXT: };

// CHECK: template <> struct KernelInfo<kernel_A> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// CHECK-NEXT: { kernel_param_kind_t::kind_accessor, 4062, 0 },
// CHECK-NEXT: { kernel_param_kind_t::kind_accessor, 4062, 12 },
// CHECK-EMPTY:
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
// CHECK-NEXT: };

// CHECK: template <> struct KernelInfo<kernel_C> {
Expand Down
1 change: 1 addition & 0 deletions clang/test/CodeGenSYCL/kernel-param-pod-array-ih.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// CHECK-NEXT: //--- _ZTSZ4mainE8kernel_D
// CHECK-NEXT: { kernel_param_kind_t::kind_std_layout, 48, 0 },
// CHECK-EMPTY:
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
// CHECK-NEXT: };

// CHECK: template <> struct KernelInfo<kernel_B> {
Expand Down
1 change: 1 addition & 0 deletions clang/test/CodeGenSYCL/struct_kernel_param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// CHECK-NEXT: { kernel_param_kind_t::kind_std_layout, 8, 32 },
// CHECK-NEXT: { kernel_param_kind_t::kind_std_layout, 12, 40 },
// CHECK-EMPTY:
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
// CHECK-NEXT:};

// This test checks if compiler accepts structures as kernel parameters.
Expand Down
1 change: 1 addition & 0 deletions clang/test/CodeGenSYCL/union-kernel-param-ih.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
// CHECK-NEXT: //--- _ZTSZ4mainE8kernel_A
// CHECK-NEXT: { kernel_param_kind_t::kind_std_layout, 12, 0 },
// CHECK-EMPTY:
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
// CHECK-NEXT:};

// CHECK: template <> struct KernelInfo<kernel_A> {
Expand Down
1 change: 1 addition & 0 deletions clang/test/CodeGenSYCL/wrapped-accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// CHECK-NEXT: //--- _ZTSZ4mainE14wrapped_access
// CHECK-NEXT: { kernel_param_kind_t::kind_accessor, 4062, 0 },
// CHECK-EMPTY:
// CHECK-NEXT: { kernel_param_kind_t::kind_invalid, -987654321, -987654321 },
// CHECK-NEXT: };

// CHECK: template <> struct KernelInfo<wrapped_access> {
Expand Down
1 change: 1 addition & 0 deletions sycl/include/CL/sycl/detail/kernel_desc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum class kernel_param_kind_t {
kind_pointer = 3,
kind_specialization_constants_buffer = 4,
kind_stream = 5,
kind_invalid = 0xf, // not a valid kernel kind
};

// describes a kernel parameter
Expand Down
3 changes: 3 additions & 0 deletions sycl/source/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,9 @@ pi_result ExecCGCommand::SetKernelParamsAndLaunch(
&SpecConstsBuffer);
break;
}
case kernel_param_kind_t::kind_invalid:
throw runtime_error("Invalid kernel param kind", PI_INVALID_VALUE);
break;
}
};

Expand Down
3 changes: 3 additions & 0 deletions sycl/source/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ void handler::processArg(void *Ptr, const detail::kernel_param_kind_t &Kind,
Index + IndexShift);
break;
}
case kernel_param_kind_t::kind_invalid:
throw runtime_error("Invalid kernel param kind", PI_INVALID_VALUE);
break;
}
}

Expand Down