Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7052,11 +7052,15 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
O << " \"\",\n";
O << "};\n\n";

O << "static constexpr unsigned kernel_args_sizes[] = {";
O << "static constexpr int kernel_args_sizes[] = {";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that array used at all? I can't grep it in sycl folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure actually. @aelovikov-intel would you know if this is just a relic of the past or whether we actually need this generated?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI says

  # | C:\Users\GH_RUN~1\AppData\Local\Temp\lit-tmp-qc0j5t24\L0_interop_test-header-a28efe.h:82:75: error: cannot initialize a parameter of type 'const unsigned int *' with an lvalue of type 'const int[2]'
  # |    82 |     sycl::detail::free_function_info_map::add(sycl::detail::kernel_names, sycl::detail::kernel_args_sizes, 1);
  # |       |                                                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

so, this seems to be used within the integration header?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea it looks like this is used for the implementation of free functions/device globals.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elizabethandrews @aelovikov-intel yes, it is used in free functions:
https://github.com/intel/llvm/blob/sycl/clang/lib/Sema/SemaSYCL.cpp#L7055
https://github.com/intel/llvm/blob/sycl/clang/lib/Sema/SemaSYCL.cpp#L7317
https://github.com/intel/llvm/blob/sycl/clang/lib/Sema/SemaSYCL.cpp#L7323

namespace detail::free_function_info_map {

If it is needed to change the type of kernel_args_sizes, then it is needed to change the whole chain..

Also, it is supposed that both arrays kernel arg sizes and kernel names have the same size. If -1 is added into kernel arg sizes, please, check which size is used during add and remove calls

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the type would be an ABI break. So I have change the PR to use a sentinel value of 0 so we can keep it unsigned. I don't see any harm with that but please let me know if you disagree.

Copy link
Contributor

@Fznamznon Fznamznon Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slightly concerned that we can actually put 0 for some arguments there. A capturless lambda is an example.
I think alternatively we could put there something like std::numeric_limits<uint32_t>::max(); Hopefully there is no argument of that size :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I had talked to @premanandrao about this. You're right in that there is an overlap about what 0 means here. Kernels without captures and no kernels will both have 0 here now. We thought it shouldn't matter since hopefully the runtime will have some other way of detecting no kernels. Maybe @dklochkov-emb can weigh in here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, using std::numeric_limits<uint32_t>::max(); is better, it looks reasonable and large enough to avoid collisions

for (unsigned I = 0; I < KernelDescs.size(); I++) {
O << KernelDescs[I].Params.size() << ", ";
}
// Add a sentinel to avoid warning if the collection is empty
// (similar to what we do for kernel_signatures below).
O << "-1, \n";
O << "};\n\n";

O << "// array representing signatures of all kernels defined in the\n";
O << "// corresponding source\n";
O << "static constexpr\n";
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGenSYCL/int-header-empty-signatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// CHECK-NEXT: ""
// CHECK-NEXT: };

// CHECK: static constexpr unsigned kernel_args_sizes[] = {
// CHECK: static constexpr int kernel_args_sizes[] = {0, -1

// CHECK: static constexpr
// CHECK-NEXT: const kernel_param_desc_t kernel_signatures[] = {
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGenSYCL/integration_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// CHECK-NEXT: ""
// CHECK-NEXT: };
//
// CHECK: static constexpr unsigned kernel_args_sizes[] = {
// CHECK: static constexpr int kernel_args_sizes[] = {5, 3, 2, 8, 3, 0, -1,
//
// CHECK: static constexpr
// CHECK-NEXT: const kernel_param_desc_t kernel_signatures[] = {
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGenSYCL/kernel-param-acc-array-ih.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// CHECK-NEXT: ""
// CHECK-NEXT: };

// CHECK: static constexpr unsigned kernel_args_sizes[] = {
// CHECK: static constexpr int kernel_args_sizes[] = {2, -1,

// CHECK: static constexpr
// CHECK-NEXT: const kernel_param_desc_t kernel_signatures[] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// CHECK-NEXT: ""
// CHECK-NEXT: };

// CHECK: static constexpr unsigned kernel_args_sizes[] = {
// CHECK: static constexpr int kernel_args_sizes[] = {2, -1,

// CHECK: static constexpr
// CHECK-NEXT: const kernel_param_desc_t kernel_signatures[] = {
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGenSYCL/kernel-param-pod-array-ih.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// CHECK-NEXT: ""
// CHECK-NEXT: };

// CHECK: static constexpr unsigned kernel_args_sizes[] = {
// CHECK: static constexpr int kernel_args_sizes[] = {1, 1, 1, -1,

// CHECK: static constexpr
// CHECK-NEXT: const kernel_param_desc_t kernel_signatures[] = {
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGenSYCL/union-kernel-param-ih.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// CHECK-NEXT: ""
// CHECK-NEXT: };

// CHECK: static constexpr unsigned kernel_args_sizes[] = {
// CHECK: static constexpr int kernel_args_sizes[] = {1, -1,

// CHECK: static constexpr
// CHECK-NEXT: const kernel_param_desc_t kernel_signatures[] = {
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGenSYCL/wrapped-accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// CHECK-NEXT: ""
// CHECK-NEXT: };

// CHECK: static constexpr unsigned kernel_args_sizes[] = {
// CHECK: static constexpr int kernel_args_sizes[] = {1, -1,

// CHECK: static constexpr
// CHECK-NEXT: const kernel_param_desc_t kernel_signatures[] = {
Expand Down
Loading