-
Notifications
You must be signed in to change notification settings - Fork 14.1k
[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.
libsycl/CMakeLists.txt
Outdated
|
||
# 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() | ||
|
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.
We have runimtes/Modules/WarningFlags.cmake
. Maybe that should be used 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.
thanks for highlighting this, I will update it
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.
libsycl/CMakeLists.txt
Outdated
#=============================================================================== | ||
|
||
# Enable all warnings by default | ||
if(MSVC) |
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 the plan to support MSVC as a compiler? AFAIK no other runtime does that currently.
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.
yes, we support MSVC.
|
||
#### How to build | ||
|
||
TBD |
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 guess this will be filled in future PRs? Maybe Make this a TODO instead? That's usually easier to grep for.
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.
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 |
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 there a reason you use double underscores everywhere? That style tends to be use by compiler-defined stuff, so we avoid it in libc++.
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.
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!
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.
#define __LIBSYCL_BEGIN_UNVERSIONED_NAMESPACE namespace sycl { | ||
#define __LIBSYCL_END_UNVERSIONED_NAMESPACE } | ||
|
||
#define __LIBSYCL_BEGIN_VERSIONED_NAMESPACE \ |
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.
Maybe name this BEGIN_NAMESPACE_SYCL
instead? Otherwise it's not really clear what namespace you're opening.
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.
Makes sense, I will rename them to the following:
_LIBSYCL_BEGIN_UNVERSIONED_NAMESPACE_SYCL
_LIBSYCL_BEGIN_NAMESPACE_SYCL
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.
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBSYCL_LIBRARY_DIR}) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBSYCL_LIBRARY_DIR}) | ||
|
||
set(LIBSYCL_MAJOR_VERSION 0) |
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 assume libsycl should only become ABI stable once the major version is bumped to 1?
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.
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"))) |
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.
#define __LIBSYCL_DLL_LOCAL __attribute__((visibility("hidden"))) | |
#define __LIBSYCL_DLL_LOCAL __attribute__((__visibility__("hidden"))) |
Is there a reason to use __attribute__
instead of [[]]
?
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. 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.
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?
|
||
#include <sycl/platform.hpp> | ||
|
||
#include <stdexcept> |
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.
Which standard libraries do you plan to support?
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.
libstdc++, MSVC STL and we will have experimental support for building and linking sycl runtime with libc++ library instead of libstdc++.
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.
@@ -0,0 +1 @@ | |||
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.
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) |
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.
Yes, there is a long way of upstreaming effort and major version will be updated with meaningful value later.
libsycl/CMakeLists.txt
Outdated
#=============================================================================== | ||
|
||
# Enable all warnings by default | ||
if(MSVC) |
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.
yes, we support MSVC.
|
||
#### How to build | ||
|
||
TBD |
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.
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.
libsycl/CMakeLists.txt
Outdated
|
||
# 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() | ||
|
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 for highlighting this, I will update it
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef __LIBSYCL_DETAIL_CONFIG_HPP |
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.
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 \ |
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.
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)) |
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.
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.
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 <kseniya.tikhomirova@intel.com>
Signed-off-by: Tikhomirova, Kseniya <kseniya.tikhomirova@intel.com>
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
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.
Minor nit. May be a small file description:
//===----------------------------------------------------------------------===//
///
/// \file
/// This file is a SYCL2020 standard header file.
///
//===----------------------------------------------------------------------===//
@@ -0,0 +1,69 @@ | |||
.. _index: |
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 doc can be reformatted as follows:
Main Heading: SYCL runtime implementation
Sub-topics:
1 .Current Status
2. Overview
3. Build steps
Thanks
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
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: