From 28ba395f87a2cc3bc8f28a8c7f3f7be0fa401104 Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Fri, 29 Mar 2024 14:01:02 -0700 Subject: [PATCH] [SYCL][Headers cleanup] Introduce This allows us to drop several ``'s dependencies. --- sycl/include/sycl/buffer.hpp | 41 +++++---- .../sycl/detail/is_device_copyable.hpp | 84 +++++++++++++++++++ sycl/include/sycl/marray.hpp | 21 +++-- sycl/include/sycl/types.hpp | 72 +--------------- sycl/test/include_deps/sycl_accessor.hpp.cpp | 13 +-- sycl/test/include_deps/sycl_buffer.hpp.cpp | 8 +- .../include_deps/sycl_detail_core.hpp.cpp | 13 +-- 7 files changed, 133 insertions(+), 119 deletions(-) create mode 100644 sycl/include/sycl/detail/is_device_copyable.hpp diff --git a/sycl/include/sycl/buffer.hpp b/sycl/include/sycl/buffer.hpp index 20dae979c8528..fd67d3da78331 100644 --- a/sycl/include/sycl/buffer.hpp +++ b/sycl/include/sycl/buffer.hpp @@ -8,28 +8,27 @@ #pragma once -#include // for placeholder -#include // for backend, backe... -#include // for context -#include // for array -#include // for code_location -#include // for __SYCL2020_DEP... -#include // for __SYCL_EXPORT -#include // for buffer_impl -#include // for OwnerLessBase +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include // for pi_native_handle and PI_ERROR_INVAL -#include // for PropWithDataKind -#include // for iterator_value... -#include // for iterator_to_const_type_t -#include // for SYCLMemObjAllo... -#include // for remove_pointer_t -#include // for event -#include // for invalid_object... -#include // for accessor_prope... -#include // for id -#include // for property_list -#include // for range, rangeTo... -#include // for is_device_copyable +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include // for size_t, nullptr_t #include // for function diff --git a/sycl/include/sycl/detail/is_device_copyable.hpp b/sycl/include/sycl/detail/is_device_copyable.hpp new file mode 100644 index 0000000000000..32556349aed2b --- /dev/null +++ b/sycl/include/sycl/detail/is_device_copyable.hpp @@ -0,0 +1,84 @@ +//==------------ is_device_copyable.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 +// +//===----------------------------------------------------------------------===// +#pragma once + +#include +#include +#include +#include + +/// This macro must be defined to 1 when SYCL implementation allows user +/// applications to explicitly declare certain class types as device copyable +/// by adding specializations of is_device_copyable type trait class. +#define SYCL_DEVICE_COPYABLE 1 + +namespace sycl { +inline namespace _V1 { +/// is_device_copyable is a user specializable class template to indicate +/// that a type T is device copyable, which means that SYCL implementation +/// may copy objects of the type T between host and device or between two +/// devices. +/// Specializing is_device_copyable such a way that +/// is_device_copyable_v == true on a T that does not satisfy all +/// the requirements of a device copyable type is undefined behavior. +template struct is_device_copyable; + +namespace detail { +template +struct is_device_copyable_impl : std::is_trivially_copyable {}; + +template +struct is_device_copyable_impl< + T, std::enable_if_t>>> + // Cannot express this "recursion" (to take user's partial non-cv + // specializations into account) without this helper struct. + : is_device_copyable> {}; +} // namespace detail + +template +struct is_device_copyable : detail::is_device_copyable_impl {}; + +// std::array is implicitly device copyable type. +template +struct is_device_copyable> : std::true_type {}; + +// std::array is implicitly device copyable type if T is device copyable. +template +struct is_device_copyable> : is_device_copyable {}; + +// std::optional is implicitly device copyable type if T is device copyable. +template +struct is_device_copyable> : is_device_copyable {}; + +// std::pair is implicitly device copyable type if T1 and T2 are device +// copyable. +template +struct is_device_copyable> + : std::bool_constant::value && + is_device_copyable::value> {}; + +// std::tuple is implicitly device copyable type if each type T of Ts... +// is device copyable. +template +struct is_device_copyable> + : std::bool_constant<(... && is_device_copyable::value)> {}; + +// std::variant is implicitly device copyable type if each type T of +// Ts... is device copyable. +template +struct is_device_copyable> + : std::bool_constant<(... && is_device_copyable::value)> {}; + +// array is device copyable if element type is device copyable. +template +struct is_device_copyable : is_device_copyable {}; + +template +inline constexpr bool is_device_copyable_v = is_device_copyable::value; +} // namespace _V1 +} // namespace sycl diff --git a/sycl/include/sycl/marray.hpp b/sycl/include/sycl/marray.hpp index 827ae13b0a741..644bae510c2f0 100644 --- a/sycl/include/sycl/marray.hpp +++ b/sycl/include/sycl/marray.hpp @@ -8,15 +8,16 @@ #pragma once -#include // for half -#include // for ArrayCreator -#include // for half +#include +#include +#include +#include -#include // for array -#include // for size_t -#include // for int64_t, int8_t, uint64_t, int16_t -#include // for enable_if_t, remove_const, is_conv... -#include // for index_sequence, make_index_sequence +#include +#include +#include +#include +#include namespace sycl { inline namespace _V1 { @@ -363,6 +364,10 @@ template class marray { } }; +// marray is device copyable if element type is device copyable. +template +struct is_device_copyable> : is_device_copyable {}; + #define __SYCL_MAKE_MARRAY_ALIAS(ALIAS, TYPE, N) \ using ALIAS##N = sycl::marray; diff --git a/sycl/include/sycl/types.hpp b/sycl/include/sycl/types.hpp index 056012fd08cf1..cbc125f213a58 100644 --- a/sycl/include/sycl/types.hpp +++ b/sycl/include/sycl/types.hpp @@ -36,6 +36,7 @@ #include // for __SYCL2020_DEPRECATED #include // for vector_basic_list #include // for is_sigeninteger, is_s... +#include #include // for memcpy #include // for is_contained #include // for is_floating_point @@ -2195,77 +2196,6 @@ __SYCL_DEFINE_BF16_VECSTORAGE(16) #undef __SYCL_DEFINE_BF16_VECSTORAGE } // namespace detail -/// This macro must be defined to 1 when SYCL implementation allows user -/// applications to explicitly declare certain class types as device copyable -/// by adding specializations of is_device_copyable type trait class. -#define SYCL_DEVICE_COPYABLE 1 - -/// is_device_copyable is a user specializable class template to indicate -/// that a type T is device copyable, which means that SYCL implementation -/// may copy objects of the type T between host and device or between two -/// devices. -/// Specializing is_device_copyable such a way that -/// is_device_copyable_v == true on a T that does not satisfy all -/// the requirements of a device copyable type is undefined behavior. -template struct is_device_copyable; - -namespace detail { -template -struct is_device_copyable_impl : std::is_trivially_copyable {}; - -template -struct is_device_copyable_impl< - T, std::enable_if_t>>> - // Cannot express this "recursion" (to take user's partial non-cv - // specializations into account) without this helper struct. - : is_device_copyable> {}; -} // namespace detail - -template -struct is_device_copyable : detail::is_device_copyable_impl {}; - -// std::array is implicitly device copyable type. -template -struct is_device_copyable> : std::true_type {}; - -// std::array is implicitly device copyable type if T is device copyable. -template -struct is_device_copyable> : is_device_copyable {}; - -// std::optional is implicitly device copyable type if T is device copyable. -template -struct is_device_copyable> : is_device_copyable {}; - -// std::pair is implicitly device copyable type if T1 and T2 are device -// copyable. -template -struct is_device_copyable> - : std::bool_constant::value && - is_device_copyable::value> {}; - -// std::tuple is implicitly device copyable type if each type T of Ts... -// is device copyable. -template -struct is_device_copyable> - : std::bool_constant<(... && is_device_copyable::value)> {}; - -// std::variant is implicitly device copyable type if each type T of -// Ts... is device copyable. -template -struct is_device_copyable> - : std::bool_constant<(... && is_device_copyable::value)> {}; - -// marray is device copyable if element type is device copyable. -template -struct is_device_copyable> : is_device_copyable {}; - -// array is device copyable if element type is device copyable. -template -struct is_device_copyable : is_device_copyable {}; - -template -inline constexpr bool is_device_copyable_v = is_device_copyable::value; - namespace detail { template struct IsDeprecatedDeviceCopyable : std::false_type {}; diff --git a/sycl/test/include_deps/sycl_accessor.hpp.cpp b/sycl/test/include_deps/sycl_accessor.hpp.cpp index 49354f2244201..1b4606d57cafc 100644 --- a/sycl/test/include_deps/sycl_accessor.hpp.cpp +++ b/sycl/test/include_deps/sycl_accessor.hpp.cpp @@ -106,23 +106,24 @@ // CHECK-NEXT: detail/property_helper.hpp // CHECK-NEXT: detail/property_list_base.hpp // CHECK-NEXT: properties/property_traits.hpp +// CHECK-NEXT: detail/is_device_copyable.hpp // CHECK-NEXT: detail/stl_type_traits.hpp // CHECK-NEXT: detail/sycl_mem_obj_allocator.hpp // CHECK-NEXT: detail/aligned_allocator.hpp // CHECK-NEXT: event.hpp // CHECK-NEXT: ext/oneapi/accessor_property_list.hpp -// CHECK-NEXT: types.hpp -// CHECK-NEXT: detail/generic_type_traits.hpp -// CHECK-NEXT: detail/memcpy.hpp -// CHECK-NEXT: detail/vector_convert.hpp -// CHECK-NEXT: marray.hpp -// CHECK-NEXT: swizzles.def // CHECK-NEXT: detail/accessor_iterator.hpp +// CHECK-NEXT: detail/generic_type_traits.hpp // CHECK-NEXT: detail/handler_proxy.hpp // CHECK-NEXT: detail/image_accessor_util.hpp // CHECK-NEXT: image.hpp // CHECK-NEXT: detail/backend_traits.hpp // CHECK-NEXT: sampler.hpp +// CHECK-NEXT: types.hpp +// CHECK-NEXT: detail/memcpy.hpp +// CHECK-NEXT: detail/vector_convert.hpp +// CHECK-NEXT: marray.hpp +// CHECK-NEXT: swizzles.def // CHECK-NEXT: pointers.hpp // CHECK-NEXT: properties/accessor_properties.hpp // CHECK-NEXT: properties/buffer_properties.hpp diff --git a/sycl/test/include_deps/sycl_buffer.hpp.cpp b/sycl/test/include_deps/sycl_buffer.hpp.cpp index fa40cde1411c5..4199187ee9488 100644 --- a/sycl/test/include_deps/sycl_buffer.hpp.cpp +++ b/sycl/test/include_deps/sycl_buffer.hpp.cpp @@ -103,16 +103,10 @@ // CHECK-NEXT: detail/property_helper.hpp // CHECK-NEXT: detail/property_list_base.hpp // CHECK-NEXT: properties/property_traits.hpp +// CHECK-NEXT: detail/is_device_copyable.hpp // CHECK-NEXT: detail/stl_type_traits.hpp // CHECK-NEXT: detail/sycl_mem_obj_allocator.hpp // CHECK-NEXT: detail/aligned_allocator.hpp // CHECK-NEXT: event.hpp // CHECK-NEXT: ext/oneapi/accessor_property_list.hpp -// CHECK-NEXT: types.hpp -// CHECK-NEXT: detail/generic_type_traits.hpp -// CHECK-NEXT: multi_ptr.hpp -// CHECK-NEXT: detail/memcpy.hpp -// CHECK-NEXT: detail/vector_convert.hpp -// CHECK-NEXT: marray.hpp -// CHECK-NEXT: swizzles.def // CHECK-EMPTY: diff --git a/sycl/test/include_deps/sycl_detail_core.hpp.cpp b/sycl/test/include_deps/sycl_detail_core.hpp.cpp index 78041a23d328d..7bd3b9d9392e2 100644 --- a/sycl/test/include_deps/sycl_detail_core.hpp.cpp +++ b/sycl/test/include_deps/sycl_detail_core.hpp.cpp @@ -107,23 +107,24 @@ // CHECK-NEXT: detail/property_helper.hpp // CHECK-NEXT: detail/property_list_base.hpp // CHECK-NEXT: properties/property_traits.hpp +// CHECK-NEXT: detail/is_device_copyable.hpp // CHECK-NEXT: detail/stl_type_traits.hpp // CHECK-NEXT: detail/sycl_mem_obj_allocator.hpp // CHECK-NEXT: detail/aligned_allocator.hpp // CHECK-NEXT: event.hpp // CHECK-NEXT: ext/oneapi/accessor_property_list.hpp -// CHECK-NEXT: types.hpp -// CHECK-NEXT: detail/generic_type_traits.hpp -// CHECK-NEXT: detail/memcpy.hpp -// CHECK-NEXT: detail/vector_convert.hpp -// CHECK-NEXT: marray.hpp -// CHECK-NEXT: swizzles.def // CHECK-NEXT: detail/accessor_iterator.hpp +// CHECK-NEXT: detail/generic_type_traits.hpp // CHECK-NEXT: detail/handler_proxy.hpp // CHECK-NEXT: detail/image_accessor_util.hpp // CHECK-NEXT: image.hpp // CHECK-NEXT: detail/backend_traits.hpp // CHECK-NEXT: sampler.hpp +// CHECK-NEXT: types.hpp +// CHECK-NEXT: detail/memcpy.hpp +// CHECK-NEXT: detail/vector_convert.hpp +// CHECK-NEXT: marray.hpp +// CHECK-NEXT: swizzles.def // CHECK-NEXT: pointers.hpp // CHECK-NEXT: properties/accessor_properties.hpp // CHECK-NEXT: properties/buffer_properties.hpp