Skip to content

[SYCL] Add libsycl, a SYCL RT library implementation project #144372

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

KseniyaTikhomirova
Copy link

This patch introduces libsycl, a SYCL runtime library implementation, as a top-level LLVM runtime project.
SYCL spec: https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html

Commit contains the basic folder layout and CMake infrastructure to build a dummy SYCL library.

This is part of the SYCL support upstreaming effort. The relevant RFCs can be found here:

https://discourse.llvm.org/t/rfc-add-full-support-for-the-sycl-programming-model/74080
https://discourse.llvm.org/t/rfc-sycl-runtime-upstreaming/74479

Upcoming PRs:

  • UR offloading library fetch & build
  • partial implementation of sycl::platform: requires offloading layer, requires classes for backend loading & enumeration.

This patch introduces libsycl, a SYCL runtime library implementation, as a top-level LLVM runtime project. It contains the basic folder layout and CMake infrastructure to build a dummy SYCL library.
@KseniyaTikhomirova KseniyaTikhomirova requested a review from a team as a code owner June 16, 2025 15:38
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the cmake Build system in general and CMake in particular label Jun 16, 2025
@KseniyaTikhomirova
Copy link
Author

Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

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

Disclaimer: I haven't seen the RFCs related to this before and haven't read through them in detail.

I don't know much about SYCL, but I do know quite a bit about libc++ and why we do things in certain ways there. In case you're interested I'd be happy to talk to you about that. Feel free to contact me on Discord, Discourse or E-Mail if you'd like to set up a meeting.

Comment on lines 11 to 13
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS OFF)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's generally a good idea to do this on a per-target level instead of globally, since there are a lot of sub-projects with lots of different requirements.

Copy link
Author

Choose a reason for hiding this comment

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

you are right, I will remove cache entry here, thank you.

Copy link
Author

Choose a reason for hiding this comment

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

Comment on lines 67 to 82

# Enable all warnings by default
if(MSVC)
append("/W4" CMAKE_CXX_FLAGS)
else()
append("-Wall -Wextra" CMAKE_CXX_FLAGS)
endif()

if(LIBSYCL_ENABLE_WERROR)
if(MSVC)
append("/WX" CMAKE_CXX_FLAGS)
else()
append("-Werror" CMAKE_CXX_FLAGS)
endif()
endif()

Copy link
Contributor

Choose a reason for hiding this comment

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

We have runimtes/Modules/WarningFlags.cmake. Maybe that should be used here?

Copy link
Author

Choose a reason for hiding this comment

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

thanks for highlighting this, I will update it

Copy link
Author

Choose a reason for hiding this comment

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

#===============================================================================

# Enable all warnings by default
if(MSVC)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the plan to support MSVC as a compiler? AFAIK no other runtime does that currently.

Copy link
Author

Choose a reason for hiding this comment

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

yes, we support MSVC.


#### How to build

TBD
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this will be filled in future PRs? Maybe Make this a TODO instead? That's usually easier to grep for.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, this is planned to be filled in future PRs, added some sections to show that the project will be properly documented.
I can replace "TBD" with "TODO", of course, although I don't see any difference in grepping by "TBD" or "TODO".
Please let me know your thoughts. Thanks.

///
//===----------------------------------------------------------------------===//

#ifndef __LIBSYCL_DETAIL_CONFIG_HPP
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason you use double underscores everywhere? That style tends to be use by compiler-defined stuff, so we avoid it in libc++.

Copy link
Author

@KseniyaTikhomirova KseniyaTikhomirova Jun 17, 2025

Choose a reason for hiding this comment

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

good catch, thanks. we have some macro like "__SYCL_DEVICE_ONLY" that have to have double underscore because it is defined by compiler. And it should be kept this way.
But the rest, the macro you are pointing to - don't need double underscores. I will update it, thank you!

Copy link
Author

Choose a reason for hiding this comment

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

