-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
base: main
Are you sure you want to change the base?
Conversation
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.
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 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. |
There was a problem hiding this 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.
libsycl/CMakeLists.txt
Outdated
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to") | ||
set(CMAKE_CXX_STANDARD_REQUIRED YES) | ||
set(CMAKE_CXX_EXTENSIONS OFF) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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":
- STANDALONE build (where value is cached, "the original code" : https://github.com/llvm/llvm-project/blob/main/openmp/CMakeLists.txt#L23)
- not STANDALONE (where value is not cached: https://github.com/llvm/llvm-project/blob/main/openmp/CMakeLists.txt#L86):
We have not provided any standalone build options yet so I think current code is aligned with other RTs.
libsycl/src/version.hpp.in
Outdated
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
libsycl/CMakeLists.txt
Outdated
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to") | ||
set(CMAKE_CXX_STANDARD_REQUIRED YES) | ||
set(CMAKE_CXX_EXTENSIONS OFF) |
There was a problem hiding this comment.
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.
libsycl/src/version.hpp.in
Outdated
There was a problem hiding this comment.
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?
Signed-off-by: Tikhomirova, Kseniya <[email protected]>
Signed-off-by: Tikhomirova, Kseniya <[email protected]>
There was a problem hiding this 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
Also, it would be great if we could get the precommit CI running ASAP. IIUC the basic configurations would be:
|
Signed-off-by: Tikhomirova, Kseniya <[email protected]>
Could you please clarify - is it a blocker for the current PR? Can we add it in the following PRs? |
There was a problem hiding this 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.
Signed-off-by: Tikhomirova, Kseniya <[email protected]>
I agree, I will add libsycl build workflow as separate PR. |
There was a problem hiding this 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.
add_library(${LIB_NAME} SHARED | ||
$<TARGET_OBJECTS:${LIB_OBJ_NAME}>) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
- we do not provide SYCL RT static lib and don't plan to
- fPIC option is set by default in LLVM (see LLVM_ENABLE_PIC)
- 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).
libsycl/src/CMakeLists.txt
Outdated
target_compile_options(${LIB_OBJ_NAME} PRIVATE ${ARG_COMPILE_OPTIONS}) | ||
endif() | ||
|
||
cxx_add_warning_flags(${LIB_OBJ_NAME} ${LIBSYCL_ENABLE_WERROR} ${LIBSYCL_ENABLE_PEDANTIC}) |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved above 83458d1
libsycl/src/CMakeLists.txt
Outdated
add_library(sycl ALIAS ${LIB_NAME}) | ||
endif() | ||
|
||
if (CMAKE_SYSTEM_NAME STREQUAL Windows) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 | |||
|
There was a problem hiding this comment.
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
add_library(${LIB_NAME} SHARED | ||
$<TARGET_OBJECTS:${LIB_OBJ_NAME}>) |
There was a problem hiding this comment.
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}) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]>
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: