From 24e7b358ef9865f895d86602061c10f135daa35b Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Mon, 14 Oct 2024 14:19:00 -0700 Subject: [PATCH] [NFC][SYCL] Move vector/marray type traits into a standalone header Use `sycl::vec`/`sycl::marray` forward declaration to remove all the dependencies, so that the new header could later be used in various type traits without introducing circular dependency. --- sycl/include/sycl/builtins_utils_vec.hpp | 15 +-- sycl/include/sycl/detail/type_traits.hpp | 40 +------ .../detail/type_traits/vec_marray_traits.hpp | 104 ++++++++++++++++++ sycl/test/include_deps/sycl_accessor.hpp.cpp | 3 +- .../include_deps/sycl_detail_core.hpp.cpp | 1 + 5 files changed, 111 insertions(+), 52 deletions(-) create mode 100644 sycl/include/sycl/detail/type_traits/vec_marray_traits.hpp diff --git a/sycl/include/sycl/builtins_utils_vec.hpp b/sycl/include/sycl/builtins_utils_vec.hpp index eeaff9450b031..178c696495c8e 100644 --- a/sycl/include/sycl/builtins_utils_vec.hpp +++ b/sycl/include/sycl/builtins_utils_vec.hpp @@ -8,6 +8,8 @@ #pragma once +#include + #include #include @@ -41,19 +43,6 @@ template struct is_valid_elem_type : std::bool_constant> {}; -// Utility trait for getting the number of elements in T. -template -struct num_elements : std::integral_constant {}; -template -struct num_elements> : std::integral_constant {}; -template -struct num_elements> : std::integral_constant {}; -template class OperationCurrentT, int... Indexes> -struct num_elements> - : std::integral_constant {}; - // Utilty trait for checking that the number of elements in T is in Ns. template struct is_valid_size diff --git a/sycl/include/sycl/detail/type_traits.hpp b/sycl/include/sycl/detail/type_traits.hpp index 90790633faa9f..17eb9faba79c4 100644 --- a/sycl/include/sycl/detail/type_traits.hpp +++ b/sycl/include/sycl/detail/type_traits.hpp @@ -8,6 +8,8 @@ #pragma once +#include + #include // for decorated, address_space #include // for vec, marray, integer_list #include // for is_contained, find_twi... @@ -171,18 +173,6 @@ template struct get_elem_type_unqual { using type = ElementType; }; -template -struct is_ext_vector : std::false_type {}; - -// FIXME: unguarded use of non-standard built-in -template -struct is_ext_vector< - T, std::void_t()))>> - : std::true_type {}; - -template -inline constexpr bool is_ext_vector_v = is_ext_vector::value; - // FIXME: unguarded use of non-standard built-in template struct get_elem_type_unqual>> { @@ -255,11 +245,6 @@ template class S> inline constexpr bool is_gen_based_on_type_sizeof_v = S::value && (sizeof(vector_element_t) == N); -template struct is_vec : std::false_type {}; -template struct is_vec> : std::true_type {}; - -template constexpr bool is_vec_v = is_vec::value; - template struct get_vec_size { static constexpr int size = 1; }; @@ -268,27 +253,6 @@ template struct get_vec_size> { static constexpr int size = N; }; -// is_swizzle -template struct is_swizzle : std::false_type {}; -template class OperationCurrentT, int... Indexes> -struct is_swizzle> : std::true_type {}; - -template constexpr bool is_swizzle_v = is_swizzle::value; - -// is_swizzle_or_vec_v - -template -constexpr bool is_vec_or_swizzle_v = is_vec_v || is_swizzle_v; - -// is_marray -template struct is_marray : std::false_type {}; -template -struct is_marray> : std::true_type {}; - -template constexpr bool is_marray_v = is_marray::value; - // is_integral template struct is_integral : std::is_integral> {}; diff --git a/sycl/include/sycl/detail/type_traits/vec_marray_traits.hpp b/sycl/include/sycl/detail/type_traits/vec_marray_traits.hpp new file mode 100644 index 0000000000000..cac13bc73de33 --- /dev/null +++ b/sycl/include/sycl/detail/type_traits/vec_marray_traits.hpp @@ -0,0 +1,104 @@ +//==---------- Forward declarations and traits for vector/marray types -----==// +// +// 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 + +namespace sycl { +inline namespace _V1 { +template class __SYCL_EBO vec; + +template class marray; + +namespace detail { +template class OperationCurrentT, int... Indexes> +class SwizzleOp; + +// --------- is_* traits ------------------ // +template struct is_vec : std::false_type {}; +template struct is_vec> : std::true_type {}; +template constexpr bool is_vec_v = is_vec::value; + +template +struct is_ext_vector : std::false_type {}; +#if defined(__has_extension) +#if __has_extension(attribute_ext_vector_type) +template +struct is_ext_vector : std::true_type {}; +#endif +#endif +template +inline constexpr bool is_ext_vector_v = is_ext_vector::value; + +template struct is_swizzle : std::false_type {}; +template class OperationCurrentT, int... Indexes> +struct is_swizzle> : std::true_type {}; +template constexpr bool is_swizzle_v = is_swizzle::value; + +template +constexpr bool is_vec_or_swizzle_v = is_vec_v || is_swizzle_v; + +template struct is_marray : std::false_type {}; +template +struct is_marray> : std::true_type {}; +template constexpr bool is_marray_v = is_marray::value; + +// --------- num_elements trait ------------------ // +template +struct num_elements : std::integral_constant {}; +template +struct num_elements> : std::integral_constant {}; +template +struct num_elements> + : std::integral_constant {}; +#if defined(__has_extension) +#if __has_extension(attribute_ext_vector_type) +template +struct num_elements + : std::integral_constant {}; +#endif +#endif +template class OperationCurrentT, int... Indexes> +struct num_elements> + : std::integral_constant {}; + +template +inline constexpr std::size_t num_elements_v = num_elements::value; + +// --------- element_type trait ------------------ // +template struct element_type { + using type = T; +}; +template struct element_type> { + using type = T; +}; +template struct element_type> { + using type = T; +}; +#if defined(__has_extension) +#if __has_extension(attribute_ext_vector_type) +template +struct element_type { + using type = T; +}; +#endif +#endif +template using element_type_t = typename element_type::type; + +} // namespace detail +} // namespace _V1 +} // namespace sycl diff --git a/sycl/test/include_deps/sycl_accessor.hpp.cpp b/sycl/test/include_deps/sycl_accessor.hpp.cpp index 2dce0b3d7696b..fd5f7b86ad79a 100644 --- a/sycl/test/include_deps/sycl_accessor.hpp.cpp +++ b/sycl/test/include_deps/sycl_accessor.hpp.cpp @@ -24,6 +24,7 @@ // CHECK-NEXT: info/aspects.def // CHECK-NEXT: info/aspects_deprecated.def // CHECK-NEXT: detail/type_traits.hpp +// CHECK-NEXT: detail/type_traits/vec_marray_traits.hpp // CHECK-NEXT: detail/generic_type_lists.hpp // CHECK-NEXT: detail/type_list.hpp // CHECK-NEXT: detail/boost/mp11/algorithm.hpp @@ -112,5 +113,5 @@ // CHECK-NEXT: detail/string_view.hpp // CHECK-NEXT: detail/util.hpp // CHECK-NEXT: device_selector.hpp -// CHECK-NEXT: buffer_properties.def +// CHECK-NEXT: properties/buffer_properties.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 917996b10cfa6..0fb9203880d36 100644 --- a/sycl/test/include_deps/sycl_detail_core.hpp.cpp +++ b/sycl/test/include_deps/sycl_detail_core.hpp.cpp @@ -25,6 +25,7 @@ // CHECK-NEXT: info/aspects.def // CHECK-NEXT: info/aspects_deprecated.def // CHECK-NEXT: detail/type_traits.hpp +// CHECK-NEXT: detail/type_traits/vec_marray_traits.hpp // CHECK-NEXT: detail/generic_type_lists.hpp // CHECK-NEXT: detail/type_list.hpp // CHECK-NEXT: detail/boost/mp11/algorithm.hpp