#define __LIBSYCL_BEGIN_UNVERSIONED_NAMESPACE namespace sycl {
#define __LIBSYCL_END_UNVERSIONED_NAMESPACE }

#define __LIBSYCL_BEGIN_VERSIONED_NAMESPACE \
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe name this BEGIN_NAMESPACE_SYCL instead? Otherwise it's not really clear what namespace you're opening.

Copy link
Author

Choose a reason for hiding this comment

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

Makes sense, I will rename them to the following:
_LIBSYCL_BEGIN_UNVERSIONED_NAMESPACE_SYCL
_LIBSYCL_BEGIN_NAMESPACE_SYCL

Thank you.

Copy link
Author

Choose a reason for hiding this comment

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

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBSYCL_LIBRARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBSYCL_LIBRARY_DIR})

set(LIBSYCL_MAJOR_VERSION 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume libsycl should only become ABI stable once the major version is bumped to 1?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, there is a long way of upstreaming effort and major version will be updated with meaningful value later.


#else // _WIN32

#define __LIBSYCL_DLL_LOCAL __attribute__((visibility("hidden")))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#define __LIBSYCL_DLL_LOCAL __attribute__((visibility("hidden")))
#define __LIBSYCL_DLL_LOCAL __attribute__((__visibility__("hidden")))

Is there a reason to use __attribute__ instead of [[]]?

Copy link
Author

Choose a reason for hiding this comment

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

I don't think so. Both versions have gnu specific view (__attribute__((visibility("hidden"))) vs [[gnu::visibility("hidden")]]). It looks like both versions are used among llvm-project subprojects. By any chance do you know if there is any preference?

AFAIK visibility and __visibility__ are both valid.

Copy link
Contributor

Choose a reason for hiding this comment

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

src seems like a weird place for a file that'll be part of the installed headers.

Copy link
Author

Choose a reason for hiding this comment

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

Well, I think that we use this approach to store file that is just an input for generator because of the way we copy headers. Probably a good chance to discuss this approach too.
I noticed that other projects do copy per file instead of doing copy of whole include directory.
I think libcxx uses file list for headers to use copy_if_different tool that copies files only if they were changed. This approach allows to store input files in the same folder with full header files.
copy_directory_if_different is added in later version, in 3.26.
We use copy_directory that doesn't detect changes but works faster. At early stages I believe there is no noticeable difference.
Do you know if there is any other reason for other projects to copy headers per file?


#include <sycl/platform.hpp>

#include <stdexcept>
Copy link
Contributor

Choose a reason for hiding this comment

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

Which standard libraries do you plan to support?

Copy link
Author

Choose a reason for hiding this comment

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

libstdc++, MSVC STL and we will have experimental support for building and linking sycl runtime with libc++ library instead of libstdc++.

Copy link
Author

@KseniyaTikhomirova KseniyaTikhomirova left a comment

Choose a reason for hiding this comment

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

philnik777 thank you for the review, I really appreciate your comments and guidance.

I replied to all your comments and will provide code updates a bit later.

Comment on lines 11 to 13
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS OFF)
Copy link
Author

Choose a reason for hiding this comment

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

you are right, I will remove cache entry here, thank you.

@@ -0,0 +1 @@
BasedOnStyle: LLVM
Copy link
Author

Choose a reason for hiding this comment

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

I don't see it to be set in any other runtime (and any other project either). It doesn't seem right to differ in style from other runtimes.

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBSYCL_LIBRARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBSYCL_LIBRARY_DIR})

set(LIBSYCL_MAJOR_VERSION 0)
Copy link
Author

Choose a reason for hiding this comment

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

Yes, there is a long way of upstreaming effort and major version will be updated with meaningful value later.

#===============================================================================

# Enable all warnings by default
if(MSVC)
Copy link
Author

Choose a reason for hiding this comment

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

yes, we support MSVC.


#### How to build

TBD
Copy link
Author

Choose a reason for hiding this comment

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

