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 6 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

I interpreted @philnik777's suggestion as applying to all three of these settings, not just to the caching behavior of the first.

The original code is consistent with what is done for many projects. See flang-rt/CMakeLists.txt, lldb/CMakeLists.txt, openmp/CMakeLists.txt, llvm/CMakeLists.txt, lld/CMakeLists.txt, bolt/CMakeLists.txt, compiler-rt/CMakeLists.txt, mlir/CMakeLists.txt, clang/CMakeLists.txt, and offload/CMakeLists.txt. I'm not sure what the suggested alternative is. I guess changes to the add_sycl_rt_library function that defines the library targets?

Note that consumers of libsycl will require C++17 as well.

Copy link
Author

Choose a reason for hiding this comment

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

IMHO "The original code is consistent with what is done for many projects." is not correct.
Other projects has 2 build "options":

We have not provided any standalone build options yet so I think current code is aligned with other RTs.

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?

Copy link
Contributor

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, though I wasn't there for that specific part of libc++'s history. Maybe @ldionne knows more.

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.

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 <[email protected]>
Signed-off-by: Tikhomirova, Kseniya <[email protected]>
@asudarsa asudarsa requested review from asudarsa and removed request for AlexeySachkov June 18, 2025 15:00
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

@philnik777
Copy link
Contributor

Also, it would be great if we could get the precommit CI running ASAP. IIUC the basic configurations would be:

  • libstdc++/GCC(?)
  • MSVC STL/MSVC
  • libunwind/libc++abi/libc++/Clang
    That should be pretty lean on the CI resources and could probably easily run in the GH-provided runners for now.

Signed-off-by: Tikhomirova, Kseniya <[email protected]>
@KseniyaTikhomirova
Copy link
Author

Also, it would be great if we could get the precommit CI running ASAP. IIUC the basic configurations would be:

  • libstdc++/GCC(?)
  • MSVC STL/MSVC
  • libunwind/libc++abi/libc++/Clang
    That should be pretty lean on the CI resources and could probably easily run in the GH-provided runners for now.

Could you please clarify - is it a blocker for the current PR? Can we add it in the following PRs?

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.

Also, it would be great if we could get the precommit CI running ASAP. IIUC the basic configurations would be:

  • libstdc++/GCC(?)
  • MSVC STL/MSVC
  • libunwind/libc++abi/libc++/Clang
    That should be pretty lean on the CI resources and could probably easily run in the GH-provided runners for now.

Could you please clarify - is it a blocker for the current PR? Can we add it in the following PRs?

I don't think it should be a blocker. I'd like it soon though, since it significantly increases confidence that code changes are correct.

@bader bader self-requested a review June 23, 2025 15:40
Signed-off-by: Tikhomirova, Kseniya <[email protected]>
@KseniyaTikhomirova
Copy link
Author

Also, it would be great if we could get the precommit CI running ASAP. IIUC the basic configurations would be:

  • libstdc++/GCC(?)
  • MSVC STL/MSVC
  • libunwind/libc++abi/libc++/Clang
    That should be pretty lean on the CI resources and could probably easily run in the GH-provided runners for now.

Could you please clarify - is it a blocker for the current PR? Can we add it in the following PRs?

I don't think it should be a blocker. I'd like it soon though, since it significantly increases confidence that code changes are correct.

I agree, I will add libsycl build workflow as separate PR.

Copy link
Contributor

@tahonermann tahonermann left a comment

Choose a reason for hiding this comment

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

Thanks @KseniyaTikhomirova! I unresolved one previous comment to follow up some more and added a few other minor comments.

Comment on lines +21 to +22
add_library(${LIB_NAME} SHARED
$<TARGET_OBJECTS:${LIB_OBJ_NAME}>)
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 add_library call specifying that the shared library is to be created using the same object files that were linked into the static library? In general, objects suitable for bundling in a static library are not necessarily suitable for bundling in a shared library (e.g., if PIC isn't enabled). I think separate objects files should be built for each with, perhaps, an opt-in to use the same objects for each where that is known to work. I briefly looked for evidence of other LLVM projects doing this and didn't find any.

Copy link
Contributor

@jhuber6 jhuber6 Jun 24, 2025

Choose a reason for hiding this comment

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

It's an object library above. I'm not sure why we need an object library and then a shared library, usually object libraries are used for some indirection before creating the final library but seems like there's just one step here.

Copy link
Author

Choose a reason for hiding this comment

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

This split is done for SYCL RT unittests (UT) target that is not included to this PR.

  1. we do not provide SYCL RT static lib and don't plan to
  2. fPIC option is set by default in LLVM (see LLVM_ENABLE_PIC)
  3. the usage is that we have object library sycl_object. It is used for shared library "sycl" creation and for UT executable creation (not included to this PR).

target_compile_options(${LIB_OBJ_NAME} PRIVATE ${ARG_COMPILE_OPTIONS})
endif()

cxx_add_warning_flags(${LIB_OBJ_NAME} ${LIBSYCL_ENABLE_WERROR} ${LIBSYCL_ENABLE_PEDANTIC})
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 the cxx_add_warning_flags call would be better colocated with the target_compile_definitions call above.

An additional call to cxx_add_warning_flags might be needed depending on how we resolve my other comment about sharing objects between the static and shared library construction (which assumes I know what I'm talking about which might not be the case).

Copy link
Author

Choose a reason for hiding this comment

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

moved above 83458d1

add_library(sycl ALIAS ${LIB_NAME})
endif()

if (CMAKE_SYSTEM_NAME STREQUAL Windows)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this checking for CMAKE_SYSTEM_NAME rather than just checking if WIN32 is true?

Copy link
Author

Choose a reason for hiding this comment

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

updated 83458d1

@@ -1 +1,4 @@
BasedOnStyle: LLVM

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking if libsycl directory should reside here
https://github.com/llvm/llvm-project/tree/main/offload

Thanks

Comment on lines +21 to +22
add_library(${LIB_NAME} SHARED
$<TARGET_OBJECTS:${LIB_OBJ_NAME}>)
Copy link
Contributor

@jhuber6 jhuber6 Jun 24, 2025

Choose a reason for hiding this comment

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

It's an object library above. I'm not sure why we need an object library and then a shared library, usually object libraries are used for some indirection before creating the final library but seems like there's just one step here.

set(LIBSYCL_BUILD_INCLUDE_DIR ${LLVM_BINARY_DIR}/${LIBSYCL_INCLUDE_DIR})
set(LIBSYCL_SOURCE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBSYCL_LIBRARY_DIR})
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer this as a property on the library, but it's not a bit deal.

Copy link
Author

Choose a reason for hiding this comment

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

I aligned this place with the libcxx approach. Since property is set based on CMAKE_ARCHIVE_OUTPUT_DIRECTORY and is implicitly applied to all corresponding targets (one for now) it should be ok.

Signed-off-by: Tikhomirova, Kseniya <[email protected]>
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.

8 participants