Skip to content

[SYCL][Doc] Add spec for "sycl" to kernel compiler #11985

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 26 commits into from
Feb 28, 2025

Conversation

gmlueck
Copy link
Contributor

@gmlueck gmlueck commented Nov 22, 2023

Update the proposed specification for the kernel compiler to allow
kernels to be written in the SYCL language, using the new proposed
"free function kernel" format.

This PR also adds some more features to the kernel compiler for
parity with cuda's nvrtc.

Update the proposed specification for the kernel compiler to allow
kernels to be written in the SYCL language, using the new proposed
"free function kernel" format.
@gmlueck gmlueck requested a review from a team as a code owner November 22, 2023 18:45
Require the source string to `#include <sycl/sycl.hpp>` in order to
get the content of that header.  Clarify that this header and other
standard headers are available even without the `include_files`
property.
These details are provided by other extensions.
This extension provides support for kernels written in SYCL according to the
"free function kernel" syntax defined in
link:../proposed/sycl_ext_oneapi_free_function_kernels.asciidoc[
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this available somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's not implemented yet. I expect that we will implement that extension at the same time as the new additions to "sycl_ext_oneapi_kernel_compiler" that are described in this PR.

@DongBaiYue
Copy link

Runtime compilation is an urgently needed feature of SYCL in project development. Thanks for your specification. Also out of curiosity, may the kernel compiler support using inline PTX assembly in SYCL kernel? opencl example. Inline Assembly makes rich low-level hardware features available to programmers.

@gmlueck
Copy link
Contributor Author

gmlueck commented Dec 20, 2023

Runtime compilation is an urgently needed feature of SYCL in project development. Thanks for your specification. Also out of curiosity, may the kernel compiler support using inline PTX assembly in SYCL kernel? opencl example. Inline Assembly makes rich low-level hardware features available to programmers.

Hi @DongBaiYue, I think this is not strongly related to this extension. Runtime compilation should work for kernels that use any of the SYCL features that available in normal kernels. I'm not sure if normal SYCL kernels can contain PTX assembly, but @AerialMantis might know.

In d49df13 we decided that the source
code string must contain `#include <sycl/sycl.hpp>`, but that commit
forgot to add this include to all the examples.
We decided to switch the syntax for identifying a free function kernel.
We now use a compile time property instead of a special macro.
@gmlueck
Copy link
Contributor Author

gmlueck commented Jan 10, 2024

Attention reviewers: I do not plan any more changes to this PR. If you have more comments, please make them soon.

@gmlueck gmlueck marked this pull request as draft January 10, 2024 23:12
@gmlueck
Copy link
Contributor Author

gmlueck commented Jan 10, 2024

Marking this PR as "draft" only to prevent it from being merged until after these new APIs have been implemented.

This is a new process I'm trying out for cases where we make proposed changes to an extension specification that is already implemented. When these new changes are implemented, we can merge this PR. That way, the extension specification in the repo will always reflect what is currently implemented.

include_files(const std::string &name, const std::string &content); (1)
include_files(const std::vector<std::string> &names, (2)
const std::vector<std::string> &contents);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I have some reservations about this include_files struct.

We know for the first implementation that we are likely going to have to write out a temporary .cpp file and invoke clang++ -fsycl on it. So now we have to also write out the include files? What about #include "path/to/file.h" ? Will we then be parsing this and instantiating directories?

I presume we need to disambiguate #include "local/path.h" from #include <system/path.h> ?

Users can't link in libraries ( even if has a header ), and there is only the one TU. Supporting #include suggests the opposite. Maybe a note proscribing it is needed?

I do see the value in that if a user has a simple function that they want to both use in the host application and call from their kernel, this allows them to do so. And, if clang were to ever have an invocation API (like ocloc) then I guess this aligns with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of the reasons we added the include_files property is for parity with CUDA, which has a similar feature in NVRTC. By adding the feature to SYCL, we make it easier to migrate code automatically using the SYCLomatic tool.

I was thinking that our implementation could create a temporary "include" directory and then write out the include_files header files into that directory. When we invoke clang, we can add a -I switch pointing at the temporary include directory.

Note that you don't need to parse any #include strings from the source code to get the file name paths. The include_files properties contains a list of (Name, Content) pairs. Each Name is the relative pathname of an include file, so you can just use this Name string verbatim.

Copy link
Contributor Author

@gmlueck gmlueck left a comment

Choose a reason for hiding this comment

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

Thanks for the careful review! See responses below.

Copy link
Contributor

@victor-eds victor-eds left a comment

Choose a reason for hiding this comment

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

Current text looks good to me 👍

We decided to remove support for `range_kernel` from the free function
kernel spec, so change all the examples to use `nd_range_kernel`
instead.

The proposed `this_kernel` namespace was changed to `this_work_item`
and it is no longer in the experimental namespace.
againull pushed a commit that referenced this pull request Jul 2, 2024
SYCL language support on the part of the kernel_compiler is specified
here: #11985

However, that specification is not presently realizable. We need more
support from the FE and post link tool to get the demangled names
propagated through. But it is usable before that, with constraints about
using extern "C" or knowing the mangled kernel name. We have folk that
want to test in the interim. I've refrained from updating the spec, and
instead this interim support in our experimental extension will be snuck
in until it can be completed in full - then we'll update the spec to
release it properly.
Clarify that the _Name_ from an `include_files` entry could contain
directory components.
Copy link
Contributor

github-actions bot commented Jan 6, 2025

This pull request is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be automatically closed in 30 days.

@github-actions github-actions bot added the Stale label Jan 6, 2025
@gmlueck gmlueck removed the Stale label Jan 6, 2025
steffenlarsen added a commit that referenced this pull request Feb 24, 2025
For the sycl kernel compiler extension, see
#11985,
#16485

---------

Co-authored-by: Steffen Larsen <steffen.larsen@intel.com>
uditagarwal97 pushed a commit that referenced this pull request Feb 27, 2025
This PR adds full support for the `registered_kernel_names` property to
query kernels by their souce code name (and instantiate template
kernels), leveraging the new
`[[__sycl_detail__::__registered_kernels__(...)]]` attribute added in
#16485 and #16821.

Also, `kernel_bundle::ext_oneapi_get_raw_kernel_name` is implemented
following the draft spec #11985.

---------

Signed-off-by: Julian Oppermann <julian.oppermann@codeplay.com>
@sommerlukas sommerlukas marked this pull request as ready for review February 28, 2025 13:20
@sommerlukas
Copy link
Contributor

Merging this extension, as the core functionality is implemented now that #17032 has been merged.

Smaller tweaks to API naming and implementation-specific notes will be added through follow-up PRs.

@sommerlukas sommerlukas merged commit c2c029e into intel:sycl Feb 28, 2025
2 checks passed
sommerlukas pushed a commit that referenced this pull request Mar 4, 2025
This PR is based on #17032. It adds
runtime tests that match the examples from the spec changes in
#11985, showing that the test run
successfully using the JIT approach for RTC.
This PR also contains a few minor fixes in the example code in the RTC
docs.
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.

9 participants