Yes, this is planned to be filled in future PRs, added some sections to show that the project will be properly documented.
I can replace "TBD" with "TODO", of course, although I don't see any difference in grepping by "TBD" or "TODO".
Please let me know your thoughts. Thanks.

Comment on lines 67 to 82

# Enable all warnings by default
if(MSVC)
append("/W4" CMAKE_CXX_FLAGS)
else()
append("-Wall -Wextra" CMAKE_CXX_FLAGS)
endif()

if(LIBSYCL_ENABLE_WERROR)
if(MSVC)
append("/WX" CMAKE_CXX_FLAGS)
else()
append("-Werror" CMAKE_CXX_FLAGS)
endif()
endif()

Copy link
Author

Choose a reason for hiding this comment

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

thanks for highlighting this, I will update it

///
//===----------------------------------------------------------------------===//

#ifndef __LIBSYCL_DETAIL_CONFIG_HPP
Copy link
Author

@KseniyaTikhomirova KseniyaTikhomirova Jun 17, 2025

Choose a reason for hiding this comment

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

good catch, thanks. we have some macro like "__SYCL_DEVICE_ONLY" that have to have double underscore because it is defined by compiler. And it should be kept this way.
But the rest, the macro you are pointing to - don't need double underscores. I will update it, thank you!

#define __LIBSYCL_BEGIN_UNVERSIONED_NAMESPACE namespace sycl {
#define __LIBSYCL_END_UNVERSIONED_NAMESPACE }

#define __LIBSYCL_BEGIN_VERSIONED_NAMESPACE \
Copy link
Author

Choose a reason for hiding this comment

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

Makes sense, I will rename them to the following:
_LIBSYCL_BEGIN_UNVERSIONED_NAMESPACE_SYCL
_LIBSYCL_BEGIN_NAMESPACE_SYCL

Thank you.


#if __LIBSYCL_BUILD_SYCL_DLL
#define __LIBSYCL_EXPORT __declspec(dllexport)
#define __LIBSYCL_EXPORT_DEPRECATED(x) __declspec(dllexport, deprecated(x))
Copy link
Author

Choose a reason for hiding this comment

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

in our codebase we have 1 exported deprecated function but I will try to get rid of it (will avoid exporting it) since ABI is not fixed yet in upstreaming version of SYCL.

I will remove this macro completely for now. Thanks.

Copy link
Author

Choose a reason for hiding this comment

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

Well, I think that we use this approach to store file that is just an input for generator because of the way we copy headers. Probably a good chance to discuss this approach too.
I noticed that other projects do copy per file instead of doing copy of whole include directory.
I think libcxx uses file list for headers to use copy_if_different tool that copies files only if they were changed. This approach allows to store input files in the same folder with full header files.
copy_directory_if_different is added in later version, in 3.26.
We use copy_directory that doesn't detect changes but works faster. At early stages I believe there is no noticeable difference.
Do you know if there is any other reason for other projects to copy headers per file?

@Fznamznon Fznamznon added the SYCL https://registry.khronos.org/SYCL label Jun 18, 2025
Signed-off-by: Tikhomirova, Kseniya <kseniya.tikhomirova@intel.com>
Signed-off-by: Tikhomirova, Kseniya <kseniya.tikhomirova@intel.com>
@asudarsa asudarsa requested review from asudarsa and removed request for AlexeySachkov June 18, 2025 15:00
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nit. May be a small file description:
//===----------------------------------------------------------------------===//
///
/// \file
/// This file is a SYCL2020 standard header file.
///
//===----------------------------------------------------------------------===//

@@ -0,0 +1,69 @@
.. _index:
Copy link
Contributor

Choose a reason for hiding this comment

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

This doc can be reformatted as follows:

Main Heading: SYCL runtime implementation
Sub-topics:
1 .Current Status
2. Overview
3. Build steps
Thanks

Copy link
Contributor

@asudarsa asudarsa left a comment

Choose a reason for hiding this comment

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

Looks good to me. Couple of minor nits.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular SYCL https://registry.khronos.org/SYCL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants