[llvm] [libsycl] Generic code cleanup (PR #224330)
Kseniya Tikhomirova via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 03:23:44 PDT 2026
https://github.com/KseniyaTikhomirova updated https://github.com/llvm/llvm-project/pull/224330
>From b477c65bf603cff2e7512f60b359dd3e6c4626d3 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 | 3 +-
.../__impl/detail/get_device_kernel_info.hpp | 10 +-
.../sycl/__impl/detail/kernel_arg_helpers.hpp | 28 +--
.../sycl/__impl/detail/kernel_submission.hpp | 22 +-
.../sycl/__impl/detail/linearization.hpp | 5 +-
.../include/sycl/__impl/detail/obj_utils.hpp | 21 +-
.../sycl/__impl/detail/unified_range_view.hpp | 6 +-
libsycl/include/sycl/__impl/device.hpp | 44 ++--
.../include/sycl/__impl/device_selector.hpp | 40 ++--
libsycl/include/sycl/__impl/event.hpp | 1 +
libsycl/include/sycl/__impl/exception.hpp | 23 +-
libsycl/include/sycl/__impl/group.hpp | 19 +-
libsycl/include/sycl/__impl/group_barrier.hpp | 17 +-
libsycl/include/sycl/__impl/handler.hpp | 10 +-
.../sycl/__impl/index_space_classes.hpp | 130 ++++++-----
libsycl/include/sycl/__impl/nd_item.hpp | 48 ++--
libsycl/include/sycl/__impl/nd_range.hpp | 33 ++-
libsycl/include/sycl/__impl/platform.hpp | 10 +-
libsycl/include/sycl/__impl/queue.hpp | 58 ++++-
libsycl/include/sycl/__impl/sub_group.hpp | 6 +-
libsycl/include/sycl/__impl/usm_functions.hpp | 15 +-
libsycl/include/sycl/__spirv/spirv_types.hpp | 4 +-
libsycl/include/sycl/__spirv/spirv_vars.hpp | 20 +-
libsycl/include/sycl/sycl.hpp | 6 +
libsycl/src/context.cpp | 7 +-
libsycl/src/detail/context_impl.cpp | 10 +-
libsycl/src/detail/context_impl.hpp | 31 +--
.../src/detail/device_binary_structures.hpp | 8 +-
libsycl/src/detail/device_image_wrapper.cpp | 7 +-
libsycl/src/detail/device_image_wrapper.hpp | 11 +-
libsycl/src/detail/device_impl.hpp | 36 +--
libsycl/src/detail/device_kernel_info.hpp | 8 +-
libsycl/src/detail/event_impl.cpp | 2 +
libsycl/src/detail/event_impl.hpp | 7 +-
libsycl/src/detail/global_objects.cpp | 14 +-
libsycl/src/detail/global_objects.hpp | 15 +-
libsycl/src/detail/handler_impl.hpp | 10 +-
.../src/detail/offload/offload_topology.hpp | 21 +-
libsycl/src/detail/offload/offload_utils.cpp | 37 +--
libsycl/src/detail/offload/offload_utils.hpp | 80 ++++---
libsycl/src/detail/platform_impl.cpp | 12 +-
libsycl/src/detail/platform_impl.hpp | 36 +--
libsycl/src/detail/program_manager.cpp | 49 ++--
libsycl/src/detail/program_manager.hpp | 8 +-
libsycl/src/detail/queue_impl.cpp | 47 ++--
libsycl/src/detail/queue_impl.hpp | 36 +--
libsycl/src/detail/spinlock.hpp | 6 +-
.../src/detail/suppress_extra_warnings.hpp | 6 +-
libsycl/src/device.cpp | 37 ++-
libsycl/src/device_selector.cpp | 32 +--
libsycl/src/event.cpp | 21 +-
libsycl/src/exception.cpp | 12 +-
libsycl/src/exception_list.cpp | 12 +-
libsycl/src/handler.cpp | 12 +-
libsycl/src/platform.cpp | 14 +-
libsycl/src/queue.cpp | 21 +-
libsycl/src/usm_functions.cpp | 36 +--
libsycl/test/basic/context.cpp | 45 ++--
libsycl/test/basic/get_backend.cpp | 31 +--
libsycl/test/basic/group.cpp | 4 +-
libsycl/test/basic/group_barrier.cpp | 2 +-
.../test/basic/group_barrier_device_code.cpp | 30 +--
libsycl/test/basic/group_local_id.cpp | 4 +-
.../handler_parallel_for_generic_lambda.cpp | 36 +--
...parallel_for_nd_range_invalid_arg_type.cpp | 6 +-
.../handler/handler_parallel_for_runtime.cpp | 174 +++++++-------
... => handler_single_task_named_functor.cpp} | 8 +-
.../basic/handler/submit_fn_ptr_handler.cpp | 20 +-
libsycl/test/basic/index_space_classes.cpp | 51 ++++-
.../test/basic/khr_get_default_context.cpp | 8 +-
libsycl/test/basic/linear_sub_group.cpp | 3 +-
libsycl/test/basic/nd_range.cpp | 64 +++---
libsycl/test/basic/parallel_for_indexers.cpp | 49 ++--
libsycl/test/basic/platform_get_devices.cpp | 33 +--
.../test/basic/queue_parallel_for_generic.cpp | 52 ++---
libsycl/test/basic/queue_single_task.cpp | 20 ++
.../basic/sub_group_by_value_semantics.cpp | 2 +-
libsycl/test/basic/sub_group_common.cpp | 2 +-
libsycl/test/basic/submit_fn_ptr.cpp | 20 --
libsycl/test/basic/wrapped_usm_pointers.cpp | 24 +-
.../test/usm/Inputs/fill_memset_common.hpp | 6 +
libsycl/test/usm/alloc_functions.cpp | 214 +++++++++---------
libsycl/test/usm/memcpy.cpp | 7 +-
libsycl/test/usm/prefetch.cpp | 1 +
libsycl/tools/sycl-ls/sycl-ls.cpp | 39 ++--
libsycl/unittests/common/unittests_helper.hpp | 2 +-
libsycl/unittests/context/context_ctors.cpp | 8 +
libsycl/unittests/handler/memcpy.cpp | 8 +
libsycl/unittests/handler/semantics.cpp | 11 +-
libsycl/unittests/handler/test_helpers.hpp | 24 +-
libsycl/unittests/mock/helpers.cpp | 37 ++-
libsycl/unittests/mock/helpers.hpp | 6 +-
libsycl/unittests/queue/memcpy.cpp | 9 +-
libsycl/unittests/queue/prefetch.cpp | 10 +
96 files changed, 1336 insertions(+), 1030 deletions(-)
rename libsycl/test/basic/handler/{handler_unnamed_lambda_functor.cpp => handler_single_task_named_functor.cpp} (52%)
create mode 100644 libsycl/test/basic/queue_single_task.cpp
delete mode 100644 libsycl/test/basic/submit_fn_ptr.cpp
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 e565e41cb3848..004e75f411372 100644
--- a/libsycl/include/sycl/__impl/detail/config.hpp
+++ b/libsycl/include/sycl/__impl/detail/config.hpp
@@ -21,7 +21,8 @@
#define _LIBSYCL_END_UNVERSIONED_NAMESPACE_SYCL }
#define _LIBSYCL_BEGIN_NAMESPACE_SYCL \
- _LIBSYCL_BEGIN_UNVERSIONED_NAMESPACE_SYCL inline namespace _LIBSYCL_ABI_NAMESPACE {
+ _LIBSYCL_BEGIN_UNVERSIONED_NAMESPACE_SYCL \
+ inline namespace _LIBSYCL_ABI_NAMESPACE {
#define _LIBSYCL_END_NAMESPACE_SYCL \
} \
_LIBSYCL_END_UNVERSIONED_NAMESPACE_SYCL
diff --git a/libsycl/include/sycl/__impl/detail/get_device_kernel_info.hpp b/libsycl/include/sycl/__impl/detail/get_device_kernel_info.hpp
index 8d3ce6c0028eb..bdc88a9d02adb 100644
--- a/libsycl/include/sycl/__impl/detail/get_device_kernel_info.hpp
+++ b/libsycl/include/sycl/__impl/detail/get_device_kernel_info.hpp
@@ -24,11 +24,11 @@ _LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
class DeviceKernelInfo;
-// Lifetime of the underlying `DeviceKernelInfo` is tied to the availability of
-// the `sycl_device_binaries` corresponding to this kernel. In other words, once
-// user library is unloaded (see __sycl_unregister_lib), program manager
-// destroys this `DeviceKernelInfo` object and the reference returned from here
-// becomes stale.
+/// Lifetime of the underlying `DeviceKernelInfo` is tied to the availability of
+/// the `sycl_device_binaries` corresponding to this kernel. In other words,
+/// once user library is unloaded (see __sycl_unregister_lib), program manager
+/// destroys this `DeviceKernelInfo` object and the reference returned from here
+/// becomes stale.
_LIBSYCL_EXPORT DeviceKernelInfo &getDeviceKernelInfo(std::string_view);
template <class KernelName>
diff --git a/libsycl/include/sycl/__impl/detail/kernel_arg_helpers.hpp b/libsycl/include/sycl/__impl/detail/kernel_arg_helpers.hpp
index 1e8980a7fa9af..56a2ce31a2957 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>
@@ -22,6 +22,7 @@
#include <sycl/__spirv/spirv_vars.hpp>
#include <type_traits>
+#include <utility>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -76,21 +77,21 @@ struct CheckFunctionSignature<F, RetT(Args...)> {
/// \name Helpers to extract types of lambda arguments.
/// @{
template <typename RetType, typename Func, typename Arg>
-[[maybe_unused]] static Arg member_ptr_helper(RetType (Func::*)(Arg) const);
+[[maybe_unused]] static Arg memberPtrHelper(RetType (Func::*)(Arg) const);
-// Non-const version of the above template to match functors whose
-// 'operator()' is declared w/o the 'const' qualifier.
+/// Non-const version of the above template to match functors whose
+/// 'operator()' is declared w/o the 'const' qualifier.
template <typename RetType, typename Func, typename Arg>
-[[maybe_unused]] static Arg member_ptr_helper(RetType (Func::*)(Arg));
+[[maybe_unused]] static Arg memberPtrHelper(RetType (Func::*)(Arg));
template <typename F, typename SuggestedArgType>
-decltype(member_ptr_helper(&F::operator())) argument_helper(int);
+decltype(memberPtrHelper(&F::operator())) argumentHelper(int);
template <typename F, typename SuggestedArgType>
-SuggestedArgType argument_helper(...);
+SuggestedArgType argumentHelper(...);
template <typename F, typename SuggestedArgType>
-using lambda_arg_type = decltype(argument_helper<F, SuggestedArgType>(0));
+using lambda_arg_type = decltype(argumentHelper<F, SuggestedArgType>(0));
#if __has_builtin(__type_pack_element)
template <int N, typename... Ts>
@@ -111,8 +112,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 +136,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 +151,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 +192,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..9f403079b8b19 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 "
@@ -59,13 +60,13 @@ template <typename DerivedT> class KernelSubmissionBase {
}
template <typename KN, typename... Args>
- void sycl_kernel_launch(const char *KernelName, Args &&...args) {
+ void sycl_kernel_launch(const char *KernelName, Args &&...KernelArgs) {
static_assert(
- sizeof...(args) == 1,
+ sizeof...(KernelArgs) == 1,
"sycl_kernel_launch expects only 2 arguments now: name of kernel and "
"callable object passed to kernel invocation by the user.");
- auto FirstArg = std::get<0>(std::tie(args...));
+ auto FirstArg = std::get<0>(std::tie(KernelArgs...));
static_cast<DerivedT *>(this)->submitKernelImpl(
detail::getDeviceKernelInfo<KN>(KernelName), &FirstArg,
sizeof(FirstArg));
@@ -73,9 +74,10 @@ 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 &&...RestArgs) {
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 =
@@ -111,7 +113,7 @@ template <typename DerivedT> class KernelSubmissionBase {
using NameT =
typename detail::get_kernel_name_t<KernelName, KernelType>::name;
return submitParallelFor<NameT, TransformedLambdaArgType, KernelType>(
- std::forward<Rest>(rest)...);
+ std::forward<Rest>(RestArgs)...);
}
};
diff --git a/libsycl/include/sycl/__impl/detail/linearization.hpp b/libsycl/include/sycl/__impl/detail/linearization.hpp
index c1ad4151f6aa8..2dbd75505859d 100644
--- a/libsycl/include/sycl/__impl/detail/linearization.hpp
+++ b/libsycl/include/sycl/__impl/detail/linearization.hpp
@@ -15,6 +15,7 @@
#ifndef _LIBSYCL___IMPL_DETAIL_LINEARIZATION_HPP
#define _LIBSYCL___IMPL_DETAIL_LINEARIZATION_HPP
+#include <sycl/__impl/detail/config.hpp>
#include <sycl/__impl/index_space_classes.hpp>
#include <cstddef>
@@ -24,8 +25,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..e8660c38ae3c0 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>
@@ -28,14 +29,14 @@ _LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
-// SYCL interface classes are required to contain an `impl` data member
-// which points to the corresponding implementation object. The data
-// member is required to be accessible by the `ImpUtils` class. SYCL
-// interface classes that declare the data member private or protected
-// are required to befriend the `ImpUtils` class.
+/// 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 `ImplUtils` class. SYCL
+/// interface classes that declare the data member private or protected
+/// are required to befriend the `ImplUtils` class.
struct ImplUtils {
- // Helper function to access an implementation object from a SYCL interface
- // object.
+ /// Helper function to access an implementation object from a SYCL interface
+ /// object.
template <typename SyclObject>
static const decltype(SyclObject::impl) &
getSyclObjImpl(const SyclObject &Obj) {
@@ -43,7 +44,7 @@ struct ImplUtils {
return Obj.impl;
}
- // Helper function to create a SYCL interface object from an implementation.
+ /// Helper function to create a SYCL interface object from an implementation.
template <typename SyclObject, typename Impl>
static SyclObject createSyclObjFromImpl(Impl &&ImplObj) {
if constexpr (std::is_same_v<decltype(SyclObject::impl),
@@ -86,7 +87,7 @@ SyclObject createSyclObjFromImpl(Impl &&ImplObj) {
std::forward<Impl>(ImplObj));
}
-// SYCL 2020 4.5.2. Common reference semantics (std::hash support).
+/// SYCL 2020 4.5.2. Common reference semantics (std::hash support).
template <typename T> struct HashBase {
size_t operator()(const T &Obj) const {
auto &Impl = sycl::detail::getSyclObjImpl(Obj);
diff --git a/libsycl/include/sycl/__impl/detail/unified_range_view.hpp b/libsycl/include/sycl/__impl/detail/unified_range_view.hpp
index ed8b789b47b88..1555e6a5ef0ff 100644
--- a/libsycl/include/sycl/__impl/detail/unified_range_view.hpp
+++ b/libsycl/include/sycl/__impl/detail/unified_range_view.hpp
@@ -19,6 +19,8 @@
#include <sycl/__impl/index_space_classes.hpp>
#include <sycl/__impl/nd_range.hpp>
+#include <cstddef>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
@@ -36,12 +38,12 @@ struct UnifiedRangeView {
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..432d8f07b1106 100644
--- a/libsycl/include/sycl/__impl/device.hpp
+++ b/libsycl/include/sycl/__impl/device.hpp
@@ -23,6 +23,11 @@
#include <sycl/__impl/detail/config.hpp>
#include <sycl/__impl/detail/obj_utils.hpp>
+#include <cstddef>
+#include <functional>
+#include <type_traits>
+#include <vector>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
class platform;
@@ -56,7 +61,7 @@ class _LIBSYCL_EXPORT device {
/// Constructs a SYCL device instance using the device
/// identified by the provided device selector.
- /// \param DeviceSelector is SYCL 2020 device selector, a simple callable that
+ /// \param deviceSelector is SYCL 2020 device selector, a simple callable that
/// takes a device and returns an int.
template <
typename DeviceSelector,
@@ -96,7 +101,7 @@ class _LIBSYCL_EXPORT device {
platform get_platform() const;
/// Queries this SYCL device for information requested by the template
- /// parameter param.
+ /// parameter Param.
///
/// \return device info of type described in 4.6.4.4.
template <typename Param>
@@ -111,62 +116,63 @@ class _LIBSYCL_EXPORT device {
/// Queries which optional features this device supports (if any).
///
+ /// \param asp is one of the values defined in SYCL 2020 Section 4.6.4.5.
/// \return true if this device has the given aspect.
bool has(aspect asp) const;
/// Partition device into sub devices.
///
- /// Available only when prop is info::partition_property::partition_equally.
+ /// Available only when Prop is info::partition_property::partition_equally.
/// If this SYCL device does not support
/// info::partition_property::partition_equally a feature_not_supported
/// exception will be thrown.
///
- /// \param ComputeUnits is a desired count of compute units in each sub
+ /// \param count is a desired count of compute units in each sub
/// device.
/// \return sub devices partitioned from this SYCL device equally based on the
- /// ComputeUnits parameter.
- template <info::partition_property prop>
- std::vector<device> create_sub_devices(size_t ComputeUnits) const;
+ /// count parameter.
+ template <info::partition_property Prop>
+ std::vector<device> create_sub_devices(std::size_t count) const;
/// Partition device into sub devices.
///
- /// Available only when prop is info::partition_property::partition_by_counts.
+ /// Available only when Prop is info::partition_property::partition_by_counts.
/// If this SYCL device does not support
/// info::partition_property::partition_by_counts a feature_not_supported
/// exception will be thrown.
///
- /// \param Counts is a std::vector of desired compute units in sub devices.
+ /// \param counts is a std::vector of desired compute units in sub devices.
/// \return sub devices partitioned from this SYCL device by count sizes based
- /// on the Counts parameter.
- template <info::partition_property prop>
+ /// on the counts parameter.
+ template <info::partition_property Prop>
std::vector<device>
- create_sub_devices(const std::vector<size_t> &Counts) const;
+ create_sub_devices(const std::vector<std::size_t> &counts) const;
/// Partition device into sub devices.
///
- /// Available only when prop is
+ /// Available only when Prop is
/// info::partition_property::partition_by_affinity_domain. If this SYCL
/// device does not support
/// info::partition_property::partition_by_affinity_domain or the SYCL device
/// does not support provided info::affinity_domain provided a
/// feature_not_supported exception will be thrown.
///
- /// \param AffinityDomain is one of the values described in Table 4.20 of the
+ /// \param affinityDomain is one of the values described in Table 4.20 of the
/// SYCL 2020 specification.
/// \return sub devices partitioned from this SYCL device by affinity domain
- /// based on the AffinityDomain parameter.
- template <info::partition_property prop>
+ /// based on the affinityDomain parameter.
+ template <info::partition_property Prop>
std::vector<device>
- create_sub_devices(info::partition_affinity_domain AffinityDomain) const;
+ create_sub_devices(info::partition_affinity_domain affinityDomain) const;
/// Query available SYCL devices.
///
- /// \param deviceType is one of the values described in A.3 of the SYCL 2020
+ /// \param type is one of the values described in A.3 of the SYCL 2020
/// specification.
/// \return all SYCL devices available in the system of the device type
/// specified.
static std::vector<device>
- get_devices(info::device_type deviceType = info::device_type::all);
+ get_devices(info::device_type type = info::device_type::all);
private:
device(detail::DeviceImpl &Impl) : impl(&Impl) {}
diff --git a/libsycl/include/sycl/__impl/device_selector.hpp b/libsycl/include/sycl/__impl/device_selector.hpp
index 00a5f0ec594bf..b38d0b6009862 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
@@ -49,59 +51,59 @@ SelectDevice(const DeviceSelectorInvocableType &DeviceSelector);
/// Standard device selector to select SYCL device from any supported SYCL
/// backend based on an implementation-defined heuristic.
///
-/// \param Dev device to calculate the score for.
+/// \param dev device to calculate the score for.
/// \return score value for the provided device. Further device selection is
/// based on score values.
-_LIBSYCL_EXPORT int default_selector_v(const device &Dev);
+_LIBSYCL_EXPORT int default_selector_v(const device &dev);
/// Standard device selector to select SYCL device from any supported SYCL
/// backend for which the device type is info::device_type::gpu.
///
-/// \param Dev device to calculate the score for.
+/// \param dev device to calculate the score for.
/// \return score value for the provided device. Further device selection is
/// based on score values.
-_LIBSYCL_EXPORT int gpu_selector_v(const device &Dev);
+_LIBSYCL_EXPORT int gpu_selector_v(const device &dev);
/// Standard device selector to select SYCL device from any supported SYCL
/// backend for which the device type is info::device_type::cpu.
///
-/// \param Dev device to calculate the score for.
+/// \param dev device to calculate the score for.
/// \return score value for the provided device. Further device selection is
/// based on score values.
-_LIBSYCL_EXPORT int cpu_selector_v(const device &Dev);
+_LIBSYCL_EXPORT int cpu_selector_v(const device &dev);
/// Standard device selector to select SYCL device from any supported SYCL
/// backend for which the device type is info::device_type::accelerator.
///
-/// \param Dev device to calculate the score for.
+/// \param dev device to calculate the score for.
/// \return score value for the provided device. Further device selection is
/// based on score values.
-_LIBSYCL_EXPORT int accelerator_selector_v(const device &Dev);
+_LIBSYCL_EXPORT int accelerator_selector_v(const device &dev);
/// Returns a selector object that selects a SYCL device from any supported SYCL
/// backend which contains all the requested aspects.
///
-/// \param RequireList requested aspects, i.e. for the specific device dev and
-/// each aspect devAspect from RequireList dev.has(devAspect) equals true.
-/// \param DenyList all the aspects that have to be avoided, i.e. for the
+/// \param aspectList requested aspects, i.e. for the specific device dev and
+/// each aspect devAspect from aspectList dev.has(devAspect) equals true.
+/// \param denyList all the aspects that have to be avoided, i.e. for the
/// specific device dev and each aspect devAspect from denyList
/// dev.has(devAspect) equals false.
/// \return a selector object
_LIBSYCL_EXPORT detail::DeviceSelectorInvocableType
-aspect_selector(const std::vector<aspect> &RequireList,
- const std::vector<aspect> &DenyList = {});
+aspect_selector(const std::vector<aspect> &aspectList,
+ const std::vector<aspect> &denyList = {});
/// Returns a selector object that selects a SYCL device from any supported SYCL
/// backend which contains all the requested aspects.
///
-/// \param AspectList requested aspects, i.e. for the specific device dev and
-/// each aspect devAspect from AspectList dev.has(devAspect) equals true.
+/// \param aspectList requested aspects, i.e. for the specific device dev and
+/// each aspect devAspect from aspectList dev.has(devAspect) equals true.
/// \return a selector object
template <typename... AspectListT>
-detail::DeviceSelectorInvocableType aspect_selector(AspectListT... AspectList) {
+detail::DeviceSelectorInvocableType aspect_selector(AspectListT... aspectList) {
std::vector<aspect> RequireList;
- RequireList.reserve(sizeof...(AspectList));
- (RequireList.emplace_back(AspectList), ...);
+ RequireList.reserve(sizeof...(aspectList));
+ (RequireList.emplace_back(aspectList), ...);
return aspect_selector(RequireList, {});
}
@@ -119,4 +121,4 @@ detail::DeviceSelectorInvocableType aspect_selector() {
_LIBSYCL_END_NAMESPACE_SYCL
-#endif //_LIBSYCL___IMPL_DEVICE_SELECTOR_HPP
+#endif // _LIBSYCL___IMPL_DEVICE_SELECTOR_HPP
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..62d81cee22799 100644
--- a/libsycl/include/sycl/__impl/group.hpp
+++ b/libsycl/include/sycl/__impl/group.hpp
@@ -26,7 +26,7 @@ _LIBSYCL_BEGIN_NAMESPACE_SYCL
template <int> class nd_item;
-// SYCL2020 4.9.1.7. group class.
+/// SYCL2020 4.9.1.7. group class.
/// The group class encapsulates all functionality required to represent a
/// particular work-group within a parallel execution.
template <int Dimensions = 1> class group {
@@ -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..1bc99b9d19810 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,15 +55,18 @@ 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 {};
+template <typename Group> struct GroupScope {};
-template <int Dimensions> struct group_scope<group<Dimensions>> {
+template <int Dimensions> struct GroupScope<group<Dimensions>> {
static constexpr __spirv::Scope value = __spirv::Scope::Workgroup;
};
-template <> struct group_scope<::sycl::sub_group> {
+template <> struct GroupScope<::sycl::sub_group> {
static constexpr __spirv::Scope value = __spirv::Scope::Subgroup;
};
@@ -73,9 +76,9 @@ template <> struct group_scope<::sycl::sub_group> {
/// point.
template <typename Group>
std::enable_if_t<is_group_v<Group>>
-group_barrier(Group /*G*/, memory_scope FenceScope = Group::fence_scope) {
- __spirv_ControlBarrier(detail::group_scope<Group>::value,
- detail::getScope(FenceScope),
+group_barrier(Group /*g*/, memory_scope fence_scope = Group::fence_scope) {
+ __spirv_ControlBarrier(detail::GroupScope<Group>::value,
+ detail::getScope(fence_scope),
__spirv::MemorySemanticsMask::SequentiallyConsistent |
__spirv::MemorySemanticsMask::SubgroupMemory |
__spirv::MemorySemanticsMask::WorkgroupMemory);
diff --git a/libsycl/include/sycl/__impl/handler.hpp b/libsycl/include/sycl/__impl/handler.hpp
index 099950ddc7cb8..7de62b739328c 100644
--- a/libsycl/include/sycl/__impl/handler.hpp
+++ b/libsycl/include/sycl/__impl/handler.hpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
///
+/// \file
/// This file contains the declaration of the SYCL handler class, which provides
/// the interface for the commands that can be executed inside the command group
/// scope.
@@ -24,10 +25,9 @@
#include <sycl/__impl/exception.hpp>
#include <sycl/__impl/index_space_classes.hpp>
-#include <array>
-#include <cstring>
+#include <cstddef>
#include <memory>
-#include <type_traits>
+#include <utility>
#include <vector>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -127,6 +127,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);
@@ -137,7 +139,7 @@ class _LIBSYCL_EXPORT handler : private detail::KernelSubmissionBase<handler> {
std::shared_ptr<detail::EventImpl> finalize();
void submitKernelImpl(detail::DeviceKernelInfo &KernelInfo, void *ArgData,
- size_t ArgSize);
+ std::size_t ArgSize);
void setKernelRange(const detail::UnifiedRangeView &Range = {});
diff --git a/libsycl/include/sycl/__impl/index_space_classes.hpp b/libsycl/include/sycl/__impl/index_space_classes.hpp
index 8f99d03d004ee..d86d62f0adf39 100644
--- a/libsycl/include/sycl/__impl/index_space_classes.hpp
+++ b/libsycl/include/sycl/__impl/index_space_classes.hpp
@@ -65,24 +65,24 @@ template <typename Derived, int Dimensions> class IndexSpaceBase {
/// Returns the value for the specified dimension.
/// Results in undefined behavior if dimension is not in the range [0,
/// Dimensions).
- /// \param Dimension the dimension to return the value for.
+ /// \param dimension the dimension to return the value for.
/// \return the value matching the requested dimension.
- std::size_t get(int Dimension) const noexcept { return MArray[Dimension]; }
+ std::size_t get(int dimension) const noexcept { return MArray[dimension]; }
/// Returns the value for the specified dimension.
/// Results in undefined behavior if dimension is not in the range [0,
/// Dimensions).
- /// \param Dimension the dimension to return the value for.
+ /// \param dimension the dimension to return the value for.
/// \return the value matching the requested dimension.
- std::size_t &operator[](int Dimension) noexcept { return MArray[Dimension]; }
+ std::size_t &operator[](int dimension) noexcept { return MArray[dimension]; }
/// Returns the value for the specified dimension.
/// Results in undefined behavior if dimension is not in the range [0,
/// Dimensions).
- /// \param Dimension the dimension to return the value for.
+ /// \param dimension the dimension to return the value for.
/// \return the value matching the requested dimension.
- std::size_t operator[](int Dimension) const noexcept {
- return MArray[Dimension];
+ std::size_t operator[](int dimension) const noexcept {
+ return MArray[dimension];
}
IndexSpaceBase(const IndexSpaceBase<Derived, Dimensions> &rhs) = default;
@@ -95,8 +95,8 @@ template <typename Derived, int Dimensions> class IndexSpaceBase {
friend bool operator==(const IndexSpaceBase<Derived, Dimensions> &lhs,
const IndexSpaceBase<Derived, Dimensions> &rhs) {
- for (int i = 0; i < Dimensions; ++i) {
- if (lhs.MArray[i] != rhs.MArray[i]) {
+ for (int I = 0; I < Dimensions; ++I) {
+ if (lhs.MArray[I] != rhs.MArray[I]) {
return false;
}
}
@@ -111,31 +111,34 @@ template <typename Derived, int Dimensions> class IndexSpaceBase {
#define _LIBSYCL_GEN_OPT(op) \
friend Derived operator op(const Derived &lhs, \
const Derived &rhs) noexcept { \
- Derived result; \
- for (int i = 0; i < Dimensions; ++i) { \
- result.MArray[i] = lhs.MArray[i] op rhs.MArray[i]; \
+ Derived Result; \
+ for (int I = 0; I < Dimensions; ++I) { \
+ Result.MArray[I] = lhs.MArray[I] op rhs.MArray[I]; \
} \
- return result; \
+ return Result; \
} \
\
template <typename T> \
friend IntegralType<T, Derived> operator op(const Derived &lhs, \
const T &rhs) noexcept { \
- Derived result; \
- for (int i = 0; i < Dimensions; ++i) { \
- result.MArray[i] = lhs.MArray[i] op rhs; \
+ /* 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 Scalar; \
} \
- return result; \
+ return Result; \
} \
\
template <typename T> \
friend IntegralType<T, Derived> operator op(const T &lhs, \
const Derived &rhs) noexcept { \
- Derived result; \
- for (int i = 0; i < Dimensions; ++i) { \
- result.MArray[i] = lhs op rhs.MArray[i]; \
+ const std::size_t Scalar = static_cast<std::size_t>(lhs); \
+ Derived Result; \
+ for (int I = 0; I < Dimensions; ++I) { \
+ Result.MArray[I] = Scalar op rhs.MArray[I]; \
} \
- return result; \
+ return Result; \
}
_LIBSYCL_GEN_OPT(+)
@@ -159,16 +162,16 @@ template <typename Derived, int Dimensions> class IndexSpaceBase {
#define _LIBSYCL_GEN_OPT(op) \
friend Derived &operator op(Derived &lhs, const Derived &rhs) noexcept { \
- for (int i = 0; i < Dimensions; ++i) { \
- lhs.MArray[i] op rhs[i]; \
+ for (int I = 0; I < Dimensions; ++I) { \
+ lhs.MArray[I] op rhs[I]; \
} \
return lhs; \
} \
template <typename T> \
friend IntegralType<T, Derived> &operator op(Derived &lhs, \
const T &rhs) noexcept { \
- for (int i = 0; i < Dimensions; ++i) { \
- lhs.MArray[i] op rhs; \
+ for (int I = 0; I < Dimensions; ++I) { \
+ lhs.MArray[I] op rhs; \
} \
return lhs; \
}
@@ -188,11 +191,11 @@ template <typename Derived, int Dimensions> class IndexSpaceBase {
#define _LIBSYCL_GEN_OPT(op) \
friend Derived operator op(const Derived &rhs) noexcept { \
- Derived result; \
- for (int i = 0; i < Dimensions; ++i) { \
- result.MArray[i] = (op rhs.MArray[i]); \
+ Derived Result; \
+ for (int I = 0; I < Dimensions; ++I) { \
+ Result.MArray[I] = (op rhs.MArray[I]); \
} \
- return result; \
+ return Result; \
}
_LIBSYCL_GEN_OPT(+)
@@ -202,17 +205,17 @@ template <typename Derived, int Dimensions> class IndexSpaceBase {
#define _LIBSYCL_GEN_OPT(op) \
friend Derived &operator op(Derived &rhs) noexcept { \
- for (int i = 0; i < Dimensions; ++i) { \
- op rhs.MArray[i]; \
+ for (int I = 0; I < Dimensions; ++I) { \
+ op rhs.MArray[I]; \
} \
return rhs; \
} \
friend Derived operator op(Derived &lhs, int) noexcept { \
- Derived oldLhs(lhs); \
- for (int i = 0; i < Dimensions; ++i) { \
- op lhs.MArray[i]; \
+ Derived OldLhs(lhs); \
+ for (int I = 0; I < Dimensions; ++I) { \
+ op lhs.MArray[I]; \
} \
- return oldLhs; \
+ return OldLhs; \
}
_LIBSYCL_GEN_OPT(++)
@@ -267,13 +270,13 @@ 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) {
- size *= Base::MArray[i];
+ std::size_t Size = 1;
+ for (int I = 0; I < Dimensions; ++I) {
+ Size *= Base::MArray[I];
}
- return size;
+ return Size;
}
};
@@ -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,36 +518,34 @@ 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];
}
}
protected:
template <bool HasOffset = WithOffset,
std::enable_if_t<HasOffset == true, bool> = true>
- item(const sycl::range<Dimensions> &range, const sycl::id<Dimensions> &id,
- const sycl::id<Dimensions> &offset)
- : MRange(range), MId(id), MOffset(offset) {}
+ item(const sycl::range<Dimensions> &Range, const sycl::id<Dimensions> &Id,
+ const sycl::id<Dimensions> &Offset)
+ : MRange(Range), MId(Id), MOffset(Offset) {}
template <bool HasOffset = WithOffset,
std::enable_if_t<HasOffset == false, bool> = true>
- item(const range<Dimensions> &range, const id<Dimensions> &id)
- : MRange(range), MId(id), MOffset() {}
+ item(const range<Dimensions> &Range, const id<Dimensions> &Id)
+ : MRange(Range), MId(Id), MOffset() {}
private:
range<Dimensions> MRange;
@@ -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..5677149b1fb55 100644
--- a/libsycl/include/sycl/__impl/nd_item.hpp
+++ b/libsycl/include/sycl/__impl/nd_item.hpp
@@ -30,7 +30,7 @@ namespace detail {
class Builder;
} // namespace detail
-// SYCL2020 4.9.1.5. nd_item class.
+/// SYCL2020 4.9.1.5. nd_item class.
/// nd_item<int Dimensions> identifies an instance of the function object
/// executing at each point in an nd_range<int Dimensions> passed to a
/// parallel_for call.
@@ -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 getGroupId()[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(getGroupId(), 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>>());
}
@@ -173,7 +165,7 @@ template <int Dimensions = 1> class nd_item {
nd_item() = default;
- id<Dimensions> get_group_id() const {
+ id<Dimensions> getGroupId() const {
return __spirv::initBuiltInWorkgroupId<Dimensions, id<Dimensions>>();
}
};
diff --git a/libsycl/include/sycl/__impl/nd_range.hpp b/libsycl/include/sycl/__impl/nd_range.hpp
index 7577b4bdd1315..321dd63d061a1 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.
+/// 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..5d55d1045f442 100644
--- a/libsycl/include/sycl/__impl/platform.hpp
+++ b/libsycl/include/sycl/__impl/platform.hpp
@@ -22,7 +22,7 @@
#include <sycl/__impl/info/device_type.hpp>
#include <sycl/__impl/info/platform.hpp>
-#include <memory>
+#include <functional>
#include <vector>
#define SYCL_KHR_DEFAULT_CONTEXT 1
@@ -68,10 +68,10 @@ class _LIBSYCL_EXPORT platform {
/// If there are no devices that match given device
/// type, resulting vector is empty.
///
- /// \param DeviceType is a SYCL device type.
+ /// \param type is a SYCL device type.
/// \return a vector of SYCL devices matching given device type.
std::vector<device>
- get_devices(info::device_type DeviceType = info::device_type::all) const;
+ get_devices(info::device_type type = info::device_type::all) const;
/// Queries this SYCL platform for info.
///
@@ -89,11 +89,11 @@ class _LIBSYCL_EXPORT platform {
/// Indicates if all of the SYCL devices on this platform have the
/// given aspect.
///
- /// \param Aspect is one of the values defined in SYCL 2020 Section 4.6.4.5.
+ /// \param asp is one of the values defined in SYCL 2020 Section 4.6.4.5.
///
/// \return true if all of the SYCL devices on this platform have the
/// given aspect.
- bool has(aspect Aspect) const;
+ bool has(aspect asp) const;
/// Returns all SYCL platforms from all backends that are available in the
/// system.
diff --git a/libsycl/include/sycl/__impl/queue.hpp b/libsycl/include/sycl/__impl/queue.hpp
index 936ea5991fd05..07b52ee61bbed 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:
@@ -69,8 +75,8 @@ class TypelessCGF {
// NOTE: Even if `F` is a pointer to a function, `&F` is a pointer to a
// pointer to a function and as such can be cast to `void *` (pointer to
// a function cannot be cast).
- : Object(static_cast<const void *>(&F)),
- InvokerF(&Invoker<std::remove_reference_t<T>>::call) {}
+ : MObject(static_cast<const void *>(&F)),
+ MInvokerF(&Invoker<std::remove_reference_t<T>>::call) {}
~TypelessCGF() = default;
TypelessCGF(const TypelessCGF &) = delete;
@@ -78,7 +84,7 @@ class TypelessCGF {
TypelessCGF &operator=(const TypelessCGF &) = delete;
TypelessCGF &operator=(TypelessCGF &&) = delete;
- void operator()(handler &CGH) const { InvokerF(Object, CGH); }
+ void operator()(handler &CGH) const { MInvokerF(MObject, CGH); }
private:
// SYCL 2020 command group function object is a type that is callable with
@@ -90,11 +96,13 @@ class TypelessCGF {
(*const_cast<T *>(static_cast<const T *>(Object)))(CGH);
}
};
- const void *Object;
+ const void *MObject;
using InvokerTy = void (*)(const void *, handler &);
- const InvokerTy InvokerF;
+ const InvokerTy MInvokerF;
};
+} // namespace detail
+
// SYCL 2020 4.6.5. Queue class.
class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
public:
@@ -449,12 +457,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) {
@@ -463,6 +490,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) {
@@ -660,6 +698,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);
@@ -681,7 +721,7 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
/// \param ArgData a pointer to the kernel argument.
/// \param ArgSize the size of the kernel argument.
void submitKernelImpl(detail::DeviceKernelInfo &KernelInfo, void *ArgData,
- size_t ArgSize);
+ std::size_t ArgSize);
/// \return an event representing last kernel invocation.
event getLastEvent();
@@ -699,7 +739,7 @@ class _LIBSYCL_EXPORT queue : private detail::KernelSubmissionBase<queue> {
event fillImpl(void *Ptr, const void *Pattern, std::size_t PatternSize,
std::size_t Count, const std::vector<event> &DepEvents);
- 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..60868ca223e42 100644
--- a/libsycl/include/sycl/__impl/sub_group.hpp
+++ b/libsycl/include/sycl/__impl/sub_group.hpp
@@ -25,7 +25,7 @@ _LIBSYCL_BEGIN_NAMESPACE_SYCL
template <int> class nd_item;
-// SYCL 2020 4.9.1.8. sub_group class.
+/// SYCL 2020 4.9.1.8. sub_group class.
/// The sub_group class encapsulates all functionality required to represent a
/// particular sub-group within a parallel execution.
class sub_group {
@@ -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..0faae83c1aef1 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,9 +579,10 @@ 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.
+/// 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);
@@ -589,9 +591,10 @@ _LIBSYCL_EXPORT void free(void *ptr, const context &ctxt);
/// Equivalent to free(ptr, q.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.
+/// 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 q a queue to determine the context associated with ptr.
_LIBSYCL_EXPORT void free(void *ptr, const queue &q);
/// @}
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 c6dc0c099dcdf..4209166d28ac1 100644
--- a/libsycl/include/sycl/__spirv/spirv_vars.hpp
+++ b/libsycl/include/sycl/__spirv/spirv_vars.hpp
@@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL___SPIRV_SPIRV_VARS
-#define _LIBSYCL___SPIRV_SPIRV_VARS
+#ifndef _LIBSYCL___SPIRV_SPIRV_VARS_HPP
+#define _LIBSYCL___SPIRV_SPIRV_VARS_HPP
#include <__clang_spirv_builtins.h>
@@ -24,10 +24,16 @@ 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; \
\
@@ -61,4 +67,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..6eb2371d74cf1 100644
--- a/libsycl/src/context.cpp
+++ b/libsycl/src/context.cpp
@@ -13,17 +13,18 @@
#include <detail/context_impl.hpp>
#include <detail/platform_impl.hpp>
-#include <algorithm>
#include <cassert>
+#include <utility>
#include <vector>
_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 0362c3d9241f0..c07aa19e15dfa 100644
--- a/libsycl/src/detail/context_impl.cpp
+++ b/libsycl/src/detail/context_impl.cpp
@@ -9,13 +9,17 @@
#include <detail/context_impl.hpp>
#include <detail/platform_impl.hpp>
+#include <cassert>
+#include <tuple>
+#include <utility>
+
_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 +57,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..7a63582929376 100644
--- a/libsycl/src/detail/context_impl.hpp
+++ b/libsycl/src/detail/context_impl.hpp
@@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL_CONTEXT_IMPL
-#define _LIBSYCL_CONTEXT_IMPL
+#ifndef _LIBSYCL_SRC_DETAIL_CONTEXT_IMPL_HPP
+#define _LIBSYCL_SRC_DETAIL_CONTEXT_IMPL_HPP
#include <sycl/__impl/async_handler.hpp>
#include <sycl/__impl/context.hpp>
@@ -24,9 +24,12 @@
#include <OffloadAPI.h>
#include <functional>
+#include <memory>
#include <mutex>
#include <string_view>
#include <unordered_map>
+#include <utility>
+#include <vector>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -40,8 +43,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 +55,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 +63,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{});
+ static std::shared_ptr<ContextImpl> create(Ts &&...Args) {
+ return std::make_shared<ContextImpl>(std::forward<Ts>(Args)...,
+ PrivateTag{});
}
/// Returns the raw underlying offload context handle.
@@ -80,9 +84,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;
@@ -130,4 +133,4 @@ class ContextImpl : public std::enable_shared_from_this<ContextImpl> {
_LIBSYCL_END_NAMESPACE_SYCL
-#endif // _LIBSYCL_CONTEXT_IMPL
+#endif // _LIBSYCL_SRC_DETAIL_CONTEXT_IMPL_HPP
diff --git a/libsycl/src/detail/device_binary_structures.hpp b/libsycl/src/detail/device_binary_structures.hpp
index f453272a3647c..0ec7b42661e69 100644
--- a/libsycl/src/detail/device_binary_structures.hpp
+++ b/libsycl/src/detail/device_binary_structures.hpp
@@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL_DEVICE_BINARY_STRUCTURES
-#define _LIBSYCL_DEVICE_BINARY_STRUCTURES
+#ifndef _LIBSYCL_SRC_DETAIL_DEVICE_BINARY_STRUCTURES_HPP
+#define _LIBSYCL_SRC_DETAIL_DEVICE_BINARY_STRUCTURES_HPP
#include <sycl/__impl/detail/config.hpp>
@@ -28,9 +28,9 @@ 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
-#endif // _LIBSYCL_DEVICE_BINARY_STRUCTURES
+#endif // _LIBSYCL_SRC_DETAIL_DEVICE_BINARY_STRUCTURES_HPP
diff --git a/libsycl/src/detail/device_image_wrapper.cpp b/libsycl/src/detail/device_image_wrapper.cpp
index 9133a28035524..c298b51e49077 100644
--- a/libsycl/src/detail/device_image_wrapper.cpp
+++ b/libsycl/src/detail/device_image_wrapper.cpp
@@ -11,6 +11,9 @@
#include <detail/context_impl.hpp>
#include <detail/offload/offload_utils.hpp>
+#include <cassert>
+#include <tuple>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
@@ -26,7 +29,7 @@ ProgramWrapper::ProgramWrapper(ContextImpl &Context, ol_device_handle_t Device,
}
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.
}
@@ -38,6 +41,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(MContext, 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 171e1a25393d2..d66e2b1e623e9 100644
--- a/libsycl/src/detail/device_image_wrapper.hpp
+++ b/libsycl/src/detail/device_image_wrapper.hpp
@@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL_DEVICE_IMAGE_WRAPPER
-#define _LIBSYCL_DEVICE_IMAGE_WRAPPER
+#ifndef _LIBSYCL_SRC_DETAIL_DEVICE_IMAGE_WRAPPER_HPP
+#define _LIBSYCL_SRC_DETAIL_DEVICE_IMAGE_WRAPPER_HPP
#include <sycl/__impl/detail/config.hpp>
@@ -28,6 +28,7 @@ _LIBSYCL_SUPPRESS_EXTRA_WARNINGS_END
#include <memory>
#include <string_view>
#include <unordered_map>
+#include <utility>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
@@ -90,7 +91,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;
@@ -104,7 +105,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;
};
@@ -112,4 +113,4 @@ class DeviceImageManager {
_LIBSYCL_END_NAMESPACE_SYCL
-#endif // _LIBSYCL_DEVICE_IMAGE_WRAPPER
+#endif // _LIBSYCL_SRC_DETAIL_DEVICE_IMAGE_WRAPPER_HPP
diff --git a/libsycl/src/detail/device_impl.hpp b/libsycl/src/detail/device_impl.hpp
index f5012fe84c069..af76ad8f7a710 100644
--- a/libsycl/src/detail/device_impl.hpp
+++ b/libsycl/src/detail/device_impl.hpp
@@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL_DEVICE_IMPL
-#define _LIBSYCL_DEVICE_IMPL
+#ifndef _LIBSYCL_SRC_DETAIL_DEVICE_IMPL_HPP
+#define _LIBSYCL_SRC_DETAIL_DEVICE_IMPL_HPP
#include <sycl/__impl/detail/config.hpp>
#include <sycl/__impl/device.hpp>
@@ -23,6 +23,10 @@
#include <OffloadAPI.h>
+#include <cassert>
+#include <string>
+#include <type_traits>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
@@ -90,35 +94,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.
@@ -133,4 +141,4 @@ class DeviceImpl {
_LIBSYCL_END_NAMESPACE_SYCL
-#endif // _LIBSYCL_DEVICE_IMPL
+#endif // _LIBSYCL_SRC_DETAIL_DEVICE_IMPL_HPP
diff --git a/libsycl/src/detail/device_kernel_info.hpp b/libsycl/src/detail/device_kernel_info.hpp
index 7899487b05369..448e885984492 100644
--- a/libsycl/src/detail/device_kernel_info.hpp
+++ b/libsycl/src/detail/device_kernel_info.hpp
@@ -13,8 +13,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL_DEVICE_KERNEL_INFO
-#define _LIBSYCL_DEVICE_KERNEL_INFO
+#ifndef _LIBSYCL_SRC_DETAIL_DEVICE_KERNEL_INFO_HPP
+#define _LIBSYCL_SRC_DETAIL_DEVICE_KERNEL_INFO_HPP
#include <sycl/__impl/detail/config.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; }
@@ -54,4 +54,4 @@ class DeviceKernelInfo {
_LIBSYCL_END_NAMESPACE_SYCL
-#endif // _LIBSYCL_DEVICE_KERNEL_INFO
+#endif // _LIBSYCL_SRC_DETAIL_DEVICE_KERNEL_INFO_HPP
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/event_impl.hpp b/libsycl/src/detail/event_impl.hpp
index 23c910a39cfe9..e1890595846f2 100644
--- a/libsycl/src/detail/event_impl.hpp
+++ b/libsycl/src/detail/event_impl.hpp
@@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL_EVENT_IMPL
-#define _LIBSYCL_EVENT_IMPL
+#ifndef _LIBSYCL_SRC_DETAIL_EVENT_IMPL_HPP
+#define _LIBSYCL_SRC_DETAIL_EVENT_IMPL_HPP
#include <sycl/__impl/backend.hpp>
#include <sycl/__impl/detail/config.hpp>
@@ -21,6 +21,7 @@
#include <OffloadAPI.h>
#include <memory>
+#include <utility>
#include <vector>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -102,4 +103,4 @@ class EventImpl {
_LIBSYCL_END_NAMESPACE_SYCL
-#endif // _LIBSYCL_EVENT_IMPL
+#endif // _LIBSYCL_SRC_DETAIL_EVENT_IMPL_HPP
diff --git a/libsycl/src/detail/global_objects.cpp b/libsycl/src/detail/global_objects.cpp
index 0ef13295d513d..55f46b2ccf01a 100644
--- a/libsycl/src/detail/global_objects.cpp
+++ b/libsycl/src/detail/global_objects.cpp
@@ -12,10 +12,6 @@
#include <detail/program_manager.hpp>
#include <detail/queue_impl.hpp>
-#ifdef _WIN32
-# include <windows.h>
-#endif
-
#include <cassert>
#include <tuple>
#include <utility>
@@ -23,6 +19,8 @@
_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
@@ -43,12 +41,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> &
@@ -104,8 +104,8 @@ void flushAsyncExceptions() {
}
if (std::shared_ptr<ContextImpl> Context = WeakContext.lock();
- Context && Context->get_async_handler()) {
- Context->get_async_handler()(std::move(Exceptions));
+ Context && Context->getAsyncHandler()) {
+ Context->getAsyncHandler()(std::move(Exceptions));
continue;
}
diff --git a/libsycl/src/detail/global_objects.hpp b/libsycl/src/detail/global_objects.hpp
index 4200d8ab1b841..539eca31b88b5 100644
--- a/libsycl/src/detail/global_objects.hpp
+++ b/libsycl/src/detail/global_objects.hpp
@@ -11,8 +11,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL_GLOBAL_OBJECTS
-#define _LIBSYCL_GLOBAL_OBJECTS
+#ifndef _LIBSYCL_SRC_DETAIL_GLOBAL_OBJECTS_HPP
+#define _LIBSYCL_SRC_DETAIL_GLOBAL_OBJECTS_HPP
#include <detail/offload/offload_topology.hpp>
#include <detail/spinlock.hpp>
@@ -20,6 +20,7 @@
#include <sycl/__impl/exception.hpp>
#include <array>
+#include <exception>
#include <map>
#include <memory>
#include <mutex>
@@ -39,7 +40,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();
@@ -48,11 +49,11 @@ 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
-// the SYCL shared library is first being unloaded.
+/// This initializes a function-local variable whose destructor is invoked as
+/// the SYCL shared library is first being unloaded.
void registerStaticVarShutdownHandler();
using AsyncExceptionKey =
@@ -89,4 +90,4 @@ void flushAsyncExceptions();
} // namespace detail
_LIBSYCL_END_NAMESPACE_SYCL
-#endif // _LIBSYCL_GLOBAL_OBJECTS
+#endif // _LIBSYCL_SRC_DETAIL_GLOBAL_OBJECTS_HPP
diff --git a/libsycl/src/detail/handler_impl.hpp b/libsycl/src/detail/handler_impl.hpp
index a6a8dbaa737b0..eaea667720bb4 100644
--- a/libsycl/src/detail/handler_impl.hpp
+++ b/libsycl/src/detail/handler_impl.hpp
@@ -13,8 +13,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL_HANDLER_IMPL
-#define _LIBSYCL_HANDLER_IMPL
+#ifndef _LIBSYCL_SRC_DETAIL_HANDLER_IMPL_HPP
+#define _LIBSYCL_SRC_DETAIL_HANDLER_IMPL_HPP
#include <sycl/__impl/detail/config.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;
@@ -42,7 +42,7 @@ struct HandlerImpl {
~HandlerImpl() = default;
- // Queue this handler is attached to.
+ /// Queue this handler is attached to.
QueueImpl &MQueue;
/// The command group function to execute at finalize time.
@@ -59,4 +59,4 @@ struct HandlerImpl {
_LIBSYCL_END_NAMESPACE_SYCL
-#endif // _LIBSYCL_HANDLER_IMPL
+#endif // _LIBSYCL_SRC_DETAIL_HANDLER_IMPL_HPP
diff --git a/libsycl/src/detail/offload/offload_topology.hpp b/libsycl/src/detail/offload/offload_topology.hpp
index a9a76cc0a7669..5ab830b4822e5 100644
--- a/libsycl/src/detail/offload/offload_topology.hpp
+++ b/libsycl/src/detail/offload/offload_topology.hpp
@@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL_OFFLOAD_TOPOLOGY
-#define _LIBSYCL_OFFLOAD_TOPOLOGY
+#ifndef _LIBSYCL_SRC_DETAIL_OFFLOAD_OFFLOAD_TOPOLOGY_HPP
+#define _LIBSYCL_SRC_DETAIL_OFFLOAD_OFFLOAD_TOPOLOGY_HPP
#include <sycl/__impl/detail/config.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;
}
@@ -74,11 +75,11 @@ struct OffloadTopology {
std::vector<OffloadPlatformGroup> MPlatformGroups;
};
-// Initialize the topologies by calling olIterateDevices.
+/// Initialize the topologies by calling olIterateDevices.
void discoverOffloadDevices();
} // namespace detail
_LIBSYCL_END_NAMESPACE_SYCL
-#endif // _LIBSYCL_OFFLOAD_TOPOLOGY
+#endif // _LIBSYCL_SRC_DETAIL_OFFLOAD_OFFLOAD_TOPOLOGY_HPP
diff --git a/libsycl/src/detail/offload/offload_utils.cpp b/libsycl/src/detail/offload/offload_utils.cpp
index 0fc984e4b1792..e0fc4e42e7d2e 100644
--- a/libsycl/src/detail/offload/offload_utils.cpp
+++ b/libsycl/src/detail/offload/offload_utils.cpp
@@ -9,6 +9,7 @@
#include <detail/offload/offload_utils.hpp>
#include <cassert>
+#include <cstdint>
#include <limits>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -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 4a4512083e8ee..d5c3f56654893 100644
--- a/libsycl/src/detail/offload/offload_utils.hpp
+++ b/libsycl/src/detail/offload/offload_utils.hpp
@@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL_OFFLOAD_UTILS
-#define _LIBSYCL_OFFLOAD_UTILS
+#ifndef _LIBSYCL_SRC_DETAIL_OFFLOAD_OFFLOAD_UTILS_HPP
+#define _LIBSYCL_SRC_DETAIL_OFFLOAD_OFFLOAD_UTILS_HPP
#include <sycl/__impl/backend.hpp>
#include <sycl/__impl/context.hpp>
@@ -25,6 +25,10 @@
#include <OffloadAPI.h>
+#include <string>
+#include <tuple>
+#include <utility>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
@@ -35,17 +39,19 @@ class ContextImpl;
///
/// \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; }
@@ -56,13 +62,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));
}
}
@@ -76,12 +82,12 @@ void checkAndThrow(ol_result_t Result) {
/// \param Context the context the failed API call was made for.
/// \param Result the liboffload result of calling API.
///
-/// \throw sycl::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(ContextImpl &Context, ol_result_t Result) {
if (isFailed(Result)) {
throw sycl::exception(createSyclObjFromImpl<sycl::context>(Context),
- sycl::make_error_code(errc),
+ sycl::make_error_code(ErrC),
detail::formatCodeString(Result));
}
}
@@ -93,7 +99,7 @@ void checkAndThrow(ContextImpl &Context, 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)...);
@@ -104,7 +110,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)...);
@@ -117,7 +124,8 @@ void callAndThrow(FunctionType &Function, ArgsT &&...Args) {
/// \param Function the liboffload API function to be called.
/// \param Args the arguments to be passed to the liboffload API function.
///
-/// \throw sycl::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(ContextImpl &Context, FunctionType &Function,
ArgsT &&...Args) {
@@ -129,51 +137,55 @@ void callAndThrow(ContextImpl &Context, FunctionType &Function,
///
/// \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>(
-/// Map::M<DescVal0>{OL_FOO_INFO_VAL0},
-/// Map::M<DescVal1>{OL_FOO_INFO_VAL1},
-/// ...)
+/// 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
@@ -184,4 +196,4 @@ ol_kernel_launch_size_args_t convertToOlRange(const UnifiedRangeView &Range);
_LIBSYCL_END_NAMESPACE_SYCL
-#endif // _LIBSYCL_OFFLOAD_UTILS
+#endif // _LIBSYCL_SRC_DETAIL_OFFLOAD_OFFLOAD_UTILS_HPP
diff --git a/libsycl/src/detail/platform_impl.cpp b/libsycl/src/detail/platform_impl.cpp
index 3e09741a9d6c8..91e699e149d55 100644
--- a/libsycl/src/detail/platform_impl.cpp
+++ b/libsycl/src/detail/platform_impl.cpp
@@ -16,13 +16,15 @@
#include <detail/platform_impl.hpp>
#include <algorithm>
+#include <cassert>
#include <memory>
+#include <utility>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
-bool PlatformImpl::rediscoverIfEmpty = false;
+bool PlatformImpl::MRediscoverIfEmpty = false;
const std::vector<PlatformImplUPtr> &PlatformImpl::getPlatforms() {
static auto InitPlatforms = []() {
@@ -47,7 +49,7 @@ const std::vector<PlatformImplUPtr> &PlatformImpl::getPlatforms() {
return true;
}();
auto &PlatformCache = getPlatformCache();
- if (rediscoverIfEmpty && PlatformCache.empty())
+ if (MRediscoverIfEmpty && PlatformCache.empty())
InitPlatforms();
return PlatformCache;
@@ -92,7 +94,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 +112,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..6233dabe08f9e 100644
--- a/libsycl/src/detail/platform_impl.hpp
+++ b/libsycl/src/detail/platform_impl.hpp
@@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL_PLATFORM_IMPL
-#define _LIBSYCL_PLATFORM_IMPL
+#ifndef _LIBSYCL_SRC_DETAIL_PLATFORM_IMPL_HPP
+#define _LIBSYCL_SRC_DETAIL_PLATFORM_IMPL_HPP
#include <sycl/__impl/backend.hpp>
#include <sycl/__impl/detail/config.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();
@@ -142,11 +148,11 @@ class PlatformImpl {
// unittests for this behavior. This flag and friend class allows to force
// device & platform rediscovery at the next getPlatforms() call if the cache
// is empty.
- static bool rediscoverIfEmpty;
+ static bool MRediscoverIfEmpty;
friend struct ::sycl::unittests::UnittestsHelper;
};
} // namespace detail
_LIBSYCL_END_NAMESPACE_SYCL
-#endif // _LIBSYCL_PLATFORM_IMPL
+#endif // _LIBSYCL_SRC_DETAIL_PLATFORM_IMPL_HPP
diff --git a/libsycl/src/detail/program_manager.cpp b/libsycl/src/detail/program_manager.cpp
index 12a38a8b75053..836b5c9525eb6 100644
--- a/libsycl/src/detail/program_manager.cpp
+++ b/libsycl/src/detail/program_manager.cpp
@@ -19,6 +19,10 @@ _LIBSYCL_SUPPRESS_EXTRA_WARNINGS_BEGIN
#include <llvm/Frontend/Offloading/Utility.h>
_LIBSYCL_SUPPRESS_EXTRA_WARNINGS_END
+#include <cassert>
+#include <string>
+#include <utility>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
@@ -29,8 +33,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;
}
@@ -91,33 +99,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,
@@ -177,8 +186,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 afe660add63f7..47db03a59c042 100644
--- a/libsycl/src/detail/program_manager.hpp
+++ b/libsycl/src/detail/program_manager.hpp
@@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL_PROGRAM_MANAGER
-#define _LIBSYCL_PROGRAM_MANAGER
+#ifndef _LIBSYCL_SRC_DETAIL_PROGRAM_MANAGER_HPP
+#define _LIBSYCL_SRC_DETAIL_PROGRAM_MANAGER_HPP
#include <sycl/__impl/detail/config.hpp>
@@ -28,8 +28,10 @@ _LIBSYCL_SUPPRESS_EXTRA_WARNINGS_END
#include <OffloadAPI.h>
+#include <cstddef>
#include <memory>
#include <mutex>
+#include <string_view>
#include <unordered_map>
#include <vector>
@@ -150,4 +152,4 @@ class ProgramAndKernelManager {
} // namespace detail
_LIBSYCL_END_NAMESPACE_SYCL
-#endif // _LIBSYCL_PROGRAM_MANAGER
+#endif // _LIBSYCL_SRC_DETAIL_PROGRAM_MANAGER_HPP
diff --git a/libsycl/src/detail/queue_impl.cpp b/libsycl/src/detail/queue_impl.cpp
index 5163d8e795673..aa9dca26038ff 100644
--- a/libsycl/src/detail/queue_impl.cpp
+++ b/libsycl/src/detail/queue_impl.cpp
@@ -16,16 +16,23 @@
#include <detail/program_manager.hpp>
#include <algorithm>
+#include <cassert>
#include <cstdint>
+#include <string>
+#include <tuple>
+#include <utility>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace detail {
+namespace {
+
thread_local bool NestedCallsDetector = false;
+
class NestedCallsTracker {
public:
- NestedCallsTracker(ContextImpl &QueueContext) {
+ explicit NestedCallsTracker(ContextImpl &QueueContext) {
if (NestedCallsDetectorRef)
throw sycl::exception(
createSyclObjFromImpl<context>(QueueContext),
@@ -42,11 +49,13 @@ class NestedCallsTracker {
bool &NestedCallsDetectorRef = NestedCallsDetector;
};
-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),
- MDevice(deviceImpl), MContext(contextImpl) {
+} // namespace
+
+QueueImpl::QueueImpl(const std::shared_ptr<ContextImpl> &Context,
+ DeviceImpl &Device, const async_handler &AsyncHandler,
+ const property_list &PropList, PrivateTag)
+ : MIsInOrder(false), MAsyncHandler(AsyncHandler), MPropList(PropList),
+ MDevice(Device), MContext(Context) {
assert(MContext && "Context impl ptr can't be nullptr");
ol_result_t Err = callNoCheck(olCreateQueue, MContext->getOLHandleRef(),
@@ -131,7 +140,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);
@@ -142,25 +151,25 @@ 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(createSyclObjFromImpl<context>(*MContext),
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(ContextImpl &Context,
- const void *ptr) {
+ 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, Context.getOLHandleRef(), ptr,
+ ol_result_t Result =
+ callNoCheck(olGetMemInfo, Context.getOLHandleRef(), Ptr,
OL_MEM_INFO_DEVICE, sizeof(ol_device_handle_t), &Device);
if (detail::isFailed(Result)) {
// NOT_FOUND: the pointer isn't a liboffload allocation at all (plain host
@@ -173,13 +182,13 @@ static ol_device_handle_t getAllocDevice(ContextImpl &Context,
checkAndThrow(Context, 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) {
assert(MContext && "Context impl ptr can't be nullptr");
checkEventsPlatformMatch(DepEvents, *MContext);
if (NumBytes == 0)
@@ -276,7 +285,7 @@ EventImplPtr QueueImpl::submitWithHandler(const TypelessCGF &CGF) {
detail::HandlerImpl HandlerImplVal(*this);
handler Handler(HandlerImplVal);
{
- NestedCallsTracker tracker(*MContext);
+ NestedCallsTracker Tracker(*MContext);
CGF(Handler);
}
diff --git a/libsycl/src/detail/queue_impl.hpp b/libsycl/src/detail/queue_impl.hpp
index 1b6bee63251f6..34fc6391ae92b 100644
--- a/libsycl/src/detail/queue_impl.hpp
+++ b/libsycl/src/detail/queue_impl.hpp
@@ -12,15 +12,18 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL_QUEUE_IMPL
-#define _LIBSYCL_QUEUE_IMPL
+#ifndef _LIBSYCL_SRC_DETAIL_QUEUE_IMPL_HPP
+#define _LIBSYCL_SRC_DETAIL_QUEUE_IMPL_HPP
#include <sycl/__impl/detail/config.hpp>
#include <sycl/__impl/queue.hpp>
#include <OffloadAPI.h>
+#include <cassert>
+#include <cstddef>
#include <memory>
+#include <utility>
#include <vector>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -40,22 +43,23 @@ class QueueImpl : public std::enable_shared_from_this<QueueImpl> {
public:
~QueueImpl();
- /// Constructs a SYCL queue from a device using an asyncHandler and
- /// a propList.
+ /// Constructs a SYCL queue from a device using an AsyncHandler and
+ /// a PropList.
///
- /// \param deviceImpl is a SYCL device that is used to dispatch tasks
+ /// \param Context is a SYCL context the queue is associated with.
+ /// \param Device is a SYCL device that is used to dispatch tasks
/// submitted to the queue.
- /// \param asyncHandler is a SYCL asynchronous exception handler.
- /// \param propList is a list of properties to use for queue construction.
- explicit QueueImpl(const std::shared_ptr<ContextImpl> &contextImpl,
- DeviceImpl &deviceImpl, const async_handler &asyncHandler,
- const property_list &propList, PrivateTag);
+ /// \param AsyncHandler is a SYCL asynchronous exception handler.
+ /// \param PropList is a list of properties to use for queue construction.
+ explicit QueueImpl(const std::shared_ptr<ContextImpl> &Context,
+ DeviceImpl &Device, const async_handler &AsyncHandler,
+ const property_list &PropList, PrivateTag);
/// Constructs a QueueImpl with the provided arguments. Variadic helper.
/// Restricts QueueImpl creation to std::shared_ptr allocations.
template <typename... Ts>
- static std::shared_ptr<QueueImpl> create(Ts &&...args) {
- return std::make_shared<QueueImpl>(std::forward<Ts>(args)..., PrivateTag{});
+ static std::shared_ptr<QueueImpl> create(Ts &&...Args) {
+ return std::make_shared<QueueImpl>(std::forward<Ts>(Args)..., PrivateTag{});
}
/// \return the SYCL backend this queue is associated with.
@@ -72,7 +76,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();
@@ -167,12 +171,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;
@@ -193,4 +197,4 @@ class QueueImpl : public std::enable_shared_from_this<QueueImpl> {
_LIBSYCL_END_NAMESPACE_SYCL
-#endif // _LIBSYCL_QUEUE_IMPL
+#endif // _LIBSYCL_SRC_DETAIL_QUEUE_IMPL_HPP
diff --git a/libsycl/src/detail/spinlock.hpp b/libsycl/src/detail/spinlock.hpp
index a8898a4e68463..82d5453dac4cd 100644
--- a/libsycl/src/detail/spinlock.hpp
+++ b/libsycl/src/detail/spinlock.hpp
@@ -11,8 +11,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL_SPINLOCK
-#define _LIBSYCL_SPINLOCK
+#ifndef _LIBSYCL_SRC_DETAIL_SPINLOCK_HPP
+#define _LIBSYCL_SRC_DETAIL_SPINLOCK_HPP
#include <sycl/__impl/detail/config.hpp>
@@ -44,4 +44,4 @@ class SpinLock {
_LIBSYCL_END_NAMESPACE_SYCL
-#endif // _LIBSYCL_SPINLOCK
+#endif // _LIBSYCL_SRC_DETAIL_SPINLOCK_HPP
diff --git a/libsycl/src/detail/suppress_extra_warnings.hpp b/libsycl/src/detail/suppress_extra_warnings.hpp
index e6fcbb65a432e..8b1645ab34d37 100644
--- a/libsycl/src/detail/suppress_extra_warnings.hpp
+++ b/libsycl/src/detail/suppress_extra_warnings.hpp
@@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef _LIBSYCL_SUPPRESS_EXTRA_WARNINGS
-#define _LIBSYCL_SUPPRESS_EXTRA_WARNINGS
+#ifndef _LIBSYCL_SRC_DETAIL_SUPPRESS_EXTRA_WARNINGS_HPP
+#define _LIBSYCL_SRC_DETAIL_SUPPRESS_EXTRA_WARNINGS_HPP
#define _LIBSYCL_DO_PRAGMA(x) _Pragma(#x)
#define _LIBSYCL_SUPPRESS_EXTRA_WARNINGS_BEGIN \
@@ -22,4 +22,4 @@
#define _LIBSYCL_SUPPRESS_EXTRA_WARNINGS_END \
_LIBSYCL_DO_PRAGMA(GCC diagnostic pop)
-#endif // _LIBSYCL_SUPPRESS_EXTRA_WARNINGS
+#endif // _LIBSYCL_SRC_DETAIL_SUPPRESS_EXTRA_WARNINGS_HPP
diff --git a/libsycl/src/device.cpp b/libsycl/src/device.cpp
index eca7beb49cb4f..c9ba322ab63ab 100644
--- a/libsycl/src/device.cpp
+++ b/libsycl/src/device.cpp
@@ -11,7 +11,7 @@
#include <detail/device_impl.hpp>
#include <detail/platform_impl.hpp>
-#include <algorithm>
+#include <cassert>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -27,55 +27,54 @@ platform device::get_platform() const {
backend device::get_backend() const noexcept { return impl->getBackend(); }
-std::vector<device> device::get_devices(info::device_type DeviceType) {
+std::vector<device> device::get_devices(info::device_type type) {
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 auto &Impl : detail::PlatformImpl::getPlatforms()) {
+ assert(Impl && "PlatformImpl can not be nullptr");
+ Impl->iterateDevices(type, [&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 {
+template <info::partition_property Prop>
+std::vector<device> device::create_sub_devices(std::size_t /*count*/) const {
throw exception(make_error_code(errc::feature_not_supported),
"Partitioning is not supported.");
}
template _LIBSYCL_EXPORT std::vector<device>
device::create_sub_devices<info::partition_property::partition_equally>(
- size_t ComputeUnits) const;
+ std::size_t count) const;
-template <info::partition_property prop>
+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<std::size_t> & /*counts*/) const {
throw exception(make_error_code(errc::feature_not_supported),
"Partitioning is not supported.");
}
template _LIBSYCL_EXPORT std::vector<device>
device::create_sub_devices<info::partition_property::partition_by_counts>(
- const std::vector<size_t> &Counts) const;
+ const std::vector<std::size_t> &counts) const;
-template <info::partition_property prop>
+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.");
}
template _LIBSYCL_EXPORT std::vector<device> device::create_sub_devices<
info::partition_property::partition_by_affinity_domain>(
- info::partition_affinity_domain AffinityDomain) const;
+ info::partition_affinity_domain affinityDomain) const;
-bool device::has(aspect Aspect) const { return impl->has(Aspect); }
+bool device::has(aspect asp) const { return impl->has(asp); }
template <typename Param>
detail::is_device_info_desc_t<Param> device::get_info() const {
diff --git a/libsycl/src/device_selector.cpp b/libsycl/src/device_selector.cpp
index f53f98d1f5bb2..ac77a3f13e587 100644
--- a/libsycl/src/device_selector.cpp
+++ b/libsycl/src/device_selector.cpp
@@ -27,13 +27,13 @@ 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))
+ if (ProgramManager.hasCompatibleImage(*Impl))
Score += CompatibleImageBonus;
- if (DeviceImpl->getBackend() == backend::level_zero)
+ if (Impl->getBackend() == backend::level_zero)
Score += LevelZeroBonus;
return Score;
@@ -52,39 +52,39 @@ _LIBSYCL_EXPORT int default_selector_v(const device &dev) {
return Score;
}
-_LIBSYCL_EXPORT int gpu_selector_v(const device &Dev) {
- return Dev.is_gpu() ? MatchedTypeDefaultScore + getDevicePreference(Dev)
+_LIBSYCL_EXPORT int gpu_selector_v(const device &dev) {
+ return dev.is_gpu() ? MatchedTypeDefaultScore + getDevicePreference(dev)
: RejectDeviceScore;
}
-_LIBSYCL_EXPORT int cpu_selector_v(const device &Dev) {
- return Dev.is_cpu() ? MatchedTypeDefaultScore + getDevicePreference(Dev)
+_LIBSYCL_EXPORT int cpu_selector_v(const device &dev) {
+ return dev.is_cpu() ? MatchedTypeDefaultScore + getDevicePreference(dev)
: RejectDeviceScore;
}
-_LIBSYCL_EXPORT int accelerator_selector_v(const device &Dev) {
- return Dev.is_accelerator()
- ? MatchedTypeDefaultScore + getDevicePreference(Dev)
+_LIBSYCL_EXPORT int accelerator_selector_v(const device &dev) {
+ return dev.is_accelerator()
+ ? MatchedTypeDefaultScore + getDevicePreference(dev)
: RejectDeviceScore;
}
_LIBSYCL_EXPORT detail::DeviceSelectorInvocableType
-aspect_selector(const std::vector<aspect> &RequireList,
- const std::vector<aspect> &DenyList) {
+aspect_selector(const std::vector<aspect> &aspectList,
+ const std::vector<aspect> &denyList) {
return [=](const sycl::device &Dev) {
// 4.6.1.1. Device selector:
// If no aspects are passed in, the generated selector behaves like
// default_selector_v.
- if (RequireList.empty() && DenyList.empty())
+ if (aspectList.empty() && denyList.empty())
return default_selector_v(Dev);
auto HasAspect = [&Dev](const aspect &Aspect) -> bool {
return Dev.has(Aspect);
};
- if (!std::all_of(RequireList.begin(), RequireList.end(), HasAspect))
+ if (!std::all_of(aspectList.begin(), aspectList.end(), HasAspect))
return RejectDeviceScore;
- if (std::any_of(DenyList.begin(), DenyList.end(), HasAspect))
+ if (std::any_of(denyList.begin(), denyList.end(), HasAspect))
return RejectDeviceScore;
return MatchedTypeDefaultScore + getDevicePreference(Dev);
@@ -104,7 +104,7 @@ SelectDevice(const DeviceSelectorInvocableType &DeviceSelector) {
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..3fd8c99e558d9 100644
--- a/libsycl/src/event.cpp
+++ b/libsycl/src/event.cpp
@@ -11,26 +11,27 @@
#include <detail/event_impl.hpp>
+#include <memory>
+#include <vector>
+
_LIBSYCL_BEGIN_NAMESPACE_SYCL
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();
- }
+void event::wait(const std::vector<event> &eventList) {
+ for (const event &Event : eventList)
+ detail::getSyclObjImpl(Event)->wait();
}
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();
- }
+void event::wait_and_throw(const std::vector<event> &eventList) {
+ 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 auto &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 72f05f51ca661..b5def894a6e73 100644
--- a/libsycl/src/handler.cpp
+++ b/libsycl/src/handler.cpp
@@ -6,11 +6,17 @@
//
//===----------------------------------------------------------------------===//
+#include <sycl/__impl/handler.hpp>
+
#include <detail/context_impl.hpp>
#include <detail/handler_impl.hpp>
#include <detail/offload/offload_utils.hpp>
#include <detail/queue_impl.hpp>
-#include <sycl/__impl/handler.hpp>
+
+#include <cstring>
+#include <functional>
+#include <memory>
+#include <utility>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -26,7 +32,7 @@ static void checkCommandGroupFunction(
}
void handler::submitKernelImpl(detail::DeviceKernelInfo &KernelInfo,
- void *ArgData, size_t ArgSize) {
+ void *ArgData, std::size_t ArgSize) {
checkCommandGroupFunction(MImpl.MCGF, MImpl.MQueue.getContext());
MImpl.MArgData.resize(ArgSize);
std::memcpy(MImpl.MArgData.data(), ArgData, ArgSize);
@@ -40,7 +46,7 @@ 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) {
diff --git a/libsycl/src/platform.cpp b/libsycl/src/platform.cpp
index b5bddc82e0d9a..ffef0152e4682 100644
--- a/libsycl/src/platform.cpp
+++ b/libsycl/src/platform.cpp
@@ -13,6 +13,8 @@
#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(); }
@@ -21,16 +23,14 @@ std::vector<platform> platform::get_platforms() {
auto &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 auto &Impl : PlatformImpls)
+ Platforms.emplace_back(detail::createSyclObjFromImpl<platform>(*Impl));
return Platforms;
}
-std::vector<device> platform::get_devices(info::device_type DeviceType) const {
+std::vector<device> platform::get_devices(info::device_type type) const {
std::vector<device> Devices;
- impl->iterateDevices(DeviceType, [&Devices](detail::DeviceImpl *DevImpl) {
+ impl->iterateDevices(type, [&Devices](detail::DeviceImpl *DevImpl) {
assert(DevImpl && "Device impl can't be nullptr");
Devices.push_back(detail::createSyclObjFromImpl<device>(*DevImpl));
});
@@ -38,7 +38,7 @@ std::vector<device> platform::get_devices(info::device_type DeviceType) const {
return Devices;
}
-bool platform::has(aspect Aspect) const { return impl->has(Aspect); }
+bool platform::has(aspect asp) const { return impl->has(asp); }
template <typename Param>
detail::is_platform_info_desc_t<Param> platform::get_info() const {
diff --git a/libsycl/src/queue.cpp b/libsycl/src/queue.cpp
index 468698eb06712..99edb2fdb2ec6 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,
@@ -25,8 +27,7 @@ queue::queue(const context &syclContext, const device &syclDevice,
queue::queue(const context &syclContext, const device &syclDevice,
const property_list &propList)
: queue(syclContext, syclDevice,
- detail::getSyclObjImpl(syclContext)->get_async_handler(),
- propList) {}
+ detail::getSyclObjImpl(syclContext)->getAsyncHandler(), propList) {}
backend queue::get_backend() const noexcept { return impl->getBackend(); }
@@ -48,18 +49,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() {
@@ -72,7 +73,7 @@ void queue::setKernelLaunchParams(const std::vector<event> &Events,
}
void queue::submitKernelImpl(detail::DeviceKernelInfo &KernelInfo,
- void *ArgData, size_t ArgSize) {
+ void *ArgData, std::size_t ArgSize) {
impl->submitKernelImpl(KernelInfo, ArgData, ArgSize);
}
@@ -84,7 +85,7 @@ event queue::fillImpl(void *Ptr, const void *Pattern, std::size_t PatternSize,
return detail::createSyclObjFromImpl<event>(EventImplPtr);
}
-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 f6278bd43df71..c643e998196bf 100644
--- a/libsycl/src/usm_functions.cpp
+++ b/libsycl/src/usm_functions.cpp
@@ -20,14 +20,14 @@ _LIBSYCL_BEGIN_NAMESPACE_SYCL
// SYCL 2020 4.8.3.2. Device allocation functions.
-void *aligned_alloc_device(size_t alignment, size_t numBytes,
+void *aligned_alloc_device(std::size_t alignment, std::size_t numBytes,
const device &syclDevice, const context &syclContext,
const property_list &propList) {
return aligned_alloc(alignment, numBytes, syclDevice, syclContext,
usm::alloc::device, propList);
}
-void *aligned_alloc_device(size_t alignment, size_t numBytes,
+void *aligned_alloc_device(std::size_t alignment, std::size_t numBytes,
const queue &syclQueue,
const property_list &propList) {
return aligned_alloc_device(alignment, numBytes, syclQueue.get_device(),
@@ -56,22 +56,22 @@ static device getHostAllocDevice(const context &syclContext) {
[](const device &Dev) { return Dev.has(aspect::usm_host_allocations); });
if (It == ContextDevices.end()) {
- throw sycl::exception(
- syclContext, sycl::errc::feature_not_supported,
+ throw exception(
+ syclContext, make_error_code(errc::feature_not_supported),
"None of the context's devices support host USM allocations.");
}
return *It;
}
-void *aligned_alloc_host(size_t alignment, size_t numBytes,
+void *aligned_alloc_host(std::size_t alignment, std::size_t numBytes,
const context &syclContext,
const property_list &propList) {
- auto device = getHostAllocDevice(syclContext);
- return aligned_alloc(alignment, numBytes, device, syclContext,
+ device Device = getHostAllocDevice(syclContext);
+ return aligned_alloc(alignment, numBytes, Device, syclContext,
usm::alloc::host, propList);
}
-void *aligned_alloc_host(size_t alignment, size_t numBytes,
+void *aligned_alloc_host(std::size_t alignment, std::size_t numBytes,
const queue &syclQueue,
const property_list &propList) {
return aligned_alloc_host(alignment, numBytes, syclQueue.get_context(),
@@ -90,14 +90,14 @@ void *malloc_host(std::size_t numBytes, const queue &syclQueue,
// SYCL 2020 4.8.3.4. Shared allocation functions.
-void *aligned_alloc_shared(size_t alignment, size_t numBytes,
+void *aligned_alloc_shared(std::size_t alignment, std::size_t numBytes,
const device &syclDevice, const context &syclContext,
const property_list &propList) {
return aligned_alloc(alignment, numBytes, syclDevice, syclContext,
usm::alloc::shared, propList);
}
-void *aligned_alloc_shared(size_t alignment, size_t numBytes,
+void *aligned_alloc_shared(std::size_t alignment, std::size_t numBytes,
const queue &syclQueue,
const property_list &propList) {
return aligned_alloc_shared(alignment, numBytes, syclQueue.get_device(),
@@ -118,9 +118,9 @@ void *malloc_shared(std::size_t numBytes, const queue &syclQueue,
// SYCL 2020 4.8.3.5. Parameterized allocation functions.
-static aspect getAspectByAllocationKind(usm::alloc kind,
+static aspect getAspectByAllocationKind(usm::alloc Kind,
const context &syclContext) {
- switch (kind) {
+ switch (Kind) {
case usm::alloc::host:
return aspect::usm_host_allocations;
case usm::alloc::device:
@@ -137,18 +137,18 @@ static aspect getAspectByAllocationKind(usm::alloc kind,
void *aligned_alloc(std::size_t alignment, std::size_t numBytes,
const device &syclDevice, const context &syclContext,
- usm::alloc kind, const property_list &propList) {
+ usm::alloc kind, const property_list & /*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(syclContext, make_error_code(errc::invalid),
"Specified device is not contained by specified context.");
if (!syclDevice.has(getAspectByAllocationKind(kind, syclContext)))
- throw sycl::exception(
- syclContext, sycl::errc::feature_not_supported,
- "Device doesn't support requested kind of USM allocation");
+ throw exception(syclContext, 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/context.cpp b/libsycl/test/basic/context.cpp
index 59e8f3d216948..90e08d95b8b9e 100644
--- a/libsycl/test/basic/context.cpp
+++ b/libsycl/test/basic/context.cpp
@@ -2,55 +2,56 @@
// RUN: %clangxx -fsycl %s -o %t.out
// RUN: %t.out
+#include <cstdlib>
#include <iostream>
#include <sycl/sycl.hpp>
using namespace sycl;
-void return_fail() {
+void returnFail() {
std::cout << "Failed" << std::endl;
exit(1);
}
void dummyAsyncHandler(sycl::exception_list) {}
-void check(const context &ctx) {
- auto devices = ctx.get_devices();
+void check(const context &Ctx) {
+ auto Devices = Ctx.get_devices();
- auto plt = ctx.get_platform();
- for (const auto &dev : devices) {
- if (dev.get_platform() != plt) {
+ auto Plt = Ctx.get_platform();
+ for (const auto &Dev : Devices) {
+ if (Dev.get_platform() != Plt) {
std::cout << "Device platform does not match context platform"
<< std::endl;
- return_fail();
+ returnFail();
}
}
- auto backend = ctx.get_backend();
- for (const auto &dev : devices) {
- if (dev.get_backend() != backend) {
+ auto Backend = Ctx.get_backend();
+ for (const auto &Dev : Devices) {
+ if (Dev.get_backend() != Backend) {
std::cout << "Device backend does not match context backend" << std::endl;
- return_fail();
+ returnFail();
}
}
}
int main() {
- context ctx;
- check(ctx);
+ context Ctx;
+ check(Ctx);
- device dev;
- context ctx2(dev);
- check(ctx2);
+ device Dev;
+ context Ctx2(Dev);
+ check(Ctx2);
- device dev2;
+ device Dev2;
- platform plt = dev.get_platform();
- context ctx3(plt);
- check(ctx3);
+ platform Plt = Dev.get_platform();
+ context Ctx3(Plt);
+ check(Ctx3);
- context ctx4({dev, dev2}, dummyAsyncHandler, {});
- check(ctx4);
+ context Ctx4({Dev, Dev2}, dummyAsyncHandler, {});
+ check(Ctx4);
std::cout << "Passed" << std::endl;
return 0;
diff --git a/libsycl/test/basic/get_backend.cpp b/libsycl/test/basic/get_backend.cpp
index e54ef2d8c1a7b..1720d9d3e80bd 100644
--- a/libsycl/test/basic/get_backend.cpp
+++ b/libsycl/test/basic/get_backend.cpp
@@ -2,6 +2,7 @@
// RUN: %clangxx -fsycl %s -o %t.out
// RUN: %t.out
+#include <cstdlib>
#include <iostream>
#include <sycl/sycl.hpp>
@@ -10,8 +11,8 @@ using namespace sycl;
class Kernel1;
-bool check(backend be) {
- switch (be) {
+bool check(backend Backend) {
+ switch (Backend) {
case backend::opencl:
case backend::level_zero:
case backend::cuda:
@@ -22,30 +23,30 @@ bool check(backend be) {
}
}
-void return_fail() {
+void returnFail() {
std::cout << "Failed" << std::endl;
exit(1);
}
int main() {
- for (const auto &plt : platform::get_platforms()) {
- if (!check(plt.get_backend())) {
- return_fail();
+ for (const auto &Plt : platform::get_platforms()) {
+ if (!check(Plt.get_backend())) {
+ returnFail();
}
- auto device = plt.get_devices()[0];
- if (device.get_backend() != plt.get_backend()) {
- return_fail();
+ auto Dev = Plt.get_devices()[0];
+ if (Dev.get_backend() != Plt.get_backend()) {
+ returnFail();
}
- queue q(device);
- if (q.get_backend() != plt.get_backend()) {
- return_fail();
+ queue Q(Dev);
+ if (Q.get_backend() != Plt.get_backend()) {
+ returnFail();
}
- event e = q.single_task<Kernel1>([]() {});
- if (e.get_backend() != plt.get_backend()) {
- return_fail();
+ event E = Q.single_task<Kernel1>([]() {});
+ if (E.get_backend() != Plt.get_backend()) {
+ returnFail();
}
}
std::cout << "Passed" << std::endl;
diff --git a/libsycl/test/basic/group.cpp b/libsycl/test/basic/group.cpp
index cfc3870b5cf99..e29d4e91cd095 100644
--- a/libsycl/test/basic/group.cpp
+++ b/libsycl/test/basic/group.cpp
@@ -25,7 +25,7 @@ int main() {
initialize(GroupRangeData, DataLen * Dims, static_cast<size_t>(0));
initialize(GroupLinearIdData, DataLen * Dims, static_cast<size_t>(0));
- Q.parallel_for<class group_get_group_range_regression>(
+ Q.parallel_for<class GroupGetGroupRangeRegression>(
sycl::nd_range<3>{GlobalRange, LocalRange}, [=](sycl::nd_item<3> It) {
const size_t Off = It.get_global_linear_id() * Dims;
const auto GR = It.get_group().get_group_range();
@@ -34,7 +34,7 @@ int main() {
GroupRangeData[Off + 2] = GR[2];
});
- Q.parallel_for<class group_get_group_linear_id_regression>(
+ Q.parallel_for<class GroupGetGroupLinearIdRegression>(
sycl::nd_range<3>{GlobalRange, LocalRange}, [=](sycl::nd_item<3> It) {
const size_t Off = It.get_global_linear_id() * Dims;
const size_t LI = It.get_group().get_group_linear_id();
diff --git a/libsycl/test/basic/group_barrier.cpp b/libsycl/test/basic/group_barrier.cpp
index f06c73566067c..d95bfdaa72636 100644
--- a/libsycl/test/basic/group_barrier.cpp
+++ b/libsycl/test/basic/group_barrier.cpp
@@ -20,7 +20,7 @@ static bool runBarrierCase(sycl::queue &Q, int Iteration) {
int *Data = sycl::malloc_shared<int>(GlobalSize, Q);
int *LocalData = sycl::malloc_shared<int>(GlobalSize, Q);
- Q.parallel_for<class barrier_kernel>(
+ Q.parallel_for<class BarrierKernel>(
sycl::nd_range<1>{GlobalSize, LocalSize}, [=](sycl::nd_item<1> It) {
const int Lid = It.get_local_id(0);
const int Gid = It.get_group().get_group_id(0);
diff --git a/libsycl/test/basic/group_barrier_device_code.cpp b/libsycl/test/basic/group_barrier_device_code.cpp
index 4387c77c01373..972e0ed00df77 100644
--- a/libsycl/test/basic/group_barrier_device_code.cpp
+++ b/libsycl/test/basic/group_barrier_device_code.cpp
@@ -6,33 +6,33 @@
#include <sycl/sycl.hpp>
void test(sycl::queue Q) {
- Q.parallel_for<class barrier_kernel>(
+ Q.parallel_for<class BarrierKernel>(
sycl::nd_range<1>{8, 4}, [=](sycl::nd_item<1> It) {
// Execution scope is Workgroup (2), memory scope defaults to the
// group's fence_scope, i.e. Workgroup (2).
- // CHECK: call spir_func void @_Z22__spirv_ControlBarrierjjj(i32 noundef
- // 2, i32 noundef 2, i32 noundef 400)
+ // CHECK: call spir_func void @_Z22__spirv_ControlBarrierjjj(
+ // CHECK-SAME: i32 noundef 2, i32 noundef 2, i32 noundef 400)
sycl::group_barrier(It.get_group());
- // CHECK: call spir_func void @_Z22__spirv_ControlBarrierjjj(i32 noundef
- // 2, i32 noundef 4, i32 noundef 400)
+ // CHECK: call spir_func void @_Z22__spirv_ControlBarrierjjj(
+ // CHECK-SAME: i32 noundef 2, i32 noundef 4, i32 noundef 400)
sycl::group_barrier(It.get_group(), sycl::memory_scope::work_item);
- // CHECK: call spir_func void @_Z22__spirv_ControlBarrierjjj(i32 noundef
- // 2, i32 noundef 3, i32 noundef 400)
+ // CHECK: call spir_func void @_Z22__spirv_ControlBarrierjjj(
+ // CHECK-SAME: i32 noundef 2, i32 noundef 3, i32 noundef 400)
sycl::group_barrier(It.get_group(), sycl::memory_scope::sub_group);
- // CHECK: call spir_func void @_Z22__spirv_ControlBarrierjjj(i32 noundef
- // 2, i32 noundef 2, i32 noundef 400)
+ // CHECK: call spir_func void @_Z22__spirv_ControlBarrierjjj(
+ // CHECK-SAME: i32 noundef 2, i32 noundef 2, i32 noundef 400)
sycl::group_barrier(It.get_group(), sycl::memory_scope::work_group);
- // CHECK: call spir_func void @_Z22__spirv_ControlBarrierjjj(i32 noundef
- // 2, i32 noundef 1, i32 noundef 400)
+ // CHECK: call spir_func void @_Z22__spirv_ControlBarrierjjj(
+ // CHECK-SAME: i32 noundef 2, i32 noundef 1, i32 noundef 400)
sycl::group_barrier(It.get_group(), sycl::memory_scope::device);
- // CHECK: call spir_func void @_Z22__spirv_ControlBarrierjjj(i32 noundef
- // 2, i32 noundef 0, i32 noundef 400)
+ // CHECK: call spir_func void @_Z22__spirv_ControlBarrierjjj(
+ // CHECK-SAME: i32 noundef 2, i32 noundef 0, i32 noundef 400)
sycl::group_barrier(It.get_group(), sycl::memory_scope::system);
// Execution scope is Subgroup (3), memory scope defaults to the
// sub-group's fence_scope, i.e. Subgroup (3).
- // CHECK: call spir_func void @_Z22__spirv_ControlBarrierjjj(i32 noundef
- // 3, i32 noundef 3, i32 noundef 400)
+ // CHECK: call spir_func void @_Z22__spirv_ControlBarrierjjj(
+ // CHECK-SAME: i32 noundef 3, i32 noundef 3, i32 noundef 400)
sycl::group_barrier(It.get_sub_group());
});
}
diff --git a/libsycl/test/basic/group_local_id.cpp b/libsycl/test/basic/group_local_id.cpp
index 499a45f55a91a..b788a10e2a0d3 100644
--- a/libsycl/test/basic/group_local_id.cpp
+++ b/libsycl/test/basic/group_local_id.cpp
@@ -6,7 +6,7 @@
#include <cassert>
-template <int Dims> class group_local_id_kernel;
+template <int Dims> class GroupLocalIdKernel;
template <int Dims>
bool runGroupLocalIdCase(sycl::queue &Q, sycl::nd_range<Dims> ExecRange,
@@ -15,7 +15,7 @@ bool runGroupLocalIdCase(sycl::queue &Q, sycl::nd_range<Dims> ExecRange,
for (size_t I = 0; I < Count; ++I)
Out[I] = -1;
- Q.parallel_for<group_local_id_kernel<Dims>>(
+ Q.parallel_for<GroupLocalIdKernel<Dims>>(
ExecRange, [=](sycl::nd_item<Dims> Item) {
Out[Item.get_global_linear_id()] =
(Item.get_local_id() == Item.get_group().get_local_id());
diff --git a/libsycl/test/basic/handler/handler_parallel_for_generic_lambda.cpp b/libsycl/test/basic/handler/handler_parallel_for_generic_lambda.cpp
index da34fab3b6741..cde51baab70fb 100644
--- a/libsycl/test/basic/handler/handler_parallel_for_generic_lambda.cpp
+++ b/libsycl/test/basic/handler/handler_parallel_for_generic_lambda.cpp
@@ -6,36 +6,36 @@
#include <type_traits>
template <typename KernelName, typename ExpectedType, typename Range>
-void test_parallel_for(Range r) {
- sycl::queue q;
- q.submit([&](sycl::handler &cgh) {
- cgh.parallel_for<KernelName>(r, [=](auto item) {
- static_assert(std::is_same<decltype(item), ExpectedType>::value,
+void testParallelFor(Range R) {
+ sycl::queue Q;
+ Q.submit([&](sycl::handler &CGH) {
+ CGH.parallel_for<KernelName>(R, [=](auto Item) {
+ static_assert(std::is_same<decltype(Item), ExpectedType>::value,
"Argument type is unexpected");
});
});
}
int main() {
- test_parallel_for<class Item1Name, sycl::item<1>>(sycl::range<1>{1});
- test_parallel_for<class Item2Name, sycl::item<2>>(sycl::range<2>{1, 1});
- test_parallel_for<class Item3Name, sycl::item<3>>(sycl::range<3>{1, 1, 1});
- test_parallel_for<class NDItem1Name, sycl::nd_item<1>>(
+ testParallelFor<class Item1Name, sycl::item<1>>(sycl::range<1>{1});
+ testParallelFor<class Item2Name, sycl::item<2>>(sycl::range<2>{1, 1});
+ testParallelFor<class Item3Name, sycl::item<3>>(sycl::range<3>{1, 1, 1});
+ testParallelFor<class NDItem1Name, sycl::nd_item<1>>(
sycl::nd_range<1>{sycl::range<1>{1}, sycl::range<1>{1}});
- test_parallel_for<class NDItem2Name, sycl::nd_item<2>>(
+ testParallelFor<class NDItem2Name, sycl::nd_item<2>>(
sycl::nd_range<2>{sycl::range<2>{2, 2}, sycl::range<2>{1, 1}});
- test_parallel_for<class NDItem3Name, sycl::nd_item<3>>(
+ testParallelFor<class NDItem3Name, sycl::nd_item<3>>(
sycl::nd_range<3>{sycl::range<3>{2, 2, 2}, sycl::range<3>{1, 1, 1}});
- sycl::queue q;
- q.submit([&](sycl::handler &cgh) {
- cgh.parallel_for<class GenericInitList1>(sycl::range{1}, [=](auto &) {});
+ sycl::queue Q;
+ Q.submit([&](sycl::handler &CGH) {
+ CGH.parallel_for<class GenericInitList1>(sycl::range{1}, [=](auto &) {});
});
- q.submit([&](sycl::handler &cgh) {
- cgh.parallel_for<class GenericInitList2>(sycl::range{1, 1}, [=](auto &) {});
+ Q.submit([&](sycl::handler &CGH) {
+ CGH.parallel_for<class GenericInitList2>(sycl::range{1, 1}, [=](auto &) {});
});
- q.submit([&](sycl::handler &cgh) {
- cgh.parallel_for<class GenericInitList3>(sycl::range{1, 1, 1},
+ Q.submit([&](sycl::handler &CGH) {
+ CGH.parallel_for<class GenericInitList3>(sycl::range{1, 1, 1},
[=](auto &) {});
});
diff --git a/libsycl/test/basic/handler/handler_parallel_for_nd_range_invalid_arg_type.cpp b/libsycl/test/basic/handler/handler_parallel_for_nd_range_invalid_arg_type.cpp
index 01be9bcd94a92..1d0aeb129e4c5 100644
--- a/libsycl/test/basic/handler/handler_parallel_for_nd_range_invalid_arg_type.cpp
+++ b/libsycl/test/basic/handler/handler_parallel_for_nd_range_invalid_arg_type.cpp
@@ -4,10 +4,10 @@
#include <sycl/sycl.hpp>
int main() {
- sycl::queue q;
+ sycl::queue Q;
- q.submit([&](sycl::handler &cgh) {
- cgh.parallel_for<class HandlerNDRangeInvalidArgType>(
+ Q.submit([&](sycl::handler &CGH) {
+ CGH.parallel_for<class HandlerNDRangeInvalidArgType>(
sycl::nd_range<1>{sycl::range<1>{4}, sycl::range<1>{2}},
[=](sycl::item<1>) {}); // expected-error@* {{must be sycl::nd_item or
// be convertible from sycl::nd_item}}
diff --git a/libsycl/test/basic/handler/handler_parallel_for_runtime.cpp b/libsycl/test/basic/handler/handler_parallel_for_runtime.cpp
index 8f6b31c332d9b..bcfc988e6038e 100644
--- a/libsycl/test/basic/handler/handler_parallel_for_runtime.cpp
+++ b/libsycl/test/basic/handler/handler_parallel_for_runtime.cpp
@@ -6,144 +6,144 @@
#include <cassert>
-void test1D(sycl::queue &q) {
+void test1D(sycl::queue &Q) {
constexpr size_t N = 16;
constexpr size_t LocalSize = 4;
- int *data = sycl::malloc_shared<int>(N, q);
- assert(data);
+ int *Data = sycl::malloc_shared<int>(N, Q);
+ assert(Data);
- for (size_t i = 0; i < N; ++i)
- data[i] = 0;
+ for (size_t I = 0; I < N; ++I)
+ Data[I] = 0;
- q.submit([&](sycl::handler &cgh) {
- cgh.parallel_for<class HandlerParallelForRuntime>(
+ Q.submit([&](sycl::handler &CGH) {
+ CGH.parallel_for<class HandlerParallelForRuntime>(
sycl::range<1>{N},
- [=](sycl::item<1> it) { data[it[0]] = static_cast<int>(it[0]) + 7; });
+ [=](sycl::item<1> It) { Data[It[0]] = static_cast<int>(It[0]) + 7; });
}).wait();
- for (size_t i = 0; i < N; ++i)
- assert(data[i] == static_cast<int>(i) + 7);
+ for (size_t I = 0; I < N; ++I)
+ assert(Data[I] == static_cast<int>(I) + 7);
- for (size_t i = 0; i < N; ++i)
- data[i] = 0;
+ for (size_t I = 0; I < N; ++I)
+ Data[I] = 0;
- q.submit([&](sycl::handler &cgh) {
- cgh.parallel_for<class HandlerParallelForNDRangeRuntime>(
+ Q.submit([&](sycl::handler &CGH) {
+ CGH.parallel_for<class HandlerParallelForNDRangeRuntime>(
sycl::nd_range<1>{sycl::range<1>{N}, sycl::range<1>{LocalSize}},
- [=](sycl::nd_item<1> it) {
- const size_t idx = it.get_global_id(0);
- data[idx] = static_cast<int>(idx) + 11;
+ [=](sycl::nd_item<1> It) {
+ const size_t Idx = It.get_global_id(0);
+ Data[Idx] = static_cast<int>(Idx) + 11;
});
}).wait();
- for (size_t i = 0; i < N; ++i)
- assert(data[i] == static_cast<int>(i) + 11);
+ for (size_t I = 0; I < N; ++I)
+ assert(Data[I] == static_cast<int>(I) + 11);
- sycl::free(data, q);
+ sycl::free(Data, Q);
}
-void test2D(sycl::queue &q) {
+void test2D(sycl::queue &Q) {
constexpr size_t G0 = 4;
constexpr size_t G1 = 6;
constexpr size_t L0 = 2;
constexpr size_t L1 = 3;
- int *data = sycl::malloc_shared<int>(G0 * G1, q);
- assert(data);
-
- for (size_t i = 0; i < G0 * G1; ++i)
- data[i] = -1;
-
- q.submit([&](sycl::handler &cgh) {
- cgh.parallel_for<class HandlerParallelFor2DRuntime>(
- sycl::range<2>{G0, G1}, [=](sycl::item<2> it) {
- const size_t i = it.get_id(0);
- const size_t j = it.get_id(1);
- data[i * G1 + j] = static_cast<int>(i * 100 + j) + 7;
+ int *Data = sycl::malloc_shared<int>(G0 * G1, Q);
+ assert(Data);
+
+ for (size_t I = 0; I < G0 * G1; ++I)
+ Data[I] = -1;
+
+ Q.submit([&](sycl::handler &CGH) {
+ CGH.parallel_for<class HandlerParallelFor2DRuntime>(
+ sycl::range<2>{G0, G1}, [=](sycl::item<2> It) {
+ const size_t I = It.get_id(0);
+ const size_t J = It.get_id(1);
+ Data[I * G1 + J] = static_cast<int>(I * 100 + J) + 7;
});
}).wait();
- for (size_t i = 0; i < G0; ++i)
- for (size_t j = 0; j < G1; ++j)
- assert(data[i * G1 + j] == static_cast<int>(i * 100 + j) + 7);
+ for (size_t I = 0; I < G0; ++I)
+ for (size_t J = 0; J < G1; ++J)
+ assert(Data[I * G1 + J] == static_cast<int>(I * 100 + J) + 7);
- for (size_t i = 0; i < G0 * G1; ++i)
- data[i] = -1;
+ for (size_t I = 0; I < G0 * G1; ++I)
+ Data[I] = -1;
- q.submit([&](sycl::handler &cgh) {
- cgh.parallel_for<class HandlerNDRange2DRuntime>(
+ Q.submit([&](sycl::handler &CGH) {
+ CGH.parallel_for<class HandlerNDRange2DRuntime>(
sycl::nd_range<2>{sycl::range<2>{G0, G1}, sycl::range<2>{L0, L1}},
- [=](sycl::nd_item<2> it) {
- const size_t i = it.get_global_id(0);
- const size_t j = it.get_global_id(1);
- data[i * G1 + j] = static_cast<int>(i * 100 + j);
+ [=](sycl::nd_item<2> It) {
+ const size_t I = It.get_global_id(0);
+ const size_t J = It.get_global_id(1);
+ Data[I * G1 + J] = static_cast<int>(I * 100 + J);
});
}).wait();
- for (size_t i = 0; i < G0; ++i)
- for (size_t j = 0; j < G1; ++j)
- assert(data[i * G1 + j] == static_cast<int>(i * 100 + j));
+ for (size_t I = 0; I < G0; ++I)
+ for (size_t J = 0; J < G1; ++J)
+ assert(Data[I * G1 + J] == static_cast<int>(I * 100 + J));
- sycl::free(data, q);
+ sycl::free(Data, Q);
}
-void test3D(sycl::queue &q) {
+void test3D(sycl::queue &Q) {
constexpr size_t G0 = 2;
constexpr size_t G1 = 3;
constexpr size_t G2 = 4;
constexpr size_t L0 = 1;
constexpr size_t L1 = 3;
constexpr size_t L2 = 2;
- int *data = sycl::malloc_shared<int>(G0 * G1 * G2, q);
- assert(data);
-
- for (size_t i = 0; i < G0 * G1 * G2; ++i)
- data[i] = -1;
-
- q.submit([&](sycl::handler &cgh) {
- cgh.parallel_for<class HandlerParallelFor3DRuntime>(
- sycl::range<3>{G0, G1, G2}, [=](sycl::item<3> it) {
- const size_t i = it.get_id(0);
- const size_t j = it.get_id(1);
- const size_t k = it.get_id(2);
- data[(i * G1 + j) * G2 + k] =
- static_cast<int>(i * 100 + j * 10 + k) + 7;
+ int *Data = sycl::malloc_shared<int>(G0 * G1 * G2, Q);
+ assert(Data);
+
+ for (size_t I = 0; I < G0 * G1 * G2; ++I)
+ Data[I] = -1;
+
+ Q.submit([&](sycl::handler &CGH) {
+ CGH.parallel_for<class HandlerParallelFor3DRuntime>(
+ sycl::range<3>{G0, G1, G2}, [=](sycl::item<3> It) {
+ const size_t I = It.get_id(0);
+ const size_t J = It.get_id(1);
+ const size_t K = It.get_id(2);
+ Data[(I * G1 + J) * G2 + K] =
+ static_cast<int>(I * 100 + J * 10 + K) + 7;
});
}).wait();
- for (size_t i = 0; i < G0; ++i)
- for (size_t j = 0; j < G1; ++j)
- for (size_t k = 0; k < G2; ++k)
- assert(data[(i * G1 + j) * G2 + k] ==
- static_cast<int>(i * 100 + j * 10 + k) + 7);
+ for (size_t I = 0; I < G0; ++I)
+ for (size_t J = 0; J < G1; ++J)
+ for (size_t K = 0; K < G2; ++K)
+ assert(Data[(I * G1 + J) * G2 + K] ==
+ static_cast<int>(I * 100 + J * 10 + K) + 7);
- for (size_t i = 0; i < G0 * G1 * G2; ++i)
- data[i] = -1;
+ for (size_t I = 0; I < G0 * G1 * G2; ++I)
+ Data[I] = -1;
- q.submit([&](sycl::handler &cgh) {
- cgh.parallel_for<class HandlerNDRange3DRuntime>(
+ Q.submit([&](sycl::handler &CGH) {
+ CGH.parallel_for<class HandlerNDRange3DRuntime>(
sycl::nd_range<3>{sycl::range<3>{G0, G1, G2},
sycl::range<3>{L0, L1, L2}},
- [=](sycl::nd_item<3> it) {
- const size_t i = it.get_global_id(0);
- const size_t j = it.get_global_id(1);
- const size_t k = it.get_global_id(2);
- data[(i * G1 + j) * G2 + k] = static_cast<int>(i * 100 + j * 10 + k);
+ [=](sycl::nd_item<3> It) {
+ const size_t I = It.get_global_id(0);
+ const size_t J = It.get_global_id(1);
+ const size_t K = It.get_global_id(2);
+ Data[(I * G1 + J) * G2 + K] = static_cast<int>(I * 100 + J * 10 + K);
});
}).wait();
- for (size_t i = 0; i < G0; ++i)
- for (size_t j = 0; j < G1; ++j)
- for (size_t k = 0; k < G2; ++k)
- assert(data[(i * G1 + j) * G2 + k] ==
- static_cast<int>(i * 100 + j * 10 + k));
+ for (size_t I = 0; I < G0; ++I)
+ for (size_t J = 0; J < G1; ++J)
+ for (size_t K = 0; K < G2; ++K)
+ assert(Data[(I * G1 + J) * G2 + K] ==
+ static_cast<int>(I * 100 + J * 10 + K));
- sycl::free(data, q);
+ sycl::free(Data, Q);
}
int main() {
- sycl::queue q;
- test1D(q);
- test2D(q);
- test3D(q);
+ sycl::queue Q;
+ test1D(Q);
+ test2D(Q);
+ test3D(Q);
return 0;
}
diff --git a/libsycl/test/basic/handler/handler_unnamed_lambda_functor.cpp b/libsycl/test/basic/handler/handler_single_task_named_functor.cpp
similarity index 52%
rename from libsycl/test/basic/handler/handler_unnamed_lambda_functor.cpp
rename to libsycl/test/basic/handler/handler_single_task_named_functor.cpp
index ae9c0790f9a99..0386a530766be 100644
--- a/libsycl/test/basic/handler/handler_unnamed_lambda_functor.cpp
+++ b/libsycl/test/basic/handler/handler_single_task_named_functor.cpp
@@ -7,12 +7,12 @@ struct SingleTaskKernel {
};
int main() {
- sycl::queue q;
+ sycl::queue Q;
- q.single_task<class QueueSingleTaskNamed>(SingleTaskKernel{});
+ Q.single_task<class QueueSingleTaskNamed>(SingleTaskKernel{});
- q.submit([&](sycl::handler &cgh) {
- cgh.single_task<class HandlerSingleTaskNamed>(SingleTaskKernel{});
+ Q.submit([&](sycl::handler &CGH) {
+ CGH.single_task<class HandlerSingleTaskNamed>(SingleTaskKernel{});
});
return 0;
diff --git a/libsycl/test/basic/handler/submit_fn_ptr_handler.cpp b/libsycl/test/basic/handler/submit_fn_ptr_handler.cpp
index c43a5deef4830..cf1839d961781 100644
--- a/libsycl/test/basic/handler/submit_fn_ptr_handler.cpp
+++ b/libsycl/test/basic/handler/submit_fn_ptr_handler.cpp
@@ -6,19 +6,19 @@
#include <cassert>
-int *p = nullptr;
+int *Ptr = nullptr;
-void foo(sycl::handler &cgh) {
- auto *copy = p;
- cgh.single_task([=]() { *copy = 42; });
+void foo(sycl::handler &CGH) {
+ auto *Copy = Ptr;
+ CGH.single_task([=]() { *Copy = 42; });
}
int main() {
- sycl::queue q;
- p = sycl::malloc_shared<int>(1, q);
- *p = 0;
- q.submit(foo).wait();
- assert(*p == 42);
- sycl::free(p, q);
+ sycl::queue Q;
+ Ptr = sycl::malloc_shared<int>(1, Q);
+ *Ptr = 0;
+ Q.submit(foo).wait();
+ assert(*Ptr == 42);
+ sycl::free(Ptr, Q);
return 0;
}
diff --git a/libsycl/test/basic/index_space_classes.cpp b/libsycl/test/basic/index_space_classes.cpp
index 1afb70e634303..cd7d072f44246 100644
--- a/libsycl/test/basic/index_space_classes.cpp
+++ b/libsycl/test/basic/index_space_classes.cpp
@@ -1,26 +1,28 @@
// 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
// theirs base class, plus class-specific behaviour for each type.
-#include <cassert>
#include <sycl/sycl.hpp>
+
+#include <cassert>
#include <type_traits>
+#include <utility>
using sycl::detail::Builder;
// Helper to create values for any dimension from three components.
// Only uses the required number of values based on dimension.
template <template <int> class T, int Dim>
-T<Dim> makeValue(std::size_t a, std::size_t b = 0, std::size_t c = 0) {
+T<Dim> makeValue(std::size_t A, std::size_t B = 0, std::size_t C = 0) {
if constexpr (Dim == 1)
- return T<1>(a);
+ return T<1>(A);
else if constexpr (Dim == 2)
- return T<2>(a, b);
+ return T<2>(A, B);
else
- return T<3>(a, b, c);
+ return T<3>(A, B, C);
}
// Tests binary and compound operators for a specific dimension.
@@ -277,8 +279,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/khr_get_default_context.cpp b/libsycl/test/basic/khr_get_default_context.cpp
index 79f52f2421518..54912e96747c4 100644
--- a/libsycl/test/basic/khr_get_default_context.cpp
+++ b/libsycl/test/basic/khr_get_default_context.cpp
@@ -13,11 +13,11 @@ using namespace sycl;
int main() {
for (const sycl::platform &P : sycl::platform::get_platforms()) {
- auto ctx_devs = P.khr_get_default_context().get_devices();
- auto root_devs = P.get_devices();
+ auto CtxDevs = P.khr_get_default_context().get_devices();
+ auto RootDevs = P.get_devices();
- for (const auto &dev : root_devs)
- if (std::find(ctx_devs.begin(), ctx_devs.end(), dev) == ctx_devs.end())
+ for (const auto &Dev : RootDevs)
+ if (std::find(CtxDevs.begin(), CtxDevs.end(), Dev) == CtxDevs.end())
return 1;
}
diff --git a/libsycl/test/basic/linear_sub_group.cpp b/libsycl/test/basic/linear_sub_group.cpp
index 4f7e88568cc36..96b774689ade2 100644
--- a/libsycl/test/basic/linear_sub_group.cpp
+++ b/libsycl/test/basic/linear_sub_group.cpp
@@ -5,6 +5,7 @@
#include <sycl/sycl.hpp>
#include <cassert>
+#include <cstdint>
int main() {
sycl::queue Q;
@@ -17,7 +18,7 @@ int main() {
for (uint32_t I = 0; I < Size; ++I)
Output[I] = -1;
- Q.parallel_for<class linear_sub_group>(
+ Q.parallel_for<class LinearSubGroup>(
sycl::nd_range<2>(sycl::range<2>(Outer, Inner),
sycl::range<2>(Outer, Inner)),
[=](sycl::nd_item<2> It) {
diff --git a/libsycl/test/basic/nd_range.cpp b/libsycl/test/basic/nd_range.cpp
index 7988e8f3509f8..67e6eb852cc03 100644
--- a/libsycl/test/basic/nd_range.cpp
+++ b/libsycl/test/basic/nd_range.cpp
@@ -7,49 +7,47 @@
#include <iostream>
int main() {
- sycl::nd_range<1> one_dim_nd_range_offset({4}, {2}, {1});
- assert(one_dim_nd_range_offset.get_global_range() == sycl::range<1>(4));
- assert(one_dim_nd_range_offset.get_local_range() == sycl::range<1>(2));
- assert(one_dim_nd_range_offset.get_group_range() == sycl::range<1>(2));
- assert(one_dim_nd_range_offset.get_offset() == sycl::id<1>(1));
+ sycl::nd_range<1> OneDimNdRangeOffset({4}, {2}, {1});
+ assert(OneDimNdRangeOffset.get_global_range() == sycl::range<1>(4));
+ assert(OneDimNdRangeOffset.get_local_range() == sycl::range<1>(2));
+ assert(OneDimNdRangeOffset.get_group_range() == sycl::range<1>(2));
+ assert(OneDimNdRangeOffset.get_offset() == sycl::id<1>(1));
std::cout << "one_dim_nd_range_offset passed " << std::endl;
- sycl::nd_range<2> two_dim_nd_range_offset({8, 16}, {4, 8}, {1, 1});
- assert(two_dim_nd_range_offset.get_global_range() == sycl::range<2>(8, 16));
- assert(two_dim_nd_range_offset.get_local_range() == sycl::range<2>(4, 8));
- assert(two_dim_nd_range_offset.get_group_range() == sycl::range<2>(2, 2));
- assert(two_dim_nd_range_offset.get_offset() == sycl::id<2>(1, 1));
+ sycl::nd_range<2> TwoDimNdRangeOffset({8, 16}, {4, 8}, {1, 1});
+ assert(TwoDimNdRangeOffset.get_global_range() == sycl::range<2>(8, 16));
+ assert(TwoDimNdRangeOffset.get_local_range() == sycl::range<2>(4, 8));
+ assert(TwoDimNdRangeOffset.get_group_range() == sycl::range<2>(2, 2));
+ assert(TwoDimNdRangeOffset.get_offset() == sycl::id<2>(1, 1));
std::cout << "two_dim_nd_range_offset passed " << std::endl;
- sycl::nd_range<3> three_dim_nd_range_offset({32, 64, 128}, {16, 32, 64},
- {1, 1, 1});
- assert(three_dim_nd_range_offset.get_global_range() ==
+ sycl::nd_range<3> ThreeDimNdRangeOffset({32, 64, 128}, {16, 32, 64},
+ {1, 1, 1});
+ assert(ThreeDimNdRangeOffset.get_global_range() ==
sycl::range<3>(32, 64, 128));
- assert(three_dim_nd_range_offset.get_local_range() ==
- sycl::range<3>(16, 32, 64));
- assert(three_dim_nd_range_offset.get_group_range() ==
- sycl::range<3>(2, 2, 2));
- assert(three_dim_nd_range_offset.get_offset() == sycl::id<3>(1, 1, 1));
+ assert(ThreeDimNdRangeOffset.get_local_range() == sycl::range<3>(16, 32, 64));
+ assert(ThreeDimNdRangeOffset.get_group_range() == sycl::range<3>(2, 2, 2));
+ assert(ThreeDimNdRangeOffset.get_offset() == sycl::id<3>(1, 1, 1));
std::cout << "three_dim_nd_range_offset passed " << std::endl;
- sycl::nd_range<1> one_dim_nd_range({4}, {2});
- assert(one_dim_nd_range.get_global_range() == sycl::range<1>(4));
- assert(one_dim_nd_range.get_local_range() == sycl::range<1>(2));
- assert(one_dim_nd_range.get_group_range() == sycl::range<1>(2));
- assert(one_dim_nd_range.get_offset() == sycl::id<1>(0));
+ sycl::nd_range<1> OneDimNdRange({4}, {2});
+ assert(OneDimNdRange.get_global_range() == sycl::range<1>(4));
+ assert(OneDimNdRange.get_local_range() == sycl::range<1>(2));
+ assert(OneDimNdRange.get_group_range() == sycl::range<1>(2));
+ assert(OneDimNdRange.get_offset() == sycl::id<1>(0));
std::cout << "one_dim_nd_range passed " << std::endl;
- sycl::nd_range<2> two_dim_nd_range({8, 16}, {4, 8});
- assert(two_dim_nd_range.get_global_range() == sycl::range<2>(8, 16));
- assert(two_dim_nd_range.get_local_range() == sycl::range<2>(4, 8));
- assert(two_dim_nd_range.get_group_range() == sycl::range<2>(2, 2));
- assert(two_dim_nd_range.get_offset() == sycl::id<2>(0, 0));
+ sycl::nd_range<2> TwoDimNdRange({8, 16}, {4, 8});
+ assert(TwoDimNdRange.get_global_range() == sycl::range<2>(8, 16));
+ assert(TwoDimNdRange.get_local_range() == sycl::range<2>(4, 8));
+ assert(TwoDimNdRange.get_group_range() == sycl::range<2>(2, 2));
+ assert(TwoDimNdRange.get_offset() == sycl::id<2>(0, 0));
std::cout << "two_dim_nd_range passed " << std::endl;
- sycl::nd_range<3> three_dim_nd_range({32, 64, 128}, {16, 32, 64});
- assert(three_dim_nd_range.get_global_range() == sycl::range<3>(32, 64, 128));
- assert(three_dim_nd_range.get_local_range() == sycl::range<3>(16, 32, 64));
- assert(three_dim_nd_range.get_group_range() == sycl::range<3>(2, 2, 2));
- assert(three_dim_nd_range.get_offset() == sycl::id<3>(0, 0, 0));
+ sycl::nd_range<3> ThreeDimNdRange({32, 64, 128}, {16, 32, 64});
+ assert(ThreeDimNdRange.get_global_range() == sycl::range<3>(32, 64, 128));
+ assert(ThreeDimNdRange.get_local_range() == sycl::range<3>(16, 32, 64));
+ assert(ThreeDimNdRange.get_group_range() == sycl::range<3>(2, 2, 2));
+ assert(ThreeDimNdRange.get_offset() == sycl::id<3>(0, 0, 0));
std::cout << "three_dim_nd_range passed " << std::endl;
}
diff --git a/libsycl/test/basic/parallel_for_indexers.cpp b/libsycl/test/basic/parallel_for_indexers.cpp
index 930bdd457c7d7..f305d2c813de5 100644
--- a/libsycl/test/basic/parallel_for_indexers.cpp
+++ b/libsycl/test/basic/parallel_for_indexers.cpp
@@ -4,9 +4,7 @@
#include <sycl/sycl.hpp>
-#include <cassert>
#include <iostream>
-#include <memory>
using namespace sycl;
@@ -21,19 +19,19 @@ int main() {
{
queue Q;
int *Data = sycl::malloc_shared<int>(DataSize, Q);
- for (size_t i = 0; i < DataSize; ++i)
- Data[i] = -1;
+ for (size_t I = 0; I < DataSize; ++I)
+ Data[I] = -1;
- Q.parallel_for<class id1>(GlobalRange,
+ Q.parallel_for<class Id1>(GlobalRange,
[=](id<1> Index) { Data[Index] = Index[0]; });
Q.wait();
Fail |= [&]() {
- for (size_t i = 0; i < DataSize; ++i) {
- const int ExpectedVal = i < GlobalRange[0] ? i : -1;
- if (Data[i] != ExpectedVal) {
- std::cout << "line: " << __LINE__ << " Data[" << i << "] is "
- << Data[i] << " expected " << ExpectedVal << std::endl;
+ for (size_t I = 0; I < DataSize; ++I) {
+ const int ExpectedVal = I < GlobalRange[0] ? I : -1;
+ if (Data[I] != ExpectedVal) {
+ std::cout << "line: " << __LINE__ << " Data[" << I << "] is "
+ << Data[I] << " expected " << ExpectedVal << std::endl;
return true;
}
}
@@ -45,30 +43,29 @@ int main() {
// Item indexer without offset
{
- // TODO: replace strcut with sycl::int2 once implemented.
+ // TODO: replace struct with sycl::int2 once implemented.
struct DoubleInt {
int Id;
int Range;
};
queue Q;
DoubleInt *Data = sycl::malloc_shared<DoubleInt>(DataSize, Q);
- for (size_t i = 0; i < DataSize; ++i)
- Data[i] = {-1, -1};
+ for (size_t I = 0; I < DataSize; ++I)
+ Data[I] = {-1, -1};
- Q.parallel_for<class item1_nooffset>(
- GlobalRange, [=](item<1, false> Index) {
- Data[Index.get_id()] = {int(Index.get_id()[0]),
- int(Index.get_range()[0])};
- });
+ Q.parallel_for<class Item1NoOffset>(GlobalRange, [=](item<1, false> Index) {
+ Data[Index.get_id()] = {int(Index.get_id()[0]),
+ int(Index.get_range()[0])};
+ });
Q.wait();
Fail |= [&]() {
- for (size_t i = 0; i < DataSize; ++i) {
- const int ExpectedValID = i < GlobalRange[0] ? i : -1;
- const int ExpectedValRange = i < GlobalRange[0] ? GlobalRange[0] : -1;
- if (Data[i].Id != ExpectedValID || Data[i].Range != ExpectedValRange) {
- std::cout << "line: " << __LINE__ << " Data[" << i << "] is {"
- << Data[i].Id << ", " << Data[i].Range << "} expected {"
+ for (size_t I = 0; I < DataSize; ++I) {
+ const int ExpectedValID = I < GlobalRange[0] ? I : -1;
+ const int ExpectedValRange = I < GlobalRange[0] ? GlobalRange[0] : -1;
+ if (Data[I].Id != ExpectedValID || Data[I].Range != ExpectedValRange) {
+ std::cout << "line: " << __LINE__ << " Data[" << I << "] is {"
+ << Data[I].Id << ", " << Data[I].Range << "} expected {"
<< ExpectedValID << ", " << ExpectedValRange << "}"
<< std::endl;
return true;
@@ -79,9 +76,7 @@ int main() {
free(Data, Q);
}
- // TODO: Item indexer with offset
- // blocked by liboffload support
- // blocked by absence of sycl::handler implementation
+ // TODO: Item indexer with offset, blocked by liboffload support.
// TODO: add nd_item check
return Fail;
diff --git a/libsycl/test/basic/platform_get_devices.cpp b/libsycl/test/basic/platform_get_devices.cpp
index 37e9550e591a9..4e43b2455271b 100644
--- a/libsycl/test/basic/platform_get_devices.cpp
+++ b/libsycl/test/basic/platform_get_devices.cpp
@@ -7,9 +7,12 @@
#include <sycl/sycl.hpp>
#include <algorithm>
+#include <cassert>
#include <iostream>
+#include <string>
+#include <vector>
-std::string BackendToString(sycl::backend Backend) {
+std::string backendToString(sycl::backend Backend) {
switch (Backend) {
case sycl::backend::opencl:
return "opencl";
@@ -24,7 +27,7 @@ std::string BackendToString(sycl::backend Backend) {
}
}
-std::string DeviceTypeToString(sycl::info::device_type DevType) {
+std::string deviceTypeToString(sycl::info::device_type DevType) {
switch (DevType) {
case sycl::info::device_type::all:
return "device_type::all";
@@ -45,14 +48,14 @@ std::string DeviceTypeToString(sycl::info::device_type DevType) {
}
}
-std::string GenerateDeviceDescription(sycl::info::device_type DevType,
+std::string generateDeviceDescription(sycl::info::device_type DevType,
const sycl::platform &Platform) {
- return std::string(DeviceTypeToString(DevType)) + " (" +
- BackendToString(Platform.get_backend()) + ")";
+ return std::string(deviceTypeToString(DevType)) + " (" +
+ backendToString(Platform.get_backend()) + ")";
}
template <typename T1, typename T2>
-int Check(const T1 &LHS, const T2 &RHS, std::string TestName) {
+int check(const T1 &LHS, const T2 &RHS, std::string TestName) {
if (LHS == RHS)
return 0;
@@ -61,7 +64,7 @@ int Check(const T1 &LHS, const T2 &RHS, std::string TestName) {
return 1;
}
-int CheckDeviceType(const sycl::platform &P, sycl::info::device_type DevType,
+int checkDeviceType(const sycl::platform &P, sycl::info::device_type DevType,
std::vector<sycl::device> &AllDevices) {
// This check verifies data of device with specific device_type and if it is
// correctly chosen among all devices (device_type::all).
@@ -73,14 +76,14 @@ int CheckDeviceType(const sycl::platform &P, sycl::info::device_type DevType,
if (DevType == sycl::info::device_type::automatic) {
if (AllDevices.empty()) {
- Failures += Check(Devices.size(), 0,
+ Failures += check(Devices.size(), 0,
"No devices reported for device_type::all query, but "
"device_type::automatic returns a device.");
} else {
- Failures += Check(Devices.size(), 1,
+ Failures += check(Devices.size(), 1,
"Number of devices for device_type::automatic query.");
if (Devices.size())
- Failures += Check(
+ Failures += check(
std::count(AllDevices.begin(), AllDevices.end(), Devices[0]), 1,
"Device is in the set of device_type::all devices in the "
"platform.");
@@ -93,18 +96,18 @@ int CheckDeviceType(const sycl::platform &P, sycl::info::device_type DevType,
for (sycl::device Device : Devices)
DevCount += (Device.get_info<sycl::info::device::device_type>() == DevType);
- Failures += Check(Devices.size(), DevCount,
+ Failures += check(Devices.size(), DevCount,
"Unexpected number of devices for " +
- GenerateDeviceDescription(DevType, P));
+ generateDeviceDescription(DevType, P));
Failures +=
- Check(std::all_of(Devices.begin(), Devices.end(),
+ check(std::all_of(Devices.begin(), Devices.end(),
[&](const auto &Dev) {
return std::count(AllDevices.begin(),
AllDevices.end(), Dev) == 1;
}),
true,
- "Not all devices for " + GenerateDeviceDescription(DevType, P) +
+ "Not all devices for " + generateDeviceDescription(DevType, P) +
" appear in the list of all devices");
return Failures;
@@ -119,7 +122,7 @@ int main() {
{sycl::info::device_type::cpu, sycl::info::device_type::gpu,
sycl::info::device_type::accelerator, sycl::info::device_type::custom,
sycl::info::device_type::automatic, sycl::info::device_type::host})
- Failures += CheckDeviceType(P, DevType, Devices);
+ Failures += checkDeviceType(P, DevType, Devices);
}
return Failures;
}
diff --git a/libsycl/test/basic/queue_parallel_for_generic.cpp b/libsycl/test/basic/queue_parallel_for_generic.cpp
index 03943f7ed141f..6bb959d61d288 100644
--- a/libsycl/test/basic/queue_parallel_for_generic.cpp
+++ b/libsycl/test/basic/queue_parallel_for_generic.cpp
@@ -4,8 +4,6 @@
#include <sycl/sycl.hpp>
-#include <cassert>
-#include <iostream>
#include <type_traits>
int main() {
@@ -19,60 +17,60 @@ int main() {
auto A = static_cast<int *>(sycl::malloc_shared(N * sizeof(int), Dev, Ctx));
- for (int i = 0; i < N; ++i) {
- A[i] = 1;
+ for (int I = 0; I < N; ++I) {
+ A[I] = 1;
}
- Q.parallel_for<class IntRange>(N, [=](auto i) {
- static_assert(std::is_same<decltype(i), sycl::item<1>>::value,
+ Q.parallel_for<class IntRange>(N, [=](auto I) {
+ static_assert(std::is_same<decltype(I), sycl::item<1>>::value,
"lambda arg type is unexpected");
- A[i]++;
+ A[I]++;
});
- Q.parallel_for<class InitRange>({N}, [=](auto i) {
- static_assert(std::is_same<decltype(i), sycl::item<1>>::value,
+ Q.parallel_for<class InitRange>({N}, [=](auto I) {
+ static_assert(std::is_same<decltype(I), sycl::item<1>>::value,
"lambda arg type is unexpected");
- A[i]++;
+ A[I]++;
});
- Q.parallel_for<class InitRange2D>({4, 2}, [=](auto i) {
- static_assert(std::is_same<decltype(i), sycl::item<2>>::value,
+ Q.parallel_for<class InitRange2D>({4, 2}, [=](auto I) {
+ static_assert(std::is_same<decltype(I), sycl::item<2>>::value,
"lambda arg type is unexpected");
- A[i.get_linear_id()]++;
+ A[I.get_linear_id()]++;
});
- Q.parallel_for<class InitRange3D>({2, 2, 2}, [=](auto i) {
- static_assert(std::is_same<decltype(i), sycl::item<3>>::value,
+ Q.parallel_for<class InitRange3D>({2, 2, 2}, [=](auto I) {
+ static_assert(std::is_same<decltype(I), sycl::item<3>>::value,
"lambda arg type is unexpected");
- A[i.get_linear_id()]++;
+ A[I.get_linear_id()]++;
});
sycl::nd_range<1> NDR(sycl::range<1>{N}, sycl::range<1>{2});
- Q.parallel_for<class NdRange1D>(NDR, [=](auto nd_i) {
- static_assert(std::is_same<decltype(nd_i), sycl::nd_item<1>>::value,
+ Q.parallel_for<class NdRange1D>(NDR, [=](auto NdItem) {
+ static_assert(std::is_same<decltype(NdItem), sycl::nd_item<1>>::value,
"lambda arg type is unexpected");
- A[nd_i.get_global_id()]++;
+ A[NdItem.get_global_id()]++;
});
sycl::nd_range<2> NDR2D(sycl::range<2>{4, 2}, sycl::range<2>{2, 1});
- Q.parallel_for<class NdRange2D>(NDR2D, [=](auto nd_i) {
- static_assert(std::is_same<decltype(nd_i), sycl::nd_item<2>>::value,
+ Q.parallel_for<class NdRange2D>(NDR2D, [=](auto NdItem) {
+ static_assert(std::is_same<decltype(NdItem), sycl::nd_item<2>>::value,
"lambda arg type is unexpected");
- A[nd_i.get_global_linear_id()]++;
+ A[NdItem.get_global_linear_id()]++;
});
sycl::nd_range<3> NDR3D(sycl::range<3>{2, 2, 2}, sycl::range<3>{1, 2, 2});
- Q.parallel_for<class NdRange3D>(NDR3D, [=](auto nd_i) {
- static_assert(std::is_same<decltype(nd_i), sycl::nd_item<3>>::value,
+ Q.parallel_for<class NdRange3D>(NDR3D, [=](auto NdItem) {
+ static_assert(std::is_same<decltype(NdItem), sycl::nd_item<3>>::value,
"lambda arg type is unexpected");
- A[nd_i.get_global_linear_id()]++;
+ A[NdItem.get_global_linear_id()]++;
});
Q.wait();
bool Fail{};
- for (int i = 0; i < N; i++) {
- Fail |= !(A[i] == 8);
+ for (int I = 0; I < N; I++) {
+ Fail |= !(A[I] == 8);
}
sycl::free(A, Ctx);
return Fail;
diff --git a/libsycl/test/basic/queue_single_task.cpp b/libsycl/test/basic/queue_single_task.cpp
new file mode 100644
index 0000000000000..139b5221590aa
--- /dev/null
+++ b/libsycl/test/basic/queue_single_task.cpp
@@ -0,0 +1,20 @@
+// REQUIRES: any-device
+// RUN: %clangxx -fsycl %s -o %t.out
+// RUN: %t.out
+
+#include <sycl/sycl.hpp>
+
+class Test;
+
+int main() {
+ sycl::queue Q;
+ int *Ptr = sycl::malloc_shared<int>(1, Q);
+ *Ptr = 0;
+ Q.single_task<Test>([=]() { *Ptr = 42; });
+ Q.wait();
+
+ bool Failed = *Ptr != 42;
+
+ sycl::free(Ptr, Q);
+ return Failed;
+}
diff --git a/libsycl/test/basic/sub_group_by_value_semantics.cpp b/libsycl/test/basic/sub_group_by_value_semantics.cpp
index 9db3e3044fd47..a3b1092cec52e 100644
--- a/libsycl/test/basic/sub_group_by_value_semantics.cpp
+++ b/libsycl/test/basic/sub_group_by_value_semantics.cpp
@@ -9,7 +9,7 @@ int main() {
bool *Result = sycl::malloc_shared<bool>(1, Q);
Result[0] = true;
- Q.parallel_for<class sub_group_by_value_semantics>(
+ Q.parallel_for<class SubGroupByValueSemantics>(
sycl::nd_range<3>({1, 1, 1}, {1, 1, 1}), [=](sycl::nd_item<3> Item) {
sycl::sub_group A = Item.get_sub_group();
diff --git a/libsycl/test/basic/sub_group_common.cpp b/libsycl/test/basic/sub_group_common.cpp
index 11ab99248cc55..9943a528b50c9 100644
--- a/libsycl/test/basic/sub_group_common.cpp
+++ b/libsycl/test/basic/sub_group_common.cpp
@@ -20,7 +20,7 @@ bool check(sycl::queue &Q, unsigned int G, unsigned int L) {
SyclData[I] = {0, 0, 0, 0, 0};
SgSize[0] = 0;
- Q.parallel_for<class sycl_subgr_common>(
+ Q.parallel_for<class SyclSubgrCommon>(
sycl::nd_range<1>(sycl::range<1>(G), sycl::range<1>(L)),
[=](sycl::nd_item<1> NdItem) {
sycl::sub_group SG = NdItem.get_sub_group();
diff --git a/libsycl/test/basic/submit_fn_ptr.cpp b/libsycl/test/basic/submit_fn_ptr.cpp
deleted file mode 100644
index b933c87e4ad15..0000000000000
--- a/libsycl/test/basic/submit_fn_ptr.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-// REQUIRES: any-device
-// RUN: %clangxx -fsycl %s -o %t.out
-// RUN: %t.out
-
-#include <sycl/sycl.hpp>
-
-class Test;
-
-int main() {
- sycl::queue q;
- int *p = sycl::malloc_shared<int>(1, q);
- *p = 0;
- q.single_task<Test>([=]() { *p = 42; });
- q.wait();
-
- bool Failed = *p != 42;
-
- sycl::free(p, q);
- return Failed;
-}
diff --git a/libsycl/test/basic/wrapped_usm_pointers.cpp b/libsycl/test/basic/wrapped_usm_pointers.cpp
index c936dcada4a6b..26a30462a1e9c 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 {
@@ -64,9 +64,9 @@ int main() {
// Test array of structs containing pointers.
Simple SimpleArr[NumOfElements];
- for (int i = 0; i < NumOfElements; ++i) {
- SimpleArr[i].Data = sycl::malloc_shared<int>(NumOfElements, Q);
- SimpleArr[i].Addition = 38 + i;
+ for (int I = 0; I < NumOfElements; ++I) {
+ SimpleArr[I].Data = sycl::malloc_shared<int>(NumOfElements, Q);
+ SimpleArr[I].Addition = 38 + I;
}
Q.parallel_for(range<2>(NumOfElements, NumOfElements), [=](item<2> Idx) {
@@ -77,10 +77,10 @@ int main() {
Q.wait();
auto Checker = [](auto Obj) {
- for (int i = 0; i < NumOfElements; ++i) {
- if (Obj.Data[i] != (i + Obj.Addition)) {
- std::cout << "line: " << __LINE__ << " result[" << i << "] is "
- << Obj.Data[i] << " expected " << i + Obj.Addition
+ for (int I = 0; I < NumOfElements; ++I) {
+ if (Obj.Data[I] != (I + Obj.Addition)) {
+ std::cout << "line: " << __LINE__ << " result[" << I << "] is "
+ << Obj.Data[I] << " expected " << I + Obj.Addition
<< std::endl;
return true; // true if fail
}
@@ -95,8 +95,8 @@ int main() {
Fail |= Checker(NonTrivialDerivedObj);
Fail |= Checker(WrapperOfSimpleObj.Obj);
- for (int i = 0; i < NumOfElements; ++i)
- Fail |= Checker(SimpleArr[i]);
+ for (int I = 0; I < NumOfElements; ++I)
+ Fail |= Checker(SimpleArr[I]);
// Free allocated memory.
sycl::free(NonTrivialObj.Data, Q);
@@ -104,8 +104,8 @@ int main() {
sycl::free(SimpleObj.Data, Q);
sycl::free(WrapperOfSimpleObj.Obj.Data, Q);
- for (int i = 0; i < NumOfElements; ++i)
- sycl::free(SimpleArr[i].Data, Q);
+ for (int I = 0; I < NumOfElements; ++I)
+ sycl::free(SimpleArr[I].Data, Q);
return Fail;
}
diff --git a/libsycl/test/usm/Inputs/fill_memset_common.hpp b/libsycl/test/usm/Inputs/fill_memset_common.hpp
index 5018aeb0ba4a9..9192e837a978f 100644
--- a/libsycl/test/usm/Inputs/fill_memset_common.hpp
+++ b/libsycl/test/usm/Inputs/fill_memset_common.hpp
@@ -5,6 +5,10 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
+
+#ifndef _LIBSYCL_TEST_USM_INPUTS_FILL_MEMSET_COMMON_HPP
+#define _LIBSYCL_TEST_USM_INPUTS_FILL_MEMSET_COMMON_HPP
+
#include <sycl/sycl.hpp>
#include <cassert>
@@ -46,3 +50,5 @@ void runTests(sycl::queue &Q, OpT Op, PatternT Pattern = 42) {
test<true>(Q, sycl::malloc_shared<DataT>(ElementCount, Q), Op, Pattern);
test<true>(Q, sycl::malloc_device<DataT>(ElementCount, Q), Op, Pattern);
}
+
+#endif // _LIBSYCL_TEST_USM_INPUTS_FILL_MEMSET_COMMON_HPP
diff --git a/libsycl/test/usm/alloc_functions.cpp b/libsycl/test/usm/alloc_functions.cpp
index 727d67e2be60d..c007a38c64595 100644
--- a/libsycl/test/usm/alloc_functions.cpp
+++ b/libsycl/test/usm/alloc_functions.cpp
@@ -6,6 +6,8 @@
#include <cassert>
#include <cstddef>
+#include <cstdint>
+#include <initializer_list>
#include <iostream>
#include <tuple>
@@ -14,15 +16,15 @@ using namespace sycl;
constexpr size_t Align = 256;
struct alignas(Align) Aligned {
- int x;
+ int X;
};
int main() {
- queue q;
- context ctx = q.get_context();
- device d = q.get_device();
+ queue Q;
+ context Ctx = Q.get_context();
+ device Dev = Q.get_device();
- auto check = [&q](size_t Alignment, auto AllocFn, int Line = __builtin_LINE(),
+ auto Check = [&Q](size_t Alignment, auto AllocFn, int Line = __builtin_LINE(),
int Case = 0) {
// First allocation might naturally be over-aligned. Do several of them to
// do the verification;
@@ -30,16 +32,16 @@ int main() {
for (auto *&Elem : Arr)
Elem = AllocFn();
for (auto *Ptr : Arr) {
- auto v = reinterpret_cast<uintptr_t>(Ptr);
- if ((v & (Alignment - 1)) != 0) {
+ auto Addr = reinterpret_cast<uintptr_t>(Ptr);
+ if ((Addr & (Alignment - 1)) != 0) {
std::cout << "Failed at line " << Line << ", case " << Case
<< std::endl;
assert(false && "Not properly aligned!");
- break; // To be used with commented out assert above.
+ break; // Reached only if asserts are disabled.
}
}
for (auto *Ptr : Arr)
- free(Ptr, q);
+ free(Ptr, Q);
};
// The strictest (largest) fundamental alignment of any type is the alignment
@@ -53,165 +55,167 @@ int main() {
[&](auto... Fs) {
int Case = 0;
(void)std::initializer_list<int>{
- (check(Expected, Fs, Line, Case++), 0)...};
+ (Check(Expected, Fs, Line, Case++), 0)...};
},
Funcs);
};
- auto MDevice = [&](auto... args) {
- return malloc_device(sizeof(std::max_align_t), args...);
+ auto MDevice = [&](auto... Args) {
+ return malloc_device(sizeof(std::max_align_t), Args...);
};
CheckAll(FAlign,
- std::tuple{[&]() { return MDevice(q); },
- [&]() { return MDevice(d, ctx); },
- [&]() { return MDevice(q, property_list{}); },
- [&]() { return MDevice(d, ctx, property_list{}); }});
+ std::tuple{[&]() { return MDevice(Q); },
+ [&]() { return MDevice(Dev, Ctx); },
+ [&]() { return MDevice(Q, property_list{}); },
+ [&]() { return MDevice(Dev, Ctx, property_list{}); }});
- auto ADevice = [&](auto... args) {
- return aligned_alloc_device(Align, 1024, args...);
+ auto ADevice = [&](auto... Args) {
+ return aligned_alloc_device(Align, 1024, Args...);
};
CheckAll(Align, std::tuple{
- [&]() { return ADevice(q); },
- [&]() { return ADevice(d, ctx); },
- [&]() { return ADevice(q, property_list{}); },
- [&]() { return ADevice(d, ctx, property_list{}); },
+ [&]() { return ADevice(Q); },
+ [&]() { return ADevice(Dev, Ctx); },
+ [&]() { return ADevice(Q, property_list{}); },
+ [&]() { return ADevice(Dev, Ctx, property_list{}); },
});
- auto MHost = [&](auto... args) {
- return malloc_host(sizeof(std::max_align_t), args...);
+ auto MHost = [&](auto... Args) {
+ return malloc_host(sizeof(std::max_align_t), Args...);
};
CheckAll(FAlign,
- std::tuple{[&]() { return MHost(q); }, [&]() { return MHost(ctx); },
- [&]() { return MHost(q, property_list{}); },
- [&]() { return MHost(ctx, property_list{}); }});
+ std::tuple{[&]() { return MHost(Q); }, [&]() { return MHost(Ctx); },
+ [&]() { return MHost(Q, property_list{}); },
+ [&]() { return MHost(Ctx, property_list{}); }});
- auto AHost = [&](auto... args) {
- return aligned_alloc_host(Align, 1024, args...);
+ auto AHost = [&](auto... Args) {
+ return aligned_alloc_host(Align, 1024, Args...);
};
CheckAll(Align, std::tuple{
- [&]() { return AHost(q); },
- [&]() { return AHost(ctx); },
- [&]() { return AHost(q, property_list{}); },
- [&]() { return AHost(ctx, property_list{}); },
+ [&]() { return AHost(Q); },
+ [&]() { return AHost(Ctx); },
+ [&]() { return AHost(Q, property_list{}); },
+ [&]() { return AHost(Ctx, property_list{}); },
});
- if (d.has(aspect::usm_shared_allocations)) {
- auto MShared = [&](auto... args) {
- return malloc_shared(sizeof(std::max_align_t), args...);
+ if (Dev.has(aspect::usm_shared_allocations)) {
+ auto MShared = [&](auto... Args) {
+ return malloc_shared(sizeof(std::max_align_t), Args...);
};
CheckAll(FAlign,
- std::tuple{[&]() { return MShared(q); },
- [&]() { return MShared(d, ctx); },
- [&]() { return MShared(q, property_list{}); },
- [&]() { return MShared(d, ctx, property_list{}); }});
+ std::tuple{[&]() { return MShared(Q); },
+ [&]() { return MShared(Dev, Ctx); },
+ [&]() { return MShared(Q, property_list{}); },
+ [&]() { return MShared(Dev, Ctx, property_list{}); }});
- auto AShared = [&](auto... args) {
- return aligned_alloc_shared(Align, 1024, args...);
+ auto AShared = [&](auto... Args) {
+ return aligned_alloc_shared(Align, 1024, Args...);
};
CheckAll(Align, std::tuple{
- [&]() { return AShared(q); },
- [&]() { return AShared(d, ctx); },
- [&]() { return AShared(q, property_list{}); },
- [&]() { return AShared(d, ctx, property_list{}); },
+ [&]() { return AShared(Q); },
+ [&]() { return AShared(Dev, Ctx); },
+ [&]() { return AShared(Q, property_list{}); },
+ [&]() { return AShared(Dev, Ctx, property_list{}); },
});
}
- auto TDevice = [&](auto... args) {
- return malloc_device<Aligned>(1, args...);
+ auto TDevice = [&](auto... Args) {
+ return malloc_device<Aligned>(1, Args...);
};
- CheckAll(Align, std::tuple{[&]() { return TDevice(q); },
- [&]() { return TDevice(d, ctx); }});
+ CheckAll(Align, std::tuple{[&]() { return TDevice(Q); },
+ [&]() { return TDevice(Dev, Ctx); }});
- auto TADevice = [&](auto... args) {
- return aligned_alloc_device<Aligned>(Align, 1, args...);
+ auto TADevice = [&](auto... Args) {
+ return aligned_alloc_device<Aligned>(Align, 1, Args...);
};
- CheckAll(Align, std::tuple{[&]() { return TADevice(q); },
- [&]() { return TADevice(d, ctx); }});
+ CheckAll(Align, std::tuple{[&]() { return TADevice(Q); },
+ [&]() { return TADevice(Dev, Ctx); }});
- auto THost = [&](auto... args) { return malloc_host<Aligned>(1, args...); };
- CheckAll(Align, std::tuple{[&]() { return THost(q); },
- [&]() { return THost(ctx); }});
+ auto THost = [&](auto... Args) { return malloc_host<Aligned>(1, Args...); };
+ CheckAll(Align, std::tuple{[&]() { return THost(Q); },
+ [&]() { return THost(Ctx); }});
- auto TAHost = [&](auto... args) {
- return aligned_alloc_host<Aligned>(Align, 1, args...);
+ auto TAHost = [&](auto... Args) {
+ return aligned_alloc_host<Aligned>(Align, 1, Args...);
};
- CheckAll(Align, std::tuple{[&]() { return TAHost(q); },
- [&]() { return TAHost(ctx); }});
+ CheckAll(Align, std::tuple{[&]() { return TAHost(Q); },
+ [&]() { return TAHost(Ctx); }});
- if (d.has(aspect::usm_shared_allocations)) {
- auto TShared = [&](auto... args) {
- return malloc_shared<Aligned>(1, args...);
+ if (Dev.has(aspect::usm_shared_allocations)) {
+ auto TShared = [&](auto... Args) {
+ return malloc_shared<Aligned>(1, Args...);
};
- CheckAll(Align, std::tuple{[&]() { return TShared(q); },
- [&]() { return TShared(d, ctx); }});
- auto TAShared = [&](auto... args) {
- return aligned_alloc_shared<Aligned>(Align, 1, args...);
+ CheckAll(Align, std::tuple{[&]() { return TShared(Q); },
+ [&]() { return TShared(Dev, Ctx); }});
+ auto TAShared = [&](auto... Args) {
+ return aligned_alloc_shared<Aligned>(Align, 1, Args...);
};
- CheckAll(Align, std::tuple{[&]() { return TAShared(q); },
- [&]() { return TAShared(d, ctx); }});
+ CheckAll(Align, std::tuple{[&]() { return TAShared(Q); },
+ [&]() { return TAShared(Dev, Ctx); }});
}
- auto Malloc = [&](auto... args) {
- return malloc(sizeof(std::max_align_t), args...);
+ auto Malloc = [&](auto... Args) {
+ return malloc(sizeof(std::max_align_t), Args...);
};
CheckAll(
FAlign,
- std::tuple{
- [&]() { return Malloc(q, usm::alloc::host); },
- [&]() { return Malloc(d, ctx, usm::alloc::host); },
- [&]() { return Malloc(q, usm::alloc::host, property_list{}); },
- [&]() { return Malloc(d, ctx, usm::alloc::host, property_list{}); }});
-
- auto AMalloc = [&](auto... args) {
- return aligned_alloc(Align, 1024, args...);
+ std::tuple{[&]() { return Malloc(Q, usm::alloc::host); },
+ [&]() { return Malloc(Dev, Ctx, usm::alloc::host); },
+ [&]() { return Malloc(Q, usm::alloc::host, property_list{}); },
+ [&]() {
+ return Malloc(Dev, Ctx, usm::alloc::host, property_list{});
+ }});
+
+ auto AMalloc = [&](auto... Args) {
+ return aligned_alloc(Align, 1024, Args...);
};
- CheckAll(
- Align,
- std::tuple{
- [&]() { return AMalloc(q, usm::alloc::host); },
- [&]() { return AMalloc(d, ctx, usm::alloc::host); },
- [&]() { return AMalloc(q, usm::alloc::host, property_list{}); },
- [&]() { return AMalloc(d, ctx, usm::alloc::host, property_list{}); },
- });
-
- auto TMalloc = [&](auto... args) { return malloc<Aligned>(1, args...); };
CheckAll(Align,
- std::tuple{[&]() { return TMalloc(q, usm::alloc::host); },
- [&]() { return TMalloc(d, ctx, usm::alloc::host); }});
+ std::tuple{
+ [&]() { return AMalloc(Q, usm::alloc::host); },
+ [&]() { return AMalloc(Dev, Ctx, usm::alloc::host); },
+ [&]() { return AMalloc(Q, usm::alloc::host, property_list{}); },
+ [&]() {
+ return AMalloc(Dev, Ctx, usm::alloc::host, property_list{});
+ },
+ });
+
+ auto TMalloc = [&](auto... Args) { return malloc<Aligned>(1, Args...); };
+ CheckAll(Align,
+ std::tuple{[&]() { return TMalloc(Q, usm::alloc::host); },
+ [&]() { return TMalloc(Dev, Ctx, usm::alloc::host); }});
- auto TAMalloc = [&](auto... args) {
- return aligned_alloc<Aligned>(Align, 1, args...);
+ auto TAMalloc = [&](auto... Args) {
+ return aligned_alloc<Aligned>(Align, 1, Args...);
};
CheckAll(Align,
- std::tuple{[&]() { return TAMalloc(q, usm::alloc::host); },
- [&]() { return TAMalloc(d, ctx, usm::alloc::host); }});
+ std::tuple{[&]() { return TAMalloc(Q, usm::alloc::host); },
+ [&]() { return TAMalloc(Dev, Ctx, usm::alloc::host); }});
// Testing invalid arguments for alignment
- assert(aligned_alloc_device(3, 1024, q) == nullptr);
- assert(aligned_alloc_host(3, 1024, q) == nullptr);
- assert(aligned_alloc_shared(3, 1024, q) == nullptr);
+ assert(aligned_alloc_device(3, 1024, Q) == nullptr);
+ assert(aligned_alloc_host(3, 1024, Q) == nullptr);
+ assert(aligned_alloc_shared(3, 1024, Q) == nullptr);
// A requested alignment of 0 means "no specific alignment" and must
// succeed, routing through the plain (non-aligned) allocation path.
- void *ZeroAlignPtr = aligned_alloc_device(0, 1024, q);
+ void *ZeroAlignPtr = aligned_alloc_device(0, 1024, Q);
assert(ZeroAlignPtr != nullptr);
- free(ZeroAlignPtr, q);
+ free(ZeroAlignPtr, Q);
- ZeroAlignPtr = aligned_alloc_host(0, 1024, q);
+ ZeroAlignPtr = aligned_alloc_host(0, 1024, Q);
assert(ZeroAlignPtr != nullptr);
- free(ZeroAlignPtr, q);
+ free(ZeroAlignPtr, Q);
- ZeroAlignPtr = aligned_alloc_shared(0, 1024, q);
+ ZeroAlignPtr = aligned_alloc_shared(0, 1024, Q);
assert(ZeroAlignPtr != nullptr);
- free(ZeroAlignPtr, q);
+ free(ZeroAlignPtr, Q);
return 0;
}
diff --git a/libsycl/test/usm/memcpy.cpp b/libsycl/test/usm/memcpy.cpp
index f297c1b36728d..58509c724b767 100644
--- a/libsycl/test/usm/memcpy.cpp
+++ b/libsycl/test/usm/memcpy.cpp
@@ -4,9 +4,12 @@
#include <sycl/sycl.hpp>
+#include <cassert>
#include <cstddef>
+#include <memory>
#include <numeric>
#include <tuple>
+#include <vector>
using namespace sycl;
@@ -17,9 +20,9 @@ constexpr std::size_t NumBytes = DataSize * sizeof(int);
// performing a sequence of copies from one allocation to the next,
// using MemCpyFunc to specify dependencies.
// Assumes that the first and the last allocations are accessible on host.
-template <typename MemcpyFuncT, typename... AllocFuncssT>
+template <typename MemcpyFuncT, typename... AllocFuncsT>
void test(queue &Q, MemcpyFuncT MemCpyFunc,
- std::tuple<AllocFuncssT...> AllocFs) {
+ std::tuple<AllocFuncsT...> AllocFs) {
constexpr std::size_t NAllocations = std::tuple_size_v<decltype(AllocFs)>;
static_assert(NAllocations > 1);
diff --git a/libsycl/test/usm/prefetch.cpp b/libsycl/test/usm/prefetch.cpp
index e13d87a9a5c6f..80951ebd80e89 100644
--- a/libsycl/test/usm/prefetch.cpp
+++ b/libsycl/test/usm/prefetch.cpp
@@ -4,6 +4,7 @@
#include <sycl/sycl.hpp>
+#include <cassert>
#include <cstddef>
using namespace sycl;
diff --git a/libsycl/tools/sycl-ls/sycl-ls.cpp b/libsycl/tools/sycl-ls/sycl-ls.cpp
index 2938d767a404b..f945820c0eaf8 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>();
- printDeviceInfo(Device, false /*Verbose*/,
- Prepend + DeviceTypeName + ", " + PlatformName);
+ const device Device(Selector);
+ const platform Platform = Device.get_info<info::device::platform>();
+ printDeviceInfo(Device, /*Verbose=*/false,
+ 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/common/unittests_helper.hpp b/libsycl/unittests/common/unittests_helper.hpp
index 49a16d5c5fb68..6109a1ed39370 100644
--- a/libsycl/unittests/common/unittests_helper.hpp
+++ b/libsycl/unittests/common/unittests_helper.hpp
@@ -32,7 +32,7 @@ struct UnittestsHelper {
// Platforms cached by earlier tests would hide the device enumeration mocked
// by the fixture, so the global state is reset on both ends.
UnittestsHelper() {
- detail::PlatformImpl::rediscoverIfEmpty = true;
+ detail::PlatformImpl::MRediscoverIfEmpty = true;
resetGlobalState();
}
diff --git a/libsycl/unittests/context/context_ctors.cpp b/libsycl/unittests/context/context_ctors.cpp
index b5d050175f4ad..0c4b48acbeeaf 100644
--- a/libsycl/unittests/context/context_ctors.cpp
+++ b/libsycl/unittests/context/context_ctors.cpp
@@ -1,3 +1,11 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
#include <mock/helpers.hpp>
#include <sycl/__impl/context.hpp>
diff --git a/libsycl/unittests/handler/memcpy.cpp b/libsycl/unittests/handler/memcpy.cpp
index 24f04376ff79c..6e7a9a2796ae2 100644
--- a/libsycl/unittests/handler/memcpy.cpp
+++ b/libsycl/unittests/handler/memcpy.cpp
@@ -1,3 +1,11 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
#include "test_helpers.hpp"
#include <mock/helpers.hpp>
diff --git a/libsycl/unittests/handler/semantics.cpp b/libsycl/unittests/handler/semantics.cpp
index b4324a508554b..8ba7b909ef5ad 100644
--- a/libsycl/unittests/handler/semantics.cpp
+++ b/libsycl/unittests/handler/semantics.cpp
@@ -1,3 +1,11 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
#include "test_helpers.hpp"
#include <mock/helpers.hpp>
@@ -10,6 +18,7 @@
#include <gtest/gtest.h>
#include <string>
+#include <vector>
using namespace sycl;
using namespace ::testing;
@@ -108,7 +117,7 @@ TEST(Handler, EmptyCommandGroupNoDependencies) {
E.wait();
}
-TEST(Queue, SubmitCannotBeNested) {
+TEST(Handler, SubmitCannotBeNested) {
mock::MockWrapper Mock;
queue Q;
diff --git a/libsycl/unittests/handler/test_helpers.hpp b/libsycl/unittests/handler/test_helpers.hpp
index 1c383e747390e..a5fdcefcf0440 100644
--- a/libsycl/unittests/handler/test_helpers.hpp
+++ b/libsycl/unittests/handler/test_helpers.hpp
@@ -1,5 +1,13 @@
-#ifndef LIBSYCL_UNITTESTS_HANDLER_TEST_HELPERS_HPP
-#define LIBSYCL_UNITTESTS_HANDLER_TEST_HELPERS_HPP
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBSYCL_UNITTESTS_HANDLER_TEST_HELPERS_HPP
+#define _LIBSYCL_UNITTESTS_HANDLER_TEST_HELPERS_HPP
#include <mock/helpers.hpp>
@@ -8,15 +16,17 @@
#include <gmock/gmock.h>
#include <algorithm>
-#include <initializer_list>
#include <vector>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
namespace unittests {
-inline void expectDeviceMemoryInfo(mock::MockWrapper &Mock,
- const std::vector<const void *> ExpectedPtrs,
- ol_device_handle_t Device, int Count) {
+/// Expects \p Count olGetMemInfo(OL_MEM_INFO_DEVICE) queries, each for one of
+/// \p ExpectedPtrs, and reports \p Device as the owning device.
+inline void
+expectDeviceMemoryInfo(mock::MockWrapper &Mock,
+ const std::vector<const void *> &ExpectedPtrs,
+ ol_device_handle_t Device, int Count) {
EXPECT_CALL(Mock.get(),
olGetMemInfo(::testing::_, ::testing::_, OL_MEM_INFO_DEVICE,
sizeof(ol_device_handle_t), ::testing::_))
@@ -34,4 +44,4 @@ inline void expectDeviceMemoryInfo(mock::MockWrapper &Mock,
} // namespace unittests
_LIBSYCL_END_NAMESPACE_SYCL
-#endif
+#endif // _LIBSYCL_UNITTESTS_HANDLER_TEST_HELPERS_HPP
diff --git a/libsycl/unittests/mock/helpers.cpp b/libsycl/unittests/mock/helpers.cpp
index bf0baf51b1917..24413675d6cbe 100644
--- a/libsycl/unittests/mock/helpers.cpp
+++ b/libsycl/unittests/mock/helpers.cpp
@@ -396,25 +396,24 @@ void mock::MockLiboffload::initDefault() {
});
ON_CALL(*this, olMemAllocAligned)
- .WillByDefault([this](ol_context_handle_t Context,
- ol_device_handle_t Device,
- ol_alloc_type_t AllocType, size_t Size,
- size_t Alignment,
- void **AllocationOut) -> ol_result_t {
- EXPECT_NE(Context, nullptr);
- EXPECT_NE(Device, nullptr);
- EXPECT_TRUE(AllocType == OL_ALLOC_TYPE_DEVICE ||
- AllocType == OL_ALLOC_TYPE_MANAGED);
- EXPECT_GT(Size, 0);
- EXPECT_GT(Alignment, 0);
- if ((Alignment & (Alignment - 1)) != 0) {
- return makeEmptyStrError(OL_ERRC_INVALID_ARGUMENT);
- }
- EXPECT_NE(AllocationOut, nullptr);
-
- *AllocationOut = mock::createDummyHandle<void *>();
- return OL_SUCCESS;
- });
+ .WillByDefault(
+ [this](ol_context_handle_t Context, ol_device_handle_t Device,
+ ol_alloc_type_t AllocType, size_t Size, size_t Alignment,
+ void **AllocationOut) -> ol_result_t {
+ EXPECT_NE(Context, nullptr);
+ EXPECT_NE(Device, nullptr);
+ EXPECT_TRUE(AllocType == OL_ALLOC_TYPE_DEVICE ||
+ AllocType == OL_ALLOC_TYPE_MANAGED);
+ EXPECT_GT(Size, 0);
+ EXPECT_GT(Alignment, 0);
+ if ((Alignment & (Alignment - 1)) != 0) {
+ return makeEmptyStrError(OL_ERRC_INVALID_ARGUMENT);
+ }
+ EXPECT_NE(AllocationOut, nullptr);
+
+ *AllocationOut = mock::createDummyHandle<void *>();
+ return OL_SUCCESS;
+ });
ON_CALL(*this, olMemAllocAlignedHost)
.WillByDefault([this](ol_context_handle_t Context,
diff --git a/libsycl/unittests/mock/helpers.hpp b/libsycl/unittests/mock/helpers.hpp
index b7b1d3a0735f2..317504ac75be2 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());
}
@@ -192,7 +192,7 @@ class MockWrapper {
Mock.initDefault();
}
- MockLiboffload &get() { return Mock; };
+ MockLiboffload &get() { return Mock; }
private:
MockLiboffload &Mock;
diff --git a/libsycl/unittests/queue/memcpy.cpp b/libsycl/unittests/queue/memcpy.cpp
index 9413c9cd5b63f..bdb13ee031c52 100644
--- a/libsycl/unittests/queue/memcpy.cpp
+++ b/libsycl/unittests/queue/memcpy.cpp
@@ -1,3 +1,11 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
#include <common/unittests_helper.hpp>
#include <mock/helpers.hpp>
@@ -6,7 +14,6 @@
#include <sycl/__impl/queue.hpp>
#include <detail/device_impl.hpp>
-#include <detail/queue_impl.hpp>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
diff --git a/libsycl/unittests/queue/prefetch.cpp b/libsycl/unittests/queue/prefetch.cpp
index 6bedd4ba8337b..32ffd2e1760ec 100644
--- a/libsycl/unittests/queue/prefetch.cpp
+++ b/libsycl/unittests/queue/prefetch.cpp
@@ -1,3 +1,11 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
#include <mock/helpers.hpp>
#include <sycl/__impl/queue.hpp>
@@ -5,6 +13,8 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+#include <cstddef>
+
using namespace sycl;
using namespace ::testing;
More information about the llvm-commits
mailing list