[llvm] [libsycl] Code style cleanup (PR #224330)
Kseniya Tikhomirova via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 17 08:02:00 PDT 2026
https://github.com/KseniyaTikhomirova created https://github.com/llvm/llvm-project/pull/224330
None
>From 87df7b132ba59a4bd0a2a18f6d6bef8e3874050a Mon Sep 17 00:00:00 2001
From: "Tikhomirova, Kseniya" <kseniya.tikhomirova at intel.com>
Date: Thu, 17 Sep 2026 08:01:24 -0700
Subject: [PATCH] [libsycl] Code style cleanup
Signed-off-by: Tikhomirova, Kseniya <kseniya.tikhomirova at intel.com>
---
libsycl/include/sycl/__impl/backend.hpp | 1 -
libsycl/include/sycl/__impl/context.hpp | 15 +++--
libsycl/include/sycl/__impl/detail/config.hpp | 2 +-
.../sycl/__impl/detail/kernel_arg_helpers.hpp | 13 ++--
.../sycl/__impl/detail/kernel_submission.hpp | 13 ++--
.../sycl/__impl/detail/linearization.hpp | 4 +-
.../include/sycl/__impl/detail/obj_utils.hpp | 7 ++-
.../sycl/__impl/detail/unified_range_view.hpp | 7 ++-
libsycl/include/sycl/__impl/device.hpp | 4 ++
.../include/sycl/__impl/device_selector.hpp | 2 +
libsycl/include/sycl/__impl/event.hpp | 1 +
libsycl/include/sycl/__impl/exception.hpp | 23 ++++----
libsycl/include/sycl/__impl/group.hpp | 17 +++---
libsycl/include/sycl/__impl/group_barrier.hpp | 5 +-
libsycl/include/sycl/__impl/handler.hpp | 5 +-
.../sycl/__impl/index_space_classes.hpp | 46 ++++++++-------
libsycl/include/sycl/__impl/nd_item.hpp | 42 ++++++-------
libsycl/include/sycl/__impl/nd_range.hpp | 31 +++++++++-
libsycl/include/sycl/__impl/platform.hpp | 1 +
libsycl/include/sycl/__impl/queue.hpp | 46 ++++++++++++++-
libsycl/include/sycl/__impl/sub_group.hpp | 4 +-
libsycl/include/sycl/__impl/usm_functions.hpp | 25 ++++----
libsycl/include/sycl/__spirv/spirv_types.hpp | 4 +-
libsycl/include/sycl/__spirv/spirv_vars.hpp | 46 ++++++++-------
libsycl/include/sycl/sycl.hpp | 6 ++
libsycl/src/context.cpp | 5 +-
libsycl/src/detail/context_impl.cpp | 9 ++-
libsycl/src/detail/context_impl.hpp | 22 +++----
.../src/detail/device_binary_structures.hpp | 2 +-
libsycl/src/detail/device_image_wrapper.cpp | 11 +++-
libsycl/src/detail/device_image_wrapper.hpp | 4 +-
libsycl/src/detail/device_impl.hpp | 28 +++++----
libsycl/src/detail/device_kernel_info.hpp | 2 +-
libsycl/src/detail/event_impl.cpp | 2 +
libsycl/src/detail/global_objects.cpp | 10 ++--
libsycl/src/detail/global_objects.hpp | 5 +-
libsycl/src/detail/handler_impl.hpp | 2 +-
.../src/detail/offload/offload_topology.hpp | 13 ++--
libsycl/src/detail/offload/offload_utils.cpp | 45 ++++++++------
libsycl/src/detail/offload/offload_utils.hpp | 59 +++++++++++--------
libsycl/src/detail/platform_impl.cpp | 7 ++-
libsycl/src/detail/platform_impl.hpp | 28 +++++----
libsycl/src/detail/program_manager.cpp | 48 ++++++++-------
libsycl/src/detail/program_manager.hpp | 1 +
libsycl/src/detail/queue_impl.cpp | 37 +++++++-----
libsycl/src/detail/queue_impl.hpp | 9 ++-
libsycl/src/device.cpp | 21 +++----
libsycl/src/device_selector.cpp | 13 ++--
libsycl/src/event.cpp | 17 +++---
libsycl/src/exception.cpp | 12 ++--
libsycl/src/exception_list.cpp | 12 ++--
libsycl/src/handler.cpp | 16 +++--
libsycl/src/platform.cpp | 11 ++--
libsycl/src/queue.cpp | 16 ++---
libsycl/src/usm_functions.cpp | 32 ++++++----
libsycl/test/basic/index_space_classes.cpp | 39 +++++++++++-
libsycl/test/basic/wrapped_usm_pointers.cpp | 2 +-
libsycl/tools/sycl-ls/sycl-ls.cpp | 37 +++++++-----
libsycl/unittests/mock/helpers.hpp | 4 +-
59 files changed, 598 insertions(+), 353 deletions(-)
diff --git a/libsycl/include/sycl/__impl/backend.hpp b/libsycl/include/sycl/__impl/backend.hpp
index 8dc5711d16b3d..60a9180ab3ed0 100644
--- a/libsycl/include/sycl/__impl/backend.hpp
+++ b/libsycl/include/sycl/__impl/backend.hpp
@@ -18,7 +18,6 @@
#include <sycl/__impl/detail/config.hpp>
-#include <string_view>
#include <type_traits>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
diff --git a/libsycl/include/sycl/__impl/context.hpp b/libsycl/include/sycl/__impl/context.hpp
index 523cb913a3e9d..9895dbc8bc176 100644
--- a/libsycl/include/sycl/__impl/context.hpp
+++ b/libsycl/include/sycl/__impl/context.hpp
@@ -27,7 +27,11 @@
#include <sycl/__impl/detail/config.hpp>
#include <sycl/__impl/detail/obj_utils.hpp>
+#include <functional>
#include <memory>
+#include <string>
+#include <system_error>
+#include <utility>
#include <vector>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -65,13 +69,13 @@ class _LIBSYCL_EXPORT context {
/// Constructs a SYCL context containing all devices in \p plt.
///
- /// \throws an exception with code errc::invalid if \p plt has no devices.
+ /// \throw sycl::exception with sycl::errc::invalid if \p plt has no devices.
explicit context(const platform &plt, const property_list &propList = {})
: context(plt.get_devices(), propList) {}
/// Constructs a SYCL context containing all devices in \p plt.
///
- /// \throws an exception with code errc::invalid if \p plt has no devices.
+ /// \throw sycl::exception with sycl::errc::invalid if \p plt has no devices.
explicit context(const platform &plt, async_handler asyncHandler,
const property_list &propList = {})
: context(plt.get_devices(), asyncHandler, propList) {}
@@ -79,7 +83,7 @@ class _LIBSYCL_EXPORT context {
/// Constructs a SYCL context associated with each device in \p deviceList.
/// All devices in \p deviceList must belong to the same platform.
///
- /// \throws an exception with code errc::invalid if \p deviceList is empty.
+ /// \throw sycl::exception with sycl::errc::invalid if \p deviceList is empty.
explicit context(const std::vector<device> &deviceList,
const property_list &propList = {})
: context(deviceList, detail::defaultAsyncHandler, propList) {}
@@ -87,7 +91,7 @@ class _LIBSYCL_EXPORT context {
/// Constructs a SYCL context associated with each device in \p deviceList.
/// All devices in \p deviceList must belong to the same platform.
///
- /// \throws an exception with code errc::invalid if \p deviceList is empty.
+ /// \throw sycl::exception with sycl::errc::invalid if \p deviceList is empty.
explicit context(const std::vector<device> &deviceList,
async_handler asyncHandler,
const property_list &propList = {});
@@ -143,7 +147,8 @@ class _LIBSYCL_EXPORT context {
// context.hpp.
inline exception::exception(context ctx, std::error_code ec,
const std::string &what_arg)
- : exception(ec, std::make_shared<context>(ctx), what_arg.c_str()) {}
+ : exception(ec, std::make_shared<context>(std::move(ctx)),
+ what_arg.c_str()) {}
inline exception::exception(context ctx, std::error_code ec,
const char *what_arg)
diff --git a/libsycl/include/sycl/__impl/detail/config.hpp b/libsycl/include/sycl/__impl/detail/config.hpp
index 885d2df88e712..e565e41cb3848 100644
--- a/libsycl/include/sycl/__impl/detail/config.hpp
+++ b/libsycl/include/sycl/__impl/detail/config.hpp
@@ -63,7 +63,7 @@ static_assert(__cplusplus >= 201703L, "Libsycl requires C++17 or later.");
#endif
#ifndef __SYCL2020_DEPRECATED
-# if SYCL_LANGUAGE_VERSION == 202012L && \
+# if defined(SYCL_LANGUAGE_VERSION) && SYCL_LANGUAGE_VERSION == 202012L && \
!defined(SYCL2020_DISABLE_DEPRECATION_WARNINGS)
# define __SYCL2020_DEPRECATED(message) [[deprecated(message)]]
# else
diff --git a/libsycl/include/sycl/__impl/detail/kernel_arg_helpers.hpp b/libsycl/include/sycl/__impl/detail/kernel_arg_helpers.hpp
index 2fc7a82d078df..0a6c9e64edf32 100644
--- a/libsycl/include/sycl/__impl/detail/kernel_arg_helpers.hpp
+++ b/libsycl/include/sycl/__impl/detail/kernel_arg_helpers.hpp
@@ -11,8 +11,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL___IMPL_DETAIL_KERNEL_ARG_HELPERS
-#define _LIBSYCL___IMPL_DETAIL_KERNEL_ARG_HELPERS
+#ifndef _LIBSYCL___IMPL_DETAIL_KERNEL_ARG_HELPERS_HPP
+#define _LIBSYCL___IMPL_DETAIL_KERNEL_ARG_HELPERS_HPP
#include <sycl/__impl/index_space_classes.hpp>
#include <sycl/__impl/nd_item.hpp>
@@ -111,8 +111,7 @@ using nth_type_t = typename nth_type<N, Ts...>::type;
template <typename T> T *declptr() { return static_cast<T *>(nullptr); }
-template <int N>
-static inline constexpr bool isValidDimensions = (N > 0) && (N < 4);
+template <int N> inline constexpr bool isValidDimensions = (N > 0) && (N < 4);
/// Class provides helper functions for iteration space coordinates in kernel
/// invocation on device.
@@ -136,7 +135,7 @@ class Builder {
/// Constructs item with the given data.
/// \param Extent a range representing the dimensions of the range of possible
/// values of the item.
- /// \param Index a constituent id representing the work-item’s position in the
+ /// \param Index a constituent id representing the work-item's position in the
/// iteration space.
/// \param Offset an id representing the n-dimensional offset that should be
/// added to the global-ID of each work-item, if this item represents a global
@@ -151,7 +150,7 @@ class Builder {
/// Constructs item with the given data.
/// \param Extent a range representing the dimensions of the range of possible
/// values of the item.
- /// \param Index a constituent id representing the work-item’s position in the
+ /// \param Index a constituent id representing the work-item's position in the
/// iteration space.
template <int Dims, bool WithOffset>
static std::enable_if_t<!WithOffset, item<Dims, WithOffset>>
@@ -192,4 +191,4 @@ class Builder {
_LIBSYCL_END_NAMESPACE_SYCL
-#endif // _LIBSYCL___IMPL_DETAIL_KERNEL_ARG_HELPERS
+#endif // _LIBSYCL___IMPL_DETAIL_KERNEL_ARG_HELPERS_HPP
diff --git a/libsycl/include/sycl/__impl/detail/kernel_submission.hpp b/libsycl/include/sycl/__impl/detail/kernel_submission.hpp
index b7381c46bf820..d4d5be39b19fc 100644
--- a/libsycl/include/sycl/__impl/detail/kernel_submission.hpp
+++ b/libsycl/include/sycl/__impl/detail/kernel_submission.hpp
@@ -23,6 +23,7 @@
#include <sycl/__impl/nd_range.hpp>
#include <tuple>
+#include <type_traits>
#include <utility>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -30,10 +31,10 @@ _LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
template <int Dims>
-void checkNDRangeAndThrow(const sycl::nd_range<Dims> executionRange) {
- if (executionRange.get_global_range() != range<Dims>{} &&
- (executionRange.get_local_range().size() == 0 ||
- executionRange.get_global_range() % executionRange.get_local_range() !=
+void checkNDRangeAndThrow(const sycl::nd_range<Dims> &ExecutionRange) {
+ if (ExecutionRange.get_global_range() != range<Dims>{} &&
+ (ExecutionRange.get_local_range().size() == 0 ||
+ ExecutionRange.get_global_range() % ExecutionRange.get_local_range() !=
range<Dims>{}))
throw sycl::exception(sycl::make_error_code(sycl::errc::nd_range),
"Invalid nd_range submission: global size must be "
@@ -73,9 +74,9 @@ template <typename DerivedT> class KernelSubmissionBase {
template <typename KernelName, int Dims, template <int> class Range,
typename... Rest>
- void parallelForImpl(Range<Dims> numWorkItems, Rest &&...rest) {
+ void parallelForImpl(const Range<Dims> & /*NumWorkItems*/, Rest &&...rest) {
if constexpr (sizeof...(Rest) != 1)
- throw sycl::exception(errc::feature_not_supported,
+ throw sycl::exception(sycl::make_error_code(errc::feature_not_supported),
"Reductions are not supported");
using KernelType =
diff --git a/libsycl/include/sycl/__impl/detail/linearization.hpp b/libsycl/include/sycl/__impl/detail/linearization.hpp
index c1ad4151f6aa8..0bb395f35d589 100644
--- a/libsycl/include/sycl/__impl/detail/linearization.hpp
+++ b/libsycl/include/sycl/__impl/detail/linearization.hpp
@@ -24,8 +24,8 @@ _LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
template <int Dimensions>
-inline std::size_t linearize_id(const id<Dimensions> &Index,
- const range<Dimensions> &Extent) noexcept {
+inline std::size_t linearizeId(const id<Dimensions> &Index,
+ const range<Dimensions> &Extent) noexcept {
if constexpr (Dimensions == 1) {
return Index[0];
} else if constexpr (Dimensions == 2) {
diff --git a/libsycl/include/sycl/__impl/detail/obj_utils.hpp b/libsycl/include/sycl/__impl/detail/obj_utils.hpp
index 8a3518be41698..2e466937051f4 100644
--- a/libsycl/include/sycl/__impl/detail/obj_utils.hpp
+++ b/libsycl/include/sycl/__impl/detail/obj_utils.hpp
@@ -18,8 +18,9 @@
#include <sycl/__impl/detail/config.hpp>
#include <cassert>
+#include <cstddef>
+#include <functional>
#include <memory>
-#include <optional>
#include <type_traits>
#include <utility>
#include <vector>
@@ -30,9 +31,9 @@ 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
+// member is required to be accessible by the `ImplUtils` class. SYCL
// interface classes that declare the data member private or protected
-// are required to befriend the `ImpUtils` class.
+// are required to befriend the `ImplUtils` class.
struct ImplUtils {
// Helper function to access an implementation object from a SYCL interface
// object.
diff --git a/libsycl/include/sycl/__impl/detail/unified_range_view.hpp b/libsycl/include/sycl/__impl/detail/unified_range_view.hpp
index ed8b789b47b88..2e4a4e5370bfb 100644
--- a/libsycl/include/sycl/__impl/detail/unified_range_view.hpp
+++ b/libsycl/include/sycl/__impl/detail/unified_range_view.hpp
@@ -34,14 +34,17 @@ struct UnifiedRangeView {
UnifiedRangeView &operator=(UnifiedRangeView &&Desc) = default;
~UnifiedRangeView() = default;
+ // The views below keep pointers into the range they are built from, so they
+ // only bind to a non-const lvalue: the caller has to own the range for as
+ // long as the view is used.
template <int Dims>
UnifiedRangeView(sycl::range<Dims> &N)
- : MGlobalSize(&(N[0])), MDims(size_t(Dims)) {}
+ : MGlobalSize(&(N[0])), MDims(static_cast<size_t>(Dims)) {}
template <int Dims>
UnifiedRangeView(sycl::nd_range<Dims> &N)
: MGlobalSize(&(N.MGlobalSize[0])), MLocalSize(&(N.MLocalSize[0])),
- MOffset(&(N.MOffset[0])), MDims{size_t(Dims)} {}
+ MOffset(&(N.MOffset[0])), MDims(static_cast<size_t>(Dims)) {}
UnifiedRangeView(const size_t *GlobalSize, const size_t *LocalSize,
const size_t *Offset, size_t Dims)
diff --git a/libsycl/include/sycl/__impl/device.hpp b/libsycl/include/sycl/__impl/device.hpp
index fa4c888d66582..540f68c1d1bf7 100644
--- a/libsycl/include/sycl/__impl/device.hpp
+++ b/libsycl/include/sycl/__impl/device.hpp
@@ -23,6 +23,10 @@
#include <sycl/__impl/detail/config.hpp>
#include <sycl/__impl/detail/obj_utils.hpp>
+#include <functional>
+#include <type_traits>
+#include <vector>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
class platform;
diff --git a/libsycl/include/sycl/__impl/device_selector.hpp b/libsycl/include/sycl/__impl/device_selector.hpp
index 00a5f0ec594bf..d5370d8cb97cd 100644
--- a/libsycl/include/sycl/__impl/device_selector.hpp
+++ b/libsycl/include/sycl/__impl/device_selector.hpp
@@ -19,6 +19,8 @@
#include <sycl/__impl/detail/config.hpp>
#include <functional>
+#include <type_traits>
+#include <vector>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
diff --git a/libsycl/include/sycl/__impl/event.hpp b/libsycl/include/sycl/__impl/event.hpp
index c9a4b67006cd2..a307c21a980c0 100644
--- a/libsycl/include/sycl/__impl/event.hpp
+++ b/libsycl/include/sycl/__impl/event.hpp
@@ -22,6 +22,7 @@
#include <sycl/__impl/info/desc_base.hpp>
#include <sycl/__impl/info/event.hpp>
+#include <functional>
#include <memory>
#include <vector>
diff --git a/libsycl/include/sycl/__impl/exception.hpp b/libsycl/include/sycl/__impl/exception.hpp
index c3c8ff32a1e05..2df0c74d7db6e 100644
--- a/libsycl/include/sycl/__impl/exception.hpp
+++ b/libsycl/include/sycl/__impl/exception.hpp
@@ -17,6 +17,7 @@
#include <sycl/__impl/detail/config.hpp>
+#include <cstddef>
#include <exception>
#include <memory>
#include <string>
@@ -56,7 +57,7 @@ enum class errc : int {
///
/// \param e SYCL 2020 error code.
///
-/// \returns constructed error code.
+/// \return constructed error code.
_LIBSYCL_EXPORT std::error_code make_error_code(sycl::errc e) noexcept;
/// Obtains a reference to the static error category object for SYCL errors.
@@ -67,7 +68,7 @@ _LIBSYCL_EXPORT std::error_code make_error_code(sycl::errc e) noexcept;
/// by the exception (Ex.code().value()) is one of the enumerated values in
/// sycl::errc.
///
-/// \returns the error category object for SYCL errors.
+/// \return the error category object for SYCL errors.
_LIBSYCL_EXPORT const std::error_category &sycl_category() noexcept;
/// \brief SYCL 2020 exception class (4.13.2.) for sync and async error handling
@@ -136,29 +137,29 @@ class _LIBSYCL_EXPORT exception : public virtual std::exception {
/// Returns the error code stored inside the exception.
///
- /// \returns the error code stored inside the exception.
+ /// \return the error code stored inside the exception.
const std::error_code &code() const noexcept;
/// Returns the error category of the error code stored inside the exception.
///
- /// \returns the error category of the error code stored inside the exception.
+ /// \return the error category of the error code stored inside the exception.
const std::error_category &category() const noexcept;
/// Returns string that describes the error that triggered the exception.
///
- /// \returns an implementation-defined non-null constant C-style string that
+ /// \return an implementation-defined non-null constant C-style string that
/// describes the error that triggered the exception.
const char *what() const noexcept final;
/// Checks if the exception has an associated SYCL context.
///
- /// \returns true if this SYCL exception has an associated SYCL context and
+ /// \return true if this SYCL exception has an associated SYCL context and
/// false if it does not.
bool has_context() const noexcept;
/// \return the SYCL context associated with this exception.
///
- /// \throws exception with sycl::errc::invalid if this exception does not
+ /// \throw sycl::exception with sycl::errc::invalid if this exception does not
/// have an associated context (has_context() == false).
context get_context() const;
@@ -169,7 +170,7 @@ class _LIBSYCL_EXPORT exception : public virtual std::exception {
// or context directly.
std::shared_ptr<std::string> MMessage;
std::shared_ptr<context> MContext;
- std::error_code MErrC = make_error_code(sycl::errc::invalid);
+ std::error_code MErrC;
};
/// \brief Used as a container for a list of asynchronous exceptions.
@@ -184,19 +185,19 @@ class _LIBSYCL_EXPORT exception_list {
/// Returns the size of the list.
///
- /// \returns the size of the list.
+ /// \return the size of the list.
size_type size() const;
/// Returns an iterator to the beginning of the list of asynchronous
/// exceptions.
///
- /// \returns an iterator to the beginning of the list of asynchronous
+ /// \return an iterator to the beginning of the list of asynchronous
/// exceptions.
iterator begin() const;
/// Returns an iterator to the end of the list of asynchronous exceptions.
///
- /// \returns an iterator to the end of the list of asynchronous exceptions.
+ /// \return an iterator to the end of the list of asynchronous exceptions.
iterator end() const;
private:
diff --git a/libsycl/include/sycl/__impl/group.hpp b/libsycl/include/sycl/__impl/group.hpp
index 529ddd54f1400..67484e66b0364 100644
--- a/libsycl/include/sycl/__impl/group.hpp
+++ b/libsycl/include/sycl/__impl/group.hpp
@@ -53,7 +53,7 @@ template <int Dimensions = 1> class group {
return get_group_id()[dimension];
}
- /// \return a SYCL id representing the calling work-item’s position within the
+ /// \return a SYCL id representing the calling work-item's position within the
/// work-group.
id<Dimensions> get_local_id() const noexcept {
return __spirv::initBuiltInLocalInvocationId<Dimensions, id<Dimensions>>();
@@ -98,24 +98,22 @@ template <int Dimensions = 1> class group {
/// \return the linearized work-group id within the nd-range.
std::size_t get_group_linear_id() const noexcept {
- return detail::linearize_id(get_group_id(), get_group_range());
+ return detail::linearizeId(get_group_id(), get_group_range());
}
- /// \return a linearized version of the calling work-item’s local id.
+ /// \return a linearized version of the calling work-item's local id.
std::size_t get_local_linear_id() const noexcept {
- return detail::linearize_id(get_local_id(), get_local_range());
+ return detail::linearizeId(get_local_id(), get_local_range());
}
/// \return the total number of work-groups in the nd-range.
std::size_t get_group_linear_range() const noexcept {
- auto groupRange = get_group_range();
- return multiply_all_dims(groupRange);
+ return multiplyAllDims(get_group_range());
}
/// \return the total number of work-items in this work-group.
std::size_t get_local_linear_range() const noexcept {
- auto localRange = get_local_range();
- return multiply_all_dims(localRange);
+ return multiplyAllDims(get_local_range());
}
/// \return true for exactly one work-item in the work-group, if the calling
@@ -128,8 +126,7 @@ template <int Dimensions = 1> class group {
protected:
group() = default;
- static std::size_t
- multiply_all_dims(const range<Dimensions> &Range) noexcept {
+ static std::size_t multiplyAllDims(const range<Dimensions> &Range) noexcept {
if constexpr (Dimensions == 1) {
return Range[0];
} else if constexpr (Dimensions == 2) {
diff --git a/libsycl/include/sycl/__impl/group_barrier.hpp b/libsycl/include/sycl/__impl/group_barrier.hpp
index d23fb0294616f..69c36774bab6b 100644
--- a/libsycl/include/sycl/__impl/group_barrier.hpp
+++ b/libsycl/include/sycl/__impl/group_barrier.hpp
@@ -42,7 +42,7 @@ inline constexpr bool is_group_v = is_group<std::decay_t<T>>::value;
namespace detail {
-static constexpr __spirv::Scope getScope(memory_scope Scope) {
+inline constexpr __spirv::Scope getScope(memory_scope Scope) {
switch (Scope) {
case memory_scope::work_item:
return __spirv::Scope::Invocation;
@@ -55,6 +55,9 @@ static constexpr __spirv::Scope getScope(memory_scope Scope) {
case memory_scope::system:
return __spirv::Scope::CrossDevice;
}
+ // A memory_scope value outside of the enumeration falls back to the widest
+ // scope instead of running off the end of the function.
+ return __spirv::Scope::CrossDevice;
}
template <typename Group> struct group_scope {};
diff --git a/libsycl/include/sycl/__impl/handler.hpp b/libsycl/include/sycl/__impl/handler.hpp
index 4b3923b19bfe7..fa153b1cb9e79 100644
--- a/libsycl/include/sycl/__impl/handler.hpp
+++ b/libsycl/include/sycl/__impl/handler.hpp
@@ -25,6 +25,7 @@
#include <sycl/__impl/index_space_classes.hpp>
#include <array>
+#include <cstddef>
#include <cstring>
#include <memory>
#include <type_traits>
@@ -33,7 +34,7 @@
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
-class HandlerImpl;
+struct HandlerImpl;
class QueueImpl;
} // namespace detail
@@ -127,6 +128,8 @@ class _LIBSYCL_EXPORT handler : private detail::KernelSubmissionBase<handler> {
private:
template <typename KernelName, int Dims, template <int> class Range,
typename... Rest>
+ // The range is taken by value on purpose: detail::UnifiedRangeView keeps
+ // pointers into it and only binds to a non-const lvalue.
void parallelForImpl(Range<Dims> numWorkItems, Rest &&...rest) {
setKernelRange(numWorkItems);
diff --git a/libsycl/include/sycl/__impl/index_space_classes.hpp b/libsycl/include/sycl/__impl/index_space_classes.hpp
index 8f99d03d004ee..879f91102a174 100644
--- a/libsycl/include/sycl/__impl/index_space_classes.hpp
+++ b/libsycl/include/sycl/__impl/index_space_classes.hpp
@@ -121,9 +121,11 @@ template <typename Derived, int Dimensions> class IndexSpaceBase {
template <typename T> \
friend IntegralType<T, Derived> operator op(const Derived &lhs, \
const T &rhs) noexcept { \
+ /* SYCL 2020 declares the scalar operand of these operators as size_t. */ \
+ const std::size_t Scalar = static_cast<std::size_t>(rhs); \
Derived result; \
for (int i = 0; i < Dimensions; ++i) { \
- result.MArray[i] = lhs.MArray[i] op rhs; \
+ result.MArray[i] = lhs.MArray[i] op Scalar; \
} \
return result; \
} \
@@ -131,9 +133,10 @@ template <typename Derived, int Dimensions> class IndexSpaceBase {
template <typename T> \
friend IntegralType<T, Derived> operator op(const T &lhs, \
const Derived &rhs) noexcept { \
+ const std::size_t Scalar = static_cast<std::size_t>(lhs); \
Derived result; \
for (int i = 0; i < Dimensions; ++i) { \
- result.MArray[i] = lhs op rhs.MArray[i]; \
+ result.MArray[i] = Scalar op rhs.MArray[i]; \
} \
return result; \
}
@@ -267,7 +270,7 @@ class range : public detail::IndexSpaceBase<range<Dimensions>, Dimensions> {
std::size_t operator[](int dimension) const noexcept;
*/
- /// \return the size of the range computed as dimension0*…*dimensionN.
+ /// \return the size of the range computed as dimension0*...*dimensionN.
std::size_t size() const noexcept {
std::size_t size = 1;
for (int i = 0; i < Dimensions; ++i) {
@@ -392,7 +395,7 @@ class id : public detail::IndexSpaceBase<id<Dimensions>, Dimensions> {
template <typename T, int N = Dimensions, \
std::enable_if_t<N == 1, bool> = true> \
detail::IntegralType<T, bool> operator op(const T &rhs) const noexcept { \
- if (this->MArray[0] != rhs) \
+ if (this->MArray[0] != static_cast<std::size_t>(rhs)) \
return false op true; \
return true op true; \
} \
@@ -400,7 +403,7 @@ class id : public detail::IndexSpaceBase<id<Dimensions>, Dimensions> {
std::enable_if_t<N == 1, bool> = true> \
friend detail::IntegralType<T, bool> operator op( \
const T &lhs, const id<dimensions> &rhs) noexcept { \
- if (lhs != rhs.MArray[0]) \
+ if (static_cast<std::size_t>(lhs) != rhs.MArray[0]) \
return false op true; \
return true op true; \
}
@@ -457,7 +460,7 @@ template <int Dimensions /* = 1*/, bool WithOffset /* = true*/> class item {
return !(lhs == rhs);
}
- /// \return the constituent id representing the work-item’s position in the
+ /// \return the constituent id representing the work-item's position in the
/// iteration space.
id<Dimensions> get_id() const noexcept { return MId; }
@@ -489,6 +492,7 @@ template <int Dimensions /* = 1*/, bool WithOffset /* = true*/> class item {
/// work-item, if this item represents a global range.
template <bool HasOffset = WithOffset,
std::enable_if_t<HasOffset == true, bool> = true>
+ __SYCL2020_DEPRECATED("offsets are deprecated in SYCL2020")
id<Dimensions> get_offset() const noexcept {
return MOffset;
}
@@ -499,9 +503,9 @@ template <int Dimensions /* = 1*/, bool WithOffset /* = true*/> class item {
/// WithOffset == false.
/// \return an item representing the same information as the object holds but
/// also includes the offset set to 0.
- template <bool HasOffset = WithOffset,
- std::enable_if_t<HasOffset == false, bool> = true>
- operator item<Dimensions, true>() const noexcept {
+ template <bool HasOffset = WithOffset>
+ operator std::enable_if_t<HasOffset == false, item<Dimensions, true>>()
+ const noexcept {
return item<Dimensions, true>(MRange, MId, id<Dimensions>{});
}
@@ -514,22 +518,20 @@ template <int Dimensions /* = 1*/, bool WithOffset /* = true*/> class item {
/// \return Return the id as a linear index value.
std::size_t get_linear_id() const noexcept {
if constexpr (WithOffset) {
- if constexpr (1 == Dimensions) {
+ if constexpr (1 == Dimensions)
return MId[0] - MOffset[0];
- }
- if constexpr (2 == Dimensions) {
+ else if constexpr (2 == Dimensions)
return (MId[0] - MOffset[0]) * MRange[1] + MId[1] - MOffset[1];
- }
- return (MId[0] - MOffset[0]) * MRange[1] * MRange[2] +
- (MId[1] - MOffset[1]) * MRange[2] + MId[2] - MOffset[2];
+ else
+ return (MId[0] - MOffset[0]) * MRange[1] * MRange[2] +
+ (MId[1] - MOffset[1]) * MRange[2] + MId[2] - MOffset[2];
} else {
- if constexpr (1 == Dimensions) {
+ if constexpr (1 == Dimensions)
return MId[0];
- }
- if constexpr (2 == Dimensions) {
+ else if constexpr (2 == Dimensions)
return MId[0] * MRange[1] + MId[1];
- }
- return MId[0] * MRange[1] * MRange[2] + MId[1] * MRange[2] + MId[2];
+ else
+ return MId[0] * MRange[1] * MRange[2] + MId[1] * MRange[2] + MId[2];
}
}
@@ -551,6 +553,10 @@ template <int Dimensions /* = 1*/, bool WithOffset /* = true*/> class item {
std::conditional_t<WithOffset, id<Dimensions>, std::monostate> MOffset;
friend class detail::Builder;
+
+ // The conversion to an item with an offset builds an item of another
+ // specialization from its protected constructor.
+ template <int, bool> friend class item;
};
_LIBSYCL_END_NAMESPACE_SYCL
diff --git a/libsycl/include/sycl/__impl/nd_item.hpp b/libsycl/include/sycl/__impl/nd_item.hpp
index f9ce98a67deb0..05a392fe4be40 100644
--- a/libsycl/include/sycl/__impl/nd_item.hpp
+++ b/libsycl/include/sycl/__impl/nd_item.hpp
@@ -52,53 +52,45 @@ template <int Dimensions = 1> class nd_item {
return !(lhs == rhs);
}
- /// \return the constituent global id representing the work-item’s position in
+ /// \return the constituent global id representing the work-item's position in
/// the global iteration space.
id<Dimensions> get_global_id() const noexcept {
return __spirv::initBuiltInGlobalInvocationId<Dimensions, id<Dimensions>>();
}
/// \return the constituent element of the global id representing the
- /// work-item’s position in the nd-range in the given Dimension.
+ /// work-item's position in the nd-range in the given Dimension.
std::size_t get_global_id(int dimension) const noexcept {
return get_global_id()[dimension];
}
/// \return the constituent global id as a linear index value, representing
- /// the work-item’s position in the global iteration space.
+ /// the work-item's position in the global iteration space.
std::size_t get_global_linear_id() const noexcept {
- id<Dimensions> adjustedIndex = get_global_id();
- const id<Dimensions> offset =
+ id<Dimensions> AdjustedIndex = get_global_id();
+ const id<Dimensions> Offset =
__spirv::initBuiltInGlobalOffset<Dimensions, id<Dimensions>>();
- if constexpr (Dimensions == 1) {
- adjustedIndex[0] -= offset[0];
- } else if constexpr (Dimensions == 2) {
- adjustedIndex[0] -= offset[0];
- adjustedIndex[1] -= offset[1];
- } else {
- adjustedIndex[0] -= offset[0];
- adjustedIndex[1] -= offset[1];
- adjustedIndex[2] -= offset[2];
- }
- return detail::linearize_id(adjustedIndex, get_global_range());
- }
-
- /// \return the constituent local id representing the work-item’s position
+ for (int I = 0; I < Dimensions; ++I)
+ AdjustedIndex[I] -= Offset[I];
+ return detail::linearizeId(AdjustedIndex, get_global_range());
+ }
+
+ /// \return the constituent local id representing the work-item's position
/// within the current work-group.
id<Dimensions> get_local_id() const noexcept {
return __spirv::initBuiltInLocalInvocationId<Dimensions, id<Dimensions>>();
}
/// \return the constituent element of the local id representing the
- /// work-item’s position within the current work-group in the given Dimension.
+ /// work-item's position within the current work-group in the given Dimension.
std::size_t get_local_id(int dimension) const noexcept {
return get_local_id()[dimension];
}
/// \return the constituent local id as a linear index value, representing the
- /// work-item’s position within the current work-group.
+ /// work-item's position within the current work-group.
std::size_t get_local_linear_id() const noexcept {
- return detail::linearize_id(get_local_id(), get_local_range());
+ return detail::linearizeId(get_local_id(), get_local_range());
}
/// \return the constituent work-group, group representing the work-group's
@@ -110,14 +102,14 @@ template <int Dimensions = 1> class nd_item {
sub_group get_sub_group() const noexcept { return sub_group(); }
/// \return the constituent element of the group id representing the
- /// work-group’s position within the overall nd_range in the given Dimension.
+ /// work-group's position within the overall nd_range in the given Dimension.
std::size_t get_group(int dimension) const noexcept {
return get_group_id()[dimension];
}
/// \return the group id as a linear index value.
std::size_t get_group_linear_id() const noexcept {
- return detail::linearize_id(get_group_id(), get_group_range());
+ return detail::linearizeId(get_group_id(), get_group_range());
}
/// \return the number of work-groups in the iteration space.
@@ -161,7 +153,7 @@ template <int Dimensions = 1> class nd_item {
/// \return the nd_range of the current execution.
nd_range<Dimensions> get_nd_range() const noexcept {
- return nd_range<Dimensions>(
+ return detail::makeNdRange(
get_global_range(), get_local_range(),
__spirv::initBuiltInGlobalOffset<Dimensions, id<Dimensions>>());
}
diff --git a/libsycl/include/sycl/__impl/nd_range.hpp b/libsycl/include/sycl/__impl/nd_range.hpp
index 7577b4bdd1315..f1f4589615087 100644
--- a/libsycl/include/sycl/__impl/nd_range.hpp
+++ b/libsycl/include/sycl/__impl/nd_range.hpp
@@ -19,14 +19,23 @@
_LIBSYCL_BEGIN_NAMESPACE_SYCL
+template <int Dimensions = 1> class nd_range;
+
namespace detail {
struct UnifiedRangeView;
+
+/// Constructs an nd_range carrying an offset without going through the
+/// deprecated public constructor.
+template <int Dimensions>
+nd_range<Dimensions> makeNdRange(const range<Dimensions> &GlobalSize,
+ const range<Dimensions> &LocalSize,
+ const id<Dimensions> &Offset) noexcept;
} // namespace detail
// SYCL 2020 4.9.1.2. nd_range class.
/// nd_range<int Dimensions> defines the iteration domain of both the
/// work-groups and the overall dispatch.
-template <int Dimensions = 1> class nd_range {
+template <int Dimensions /* = 1*/> class nd_range {
static_assert(Dimensions >= 1 && Dimensions <= 3,
"nd_range can only be 1-, 2-, or 3-dimensional.");
@@ -54,7 +63,7 @@ template <int Dimensions = 1> class nd_range {
id<Dimensions> offset) noexcept
: MGlobalSize(globalSize), MLocalSize(localSize), MOffset(offset) {}
- nd_range(range<Dimensions> globalSize, range<Dimensions> localSize)
+ nd_range(range<Dimensions> globalSize, range<Dimensions> localSize) noexcept
: MGlobalSize(globalSize), MLocalSize(localSize),
MOffset(id<Dimensions>()) {}
@@ -82,8 +91,26 @@ template <int Dimensions = 1> class nd_range {
id<Dimensions> MOffset;
friend struct detail::UnifiedRangeView;
+
+ friend nd_range<Dimensions>
+ detail::makeNdRange<Dimensions>(const range<Dimensions> &,
+ const range<Dimensions> &,
+ const id<Dimensions> &) noexcept;
};
+namespace detail {
+
+template <int Dimensions>
+nd_range<Dimensions> makeNdRange(const range<Dimensions> &GlobalSize,
+ const range<Dimensions> &LocalSize,
+ const id<Dimensions> &Offset) noexcept {
+ nd_range<Dimensions> Result(GlobalSize, LocalSize);
+ Result.MOffset = Offset;
+ return Result;
+}
+
+} // namespace detail
+
_LIBSYCL_END_NAMESPACE_SYCL
#endif // _LIBSYCL___IMPL_ND_RANGE_HPP
diff --git a/libsycl/include/sycl/__impl/platform.hpp b/libsycl/include/sycl/__impl/platform.hpp
index 8512e53a11385..35907856b7946 100644
--- a/libsycl/include/sycl/__impl/platform.hpp
+++ b/libsycl/include/sycl/__impl/platform.hpp
@@ -22,6 +22,7 @@
#include <sycl/__impl/info/device_type.hpp>
#include <sycl/__impl/info/platform.hpp>
+#include <functional>
#include <memory>
#include <vector>
diff --git a/libsycl/include/sycl/__impl/queue.hpp b/libsycl/include/sycl/__impl/queue.hpp
index ef4b6c59fd8cb..e112949c449b3 100644
--- a/libsycl/include/sycl/__impl/queue.hpp
+++ b/libsycl/include/sycl/__impl/queue.hpp
@@ -19,6 +19,7 @@
#include <sycl/__impl/context.hpp>
#include <sycl/__impl/device.hpp>
#include <sycl/__impl/event.hpp>
+#include <sycl/__impl/exception.hpp>
#include <sycl/__impl/handler.hpp>
#include <sycl/__impl/platform.hpp>
#include <sycl/__impl/property_list.hpp>
@@ -29,7 +30,13 @@
#include <sycl/__impl/detail/kernel_submission.hpp>
#include <sycl/__impl/detail/obj_utils.hpp>
#include <sycl/__impl/detail/unified_range_view.hpp>
-#include <sycl/__impl/exception.hpp>
+
+#include <cstddef>
+#include <functional>
+#include <memory>
+#include <type_traits>
+#include <utility>
+#include <vector>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -60,7 +67,6 @@ struct CheckFunctionCallOperator<F, RetT(Args...)> {
public:
static constexpr bool value = type::value;
};
-} // namespace detail
class TypelessCGF {
public:
@@ -95,6 +101,8 @@ class TypelessCGF {
const InvokerTy InvokerF;
};
+} // namespace detail
+
// SYCL 2020 4.6.5. Queue class.
class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
public:
@@ -451,12 +459,31 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
std::forward<Rest>(rest)...);
}
+ /// Defines and invokes a SYCL kernel function as a lambda expression or a
+ /// named function object type, for the specified nd_range.
+ ///
+ /// \param executionRange specifies the global and local work space of the
+ /// kernel.
+ /// \param rest acts as if it was "const KernelType &KernelFunc".
+ /// \throw sycl::exception with sycl::errc::nd_range if the global size is
+ /// not evenly divisible by the local size.
+ // TODO: Rest will represent reduction types once it is supported.
template <typename KernelName = detail::AutoName, int Dims, typename... Rest>
event parallel_for(nd_range<Dims> executionRange, Rest &&...rest) {
return parallel_for<KernelName, Dims, Rest...>(
executionRange, std::vector<event>{}, std::forward<Rest>(rest)...);
}
+ /// Defines and invokes a SYCL kernel function as a lambda expression or a
+ /// named function object type, for the specified nd_range.
+ ///
+ /// \param executionRange specifies the global and local work space of the
+ /// kernel.
+ /// \param depEvent is an event that specifies the kernel dependency.
+ /// \param rest acts as if it was "const KernelType &KernelFunc".
+ /// \throw sycl::exception with sycl::errc::nd_range if the global size is
+ /// not evenly divisible by the local size.
+ // TODO: Rest will represent reduction types once it is supported.
template <typename KernelName = detail::AutoName, int Dims, typename... Rest>
event parallel_for(nd_range<Dims> executionRange, event depEvent,
Rest &&...rest) {
@@ -465,6 +492,17 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
std::forward<Rest>(rest)...);
}
+ /// Defines and invokes a SYCL kernel function as a lambda expression or a
+ /// named function object type, for the specified nd_range.
+ ///
+ /// \param executionRange specifies the global and local work space of the
+ /// kernel.
+ /// \param depEvents is a vector of events that specifies the kernel
+ /// dependencies.
+ /// \param rest acts as if it was "const KernelType &KernelFunc".
+ /// \throw sycl::exception with sycl::errc::nd_range if the global size is
+ /// not evenly divisible by the local size.
+ // TODO: Rest will represent reduction types once it is supported.
template <typename KernelName = detail::AutoName, int Dims, typename... Rest>
event parallel_for(nd_range<Dims> executionRange,
const std::vector<event> &depEvents, Rest &&...rest) {
@@ -577,6 +615,8 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
private:
template <typename KernelName, int Dims, template <int> class Range,
typename... Rest>
+ // The range is taken by value on purpose: detail::UnifiedRangeView keeps
+ // pointers into it and only binds to a non-const lvalue.
event parallelForImpl(Range<Dims> numWorkItems,
const std::vector<event> &depEvents, Rest &&...rest) {
setKernelLaunchParams(depEvents, numWorkItems);
@@ -603,7 +643,7 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
/// \return an event representing last kernel invocation.
event getLastEvent();
- event submitWithHandler(const TypelessCGF &CGF);
+ event submitWithHandler(const detail::TypelessCGF &CGF);
queue(const std::shared_ptr<detail::QueueImpl> &Impl) : impl(Impl) {}
std::shared_ptr<detail::QueueImpl> impl;
diff --git a/libsycl/include/sycl/__impl/sub_group.hpp b/libsycl/include/sycl/__impl/sub_group.hpp
index fbcba75170e03..5124b2ba63b54 100644
--- a/libsycl/include/sycl/__impl/sub_group.hpp
+++ b/libsycl/include/sycl/__impl/sub_group.hpp
@@ -53,7 +53,7 @@ class sub_group {
/// work-group.
id_type get_group_id() const noexcept { return __spirv_BuiltInSubgroupId(); }
- /// \return a SYCL id representing the calling work-item’s position within the
+ /// \return a SYCL id representing the calling work-item's position within the
/// sub-group.
id_type get_local_id() const noexcept {
return __spirv_BuiltInSubgroupLocalInvocationId();
@@ -104,7 +104,7 @@ class sub_group {
protected:
sub_group() = default;
- template <int dimensions> friend class sycl::nd_item;
+ template <int> friend class sycl::nd_item;
};
_LIBSYCL_END_NAMESPACE_SYCL
diff --git a/libsycl/include/sycl/__impl/usm_functions.hpp b/libsycl/include/sycl/__impl/usm_functions.hpp
index 376200faa7901..48ffebc4a28a6 100644
--- a/libsycl/include/sycl/__impl/usm_functions.hpp
+++ b/libsycl/include/sycl/__impl/usm_functions.hpp
@@ -21,6 +21,7 @@
#include <sycl/__impl/detail/config.hpp>
#include <algorithm>
+#include <cstddef>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -578,22 +579,24 @@ T *malloc(std::size_t count, const queue &syclQueue, usm::alloc kind,
/// Deallocate USM of any kind.
///
/// \param ptr a pointer that satisfies the following preconditions: points to
-/// memory allocated against ctxt using one of the USM allocation routines, or
-/// is a null pointer; ptr has not previously been deallocated; there are no
-/// in-progress or enqueued commands using the memory pointed to by ptr.
-/// \param ctxt the context that is associated with ptr.
-_LIBSYCL_EXPORT void free(void *ptr, const context &ctxt);
+/// memory allocated against syclContext using one of the USM allocation
+/// routines, or is a null pointer; ptr has not previously been deallocated;
+/// there are no in-progress or enqueued commands using the memory pointed to
+/// by ptr.
+/// \param syclContext the context that is associated with ptr.
+_LIBSYCL_EXPORT void free(void *ptr, const context &syclContext);
/// Deallocate USM of any kind.
///
-/// Equivalent to free(ptr, q.get_context()).
+/// Equivalent to free(ptr, syclQueue.get_context()).
///
/// \param ptr a pointer that satisfies the following preconditions: points to
-/// memory allocated against ctxt using one of the USM allocation routines, or
-/// is a null pointer; ptr has not previously been deallocated; there are no
-/// in-progress or enqueued commands using the memory pointed to by ptr.
-/// \param q a queue to determine the context associated with ptr.
-_LIBSYCL_EXPORT void free(void *ptr, const queue &q);
+/// memory allocated against a context using one of the USM allocation
+/// routines, or is a null pointer; ptr has not previously been deallocated;
+/// there are no in-progress or enqueued commands using the memory pointed to
+/// by ptr.
+/// \param syclQueue a queue to determine the context associated with ptr.
+_LIBSYCL_EXPORT void free(void *ptr, const queue &syclQueue);
/// @}
_LIBSYCL_END_NAMESPACE_SYCL
diff --git a/libsycl/include/sycl/__spirv/spirv_types.hpp b/libsycl/include/sycl/__spirv/spirv_types.hpp
index 47f29367df3b4..4633846989ced 100644
--- a/libsycl/include/sycl/__spirv/spirv_types.hpp
+++ b/libsycl/include/sycl/__spirv/spirv_types.hpp
@@ -18,7 +18,7 @@
namespace __spirv {
-enum Scope : int32_t {
+enum Scope : std::int32_t {
CrossDevice = 0,
Device = 1,
Workgroup = 2,
@@ -26,7 +26,7 @@ enum Scope : int32_t {
Invocation = 4,
};
-enum MemorySemanticsMask : int32_t {
+enum MemorySemanticsMask : std::int32_t {
None = 0x0,
Acquire = 0x2,
Release = 0x4,
diff --git a/libsycl/include/sycl/__spirv/spirv_vars.hpp b/libsycl/include/sycl/__spirv/spirv_vars.hpp
index 854ae64b0f665..773b2c02c48ae 100644
--- a/libsycl/include/sycl/__spirv/spirv_vars.hpp
+++ b/libsycl/include/sycl/__spirv/spirv_vars.hpp
@@ -12,37 +12,43 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL___SPIRV_SPIRV_VARS
-#define _LIBSYCL___SPIRV_SPIRV_VARS
+#ifndef _LIBSYCL___SPIRV_SPIRV_VARS_HPP
+#define _LIBSYCL___SPIRV_SPIRV_VARS_HPP
#include <cstddef>
#include <cstdint>
// SPIR-V built-in variables mapped to function call.
-__attribute__((const)) size_t __spirv_BuiltInGlobalInvocationId(int);
-__attribute__((const)) size_t __spirv_BuiltInGlobalSize(int);
-__attribute__((const)) size_t __spirv_BuiltInGlobalOffset(int);
-__attribute__((const)) size_t __spirv_BuiltInWorkgroupId(int);
-__attribute__((const)) size_t __spirv_BuiltInLocalInvocationId(int);
-__attribute__((const)) size_t __spirv_BuiltInWorkgroupSize(int);
-__attribute__((const)) size_t __spirv_BuiltInNumWorkgroups(int);
+__attribute__((const)) std::size_t __spirv_BuiltInGlobalInvocationId(int);
+__attribute__((const)) std::size_t __spirv_BuiltInGlobalSize(int);
+__attribute__((const)) std::size_t __spirv_BuiltInGlobalOffset(int);
+__attribute__((const)) std::size_t __spirv_BuiltInWorkgroupId(int);
+__attribute__((const)) std::size_t __spirv_BuiltInLocalInvocationId(int);
+__attribute__((const)) std::size_t __spirv_BuiltInWorkgroupSize(int);
+__attribute__((const)) std::size_t __spirv_BuiltInNumWorkgroups(int);
-__attribute__((const)) uint32_t __spirv_BuiltInSubgroupSize();
-__attribute__((const)) uint32_t __spirv_BuiltInSubgroupMaxSize();
-__attribute__((const)) uint32_t __spirv_BuiltInNumSubgroups();
-__attribute__((const)) uint32_t __spirv_BuiltInSubgroupId();
-__attribute__((const)) uint32_t __spirv_BuiltInSubgroupLocalInvocationId();
+__attribute__((const)) std::uint32_t __spirv_BuiltInSubgroupSize();
+__attribute__((const)) std::uint32_t __spirv_BuiltInSubgroupMaxSize();
+__attribute__((const)) std::uint32_t __spirv_BuiltInNumSubgroups();
+__attribute__((const)) std::uint32_t __spirv_BuiltInSubgroupId();
+__attribute__((const)) std::uint32_t __spirv_BuiltInSubgroupLocalInvocationId();
namespace __spirv {
// Helper function templates to initialize and get vector component from SPIR-V
// built-in variables
#define __SPIRV_DEFINE_INIT_AND_GET_HELPERS(POSTFIX) \
- template <int ID> size_t get##POSTFIX(); \
- template <> inline size_t get##POSTFIX<0>() { return __spirv_##POSTFIX(0); } \
- template <> inline size_t get##POSTFIX<1>() { return __spirv_##POSTFIX(1); } \
- template <> inline size_t get##POSTFIX<2>() { return __spirv_##POSTFIX(2); } \
+ template <int ID> std::size_t get##POSTFIX(); \
+ template <> inline std::size_t get##POSTFIX<0>() { \
+ return __spirv_##POSTFIX(0); \
+ } \
+ template <> inline std::size_t get##POSTFIX<1>() { \
+ return __spirv_##POSTFIX(1); \
+ } \
+ template <> inline std::size_t get##POSTFIX<2>() { \
+ return __spirv_##POSTFIX(2); \
+ } \
\
template <int Dim, class DstT> struct InitSizesST##POSTFIX; \
\
@@ -64,7 +70,7 @@ namespace __spirv {
return InitSizesST##POSTFIX<Dims, DstT>::initSize(); \
}
-__SPIRV_DEFINE_INIT_AND_GET_HELPERS(BuiltInGlobalSize);
+__SPIRV_DEFINE_INIT_AND_GET_HELPERS(BuiltInGlobalSize)
__SPIRV_DEFINE_INIT_AND_GET_HELPERS(BuiltInGlobalInvocationId)
__SPIRV_DEFINE_INIT_AND_GET_HELPERS(BuiltInGlobalOffset)
__SPIRV_DEFINE_INIT_AND_GET_HELPERS(BuiltInWorkgroupId)
@@ -76,4 +82,4 @@ __SPIRV_DEFINE_INIT_AND_GET_HELPERS(BuiltInNumWorkgroups)
} // namespace __spirv
-#endif // _LIBSYCL___SPIRV_SPIRV_VARS
+#endif // _LIBSYCL___SPIRV_SPIRV_VARS_HPP
diff --git a/libsycl/include/sycl/sycl.hpp b/libsycl/include/sycl/sycl.hpp
index 4c5e3e62a11c8..44678228e8fa7 100644
--- a/libsycl/include/sycl/sycl.hpp
+++ b/libsycl/include/sycl/sycl.hpp
@@ -14,6 +14,9 @@
#ifndef _LIBSYCL_SYCL_HPP
#define _LIBSYCL_SYCL_HPP
+#include <sycl/__impl/aspect.hpp>
+#include <sycl/__impl/async_handler.hpp>
+#include <sycl/__impl/backend.hpp>
#include <sycl/__impl/context.hpp>
#include <sycl/__impl/device.hpp>
#include <sycl/__impl/device_selector.hpp>
@@ -21,13 +24,16 @@
#include <sycl/__impl/exception.hpp>
#include <sycl/__impl/group.hpp>
#include <sycl/__impl/group_barrier.hpp>
+#include <sycl/__impl/handler.hpp>
#include <sycl/__impl/index_space_classes.hpp>
#include <sycl/__impl/memory_enums.hpp>
#include <sycl/__impl/nd_item.hpp>
#include <sycl/__impl/nd_range.hpp>
#include <sycl/__impl/platform.hpp>
+#include <sycl/__impl/property_list.hpp>
#include <sycl/__impl/queue.hpp>
#include <sycl/__impl/sub_group.hpp>
+#include <sycl/__impl/usm_alloc_type.hpp>
#include <sycl/__impl/usm_functions.hpp>
#endif // _LIBSYCL_SYCL_HPP
diff --git a/libsycl/src/context.cpp b/libsycl/src/context.cpp
index 1f1be69e89139..67cfa998e57c9 100644
--- a/libsycl/src/context.cpp
+++ b/libsycl/src/context.cpp
@@ -21,9 +21,10 @@ _LIBSYCL_BEGIN_NAMESPACE_SYCL
context::context(const std::vector<device> &deviceList,
async_handler asyncHandler, const property_list &propList) {
- auto deviceImpls = detail::getSyclObjImpls(deviceList);
+ std::vector<detail::DeviceImpl *> DeviceImpls =
+ detail::getSyclObjImpls(deviceList);
- impl = detail::ContextImpl::create(std::move(deviceImpls), asyncHandler,
+ impl = detail::ContextImpl::create(std::move(DeviceImpls), asyncHandler,
propList);
}
diff --git a/libsycl/src/detail/context_impl.cpp b/libsycl/src/detail/context_impl.cpp
index 0525cee4535c7..c04101680049b 100644
--- a/libsycl/src/detail/context_impl.cpp
+++ b/libsycl/src/detail/context_impl.cpp
@@ -9,13 +9,16 @@
#include <detail/context_impl.hpp>
#include <detail/platform_impl.hpp>
+#include <cassert>
+#include <tuple>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
ContextImpl::ContextImpl(std::vector<DeviceImpl *> &&DeviceList,
const async_handler &AsyncHandler,
- const property_list &PropList, Private)
+ const property_list &PropList, PrivateTag)
: MAsyncHandler(AsyncHandler), MDevices(std::move(DeviceList)) {
// TODO: Remove this when property_list is implemented
std::ignore = PropList;
@@ -53,9 +56,9 @@ PlatformImpl &ContextImpl::getPlatformImpl() const {
}
void ContextImpl::iterateDevices(
- const std::function<void(DeviceImpl *)> &callback) const {
+ const std::function<void(DeviceImpl *)> &Callback) const {
for (DeviceImpl *Device : MDevices)
- callback(Device);
+ Callback(Device);
}
backend ContextImpl::getBackend() const { return MDevices[0]->getBackend(); }
diff --git a/libsycl/src/detail/context_impl.hpp b/libsycl/src/detail/context_impl.hpp
index 2b01e911aa603..c9193c47c197e 100644
--- a/libsycl/src/detail/context_impl.hpp
+++ b/libsycl/src/detail/context_impl.hpp
@@ -24,9 +24,11 @@
#include <OffloadAPI.h>
#include <functional>
+#include <memory>
#include <mutex>
#include <string_view>
#include <unordered_map>
+#include <vector>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -40,8 +42,8 @@ class DeviceImpl;
/// Context represents the runtime data structures and state required by a SYCL
/// backend API to interact with a group of devices associated with a platform.
class ContextImpl : public std::enable_shared_from_this<ContextImpl> {
- struct Private {
- explicit Private() = default;
+ struct PrivateTag {
+ explicit PrivateTag() = default;
};
public:
@@ -52,7 +54,7 @@ class ContextImpl : public std::enable_shared_from_this<ContextImpl> {
/// \param PropList is a list of context properties.
ContextImpl(std::vector<DeviceImpl *> &&DeviceList,
const async_handler &AsyncHandler, const property_list &PropList,
- Private);
+ PrivateTag);
/// Releases the underlying offload context handle.
~ContextImpl();
@@ -60,13 +62,14 @@ class ContextImpl : public std::enable_shared_from_this<ContextImpl> {
/// Gets asynchronous exception handler.
///
/// \return an instance of SYCL async_handler.
- const async_handler &get_async_handler() const { return MAsyncHandler; }
+ const async_handler &getAsyncHandler() const { return MAsyncHandler; }
- /// Constructs a ContextImpl with a provided arguments. Variadic helper.
- /// Restrics ways of ContextImpl creation.
+ /// Constructs a ContextImpl with the provided arguments. Variadic helper.
+ /// Restricts ContextImpl creation to std::shared_ptr allocations.
template <typename... Ts>
static std::shared_ptr<ContextImpl> create(Ts &&...args) {
- return std::make_shared<ContextImpl>(std::forward<Ts>(args)..., Private{});
+ return std::make_shared<ContextImpl>(std::forward<Ts>(args)...,
+ PrivateTag{});
}
/// Returns the raw underlying offload context handle.
@@ -80,9 +83,8 @@ class ContextImpl : public std::enable_shared_from_this<ContextImpl> {
/// \return the platform this context is associated with.
PlatformImpl &getPlatformImpl() const;
- /// Calls "callback" with every device associated
- /// with this context.
- void iterateDevices(const std::function<void(DeviceImpl *)> &callback) const;
+ /// Calls Callback with every device associated with this context.
+ void iterateDevices(const std::function<void(DeviceImpl *)> &Callback) const;
/// \return backend of the platform this context is associated with.
backend getBackend() const;
diff --git a/libsycl/src/detail/device_binary_structures.hpp b/libsycl/src/detail/device_binary_structures.hpp
index f453272a3647c..cd8d25b3e86ef 100644
--- a/libsycl/src/detail/device_binary_structures.hpp
+++ b/libsycl/src/detail/device_binary_structures.hpp
@@ -28,7 +28,7 @@ namespace detail {
/// to map the image type onto the device target triple.
/// SPIR-V with 64-bit pointers.
-static constexpr char DeviceBinaryTripleSPIRV64[] = "spirv64-unknown-unknown";
+inline constexpr char DeviceBinaryTripleSPIRV64[] = "spirv64-unknown-unknown";
} // namespace detail
_LIBSYCL_END_NAMESPACE_SYCL
diff --git a/libsycl/src/detail/device_image_wrapper.cpp b/libsycl/src/detail/device_image_wrapper.cpp
index 7f5582f3b680b..2f250f91c1006 100644
--- a/libsycl/src/detail/device_image_wrapper.cpp
+++ b/libsycl/src/detail/device_image_wrapper.cpp
@@ -10,14 +10,17 @@
#include <detail/offload/offload_utils.hpp>
+#include <cassert>
+#include <tuple>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
ProgramWrapper::ProgramWrapper(ol_context_handle_t Context,
ol_device_handle_t Device,
const DeviceImageManager &DevImage) {
- assert(Context);
- assert(Device);
+ assert(Context && "Context handle can't be nullptr");
+ assert(Device && "Device handle can't be nullptr");
llvm::StringRef Image = DevImage.getOffloadBinary().getImage();
callAndThrow(olCreateProgram, Context, Device, Image.data(), Image.size(),
@@ -25,7 +28,7 @@ ProgramWrapper::ProgramWrapper(ol_context_handle_t Context,
}
ProgramWrapper::~ProgramWrapper() {
- assert(MProgram);
+ assert(MProgram && "Program handle can't be nullptr");
std::ignore = olDestroyProgram(MProgram);
// TODO: define a way to report errors from dtors.
}
@@ -37,6 +40,8 @@ ProgramWrapper::getOrCreateKernel(std::string_view KernelName) {
return It->second;
ol_symbol_handle_t Kernel{};
+ // Kernel names are views into the "symbols" blob of the device image, which
+ // stores them as packed null-terminated strings, so data() is a C string.
callAndThrow(olGetSymbol, MProgram, KernelName.data(), OL_SYMBOL_KIND_KERNEL,
&Kernel);
MKernels.emplace(KernelName, Kernel);
diff --git a/libsycl/src/detail/device_image_wrapper.hpp b/libsycl/src/detail/device_image_wrapper.hpp
index 5d639a2fe2970..cd90cbef1341c 100644
--- a/libsycl/src/detail/device_image_wrapper.hpp
+++ b/libsycl/src/detail/device_image_wrapper.hpp
@@ -83,7 +83,7 @@ class ProgramWrapper {
/// This class manages data parsing of device images.
class DeviceImageManager {
public:
- DeviceImageManager(std::unique_ptr<llvm::object::OffloadBinary> Bin)
+ explicit DeviceImageManager(std::unique_ptr<llvm::object::OffloadBinary> Bin)
: MBin(std::move(Bin)) {}
// Explicitly delete copy constructor/operator= to avoid unintentional copies.
DeviceImageManager(const DeviceImageManager &) = delete;
@@ -97,7 +97,7 @@ class DeviceImageManager {
/// \return a reference to the corresponding parsed OffloadBinary object.
const llvm::object::OffloadBinary &getOffloadBinary() const { return *MBin; }
-protected:
+private:
std::unique_ptr<llvm::object::OffloadBinary> MBin;
};
diff --git a/libsycl/src/detail/device_impl.hpp b/libsycl/src/detail/device_impl.hpp
index f5012fe84c069..f327d7bec75b9 100644
--- a/libsycl/src/detail/device_impl.hpp
+++ b/libsycl/src/detail/device_impl.hpp
@@ -23,6 +23,8 @@
#include <OffloadAPI.h>
+#include <cassert>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
@@ -90,35 +92,39 @@ class DeviceImpl {
/// The return type depends on information being queried.
template <typename Param> typename Param::return_type getInfo() const {
using namespace info::device;
- using Map = info_ol_mapping<ol_device_info_t>;
+ using Map = InfoOLMapping<ol_device_info_t>;
- constexpr ol_device_info_t olInfo = map_info_desc<Param, ol_device_info_t>(
+ constexpr ol_device_info_t OLInfo = mapInfoDesc<Param, ol_device_info_t>(
Map::M<device_type>{OL_DEVICE_INFO_TYPE},
Map::M<name>{OL_DEVICE_INFO_NAME},
Map::M<vendor>{OL_DEVICE_INFO_VENDOR},
Map::M<driver_version>{OL_DEVICE_INFO_DRIVER_VERSION});
size_t ExpectedSize = 0;
- callAndThrow(olGetDeviceInfoSize, MOffloadDevice, olInfo, &ExpectedSize);
+ callAndThrow(olGetDeviceInfoSize, MOffloadDevice, OLInfo, &ExpectedSize);
if constexpr (std::is_same_v<typename Param::return_type, std::string>) {
+ assert(ExpectedSize > 0 && "String info descriptor size must account for "
+ "the null terminator");
std::string Result;
// liboffload counts null terminator in the size while std::string
// doesn't.
Result.resize(ExpectedSize - 1);
- callAndThrow(olGetDeviceInfo, MOffloadDevice, olInfo, ExpectedSize,
+ callAndThrow(olGetDeviceInfo, MOffloadDevice, OLInfo, ExpectedSize,
Result.data());
return Result;
- } else if constexpr (olInfo == OL_DEVICE_INFO_TYPE) {
+ } else if constexpr (OLInfo == OL_DEVICE_INFO_TYPE) {
assert((sizeof(typename Param::return_type) == ExpectedSize) &&
"Size of info descriptor reported by backend doesn't match with "
"expected.");
- ol_device_type_t olType{};
- callAndThrow(olGetDeviceInfo, MOffloadDevice, olInfo, sizeof(olType),
- &olType);
- return convertDeviceTypeToSYCL(olType);
- } else
- static_assert(false && "Info descriptor is not properly supported");
+ ol_device_type_t OLType{};
+ callAndThrow(olGetDeviceInfo, MOffloadDevice, OLInfo, sizeof(OLType),
+ &OLType);
+ return convertDeviceTypeToSYCL(OLType);
+ } else {
+ static_assert(AlwaysFalse<Param>,
+ "Info descriptor is not properly supported");
+ }
}
/// \return the corresponding liboffload device handle.
diff --git a/libsycl/src/detail/device_kernel_info.hpp b/libsycl/src/detail/device_kernel_info.hpp
index 7899487b05369..58e999dc4ad3a 100644
--- a/libsycl/src/detail/device_kernel_info.hpp
+++ b/libsycl/src/detail/device_kernel_info.hpp
@@ -40,7 +40,7 @@ class DeviceKernelInfo {
: MName(KernelName), MDeviceImage(DeviceImage) {}
/// \return the name of this kernel.
- std::string_view getName() { return MName; }
+ std::string_view getName() const { return MName; }
/// \return the device image containing the device code of this kernel.
DeviceImageManager &getDeviceImage() const { return MDeviceImage; }
diff --git a/libsycl/src/detail/event_impl.cpp b/libsycl/src/detail/event_impl.cpp
index 11d920a7536ab..6484025467b23 100644
--- a/libsycl/src/detail/event_impl.cpp
+++ b/libsycl/src/detail/event_impl.cpp
@@ -12,6 +12,8 @@
#include <detail/platform_impl.hpp>
#include <detail/queue_impl.hpp>
+#include <tuple>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
diff --git a/libsycl/src/detail/global_objects.cpp b/libsycl/src/detail/global_objects.cpp
index aa45961a1bee0..2f7346fbd1fff 100644
--- a/libsycl/src/detail/global_objects.cpp
+++ b/libsycl/src/detail/global_objects.cpp
@@ -11,15 +11,13 @@
#include <detail/program_manager.hpp>
#include <detail/queue_impl.hpp>
-#ifdef _WIN32
-# include <windows.h>
-#endif
-
#include <tuple>
#include <vector>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
+
+namespace {
// libsycl follows SYCL 2020 specification that doesn't declare any
// init/shutdown methods that can help to avoid usage of static variables.
// liboffload uses static variables too. In the first call of get_platforms
@@ -40,12 +38,14 @@ struct StaticVarShutdownHandler {
}
};
+} // namespace
+
void registerStaticVarShutdownHandler() {
// Touch the program manager singleton first: static objects are destroyed in
// reverse order of construction, so this guarantees it is still alive when
// ~StaticVarShutdownHandler() calls releaseResources() on it.
std::ignore = ProgramAndKernelManager::getInstance();
- static StaticVarShutdownHandler handler{};
+ static StaticVarShutdownHandler ShutdownHandler{};
}
std::array<detail::OffloadTopology, OL_PLATFORM_BACKEND_LAST> &
diff --git a/libsycl/src/detail/global_objects.hpp b/libsycl/src/detail/global_objects.hpp
index fc598ad8ce29b..c2a0ee9e353d3 100644
--- a/libsycl/src/detail/global_objects.hpp
+++ b/libsycl/src/detail/global_objects.hpp
@@ -20,6 +20,7 @@
#include <sycl/__impl/exception.hpp>
#include <array>
+#include <exception>
#include <map>
#include <memory>
#include <mutex>
@@ -38,7 +39,7 @@ template <typename T> using InstanceWithLock = std::pair<T, SpinLock>;
///
/// This vector is populated only once at the first call of get_platforms().
///
-/// \returns std::array of all offload topologies.
+/// \return std::array of all offload topologies.
std::array<detail::OffloadTopology, OL_PLATFORM_BACKEND_LAST> &
getOffloadTopologies();
@@ -47,7 +48,7 @@ getOffloadTopologies();
///
/// This vector is populated only once at the first call of get_platforms().
///
-/// \returns std::vector of implementation objects for all platforms.
+/// \return std::vector of implementation objects for all platforms.
std::vector<std::unique_ptr<PlatformImpl>> &getPlatformCache();
// This initializes a function-local variable whose destructor is invoked as
diff --git a/libsycl/src/detail/handler_impl.hpp b/libsycl/src/detail/handler_impl.hpp
index a6a8dbaa737b0..352e33a707a03 100644
--- a/libsycl/src/detail/handler_impl.hpp
+++ b/libsycl/src/detail/handler_impl.hpp
@@ -33,7 +33,7 @@ class QueueImpl;
/// Stores the deferred command group state for a sycl::handler submission.
struct HandlerImpl {
- HandlerImpl(QueueImpl &Queue) : MQueue(Queue) {}
+ explicit HandlerImpl(QueueImpl &Queue) : MQueue(Queue) {}
HandlerImpl(const HandlerImpl &) = delete;
HandlerImpl(HandlerImpl &&) = delete;
diff --git a/libsycl/src/detail/offload/offload_topology.hpp b/libsycl/src/detail/offload/offload_topology.hpp
index a9a76cc0a7669..5f1f9d2f2f192 100644
--- a/libsycl/src/detail/offload/offload_topology.hpp
+++ b/libsycl/src/detail/offload/offload_topology.hpp
@@ -42,22 +42,23 @@ struct OffloadPlatformGroup {
/// Storage of platform driver groups and their device handles for a backend.
struct OffloadTopology {
- OffloadTopology() : MBackend(OL_PLATFORM_BACKEND_UNKNOWN) {}
- OffloadTopology(ol_platform_backend_t OlBackend) : MBackend(OlBackend) {}
+ OffloadTopology() = default;
+ explicit OffloadTopology(ol_platform_backend_t OLBackend)
+ : MBackend(OLBackend) {}
/// Updates backend for this topology.
///
- /// \param B new backend value.
- void setBackend(ol_platform_backend_t B) { MBackend = B; }
+ /// \param Backend new backend value.
+ void setBackend(ol_platform_backend_t Backend) { MBackend = Backend; }
/// Queries backend of this topology.
///
- /// \returns backend of this topology.
+ /// \return backend of this topology.
ol_platform_backend_t getBackend() const { return MBackend; }
/// Returns all platform driver groups associated with this topology.
///
- /// \returns platform driver groups associated with this topology.
+ /// \return platform driver groups associated with this topology.
const std::vector<OffloadPlatformGroup> &getPlatformGroups() const {
return MPlatformGroups;
}
diff --git a/libsycl/src/detail/offload/offload_utils.cpp b/libsycl/src/detail/offload/offload_utils.cpp
index 0fc984e4b1792..3926ddbb65191 100644
--- a/libsycl/src/detail/offload/offload_utils.cpp
+++ b/libsycl/src/detail/offload/offload_utils.cpp
@@ -100,11 +100,12 @@ ol_alloc_type_t getOlAllocType(usm::alloc USMKind) {
case usm::alloc::shared:
return OL_ALLOC_TYPE_MANAGED;
case usm::alloc::unknown:
- // usm::alloc::unknown can be returned to user from get_pointer_type but it
- // can't be converted to a valid backend type.
- throw exception(sycl::make_error_code(sycl::errc::runtime),
- "USM kind is not supported");
+ break;
}
+ // usm::alloc::unknown can be returned to user from get_pointer_type but it
+ // can't be converted to a valid backend type.
+ throw exception(sycl::make_error_code(sycl::errc::runtime),
+ "USM kind is not supported");
}
ol_kernel_launch_size_args_t convertToOlRange(const UnifiedRangeView &Range) {
@@ -121,9 +122,12 @@ ol_kernel_launch_size_args_t convertToOlRange(const UnifiedRangeView &Range) {
uint32_t GroupSize[3] = {1, 1, 1};
if (Range.MLocalSize) {
for (size_t I = 0; I < Range.MDims; ++I) {
- assert(Range.MLocalSize[I] <= std::numeric_limits<uint32_t>::max() &&
- Range.MLocalSize[I] != 0);
- GroupSize[I] = static_cast<uint32_t>(Range.MLocalSize[I]);
+ assert(Range.MLocalSize[I] <= std::numeric_limits<uint32_t>::max());
+ // An empty nd_range passes checkNDRangeAndThrow() with a zero local
+ // range. Keep the group size at 1 in that case, so that the group count
+ // below is zero instead of dividing by zero.
+ if (Range.MLocalSize[I] != 0)
+ GroupSize[I] = static_cast<uint32_t>(Range.MLocalSize[I]);
}
}
@@ -139,16 +143,23 @@ ol_kernel_launch_size_args_t convertToOlRange(const UnifiedRangeView &Range) {
std::swap(GroupSize[0], GroupSize[Range.MDims - 1]);
}
- ol_kernel_launch_size_args_t olRange = {};
- olRange.Dimensions = Range.MDims;
- olRange.NumGroups.x = GlobalSize[0] / GroupSize[0];
- olRange.NumGroups.y = GlobalSize[1] / GroupSize[1];
- olRange.NumGroups.z = GlobalSize[2] / GroupSize[2];
- olRange.GroupSize.x = GroupSize[0];
- olRange.GroupSize.y = GroupSize[1];
- olRange.GroupSize.z = GroupSize[2];
- olRange.DynSharedMemory = 0;
- return olRange;
+ // nd_range submissions are validated by checkNDRangeAndThrow(), and plain
+ // range submissions have a group size of 1, so the division below is exact.
+ assert(GlobalSize[0] % GroupSize[0] == 0 &&
+ GlobalSize[1] % GroupSize[1] == 0 &&
+ GlobalSize[2] % GroupSize[2] == 0 &&
+ "Global size must be evenly divisible by group size.");
+
+ ol_kernel_launch_size_args_t OLRange = {};
+ OLRange.Dimensions = Range.MDims;
+ OLRange.NumGroups.x = GlobalSize[0] / GroupSize[0];
+ OLRange.NumGroups.y = GlobalSize[1] / GroupSize[1];
+ OLRange.NumGroups.z = GlobalSize[2] / GroupSize[2];
+ OLRange.GroupSize.x = GroupSize[0];
+ OLRange.GroupSize.y = GroupSize[1];
+ OLRange.GroupSize.z = GroupSize[2];
+ OLRange.DynSharedMemory = 0;
+ return OLRange;
}
} // namespace detail
diff --git a/libsycl/src/detail/offload/offload_utils.hpp b/libsycl/src/detail/offload/offload_utils.hpp
index f565ca86aef4d..dce24cb07b98e 100644
--- a/libsycl/src/detail/offload/offload_utils.hpp
+++ b/libsycl/src/detail/offload/offload_utils.hpp
@@ -24,6 +24,10 @@
#include <OffloadAPI.h>
+#include <string>
+#include <tuple>
+#include <utility>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
@@ -32,17 +36,19 @@ namespace detail {
///
/// \param Error liboffload error code.
///
-/// \returns C-string representing the name of Error as specified in enum.
+/// \return C-string representing the name of Error as specified in enum.
const char *stringifyErrorCode(ol_errc_t Error);
-/// Contructs C++-string with information about liboffload error.
+/// Constructs C++-string with information about liboffload error.
///
-/// \param Error liboffload result of calling API.
+/// \param Result liboffload result of calling API.
///
-/// \returns C++-string containing all available data of failure.
+/// \return C++-string containing all available data of failure.
inline std::string formatCodeString(ol_result_t Result) {
+ // liboffload leaves Details unset for errors it has no message for.
+ const char *Details = Result->Details ? Result->Details : "";
return std::to_string(Result->Code) + " (" +
- std::string(stringifyErrorCode(Result->Code)) + ") " + Result->Details;
+ std::string(stringifyErrorCode(Result->Code)) + ") " + Details;
}
inline bool isFailed(const ol_result_t &Result) { return Result != OL_SUCCESS; }
@@ -53,13 +59,13 @@ inline bool isFailed(const ol_result_t &Result) { return Result != OL_SUCCESS; }
/// To be called when specific handling is needed and explicitly done by
/// developer before throwing exception.
///
-/// \param Error liboffload result of calling API.
+/// \param Result liboffload result of calling API.
///
-/// \throw sycl::runtime_exception if the call was not successful.
-template <sycl::errc errc = sycl::errc::runtime>
+/// \throw sycl::exception with ErrC if the call was not successful.
+template <sycl::errc ErrC = sycl::errc::runtime>
void checkAndThrow(ol_result_t Result) {
if (isFailed(Result)) {
- throw sycl::exception(sycl::make_error_code(errc),
+ throw sycl::exception(sycl::make_error_code(ErrC),
detail::formatCodeString(Result));
}
}
@@ -71,7 +77,7 @@ void checkAndThrow(ol_result_t Result) {
/// \param Function liboffload API function to be called.
/// \param Args arguments to be passed to the liboffload API function.
///
-/// \returns liboffload error code returned by API call.
+/// \return liboffload error code returned by API call.
template <typename FunctionType, typename... ArgsT>
ol_result_t callNoCheck(FunctionType &Function, ArgsT &&...Args) {
return Function(std::forward<ArgsT>(Args)...);
@@ -82,7 +88,8 @@ ol_result_t callNoCheck(FunctionType &Function, ArgsT &&...Args) {
/// \param Function liboffload API function to be called.
/// \param Args arguments to be passed to the liboffload API function.
///
-/// \throw sycl::runtime_exception if the call was not successful.
+/// \throw sycl::exception with sycl::errc::runtime if the call was not
+/// successful.
template <typename FunctionType, typename... ArgsT>
void callAndThrow(FunctionType &Function, ArgsT &&...Args) {
auto Err = callNoCheck(Function, std::forward<ArgsT>(Args)...);
@@ -93,51 +100,55 @@ void callAndThrow(FunctionType &Function, ArgsT &&...Args) {
///
/// \param Backend liboffload backend.
///
-/// \returns sycl::backend matching specified liboffload backend.
+/// \return sycl::backend matching specified liboffload backend.
backend convertBackend(ol_platform_backend_t Backend);
/// Converts SYCL device type to liboffload type.
///
/// \param DeviceType SYCL device type.
///
-/// \returns ol_device_type_t matching specified SYCL device type.
+/// \return ol_device_type_t matching specified SYCL device type.
ol_device_type_t convertDeviceTypeToOL(info::device_type DeviceType);
/// Converts liboffload device type to SYCL type.
///
/// \param DeviceType liboffload device type.
///
-/// \returns SYCL device type matching specified liboffload device type.
+/// \return SYCL device type matching specified liboffload device type.
info::device_type convertDeviceTypeToSYCL(ol_device_type_t DeviceType);
/// Converts a SYCL USM kind to a liboffload type.
///
/// \param USMKind a SYCL USM kind.
///
-/// \returns ol_alloc_type_t matching the specified SYCL USM kind.
+/// \return ol_alloc_type_t matching the specified SYCL USM kind.
ol_alloc_type_t getOlAllocType(usm::alloc USMKind);
+/// Helper for static assertions in the discarded branch of an if constexpr.
+template <typename> inline constexpr bool AlwaysFalse = false;
+
/// Helper to map SYCL information descriptors to OL_<HANDLE>_INFO_<SMTH>.
///
/// Typical usage:
/// \code
-/// using Map = info_ol_mapping<ol_foo_info_t>;
-/// constexpr auto olInfo = map_info_desc<FromDesc, ol_foo_info_t>(
+/// using Map = InfoOLMapping<ol_foo_info_t>;
+/// constexpr auto OLInfo = mapInfoDesc<FromDesc, ol_foo_info_t>(
/// Map::M<DescVal0>{OL_FOO_INFO_VAL0},
/// Map::M<DescVal1>{OL_FOO_INFO_VAL1},
/// ...)
/// \endcode
-template <typename To> struct info_ol_mapping {
+template <typename To> struct InfoOLMapping {
template <typename From> struct M {
- To value;
- constexpr M(To value) : value(value) {}
+ To Value;
+ constexpr M(To Val) : Value(Val) {}
};
};
template <typename From, typename To, typename... Ts>
-constexpr To map_info_desc(typename info_ol_mapping<To>::template M<Ts>... ms) {
- return std::get<typename info_ol_mapping<To>::template M<From>>(
- std::tuple{ms...})
- .value;
+constexpr To
+mapInfoDesc(typename InfoOLMapping<To>::template M<Ts>... Mappings) {
+ return std::get<typename InfoOLMapping<To>::template M<From>>(
+ std::tuple{Mappings...})
+ .Value;
}
/// Converts a UnifiedRangeView into the liboffload
diff --git a/libsycl/src/detail/platform_impl.cpp b/libsycl/src/detail/platform_impl.cpp
index 3e09741a9d6c8..3233e5b7e2e14 100644
--- a/libsycl/src/detail/platform_impl.cpp
+++ b/libsycl/src/detail/platform_impl.cpp
@@ -16,6 +16,7 @@
#include <detail/platform_impl.hpp>
#include <algorithm>
+#include <cassert>
#include <memory>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -92,7 +93,7 @@ bool PlatformImpl::has(aspect Aspect) const {
void PlatformImpl::iterateDevices(
info::device_type DeviceType,
- std::function<void(DeviceImpl *)> callback) const {
+ const std::function<void(DeviceImpl *)> &Callback) const {
// Early exit if host/custom/accelerator device is requested:
// - host device is deprecated and not required by the SYCL 2020
// specification.
@@ -110,14 +111,14 @@ void PlatformImpl::iterateDevices(
// As a temporal solution just return the first device for DeviceType ==
// automatic.
if (DeviceType == info::device_type::automatic) {
- callback(DeviceImpls[0].get());
+ Callback(DeviceImpls[0].get());
return;
}
bool KeepAll = DeviceType == info::device_type::all;
for (auto &Impl : DeviceImpls) {
if (KeepAll || DeviceType == Impl->getDeviceType())
- callback(Impl.get());
+ Callback(Impl.get());
}
}
diff --git a/libsycl/src/detail/platform_impl.hpp b/libsycl/src/detail/platform_impl.hpp
index 5926403f96b1e..e012536c5f6ba 100644
--- a/libsycl/src/detail/platform_impl.hpp
+++ b/libsycl/src/detail/platform_impl.hpp
@@ -24,6 +24,7 @@
#include <OffloadAPI.h>
+#include <cassert>
#include <functional>
#include <memory>
#include <string>
@@ -63,13 +64,13 @@ class PlatformImpl {
~PlatformImpl() = default;
- /// \returns sycl::backend associated with this platform.
+ /// \return sycl::backend associated with this platform.
backend getBackend() const noexcept { return MBackend; }
/// Returns all SYCL platforms from all backends that are
/// available in the system.
///
- /// \returns std::vector of all platforms that are available in the system.
+ /// \return std::vector of all platforms that are available in the system.
static const std::vector<PlatformImplUPtr> &getPlatforms();
/// Returns the raw underlying offload platform handle.
@@ -97,31 +98,36 @@ class PlatformImpl {
/// The return type depends on information being queried.
template <typename Param> typename Param::return_type getInfo() const {
// For now we have only std::string properties
- static_assert(std::is_same_v<typename Param::return_type, std::string>);
+ static_assert(std::is_same_v<typename Param::return_type, std::string>,
+ "Only string platform info descriptors are supported");
using namespace info::platform;
- using Map = info_ol_mapping<ol_platform_info_t>;
+ using Map = InfoOLMapping<ol_platform_info_t>;
- constexpr ol_platform_info_t olInfo =
- map_info_desc<Param, ol_platform_info_t>(
+ constexpr ol_platform_info_t OLInfo =
+ mapInfoDesc<Param, ol_platform_info_t>(
Map::M<version>{OL_PLATFORM_INFO_VERSION},
Map::M<name>{OL_PLATFORM_INFO_NAME},
Map::M<vendor>{OL_PLATFORM_INFO_VENDOR_NAME});
size_t ExpectedSize = 0;
- callAndThrow(olGetPlatformInfoSize, MOffloadPlatform, olInfo,
+ callAndThrow(olGetPlatformInfoSize, MOffloadPlatform, OLInfo,
&ExpectedSize);
+ assert(ExpectedSize > 0 && "String info descriptor size must account for "
+ "the null terminator");
+ // liboffload counts the null terminator in the size while std::string
+ // doesn't.
std::string Result;
Result.resize(ExpectedSize - 1);
- callAndThrow(olGetPlatformInfo, MOffloadPlatform, olInfo, ExpectedSize,
+ callAndThrow(olGetPlatformInfo, MOffloadPlatform, OLInfo, ExpectedSize,
Result.data());
return Result;
}
- /// Calls "callback" with every root device of type == DeviceType associated
- /// with this platform
+ /// Calls Callback with every root device of type == DeviceType associated
+ /// with this platform.
void iterateDevices(info::device_type DeviceType,
- std::function<void(DeviceImpl *)> callback) const;
+ const std::function<void(DeviceImpl *)> &Callback) const;
/// \return the default context containing all devices in this platform.
ContextImpl &getDefaultContext();
diff --git a/libsycl/src/detail/program_manager.cpp b/libsycl/src/detail/program_manager.cpp
index c594f8fe6542e..441d7b7c94b01 100644
--- a/libsycl/src/detail/program_manager.cpp
+++ b/libsycl/src/detail/program_manager.cpp
@@ -17,6 +17,9 @@
#include <llvm/Frontend/Offloading/Utility.h>
+#include <cassert>
+#include <string>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
@@ -27,8 +30,12 @@ getDeviceKernelInfo(std::string_view KernelName) {
DeviceKernelInfo &
ProgramAndKernelManager::getDeviceKernelInfo(std::string_view KernelName) {
+ std::lock_guard<std::mutex> Guard(MDataCollectionMutex);
auto It = MDeviceKernelInfoMap.find(KernelName);
- assert(It != MDeviceKernelInfoMap.end());
+ if (It == MDeviceKernelInfoMap.end())
+ throw sycl::exception(sycl::make_error_code(sycl::errc::invalid),
+ "No registered device image provides kernel " +
+ std::string(KernelName));
return It->second;
}
@@ -89,33 +96,34 @@ void ProgramAndKernelManager::registerFatBin(const void *BinaryStart,
DeviceImageManagerVec Images;
Images.reserve(BinOrErr->size());
- std::lock_guard<std::mutex> Guard(MDataCollectionMutex);
for (std::unique_ptr<llvm::object::OffloadBinary> &OB : *BinOrErr) {
if (!checkDeviceImageValidity(*OB))
throw sycl::exception(sycl::make_error_code(sycl::errc::runtime),
"Incompatible device image.");
- llvm::StringRef Symbols = OB->getString("symbols");
-
Images.push_back(std::make_unique<DeviceImageManager>(std::move(OB)));
- DeviceImageManager &NewImageWrapper = *Images.back();
-
- llvm::offloading::sycl::forEachSymbol(Symbols, [&](llvm::StringRef Name) {
- auto It = MDeviceKernelInfoMap.find(std::string_view(Name));
- if (It == MDeviceKernelInfoMap.end()) {
- [[maybe_unused]] auto [Iterator, EmplaceSucceeded] =
- MDeviceKernelInfoMap.emplace(
- std::piecewise_construct,
- std::forward_as_tuple(std::string_view(Name)),
- std::forward_as_tuple(std::string_view(Name), NewImageWrapper));
- assert(EmplaceSucceeded && "Kernel name found in multiple images");
- }
- });
}
- [[maybe_unused]] auto [It, Inserted] =
+ std::lock_guard<std::mutex> Guard(MDataCollectionMutex);
+ // The kernel info entries below hold references to the image managers, so the
+ // images have to be installed first: nothing may be recorded in
+ // MDeviceKernelInfoMap until their owner is in place and unregisterFatBin()
+ // can reach it.
+ auto [ImagesIt, Inserted] =
MDeviceImageManagers.emplace(BinaryStart, std::move(Images));
assert(Inserted && "Fat binary registered twice");
+ if (!Inserted)
+ return;
+
+ for (const std::unique_ptr<DeviceImageManager> &Image : ImagesIt->second) {
+ llvm::StringRef Symbols = Image->getOffloadBinary().getString("symbols");
+ llvm::offloading::sycl::forEachSymbol(Symbols, [&](llvm::StringRef Name) {
+ // A kernel name may be provided by several images of the same fat binary;
+ // the first one that provides it wins.
+ MDeviceKernelInfoMap.try_emplace(std::string_view(Name),
+ std::string_view(Name), *Image);
+ });
+ }
}
void ProgramAndKernelManager::unregisterFatBin(const void *BinaryStart,
@@ -175,8 +183,8 @@ ol_symbol_handle_t ProgramAndKernelManager::getOrCreateKernel(
if (!isImageCompatible(DeviceImage, Device))
throw exception(make_error_code(errc::runtime),
- std::string("No compatible image for ") +
- KernelInfo.getName().data() + " was found");
+ "No compatible image for " +
+ std::string(KernelInfo.getName()) + " was found");
// Track the context before it caches anything, so that unregisterFatBin() can
// reach the programs it is about to create.
diff --git a/libsycl/src/detail/program_manager.hpp b/libsycl/src/detail/program_manager.hpp
index 64df1834fc8cc..3fbd5e56babd7 100644
--- a/libsycl/src/detail/program_manager.hpp
+++ b/libsycl/src/detail/program_manager.hpp
@@ -27,6 +27,7 @@
#include <memory>
#include <mutex>
+#include <string_view>
#include <unordered_map>
#include <vector>
diff --git a/libsycl/src/detail/queue_impl.cpp b/libsycl/src/detail/queue_impl.cpp
index 98ef958735f5e..0231883a71c5d 100644
--- a/libsycl/src/detail/queue_impl.cpp
+++ b/libsycl/src/detail/queue_impl.cpp
@@ -16,12 +16,18 @@
#include <detail/program_manager.hpp>
#include <algorithm>
+#include <cassert>
+#include <string>
+#include <tuple>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
+namespace {
+
thread_local bool NestedCallsDetector = false;
+
class NestedCallsTracker {
public:
NestedCallsTracker() {
@@ -40,10 +46,12 @@ class NestedCallsTracker {
bool &NestedCallsDetectorRef = NestedCallsDetector;
};
+} // namespace
+
QueueImpl::QueueImpl(const std::shared_ptr<ContextImpl> &contextImpl,
DeviceImpl &deviceImpl, const async_handler &asyncHandler,
const property_list &propList, PrivateTag)
- : MIsInorder(false), MAsyncHandler(asyncHandler), MPropList(propList),
+ : MIsInOrder(false), MAsyncHandler(asyncHandler), MPropList(propList),
MDevice(deviceImpl), MContext(contextImpl) {
assert(MContext && "Context impl ptr can't be nullptr");
@@ -121,7 +129,7 @@ void QueueImpl::submitKernelImpl(DeviceKernelInfo &KernelInfo, void *ArgData,
ol_symbol_handle_t Kernel =
detail::ProgramAndKernelManager::getInstance().getOrCreateKernel(
KernelInfo, MContext, MDevice);
- assert(Kernel);
+ assert(Kernel && "Kernel symbol can't be nullptr");
handleEventDependencies(MCurrentSubmitInfo.DepEvents);
@@ -132,24 +140,23 @@ void QueueImpl::submitKernelImpl(DeviceKernelInfo &KernelInfo, void *ArgData,
size_t ArgSizes[] = {ArgSize};
auto Result =
olLaunchKernel(MOffloadQueue, MDevice.getOLHandle(), Kernel,
- &MCurrentSubmitInfo.Range, NULL, 1, ArgPtrs, ArgSizes);
+ &MCurrentSubmitInfo.Range, nullptr, 1, ArgPtrs, ArgSizes);
if (isFailed(Result))
throw sycl::exception(sycl::make_error_code(sycl::errc::runtime),
- std::string("Kernel submission (") +
- KernelInfo.getName().data() + ") failed with " +
- formatCodeString(Result));
+ "Kernel submission (" +
+ std::string(KernelInfo.getName()) +
+ ") failed with " + formatCodeString(Result));
MCurrentSubmitInfo.LastEvent =
createEvent(std::move(MCurrentSubmitInfo.DepEvents));
}
-static ol_device_handle_t getAllocDevice(const void *ptr) {
+static ol_device_handle_t getAllocDevice(const void *Ptr) {
// TODO: consider caching this information to avoid querying it every time.
ol_device_handle_t Device{};
- [[maybe_unused]] ol_result_t Result =
- callNoCheck(olGetMemInfo, ptr, OL_MEM_INFO_DEVICE,
- sizeof(ol_device_handle_t), &Device);
+ ol_result_t Result = callNoCheck(olGetMemInfo, Ptr, OL_MEM_INFO_DEVICE,
+ sizeof(ol_device_handle_t), &Device);
if (detail::isFailed(Result)) {
// If liboffload could not find the allocation, assume it is a host one.
if (Result->Code == OL_ERRC_NOT_FOUND) {
@@ -158,13 +165,13 @@ static ol_device_handle_t getAllocDevice(const void *ptr) {
checkAndThrow(Result);
}
- assert(Device);
+ assert(Device && "Device handle can't be nullptr");
return Device;
}
-std::shared_ptr<EventImpl>
-QueueImpl::memcpy(void *Dest, const void *Src, std::size_t NumBytes,
- const std::vector<EventImplPtr> &DepEvents) {
+EventImplPtr QueueImpl::memcpy(void *Dest, const void *Src,
+ std::size_t NumBytes,
+ const std::vector<EventImplPtr> &DepEvents) {
checkEventsPlatformMatch(DepEvents, MDevice.getPlatformImpl());
if (NumBytes == 0) {
return submitWait(DepEvents);
@@ -236,7 +243,7 @@ EventImplPtr QueueImpl::submitWithHandler(const TypelessCGF &CGF) {
detail::HandlerImpl HandlerImplVal(*this);
handler Handler(HandlerImplVal);
{
- NestedCallsTracker tracker;
+ NestedCallsTracker Tracker;
CGF(Handler);
}
diff --git a/libsycl/src/detail/queue_impl.hpp b/libsycl/src/detail/queue_impl.hpp
index feaa128bc1629..7fcb1ff481ac1 100644
--- a/libsycl/src/detail/queue_impl.hpp
+++ b/libsycl/src/detail/queue_impl.hpp
@@ -20,6 +20,8 @@
#include <OffloadAPI.h>
+#include <cassert>
+#include <cstddef>
#include <memory>
#include <vector>
@@ -43,6 +45,7 @@ class QueueImpl : public std::enable_shared_from_this<QueueImpl> {
/// Constructs a SYCL queue from a device using an asyncHandler and
/// a propList.
///
+ /// \param contextImpl is a SYCL context the queue is associated with.
/// \param deviceImpl is a SYCL device that is used to dispatch tasks
/// submitted to the queue.
/// \param asyncHandler is a SYCL asynchronous exception handler.
@@ -68,7 +71,7 @@ class QueueImpl : public std::enable_shared_from_this<QueueImpl> {
DeviceImpl &getDevice() { return MDevice; }
/// \return true if and only if the queue is in order.
- bool isInOrder() const { return MIsInorder; }
+ bool isInOrder() const { return MIsInOrder; }
/// Waits for completion of all commands submitted to this queue.
void wait();
@@ -150,12 +153,12 @@ class QueueImpl : public std::enable_shared_from_this<QueueImpl> {
const std::vector<EventImplPtr> &DepEvents);
private:
- void handleEventDependencies(const std::vector<EventImplPtr> &Dep);
+ void handleEventDependencies(const std::vector<EventImplPtr> &Deps);
EventImplPtr createEvent(std::vector<EventImplPtr> &&Deps = {});
// Queue features.
ol_queue_handle_t MOffloadQueue = {};
- const bool MIsInorder;
+ const bool MIsInOrder;
const async_handler MAsyncHandler;
const property_list MPropList;
DeviceImpl &MDevice;
diff --git a/libsycl/src/device.cpp b/libsycl/src/device.cpp
index eca7beb49cb4f..2b882c0b7a541 100644
--- a/libsycl/src/device.cpp
+++ b/libsycl/src/device.cpp
@@ -12,6 +12,7 @@
#include <detail/platform_impl.hpp>
#include <algorithm>
+#include <cassert>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -31,20 +32,20 @@ std::vector<device> device::get_devices(info::device_type DeviceType) {
std::vector<device> Devices;
// Not calling platform::get_devices to avoid multiple vector packing
- for (auto &PlatformImpl : detail::PlatformImpl::getPlatforms()) {
- assert(PlatformImpl && "PlatformImpl can not be nullptr");
- PlatformImpl->iterateDevices(
- DeviceType, [&Devices](detail::DeviceImpl *DevImpl) {
- assert(DevImpl && "Device impl can't be nullptr");
- Devices.push_back(detail::createSyclObjFromImpl<device>(*DevImpl));
- });
+ for (const detail::PlatformImplUPtr &Impl :
+ detail::PlatformImpl::getPlatforms()) {
+ assert(Impl && "PlatformImpl can not be nullptr");
+ Impl->iterateDevices(DeviceType, [&Devices](detail::DeviceImpl *DevImpl) {
+ assert(DevImpl && "Device impl can't be nullptr");
+ Devices.push_back(detail::createSyclObjFromImpl<device>(*DevImpl));
+ });
}
return Devices;
}
template <info::partition_property prop>
-std::vector<device> device::create_sub_devices(size_t ComputeUnits) const {
+std::vector<device> device::create_sub_devices(size_t /*ComputeUnits*/) const {
throw exception(make_error_code(errc::feature_not_supported),
"Partitioning is not supported.");
}
@@ -55,7 +56,7 @@ device::create_sub_devices<info::partition_property::partition_equally>(
template <info::partition_property prop>
std::vector<device>
-device::create_sub_devices(const std::vector<size_t> &Counts) const {
+device::create_sub_devices(const std::vector<size_t> & /*Counts*/) const {
throw exception(make_error_code(errc::feature_not_supported),
"Partitioning is not supported.");
}
@@ -66,7 +67,7 @@ device::create_sub_devices<info::partition_property::partition_by_counts>(
template <info::partition_property prop>
std::vector<device> device::create_sub_devices(
- info::partition_affinity_domain AffinityDomain) const {
+ info::partition_affinity_domain /*AffinityDomain*/) const {
throw exception(make_error_code(errc::feature_not_supported),
"Partitioning is not supported.");
}
diff --git a/libsycl/src/device_selector.cpp b/libsycl/src/device_selector.cpp
index f53f98d1f5bb2..c916aa7d41663 100644
--- a/libsycl/src/device_selector.cpp
+++ b/libsycl/src/device_selector.cpp
@@ -27,13 +27,14 @@ static constexpr int LevelZeroBonus = 50;
static int getDevicePreference(const device &Device) {
int Score = 0;
- const auto &DeviceImpl = detail::getSyclObjImpl(Device);
+ detail::DeviceImpl *Impl = detail::getSyclObjImpl(Device);
- auto &ProgramManager = detail::ProgramAndKernelManager::getInstance();
- if (ProgramManager.hasCompatibleImage(*DeviceImpl))
+ detail::ProgramAndKernelManager &ProgramManager =
+ detail::ProgramAndKernelManager::getInstance();
+ if (ProgramManager.hasCompatibleImage(*Impl))
Score += CompatibleImageBonus;
- if (DeviceImpl->getBackend() == backend::level_zero)
+ if (Impl->getBackend() == backend::level_zero)
Score += LevelZeroBonus;
return Score;
@@ -99,12 +100,12 @@ SelectDevice(const DeviceSelectorInvocableType &DeviceSelector) {
const device *ChosenDevice = nullptr;
std::vector<device> Devices = device::get_devices();
- for (const auto &Device : Devices) {
+ for (const device &Device : Devices) {
int CurrentDevScore = DeviceSelector(Device);
if (CurrentDevScore < 0)
continue;
- if ((ChosenDeviceScore < CurrentDevScore) ||
+ if (!ChosenDevice || (ChosenDeviceScore < CurrentDevScore) ||
((ChosenDeviceScore == CurrentDevScore) &&
(getDevicePreference(*ChosenDevice) < getDevicePreference(Device)))) {
ChosenDevice = &Device;
diff --git a/libsycl/src/event.cpp b/libsycl/src/event.cpp
index 6994790ab537a..31f770a20b828 100644
--- a/libsycl/src/event.cpp
+++ b/libsycl/src/event.cpp
@@ -11,6 +11,9 @@
#include <detail/event_impl.hpp>
+#include <memory>
+#include <vector>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
event::event() : impl(detail::EventImpl::createDefaultEvent()) {}
@@ -18,9 +21,8 @@ event::event() : impl(detail::EventImpl::createDefaultEvent()) {}
backend event::get_backend() const noexcept { return impl->getBackend(); }
void event::wait(const std::vector<event> &EventList) {
- for (auto Event : EventList) {
- Event.wait();
- }
+ for (const event &Event : EventList)
+ detail::getSyclObjImpl(Event)->wait();
}
void event::wait() { impl->wait(); }
@@ -28,9 +30,8 @@ void event::wait() { impl->wait(); }
void event::wait_and_throw() { impl->waitAndThrow(); }
void event::wait_and_throw(const std::vector<event> &EventList) {
- for (auto E : EventList) {
- E.wait_and_throw();
- }
+ for (const event &Event : EventList)
+ detail::getSyclObjImpl(Event)->waitAndThrow();
}
std::vector<event> event::get_wait_list() {
@@ -38,8 +39,8 @@ std::vector<event> event::get_wait_list() {
std::vector<event> Result;
Result.reserve(WaitList.size());
- for (const auto &EventImpl : WaitList)
- Result.push_back(detail::createSyclObjFromImpl<event>(EventImpl));
+ for (const std::shared_ptr<detail::EventImpl> &Event : WaitList)
+ Result.push_back(detail::createSyclObjFromImpl<event>(Event));
return Result;
}
diff --git a/libsycl/src/exception.cpp b/libsycl/src/exception.cpp
index 4db4cff50f9f2..1abca61fc29b3 100644
--- a/libsycl/src/exception.cpp
+++ b/libsycl/src/exception.cpp
@@ -10,19 +10,21 @@
#include <sycl/__impl/detail/config.hpp>
#include <sycl/__impl/exception.hpp>
+#include <utility>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
-namespace detail {
+namespace {
class SYCLCategory : public std::error_category {
public:
const char *name() const noexcept override { return "sycl"; }
std::string message(int) const override { return "SYCL Error"; }
};
-} // namespace detail
+} // namespace
// Free functions
const std::error_category &sycl_category() noexcept {
- static const detail::SYCLCategory SYCLCategoryObj;
+ static const SYCLCategory SYCLCategoryObj;
return SYCLCategoryObj;
}
@@ -33,8 +35,8 @@ std::error_code make_error_code(sycl::errc e) noexcept {
// Exception methods implementation
exception::exception(std::error_code EC, std::shared_ptr<context> SharedPtrCtx,
const char *WhatArg)
- : MMessage(std::make_shared<std::string>(WhatArg)), MContext(SharedPtrCtx),
- MErrC(EC) {}
+ : MMessage(std::make_shared<std::string>(WhatArg)),
+ MContext(std::move(SharedPtrCtx)), MErrC(EC) {}
exception::~exception() = default;
diff --git a/libsycl/src/exception_list.cpp b/libsycl/src/exception_list.cpp
index 61409fd6db77f..e6ea5d5712025 100644
--- a/libsycl/src/exception_list.cpp
+++ b/libsycl/src/exception_list.cpp
@@ -15,7 +15,9 @@ _LIBSYCL_BEGIN_NAMESPACE_SYCL
exception_list::size_type exception_list::size() const { return MList.size(); }
-exception_list::iterator exception_list::begin() const { return MList.begin(); }
+exception_list::iterator exception_list::begin() const {
+ return MList.cbegin();
+}
exception_list::iterator exception_list::end() const { return MList.cend(); }
@@ -26,13 +28,15 @@ void detail::addAsyncException(exception_list &List,
void detail::defaultAsyncHandler(exception_list Exceptions) {
std::cerr << "Default async_handler caught exceptions:";
- for (auto &EIt : Exceptions) {
+ for (const std::exception_ptr &ExceptionPtr : Exceptions) {
try {
- if (EIt) {
- std::rethrow_exception(EIt);
+ if (ExceptionPtr) {
+ std::rethrow_exception(ExceptionPtr);
}
} catch (const std::exception &E) {
std::cerr << "\n\t" << E.what();
+ } catch (...) {
+ std::cerr << "\n\tUnknown exception";
}
}
std::cerr << std::endl;
diff --git a/libsycl/src/handler.cpp b/libsycl/src/handler.cpp
index a8cc6004098fe..33ad0cd4e3966 100644
--- a/libsycl/src/handler.cpp
+++ b/libsycl/src/handler.cpp
@@ -11,10 +11,16 @@
#include <detail/queue_impl.hpp>
#include <sycl/__impl/handler.hpp>
+#include <cstring>
+#include <functional>
+#include <memory>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
+namespace detail {
+
static void checkCommandGroupFunction(
- const std::function<std::shared_ptr<detail::EventImpl>()> &CGF) {
+ const std::function<std::shared_ptr<EventImpl>()> &CGF) {
if (CGF) {
throw sycl::exception(
sycl::make_error_code(sycl::errc::invalid),
@@ -22,9 +28,11 @@ static void checkCommandGroupFunction(
}
}
+} // namespace detail
+
void handler::submitKernelImpl(detail::DeviceKernelInfo &KernelInfo,
void *ArgData, size_t ArgSize) {
- checkCommandGroupFunction(MImpl.MCGF);
+ detail::checkCommandGroupFunction(MImpl.MCGF);
MImpl.MArgData.resize(ArgSize);
std::memcpy(MImpl.MArgData.data(), ArgData, ArgSize);
MImpl.MCGF = [this, &KernelInfo]() {
@@ -37,11 +45,11 @@ void handler::submitKernelImpl(detail::DeviceKernelInfo &KernelInfo,
}
void handler::setKernelRange(const detail::UnifiedRangeView &Range) {
- MImpl.MRange = convertToOlRange(Range);
+ MImpl.MRange = detail::convertToOlRange(Range);
}
void handler::memcpy(void *dest, const void *src, std::size_t numBytes) {
- checkCommandGroupFunction(MImpl.MCGF);
+ detail::checkCommandGroupFunction(MImpl.MCGF);
MImpl.MCGF = [this, dest, src, numBytes]() {
return MImpl.MQueue.memcpy(dest, src, numBytes,
detail::getSyclObjImpls(MDepEvents));
diff --git a/libsycl/src/platform.cpp b/libsycl/src/platform.cpp
index b5bddc82e0d9a..4b1b678dc87b5 100644
--- a/libsycl/src/platform.cpp
+++ b/libsycl/src/platform.cpp
@@ -13,18 +13,19 @@
#include <detail/device_impl.hpp>
#include <detail/platform_impl.hpp>
+#include <cassert>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
backend platform::get_backend() const noexcept { return impl->getBackend(); }
std::vector<platform> platform::get_platforms() {
- auto &PlatformImpls = detail::PlatformImpl::getPlatforms();
+ const std::vector<detail::PlatformImplUPtr> &PlatformImpls =
+ detail::PlatformImpl::getPlatforms();
std::vector<platform> Platforms;
Platforms.reserve(PlatformImpls.size());
- for (auto &PlatformImpl : PlatformImpls) {
- Platforms.emplace_back(
- detail::createSyclObjFromImpl<platform>(*PlatformImpl.get()));
- }
+ for (const detail::PlatformImplUPtr &Impl : PlatformImpls)
+ Platforms.emplace_back(detail::createSyclObjFromImpl<platform>(*Impl));
return Platforms;
}
diff --git a/libsycl/src/queue.cpp b/libsycl/src/queue.cpp
index e3ab116229564..2136d8805984a 100644
--- a/libsycl/src/queue.cpp
+++ b/libsycl/src/queue.cpp
@@ -13,6 +13,8 @@
#include <detail/device_impl.hpp>
#include <detail/queue_impl.hpp>
+#include <cassert>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
queue::queue(const context &syclContext, const device &syclDevice,
@@ -42,18 +44,18 @@ void queue::throw_asynchronous() { impl->throwAsynchronous(); }
event queue::memcpy(void *dest, const void *src, std::size_t numBytes,
const std::vector<event> &depEvents) {
- std::shared_ptr<detail::EventImpl> EventImplPtr =
+ detail::EventImplPtr Event =
impl->memcpy(dest, src, numBytes, detail::getSyclObjImpls(depEvents));
- assert(EventImplPtr);
- return detail::createSyclObjFromImpl<event>(EventImplPtr);
+ assert(Event && "Queue operation must produce an event");
+ return detail::createSyclObjFromImpl<event>(Event);
}
event queue::prefetch(void *ptr, std::size_t numBytes,
const std::vector<event> &depEvents) {
- std::shared_ptr<detail::EventImpl> EventImplPtr =
+ detail::EventImplPtr Event =
impl->prefetch(ptr, numBytes, detail::getSyclObjImpls(depEvents));
- assert(EventImplPtr);
- return detail::createSyclObjFromImpl<event>(EventImplPtr);
+ assert(Event && "Queue operation must produce an event");
+ return detail::createSyclObjFromImpl<event>(Event);
}
event queue::getLastEvent() {
@@ -70,7 +72,7 @@ void queue::submitKernelImpl(detail::DeviceKernelInfo &KernelInfo,
impl->submitKernelImpl(KernelInfo, ArgData, ArgSize);
}
-event queue::submitWithHandler(const TypelessCGF &CGF) {
+event queue::submitWithHandler(const detail::TypelessCGF &CGF) {
return detail::createSyclObjFromImpl<event>(impl->submitWithHandler(CGF));
}
diff --git a/libsycl/src/usm_functions.cpp b/libsycl/src/usm_functions.cpp
index 6354b61fbf976..02029dd9e02fb 100644
--- a/libsycl/src/usm_functions.cpp
+++ b/libsycl/src/usm_functions.cpp
@@ -14,6 +14,7 @@
#include <OffloadAPI.h>
#include <algorithm>
+#include <tuple>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -47,6 +48,8 @@ void *malloc_device(std::size_t numBytes, const queue &syclQueue,
// SYCL 2020 4.8.3.3. Host allocation functions.
+namespace detail {
+
static device getHostAllocDevice(const context &syclContext) {
auto ContextDevices = syclContext.get_devices();
@@ -55,18 +58,20 @@ static device getHostAllocDevice(const context &syclContext) {
[](const device &Dev) { return Dev.has(aspect::usm_host_allocations); });
if (It == ContextDevices.end()) {
- throw sycl::exception(
- sycl::errc::feature_not_supported,
+ throw exception(
+ make_error_code(errc::feature_not_supported),
"None of the context's devices support host USM allocations.");
}
return *It;
}
+} // namespace detail
+
void *aligned_alloc_host(size_t alignment, size_t numBytes,
const context &syclContext,
const property_list &propList) {
- auto device = getHostAllocDevice(syclContext);
- return aligned_alloc(alignment, numBytes, device, syclContext,
+ device Device = detail::getHostAllocDevice(syclContext);
+ return aligned_alloc(alignment, numBytes, Device, syclContext,
usm::alloc::host, propList);
}
@@ -117,6 +122,8 @@ void *malloc_shared(std::size_t numBytes, const queue &syclQueue,
// SYCL 2020 4.8.3.5. Parameterized allocation functions.
+namespace detail {
+
static aspect getAspectByAllocationKind(usm::alloc kind) {
switch (kind) {
case usm::alloc::host:
@@ -131,22 +138,27 @@ static aspect getAspectByAllocationKind(usm::alloc kind) {
throw exception(sycl::make_error_code(sycl::errc::invalid),
"Invalid USM allocation kind requested");
}
+ throw exception(sycl::make_error_code(sycl::errc::invalid),
+ "Unknown USM allocation kind requested");
}
+} // namespace detail
+
void *aligned_alloc(std::size_t alignment, std::size_t numBytes,
const device &syclDevice, const context &syclContext,
usm::alloc kind, const property_list &propList) {
+ std::ignore = propList;
auto ContextDevices = syclContext.get_devices();
- if (std::none_of(ContextDevices.begin(), ContextDevices.end(),
- [&syclDevice](device Dev) { return Dev == syclDevice; }))
+ if (std::none_of(
+ ContextDevices.begin(), ContextDevices.end(),
+ [&syclDevice](const device &Dev) { return Dev == syclDevice; }))
throw exception(make_error_code(errc::invalid),
"Specified device is not contained by specified context.");
- if (!syclDevice.has(getAspectByAllocationKind(kind)))
- throw sycl::exception(
- sycl::errc::feature_not_supported,
- "Device doesn't support requested kind of USM allocation");
+ if (!syclDevice.has(detail::getAspectByAllocationKind(kind)))
+ throw exception(make_error_code(errc::feature_not_supported),
+ "Device doesn't support requested kind of USM allocation");
if (!numBytes)
return nullptr;
diff --git a/libsycl/test/basic/index_space_classes.cpp b/libsycl/test/basic/index_space_classes.cpp
index 1afb70e634303..8cd81336f3db4 100644
--- a/libsycl/test/basic/index_space_classes.cpp
+++ b/libsycl/test/basic/index_space_classes.cpp
@@ -1,5 +1,5 @@
// REQUIRES: any-device
-// RUN: %clangxx -fsycl %s -o %t.out
+// RUN: %clangxx -fsycl -Wno-error=deprecated-declarations %s -o %t.out
// RUN: %t.out
//
// Unified test for sycl::range and sycl::id covering all operators defined in
@@ -277,8 +277,45 @@ void testId() {
assert(static_cast<short>(9) != ConstId);
}
+// Tests the deprecated conversion from an item without an offset to an item
+// with an offset, which must produce an all-zeros offset and keep the range,
+// the id and the linear id.
+template <int Dim> void testItemOffsetConversionForDim() {
+ const sycl::range<Dim> Extent = makeValue<sycl::range, Dim>(4, 8, 16);
+ const sycl::id<Dim> Index = makeValue<sycl::id, Dim>(2, 3, 5);
+
+ const sycl::item<Dim, false> NoOffset =
+ Builder::createItem<Dim, false>(Extent, Index);
+ const sycl::item<Dim, true> WithOffset = NoOffset;
+
+ assert(WithOffset.get_range() == Extent);
+ assert(WithOffset.get_id() == Index);
+ assert(WithOffset.get_offset() == sycl::id<Dim>{});
+ assert(WithOffset.get_linear_id() == NoOffset.get_linear_id());
+ assert((WithOffset ==
+ Builder::createItem<Dim, true>(Extent, Index, sycl::id<Dim>{})));
+}
+
+void testItem() {
+ testItemOffsetConversionForDim<1>();
+ testItemOffsetConversionForDim<2>();
+ testItemOffsetConversionForDim<3>();
+
+ // The conversion is only available on items without an offset.
+ static_assert(
+ (std::is_convertible_v<sycl::item<1, false>, sycl::item<1, true>>));
+ static_assert(
+ (!std::is_convertible_v<sycl::item<1, true>, sycl::item<1, false>>));
+
+ // An item with an offset reports the linear id relative to the offset.
+ const sycl::item<2, true> Offsetted =
+ Builder::createItem<2, true>({4, 8}, {3, 5}, {1, 1});
+ assert(Offsetted.get_linear_id() == 2 * 8 + 4);
+}
+
int main() {
testRange();
testId();
+ testItem();
return 0;
}
diff --git a/libsycl/test/basic/wrapped_usm_pointers.cpp b/libsycl/test/basic/wrapped_usm_pointers.cpp
index c936dcada4a6b..70ca2cacecb09 100644
--- a/libsycl/test/basic/wrapped_usm_pointers.cpp
+++ b/libsycl/test/basic/wrapped_usm_pointers.cpp
@@ -20,7 +20,7 @@ struct NonTrivial {
int Addition;
int *Data;
- NonTrivial(int *D, int A) : Data(D), Addition(A) {}
+ NonTrivial(int *D, int A) : Addition(A), Data(D) {}
};
struct NonTrivialDerived : NonTrivial {
diff --git a/libsycl/tools/sycl-ls/sycl-ls.cpp b/libsycl/tools/sycl-ls/sycl-ls.cpp
index 2938d767a404b..4eea25bd9b712 100644
--- a/libsycl/tools/sycl-ls/sycl-ls.cpp
+++ b/libsycl/tools/sycl-ls/sycl-ls.cpp
@@ -16,12 +16,15 @@
#include "llvm/Support/CommandLine.h"
+#include <cstdint>
+#include <cstdlib>
#include <iostream>
+#include <string>
+#include <string_view>
using namespace sycl;
-using namespace std::literals;
-inline std::string_view getBackendName(const backend &Backend) {
+static std::string_view getBackendName(backend Backend) {
switch (Backend) {
case backend::opencl:
return "opencl";
@@ -36,9 +39,8 @@ inline std::string_view getBackendName(const backend &Backend) {
return "";
}
-std::string getDeviceTypeName(const device &Device) {
- auto DeviceType = Device.get_info<info::device::device_type>();
- switch (DeviceType) {
+static std::string_view getDeviceTypeName(const device &Device) {
+ switch (Device.get_info<info::device::device_type>()) {
case info::device_type::cpu:
return "cpu";
case info::device_type::gpu:
@@ -47,9 +49,15 @@ std::string getDeviceTypeName(const device &Device) {
return "host";
case info::device_type::accelerator:
return "accelerator";
- default:
- return "unknown";
+ case info::device_type::custom:
+ return "custom";
+ case info::device_type::automatic:
+ return "automatic";
+ case info::device_type::all:
+ return "all";
}
+
+ return "unknown";
}
static void printDeviceInfo(const device &Device, bool Verbose,
@@ -75,12 +83,11 @@ static void
printSelectorChoice(const detail::DeviceSelectorInvocableType &Selector,
const std::string &Prepend) {
try {
- const auto &Device = device(Selector);
- std::string DeviceTypeName = getDeviceTypeName(Device);
- auto Platform = Device.get_info<info::device::platform>();
- auto PlatformName = Platform.get_info<info::platform::name>();
+ const device Device(Selector);
+ const platform Platform = Device.get_info<info::device::platform>();
printDeviceInfo(Device, false /*Verbose*/,
- Prepend + DeviceTypeName + ", " + PlatformName);
+ Prepend + std::string(getDeviceTypeName(Device)) + ", " +
+ Platform.get_info<info::platform::name>());
} catch (const sycl::exception &Exception) {
std::string What = Exception.what();
constexpr size_t MaxLength = 80;
@@ -125,7 +132,7 @@ int main(int argc, char **argv) {
if (Verbose) {
std::cout << "\nPlatforms: " << Platforms.size() << std::endl;
- uint32_t PlatformNum = 0;
+ std::uint32_t PlatformNum = 0;
for (const auto &Platform : Platforms) {
++PlatformNum;
auto PlatformVersion = Platform.get_info<info::platform::version>();
@@ -149,8 +156,8 @@ int main(int argc, char **argv) {
printSelectorChoice(cpu_selector_v, "cpu_selector() : ");
printSelectorChoice(gpu_selector_v, "gpu_selector() : ");
}
- } catch (sycl::exception &e) {
- std::cerr << "SYCL Exception encountered: " << e.what() << std::endl
+ } catch (const sycl::exception &Exception) {
+ std::cerr << "SYCL Exception encountered: " << Exception.what() << std::endl
<< std::endl;
return EXIT_FAILURE;
}
diff --git a/libsycl/unittests/mock/helpers.hpp b/libsycl/unittests/mock/helpers.hpp
index 387b86e7d5fea..055cad0c67ce8 100644
--- a/libsycl/unittests/mock/helpers.hpp
+++ b/libsycl/unittests/mock/helpers.hpp
@@ -29,14 +29,14 @@
namespace mock {
struct ol_dummy_handle_t {
- ol_dummy_handle_t(size_t DataSize = 0) : MStorage(DataSize) {}
+ explicit ol_dummy_handle_t(size_t DataSize = 0) : MStorage(DataSize) {}
ol_dummy_handle_t(unsigned char *Data, size_t Size) : MStorage(Size) {
std::memcpy(MStorage.data(), Data, Size);
}
std::vector<unsigned char> MStorage;
- template <typename T> const T getDataAs() const {
+ template <typename T> T getDataAs() const {
assert(MStorage.size() >= sizeof(T));
return *reinterpret_cast<const T *>(MStorage.data());
}
More information about the llvm-commits
mailing list