Skip to content
Closed
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7981a31
enable standalone build
KseniyaTikhomirova Oct 16, 2025
ceb9e0a
add offload agnostic code
KseniyaTikhomirova Oct 16, 2025
f9d0203
Add the rest and fix the build; no liboffload integration here yet
KseniyaTikhomirova Oct 16, 2025
971443e
add part related to offload integration
KseniyaTikhomirova Oct 17, 2025
260e2b2
draft of sycl-ls
KseniyaTikhomirova Oct 17, 2025
9ce8393
add get_info impl
KseniyaTikhomirova Oct 21, 2025
08e6e2f
fix attributes
KseniyaTikhomirova Oct 21, 2025
99f1f3c
update build cmdline
KseniyaTikhomirova Oct 21, 2025
ede48e7
change build output dir for sycl-ls
KseniyaTikhomirova Oct 22, 2025
3abb743
fix my comments
KseniyaTikhomirova Oct 22, 2025
9a3ca28
try to run WF
KseniyaTikhomirova Oct 22, 2025
f9913fd
remove extra job
KseniyaTikhomirova Oct 22, 2025
e5e1971
fix dirs
KseniyaTikhomirova Oct 22, 2025
7de749a
remove shared_ptr for platform
KseniyaTikhomirova Oct 22, 2025
73b92f1
runner can't build it, no space left on device, removing
KseniyaTikhomirova Oct 22, 2025
fce9a01
fix eof
KseniyaTikhomirova Oct 22, 2025
0158005
format & extra include removal
KseniyaTikhomirova Oct 22, 2025
38400c0
revert incorrect changes
KseniyaTikhomirova Oct 22, 2025
7357f63
use llvmSupport for sycl-ls
KseniyaTikhomirova Oct 23, 2025
ed1507e
remove comments to includes and fix the order
KseniyaTikhomirova Oct 23, 2025
9925ce3
remove dpcpp mentioning
KseniyaTikhomirova Oct 23, 2025
bf07166
remove comments from exception.hpp
KseniyaTikhomirova Oct 23, 2025
715a33b
tiny extra cleanup in exception.hpp
KseniyaTikhomirova Oct 23, 2025
d530135
change call_once to plain static
KseniyaTikhomirova Oct 23, 2025
be62903
change comments in offload_topology.cpp
KseniyaTikhomirova Oct 23, 2025
46baff0
fix comments in offload_topology.hpp
KseniyaTikhomirova Oct 23, 2025
ae6c2ef
remove unnecessary include file
KseniyaTikhomirova Oct 23, 2025
4cfcb73
fix limitation description
KseniyaTikhomirova Oct 23, 2025
570f4c3
fix comment
KseniyaTikhomirova Oct 23, 2025
219c65a
fix more comments
KseniyaTikhomirova Oct 30, 2025
44009a2
remove global_handler
KseniyaTikhomirova Oct 30, 2025
f02d2e0
remove range for index
KseniyaTikhomirova Oct 30, 2025
9fb166d
return back array
KseniyaTikhomirova Oct 30, 2025
e584620
move impl stuff to base class
KseniyaTikhomirova Oct 31, 2025
f51c6df
remove index range
KseniyaTikhomirova Oct 31, 2025
6986a69
change to ref
KseniyaTikhomirova Oct 31, 2025
798d6d5
remove leftover from handler removal
KseniyaTikhomirova Oct 31, 2025
1165274
fix comments related to style
KseniyaTikhomirova Nov 7, 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
18 changes: 14 additions & 4 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,22 @@ 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})
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()

add_subdirectory(src)

set(LIBSYCL_RT_LIBS ${LIBSYCL_SHARED_OUTPUT_NAME})
add_custom_target(libsycl-runtime-libraries
DEPENDS ${LIBSYCL_RT_LIBS}
)
add_subdirectory(tools)
12 changes: 10 additions & 2 deletions libsycl/docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,19 @@ 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
========

Offloading runtime (liboffload) used by SYCL runtime doesn't support Windows now. So Windows support in SYCL RT is not guaranteed and not tested now.
The limitation to be revised once liboffload will add support of Windows.


69 changes: 69 additions & 0 deletions libsycl/include/sycl/__impl/backend.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// 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 <string_view>
#include <sycl/__impl/detail/config.hpp> // namespace macro
#include <type_traits> // std::false_type

_LIBSYCL_BEGIN_NAMESPACE_SYCL

// 4.1. Backends
enum class backend : char {
opencl = 1,
level_zero = 2,
cuda = 3,
all = 4,
hip = 6,
};

namespace detail {
template <typename T> struct is_backend_info_desc : std::false_type {};
} // namespace detail

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

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

