Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f6c7d92
[SYCL] Add platform enumeration and info query using liboffload (#2)
KseniyaTikhomirova Nov 7, 2025
6d4d748
add partial spec and base for std::hash support
KseniyaTikhomirova Nov 18, 2025
32e352f
fix comments
KseniyaTikhomirova Nov 19, 2025
0dab958
early init of platforms
KseniyaTikhomirova Nov 19, 2025
17004f9
remove unique_ptr, make ref const, add operator==
KseniyaTikhomirova Nov 20, 2025
3a00063
fix installation
KseniyaTikhomirova Nov 20, 2025
dd8603f
fix format
KseniyaTikhomirova Nov 20, 2025
e10d953
remove offload codes from distributed headers
KseniyaTikhomirova Nov 26, 2025
ec9f858
change ref to impl to raw ptr
KseniyaTikhomirova Nov 27, 2025
c4d78c5
add asserts for impl
KseniyaTikhomirova Nov 27, 2025
cdb9dc1
apply proposed impl of get_info
KseniyaTikhomirova Dec 1, 2025
5ef2ccc
fix leftover of base class impl w/o friend funcs
KseniyaTikhomirova Dec 2, 2025
1c8fbaa
fix comments
KseniyaTikhomirova Dec 5, 2025
0da4c95
remove file common.hpp
KseniyaTikhomirova Dec 5, 2025
3a7367b
fix code-review comments
KseniyaTikhomirova Dec 11, 2025
02b8db9
fix more comments
KseniyaTikhomirova Dec 12, 2025
6fb819c
fix doc
KseniyaTikhomirova Dec 15, 2025
d6e34e1
fix comments
KseniyaTikhomirova Dec 15, 2025
605ac55
remove device macro from hash impl
KseniyaTikhomirova Dec 15, 2025
3bd9d15
remove from backend enum
KseniyaTikhomirova Dec 15, 2025
a3d8ea6
fix comments
KseniyaTikhomirova Dec 16, 2025
315c7af
fix comments
KseniyaTikhomirova Dec 18, 2025
9c2cf16
align style
KseniyaTikhomirova Jan 5, 2026
3f78ff9
enable l0
KseniyaTikhomirova Jan 5, 2026
be62545
return get_backend_info declaration
KseniyaTikhomirova Jan 15, 2026
1ca2ca6
fix comments
KseniyaTikhomirova Jan 16, 2026
2767396
fix last comments
KseniyaTikhomirova Jan 19, 2026
5944913
Merge branch 'main' into add_get_platforms
KseniyaTikhomirova Jan 19, 2026
9f24a18
fix assert text
KseniyaTikhomirova Jan 20, 2026
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
44 changes: 29 additions & 15 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,20 @@ 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" \
-DCMAKE_BUILD_TYPE=Release
-DLLVM_ENABLE_RUNTIMES="offload;openmp;libsycl" \
-DCMAKE_BUILD_TYPE=Release \
# must be default and configured in liboffload,
# requires level zero, see offload/cmake/Modules/LibomptargetGetDependencies.cmake
-DLIBOMPTARGET_PLUGINS_TO_BUILD=level_zero

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

// 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
40 changes: 38 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 All @@ -56,4 +56,40 @@

#endif // __SYCL_DEVICE_ONLY__

#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

#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
// 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_CONFIG_HPP
80 changes: 80 additions & 0 deletions libsycl/include/sycl/__impl/detail/obj_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//===----------------------------------------------------------------------===//
//
// 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 used to navigate between SYCL interface
/// objects and their corresponding implementation 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 {

// SYCL interface classes are required to contain an `impl` data member
// which points to the corresponding implementation object. The data
// member is required to be accessible by the `ImpUtils` class. SYCL
// interface classes that declare the data member private or protected
// are required to befriend the `ImpUtils` class.
struct ImplUtils {
// Helper function to access an implementation object from a SYCL interface
// object.
template <typename SyclObject>
static const decltype(SyclObject::impl) &
getSyclObjImpl(const SyclObject &Obj) {
assert(Obj.impl && "every constructor should create an impl");
return Obj.impl;
}

// Helper function to create a SYCL interface object from an implementation.
template <typename SyclObject, typename Impl>
static SyclObject createSyclObjFromImpl(Impl &&ImplObj) {
if constexpr (std::is_same_v<decltype(SyclObject::impl),
std::shared_ptr<std::decay_t<Impl>>>)
return SyclObject{ImplObj.shared_from_this()};
else
return SyclObject{std::forward<Impl>(ImplObj)};
}
};

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

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

// 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