Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b22192a
[SYCL] Add platform enumeration and info query using liboffload (#2)
KseniyaTikhomirova Nov 7, 2025
bcb2711
add partial spec and base for std::hash support
KseniyaTikhomirova Nov 18, 2025
b15b6c0
fix comments
KseniyaTikhomirova Nov 19, 2025
88d313c
early init of platforms
KseniyaTikhomirova Nov 19, 2025
849fed9
remove unique_ptr, make ref const, add operator==
KseniyaTikhomirova Nov 20, 2025
7f62590
fix installation
KseniyaTikhomirova Nov 20, 2025
f081eea
fix format
KseniyaTikhomirova Nov 20, 2025
2224ab8
remove offload codes from distributed headers
KseniyaTikhomirova Nov 26, 2025
71dcdf9
change ref to impl to raw ptr
KseniyaTikhomirova Nov 27, 2025
51529c1
add asserts for impl
KseniyaTikhomirova Nov 27, 2025
821a306
apply proposed impl of get_info
KseniyaTikhomirova Dec 1, 2025
87442d1
fix leftover of base class impl w/o friend funcs
KseniyaTikhomirova Dec 2, 2025
e4e6fd2
fix comments
KseniyaTikhomirova Dec 5, 2025
e8e2811
remove file common.hpp
KseniyaTikhomirova Dec 5, 2025
9ce7695
fix code-review comments
KseniyaTikhomirova Dec 11, 2025
9653e23
fix more comments
KseniyaTikhomirova Dec 12, 2025
885947b
fix doc
KseniyaTikhomirova Dec 15, 2025
656227b
fix comments
KseniyaTikhomirova Dec 15, 2025
002eeb3
remove device macro from hash impl
KseniyaTikhomirova Dec 15, 2025
72ee9cd
Merge branch 'main' into add_get_platforms
KseniyaTikhomirova Dec 15, 2025
fb91c2b
remove from backend enum
KseniyaTikhomirova Dec 15, 2025
c90c2a7
fix comments
KseniyaTikhomirova Dec 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions libsycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ option(LIBSYCL_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

set(LIBSYCL_SHARED_OUTPUT_NAME "sycl" CACHE STRING "Output name for the shared libsycl runtime library.")

if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(LIBSYCL_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})
if(LIBSYCL_LIBDIR_SUBDIR)
Expand All @@ -65,7 +63,7 @@ set(LIBSYCL_SOURCE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)

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

set(LIBSYCL_MAJOR_VERSION 0)
set(LIBSYCL_MINOR_VERSION 1)
Expand Down Expand Up @@ -117,10 +115,23 @@ add_custom_command(
install(DIRECTORY "${LIBSYCL_SOURCE_INCLUDE_DIR}/sycl" DESTINATION ${LIBSYCL_INCLUDE_DIR} COMPONENT sycl-headers)
install(DIRECTORY "${LIBSYCL_SOURCE_INCLUDE_DIR}/CL" DESTINATION ${LIBSYCL_INCLUDE_DIR} COMPONENT sycl-headers)

set(LIBSYCL_RT_LIBS ${LIBSYCL_SHARED_OUTPUT_NAME})

add_subdirectory(src)
set(LIBSYCL_LIB_NAME "sycl")
set(LIBSYCL_SHARED_OUTPUT_NAME "${LIBSYCL_LIB_NAME}")
if (CMAKE_SYSTEM_NAME STREQUAL Windows)
if (CMAKE_MSVC_RUNTIME_LIBRARY AND (NOT CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$"))
message(FATAL_ERROR "libsycl requires a DLL version of the MSVC CRT.")
endif()
if ((NOT CMAKE_MSVC_RUNTIME_LIBRARY AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
OR (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDebugDLL"))
set(LIBSYCL_SHARED_OUTPUT_NAME "${LIBSYCL_SHARED_OUTPUT_NAME}d")
endif()
endif()

set(LIBSYCL_RT_LIBS ${LIBSYCL_SHARED_OUTPUT_NAME})
add_custom_target(libsycl-runtime-libraries
DEPENDS ${LIBSYCL_RT_LIBS}
)

add_subdirectory(src)

add_subdirectory(tools)
2 changes: 1 addition & 1 deletion libsycl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The libsycl subproject is an implementation of the SYCL runtime library as defined by the
[SYCL 2020 specification](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html).

Subproject documentation is available at: [SYCL RT documentation](./docs).
Subproject documentation is available at: [Libsycl documentation](./docs).

libsycl runtime library and headers require C++17 support or higher.

Expand Down
39 changes: 25 additions & 14 deletions libsycl/docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ SYCL runtime implementation
Current Status
========

The implementation is in the very early stages of upstreaming. The first milestone is to get
support for a simple SYCL application with device code using Unified Shared Memory:
The implementation is in the very early stages of upstreaming. The first
milestone is to get
support for a simple SYCL application with device code using Unified Shared
Memory:

.. code-block:: c++

Expand Down Expand Up @@ -43,15 +45,18 @@ support for a simple SYCL application with device code using Unified Shared Memo
return error;
}

This requires at least partial support of the following functionality on the libsycl side:
* ``sycl::platform`` class
* ``sycl::device`` class
* ``sycl::context`` class
* ``sycl::queue`` class
* ``sycl::handler`` class
* ``sycl::id`` and ``sycl::range`` classes
* Unified shared memory allocation/deallocation
* Program manager, an internal component for retrieving and using device images from the multi-architectural binaries
This requires at least partial support of the following functionality on the
libsycl side:

* ``sycl::platform`` class
* ``sycl::device`` class
* ``sycl::context`` class
* ``sycl::queue`` class
* ``sycl::handler`` class
* ``sycl::id`` and ``sycl::range`` classes
* Unified shared memory allocation/deallocation
* Program manager, an internal component for retrieving and using device images
from the multi-architectural binaries

Build steps
========
Expand All @@ -69,11 +74,17 @@ To build LLVM with libsycl runtime enabled the following script can be used.
mkdir -p $installprefix

cmake -G Ninja -S $llvm/llvm -B $build_llvm \
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" \
-DLLVM_ENABLE_PROJECTS="clang" \
-DLLVM_INSTALL_UTILS=ON \
-DCMAKE_INSTALL_PREFIX=$installprefix \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libsycl;libunwind" \
-DLLVM_ENABLE_RUNTIMES="offload;openmp;libsycl" \
-DCMAKE_BUILD_TYPE=Release

ninja -C $build_llvm install



Limitations
========

Libsycl is not currently supported on Windows because it depends on liboffload
which doesn't currently support Windows.
50 changes: 50 additions & 0 deletions libsycl/include/sycl/__impl/backend.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file contains the declaration of the SYCL enum class backend that is
/// implementation-defined and is populated with a unique identifier for each
/// SYCL backend that the SYCL implementation can support.
///
//===----------------------------------------------------------------------===//

#ifndef _LIBSYCL___IMPL_BACKEND_HPP
#define _LIBSYCL___IMPL_BACKEND_HPP

#include <sycl/__impl/detail/config.hpp>

#include <string_view>
#include <type_traits>

_LIBSYCL_BEGIN_NAMESPACE_SYCL

// SYCL 2020 4.1. Backends.
enum class backend : unsigned char {
opencl = 0,
level_zero,
cuda,
hip,
};

namespace detail {
template <typename T> struct is_backend_info_desc : std::false_type {};
} // namespace detail
Comment on lines +34 to +36
Copy link
Contributor

Choose a reason for hiding this comment

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

detail::is_backend_info_desc doesn't appear to be used in this PR. Should it be omitted for now? I see platform::get_backend_info() isn't implemented yet.


// SYCL 2020 4.5.1.1. Type traits backend_traits.
template <backend Backend> class backend_traits;

template <backend Backend, typename SyclType>
using backend_input_t =
typename backend_traits<Backend>::template input_type<SyclType>;
template <backend Backend, typename SyclType>
using backend_return_t =
typename backend_traits<Backend>::template return_type<SyclType>;

_LIBSYCL_END_NAMESPACE_SYCL

#endif // _LIBSYCL___IMPL_BACKEND_HPP
4 changes: 2 additions & 2 deletions libsycl/include/sycl/__impl/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@

# else // _WIN32

# define _LIBSYCL_DLL_LOCAL [[__gnu__::__visibility__("hidden")]]
# define _LIBSYCL_EXPORT [[__gnu__::__visibility__("default")]]
# define _LIBSYCL_DLL_LOCAL __attribute__((visibility("hidden")))
# define _LIBSYCL_EXPORT __attribute__((visibility("default")))

# endif // _WIN32
# endif // _LIBSYCL_EXPORT
Expand Down
49 changes: 49 additions & 0 deletions libsycl/include/sycl/__impl/detail/macro_definitions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file contains macro definitions used in SYCL implementation.
///
//===----------------------------------------------------------------------===//

#ifndef _LIBSYCL___IMPL_DETAIL_MACRO_DEFINITIONS_HPP
#define _LIBSYCL___IMPL_DETAIL_MACRO_DEFINITIONS_HPP

static_assert(__cplusplus >= 201703L, "Libsycl requires C++17 or later.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Testing the value of __cplusplus will require compilation with the /Zc:__cplusplus option when compiling with MSVC (documentation). We can avoid pushing that requirement on users by checking the _MSVC_LANG predefined macro when compiling with MSVC instead (documentation).

Suggested change
static_assert(__cplusplus >= 201703L, "Libsycl requires C++17 or later.");
#if defined(_MSC_VER)
static_assert(_MSVC_LANG >= 201703L, "Libsycl requires C++17 or later.");
#else
static_assert(__cplusplus >= 201703L, "Libsycl requires C++17 or later.");
#endif

Yes, this is super annoying.


#ifndef __SYCL2020_DEPRECATED
# if SYCL_LANGUAGE_VERSION == 202012L && \
!defined(SYCL2020_DISABLE_DEPRECATION_WARNINGS)
# define __SYCL2020_DEPRECATED(message) [[deprecated(message)]]
# else
# define __SYCL2020_DEPRECATED(message)
# endif
#endif // __SYCL2020_DEPRECATED

#if defined(_WIN32) && !defined(_DLL) && !defined(__SYCL_DEVICE_ONLY__)
// When built for use with the MSVC C++ standard library, libsycl requires
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to care about this now before we claim support for Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now I don't use any OS-specific features in libsycl. So theoretically, once liboffload adds win support - base libsycl support on Win should be enabled automatically. (we will need some advanced handling of Win for shutdown but I want to keep this part for later upstreaming phases)
So I added this check from the very beginning.

// use of the DLL versions of the MSVC run-time (RT) library. This requirement
// extends to applications that link with libsycl since the same MSVC run-time
// library must be used to ensure ABI compatibility for objects of C++ standard
// library types like std::vector that are passed to or returned from SYCL
// interfaces. Applications must therefore compile and link with the /MD option
// when linking to a release build of libsycl and with the /MDd option when
// linking to a debug build.
# define ERROR_MESSAGE \
"Libsycl requires use of a DLL version of the MSVC RT library. " \
"Please use /MD to link with a release build of libsycl or /MDd to link" \
" with a debug build."
# if defined(_MSC_VER)
# pragma message(ERROR_MESSAGE)
# else
# warning ERROR_MESSAGE
# endif
# undef ERROR_MESSAGE
#endif // defined(_WIN32) && !defined(_DLL) && !defined(__SYCL_DEVICE_ONLY__)

#endif //_LIBSYCL___IMPL_DETAIL_MACRO_DEFINITIONS_HPP
76 changes: 76 additions & 0 deletions libsycl/include/sycl/__impl/detail/obj_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file contains helper functions for tranformation between implementation
/// and SYCL's interface objects.
///
//===----------------------------------------------------------------------===//

#ifndef _LIBSYCL___IMPL_DETAIL_OBJ_UTILS_HPP
#define _LIBSYCL___IMPL_DETAIL_OBJ_UTILS_HPP

#include <sycl/__impl/detail/config.hpp>

#include <cassert>
#include <memory>
#include <optional>
#include <type_traits>
#include <utility>

_LIBSYCL_BEGIN_NAMESPACE_SYCL

namespace detail {

// Note! This class relies on the fact that all SYCL interface
// classes contain "impl" field that points to implementation object. "impl"
// field should be accessible from this class.
Comment on lines +30 to +32
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 the pointer-to-impl idiom being used so extensively? I'm personally not a fan of it for performance reasons. If the reason is to create an ABI boundary, I think there are better ways to do that.

struct ImplUtils {
// Helper function for extracting implementation from SYCL's interface
// objects.
template <class Obj>
static const decltype(Obj::impl) &getSyclObjImpl(const Obj &SyclObj) {
assert(SyclObj.impl && "every constructor should create an impl");
return SyclObj.impl;
}

// Helper function for creation SYCL interface objects from implementations.
template <typename SyclObject, typename From>
static SyclObject createSyclObjFromImpl(From &&from) {
if constexpr (std::is_same_v<decltype(SyclObject::impl),
std::shared_ptr<std::decay_t<From>>>)
return SyclObject{from.shared_from_this()};
else
return SyclObject{std::forward<From>(from)};
}
};

template <class Obj>
auto getSyclObjImpl(const Obj &SyclObj)
-> decltype(ImplUtils::getSyclObjImpl(SyclObj)) {
return ImplUtils::getSyclObjImpl(SyclObj);
}

template <typename SyclObject, typename From>
SyclObject createSyclObjFromImpl(From &&from) {
return ImplUtils::createSyclObjFromImpl<SyclObject>(std::forward<From>(from));
}

// SYCL 2020 4.5.2. Common reference semantics (std::hash support).
template <typename T> struct HashBase {
size_t operator()(const T &Obj) const {
auto &Impl = sycl::detail::getSyclObjImpl(Obj);
return std::hash<std::decay_t<decltype(Impl)>>{}(Impl);
}
};

} // namespace detail

_LIBSYCL_END_NAMESPACE_SYCL

#endif // _LIBSYCL___IMPL_DETAIL_OBJ_UTILS_HPP
Loading
Loading