From a7bf1ca4e414ca10bcd8f398e03d85c05b6f5346 Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Thu, 6 Feb 2025 15:11:45 -0800 Subject: [PATCH] [NFCI][SYCL] Eliminate `sycl/builtins_utils_*.hpp` Split the helper they used to provide between the builtins implementation and `sycl/detail/type_traits/vec_marray_traits.hpp`. --- sycl/include/sycl/builtins_utils_scalar.hpp | 73 ----------------- sycl/include/sycl/builtins_utils_vec.hpp | 79 ------------------ .../include/sycl/detail/builtins/builtins.hpp | 81 ++++++++++++++++++- .../detail/type_traits/vec_marray_traits.hpp | 16 ++++ .../ext/oneapi/experimental/bfloat16_math.hpp | 1 - .../sycl/ext/oneapi/experimental/builtins.hpp | 1 - 6 files changed, 96 insertions(+), 155 deletions(-) delete mode 100644 sycl/include/sycl/builtins_utils_scalar.hpp delete mode 100644 sycl/include/sycl/builtins_utils_vec.hpp diff --git a/sycl/include/sycl/builtins_utils_scalar.hpp b/sycl/include/sycl/builtins_utils_scalar.hpp deleted file mode 100644 index 7bb9e7b2ec502..0000000000000 --- a/sycl/include/sycl/builtins_utils_scalar.hpp +++ /dev/null @@ -1,73 +0,0 @@ -//==--- builtins_utils_scalar.hpp - SYCL built-in function utilities -------==// -// -// 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 -#include -#include -#include - -#include -#include - -namespace sycl { -inline namespace _V1 { - -namespace detail { -#ifdef __FAST_MATH__ -template -struct use_fast_math - : std::is_same>, float> {}; -#else -template struct use_fast_math : std::false_type {}; -#endif -template constexpr bool use_fast_math_v = use_fast_math::value; - -// Utility for converting a swizzle to a vector or preserve the type if it isn't -// a swizzle. -template struct simplify_if_swizzle { - using type = T; -}; - -template -using simplify_if_swizzle_t = typename simplify_if_swizzle::type; - -// Utility trait for getting the decoration of a multi_ptr. -template struct get_multi_ptr_decoration; -template -struct get_multi_ptr_decoration< - multi_ptr> { - static constexpr access::decorated value = DecorateAddress; -}; - -template -constexpr access::decorated get_multi_ptr_decoration_v = - get_multi_ptr_decoration::value; - -// Utility trait for checking if a multi_ptr has a "writable" address space, -// i.e. global, local, private or generic. -template struct has_writeable_addr_space : std::false_type {}; -template -struct has_writeable_addr_space> - : std::bool_constant {}; - -template -constexpr bool has_writeable_addr_space_v = has_writeable_addr_space::value; - -} // namespace detail -} // namespace _V1 -} // namespace sycl diff --git a/sycl/include/sycl/builtins_utils_vec.hpp b/sycl/include/sycl/builtins_utils_vec.hpp deleted file mode 100644 index 3fd2336008654..0000000000000 --- a/sycl/include/sycl/builtins_utils_vec.hpp +++ /dev/null @@ -1,79 +0,0 @@ -//==--- builtins_utils_vec.hpp - SYCL built-in function utilities for vec --==// -// -// 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 -#include // for marray -#include // for vec - -namespace sycl { -inline namespace _V1 { -namespace detail { -// Utility for converting a swizzle to a vector or preserve the type if it isn't -// a swizzle. -template class OperationCurrentT, int... Indexes> -struct simplify_if_swizzle> { - using type = vec; -}; - -// Utility trait for changing the element type of a type T. If T is a scalar, -// the new type replaces T completely. -template struct change_elements { - using type = NewElemT; -}; -template -struct change_elements> { - using type = marray::type, N>; -}; -template -struct change_elements> { - using type = vec::type, N>; -}; -template class OperationCurrentT, - int... Indexes> -struct change_elements> { - // Converts to vec for simplicity. - using type = - vec::type, - sizeof...(Indexes)>; -}; - -template -using change_elements_t = typename change_elements::type; - -// Utility functions for converting to/from vec/marray. -template vec to_vec2(marray X, size_t Start) { - return {X[Start], X[Start + 1]}; -} -template vec to_vec(marray X) { - vec Vec; - for (size_t I = 0; I < N; I++) - Vec[I] = X[I]; - return Vec; -} -template marray to_marray(vec X) { - marray Marray; - for (size_t I = 0; I < N; I++) - Marray[I] = X[I]; - return Marray; -} - -} // namespace detail -} // namespace _V1 -} // namespace sycl diff --git a/sycl/include/sycl/detail/builtins/builtins.hpp b/sycl/include/sycl/detail/builtins/builtins.hpp index 1f291fc4f60ac..4ce211cb1657b 100644 --- a/sycl/include/sycl/detail/builtins/builtins.hpp +++ b/sycl/include/sycl/detail/builtins/builtins.hpp @@ -63,11 +63,73 @@ #pragma once -#include +#include +#include +#include +#include // for marray +#include // for vec namespace sycl { inline namespace _V1 { namespace detail { +#ifdef __FAST_MATH__ +template +struct use_fast_math + : std::is_same>, float> {}; +#else +template struct use_fast_math : std::false_type {}; +#endif +template constexpr bool use_fast_math_v = use_fast_math::value; + +// Utility trait for getting the decoration of a multi_ptr. +template struct get_multi_ptr_decoration; +template +struct get_multi_ptr_decoration< + multi_ptr> { + static constexpr access::decorated value = DecorateAddress; +}; + +template +constexpr access::decorated get_multi_ptr_decoration_v = + get_multi_ptr_decoration::value; + +// Utility trait for checking if a multi_ptr has a "writable" address space, +// i.e. global, local, private or generic. +template struct has_writeable_addr_space : std::false_type {}; +template +struct has_writeable_addr_space> + : std::bool_constant {}; + +template +constexpr bool has_writeable_addr_space_v = has_writeable_addr_space::value; + +// Utility trait for changing the element type of a type T. If T is a scalar, +// the new type replaces T completely. +template +struct change_elements { + using type = NewElemT; +}; +template +struct change_elements>> { + using type = + marray::type, + T::size()>; +}; +template +struct change_elements>> { + using type = + vec::type, + T::size()>; +}; + +template +using change_elements_t = typename change_elements::type; + template inline constexpr bool builtin_same_shape_v = ((... && is_scalar_arithmetic_v) || (... && is_marray_v) || @@ -80,6 +142,23 @@ inline constexpr bool builtin_same_or_swizzle_v = // Use builtin_same_shape_v to filter out types unrelated to builtins. builtin_same_shape_v && all_same_v...>; +// Utility functions for converting to/from vec/marray. +template vec to_vec2(marray X, size_t Start) { + return {X[Start], X[Start + 1]}; +} +template vec to_vec(marray X) { + vec Vec; + for (size_t I = 0; I < N; I++) + Vec[I] = X[I]; + return Vec; +} +template marray to_marray(vec X) { + marray Marray; + for (size_t I = 0; I < N; I++) + Marray[I] = X[I]; + return Marray; +} + namespace builtins { #ifdef __SYCL_DEVICE_ONLY__ template auto convert_arg(T &&x) { diff --git a/sycl/include/sycl/detail/type_traits/vec_marray_traits.hpp b/sycl/include/sycl/detail/type_traits/vec_marray_traits.hpp index 86e8764dc87a0..6ce39bf6a072a 100644 --- a/sycl/include/sycl/detail/type_traits/vec_marray_traits.hpp +++ b/sycl/include/sycl/detail/type_traits/vec_marray_traits.hpp @@ -24,6 +24,22 @@ template class OperationCurrentT, int... Indexes> class SwizzleOp; +// Utility for converting a swizzle to a vector or preserve the type if it isn't +// a swizzle. +template struct simplify_if_swizzle { + using type = T; +}; + +template class OperationCurrentT, int... Indexes> +struct simplify_if_swizzle> { + using type = vec; +}; + +template +using simplify_if_swizzle_t = typename simplify_if_swizzle::type; + // --------- is_* traits ------------------ // template struct is_vec : std::false_type {}; template struct is_vec> : std::true_type {}; diff --git a/sycl/include/sycl/ext/oneapi/experimental/bfloat16_math.hpp b/sycl/include/sycl/ext/oneapi/experimental/bfloat16_math.hpp index 11dec596b1f45..49ed23008607e 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/bfloat16_math.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/bfloat16_math.hpp @@ -9,7 +9,6 @@ #pragma once #include // for ceil, cos, exp, exp10, exp2 -#include // For simplify_if_swizzle, is_swizzle #include // sycl::detail::memcpy #include #include // for bfloat16, bfloat16ToBits diff --git a/sycl/include/sycl/ext/oneapi/experimental/builtins.hpp b/sycl/include/sycl/ext/oneapi/experimental/builtins.hpp index d42df1fee26c8..e6fdba4cdad45 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/builtins.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/builtins.hpp @@ -10,7 +10,6 @@ #include // for half #include // for to_vec2 -#include // for to_vec, to_marray... #include // for __SYCL_ALWAYS_INLINE #include // for is_svgenfloath, is_sv... #include // detail::memcpy