namespace detail {
inline std::string_view get_backend_name(const backend &Backend) {
switch (Backend) {
case backend::opencl:
return "opencl";
case backend::level_zero:
return "level_zero";
case backend::cuda:
return "cuda";
case backend::hip:
return "hip";
case backend::all:
return "all";
}

return "";
}
} // namespace detail

_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
65 changes: 65 additions & 0 deletions libsycl/include/sycl/__impl/detail/impl_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//===----------------------------------------------------------------------===//
//
// 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_IMPL_UTILS_HPP
#define _LIBSYCL___IMPL_DETAIL_IMPL_UTILS_HPP

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

#include <cassert> // for assert
#include <type_traits> // for add_rvalue_reference_t and others
#include <utility> // for forward

_LIBSYCL_BEGIN_NAMESPACE_SYCL

namespace detail {

// Helper function for extracting implementation from SYCL's interface objects.
// Note! This function relies on the fact that all SYCL interface classes
// contain "impl" field that points to implementation object. "impl" field
// should be accessible from this function.
//
// Note that due to a bug in MSVC compilers (including MSVC2019 v19.20), it
// may not recognize the usage of this function in friend member declarations
// if the template parameter name there is not equal to the name used here,
// i.e. 'Obj'. For example, using 'Obj' here and 'T' in such declaration
// would trigger that error in MSVC:
// template <class T>
// friend decltype(T::impl) detail::getSyclObjImpl(const T &SyclObject);
template <class Obj>
const decltype(Obj::impl) &getSyclObjImpl(const Obj &SyclObject) {
assert(SyclObject.impl && "every constructor should create an impl");
return SyclObject.impl;
}

// Helper function for creation SYCL interface objects from implementations.
// Note! These functions rely on the fact that all SYCL interface classes
// contain "impl" field that points to implementation object. "impl" field
// should be accessible from these functions.
template <class T>
T createSyclObjFromImpl(
std::add_rvalue_reference_t<decltype(T::impl)> ImplObj) {
return T(std::forward<decltype(ImplObj)>(ImplObj));
}

template <class T>
T createSyclObjFromImpl(
std::add_lvalue_reference_t<const decltype(T::impl)> ImplObj) {
return T(ImplObj);
}

} // namespace detail
_LIBSYCL_END_NAMESPACE_SYCL

#endif // _LIBSYCL___IMPL_DETAIL_IMPL_UTILS_HPP
52 changes: 52 additions & 0 deletions libsycl/include/sycl/__impl/detail/macro_definitions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// 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

#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

static_assert(__cplusplus >= 201703L,
"DPCPP does not support C++ version earlier than C++17.");

#if defined(_WIN32) && !defined(_DLL) && !defined(__SYCL_DEVICE_ONLY__)
// SYCL library is designed such a way that STL objects cross DLL boundary,
// which is guaranteed to work properly only when the application uses the same
// C++ runtime that SYCL library uses.
// The appplications using sycl.dll must be linked with dynamic/release C++ MSVC
// runtime, i.e. be compiled with /MD switch. Similarly, the applications using
// sycld.dll must be linked with dynamic/debug C++ runtime and be compiled with
// /MDd switch.
// Compiler automatically adds /MD or /MDd when -fsycl switch is used.
// The options /MD and /MDd that make the code to use dynamic runtime also
// define the _DLL macro.
# define ERROR_MESSAGE \
"SYCL library is designed to work safely with dynamic C++ runtime." \
"Please use /MD switch with sycl.dll, /MDd switch with sycld.dll, " \
"or -fsycl switch to set C++ runtime automatically."
# 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
50 changes: 50 additions & 0 deletions libsycl/include/sycl/__impl/detail/spinlock.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 helper class SpinLock.
/// SpinLock is a synchronization primitive, that uses atomic variable and
/// causes thread trying acquire lock wait in loop while repeatedly check if
/// the lock is available.
///
/// One important feature of this implementation is that std::atomic<bool> can
/// be zero-initialized. This allows SpinLock to have trivial constructor and
/// destructor, which makes it possible to use it in global context (unlike
/// std::mutex, that doesn't provide such guarantees).
///
//===----------------------------------------------------------------------===//

#ifndef _LIBSYCL___IMPL_SPINLOCK_HPP
#define _LIBSYCL___IMPL_SPINLOCK_HPP

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

#include <atomic>
#include <thread>

_LIBSYCL_BEGIN_NAMESPACE_SYCL

namespace detail {
class SpinLock {
public:
bool try_lock() { return !MLock.test_and_set(std::memory_order_acquire); }

void lock() {
while (MLock.test_and_set(std::memory_order_acquire))
std::this_thread::yield();
}
void unlock() { MLock.clear(std::memory_order_release); }

private:
std::atomic_flag MLock = ATOMIC_FLAG_INIT;
};
} // namespace detail

_LIBSYCL_END_NAMESPACE_SYCL

#endif // _LIBSYCL___IMPL_SPINLOCK_HPP
Loading