Skip to content

[SYCL][KHR] Implement sycl_khr_kernel_properties - #23891

Draft
lbushi25 wants to merge 1 commit into
intel:syclfrom
lbushi25:khr-kernel-properties
Draft

lbushi25 wants to merge 1 commit into
intel:syclfrom
lbushi25:khr-kernel-properties

Conversation

@lbushi25

@lbushi25 lbushi25 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Implement the sycl_khr_kernel_properties extension

Add the khr::property::tag::kernel tag and the work_group_size,
work_group_size_hint and sub_group_size properties. A named function
object kernel can embed them with a get(khr::property::tag::kernel)
member. Each property lowers to the same IR attribute as its
sycl_ext_oneapi_kernel_properties equivalent.

Diagnose conflicts:
- in the headers, between the khr getter and get(properties_tag)
  when the same property has a different value;
- in Sema, between the khr getter and the matching kernel attribute
  on operator() when the values differ.

Define SYCL_KHR_KERNEL_PROPERTIES.

KHR Link: KhronosGroup/SYCL-Docs#1078

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@koparasy koparasy left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for putting the draft up early. I like the overall direction. Great!

My main concern is the following example:

namespace syclexp = sycl::ext::oneapi::experimental;

struct Scale {
  float *data;
  [[sycl::reqd_work_group_size(32)]]                     // attribute says 32
  void operator()(sycl::nd_item<1> it) const { /* ... */ }
  auto get(syclexp::properties_tag) const {
    return syclexp::properties{syclexp::work_group_size<64>}; // property says 64
  }
};

q.parallel_for(sycl::nd_range<1>{1024, 64}, Scale{data});

Currently, if I understand correctly, you will throw a warning and move on. I would prefer here to throw an error. Using the same mental model, I would also throw an error in the case of using a different oneapi property:

namespace syclexp = sycl::ext::oneapi::experimental;
namespace kp = sycl::khr::property;

struct Scale {
  float *data;
  void operator()(sycl::nd_item<1> it) const { /* ... */ }

  auto get(syclexp::properties_tag) const {      // oneAPI: 64
    return syclexp::properties{syclexp::work_group_size<64>};
  }
  auto get(kp::tag::kernel) const {               // KHR: 32
    return kp::work_group_size<32>;
  }
};

q.parallel_for(sycl::nd_range<1>{1024, 64}, Scale{data});

If you take the case of erroring out, your sema changes become simpler, right? Most of the front-end code exists for one reason: to tell KHR properties apart from oneAPI properties, so a KHR mismatch is an error while a oneAPI mismatch keeps the old warning. If we error out, we just need in sema to compare the values of the same attribute name sycl-work-group-size in this case. I think the above will simplify the implementation.

We also have the have the __SYCL_TYPE(x) macro that goes to [[sycl_detail::sycl_type(x)]]. I am not sure if this is useful here, and whether it would simplify or complicate the code, but I think it is worh exploring.

Lastly, I think we have some test gaps, and I am not convinced your reduction handling is proper. We can iterate that at a later review about reductions.

@gmlueck are we on the same page for emitting an error when we use different APIs to assign attributes to kernels with different values, but same semantic meaning. For example sycl::khr::property::work_group_size<N> vs syclexp::properties{syclexp::work_group_size<M> vs [[sycl::reqd_work_group_size(K)]] where the len(set(N, M, K)) > 1 .

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants