From 15e70e0659a84cb21aa036c2bf8d501ce7f4bb5f Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Thu, 11 Sep 2025 16:23:17 -0700 Subject: [PATCH] [NFC][SYCL] Reduce dependencies of `` --- .../include/sycl/detail/builtins/builtins.hpp | 6 ++- sycl/include/sycl/detail/fwd/half.hpp | 51 +++++++++++++++++++ .../sycl/detail/generic_type_traits.hpp | 23 +++++---- sycl/include/sycl/detail/spirv.hpp | 1 + sycl/include/sycl/detail/usm_impl.hpp | 1 + sycl/include/sycl/detail/vector_convert.hpp | 3 +- .../oneapi/experimental/group_load_store.hpp | 1 + .../sycl/ext/oneapi/experimental/prefetch.hpp | 2 + sycl/include/sycl/half_type.hpp | 31 +---------- sycl/include/sycl/vector.hpp | 9 ++-- sycl/test/include_deps/sycl_accessor.hpp.cpp | 11 ++-- .../include_deps/sycl_detail_core.hpp.cpp | 11 ++-- 12 files changed, 93 insertions(+), 57 deletions(-) create mode 100644 sycl/include/sycl/detail/fwd/half.hpp diff --git a/sycl/include/sycl/detail/builtins/builtins.hpp b/sycl/include/sycl/detail/builtins/builtins.hpp index 4cab71dac4be8..d69c0b93ce7c1 100644 --- a/sycl/include/sycl/detail/builtins/builtins.hpp +++ b/sycl/include/sycl/detail/builtins/builtins.hpp @@ -63,11 +63,13 @@ #pragma once +#include #include #include #include -#include // for marray -#include // for vec +#include +#include +#include namespace sycl { inline namespace _V1 { diff --git a/sycl/include/sycl/detail/fwd/half.hpp b/sycl/include/sycl/detail/fwd/half.hpp new file mode 100644 index 0000000000000..751885befd6ca --- /dev/null +++ b/sycl/include/sycl/detail/fwd/half.hpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +namespace sycl { +inline namespace _V1 { +namespace detail::half_impl { +class half; + +// Several aliases are defined below: +// - StorageT: actual representation of half data type. It is used by scalar +// half values. On device side, it points to some native half data type, while +// on host it is represented by a 16-bit integer that the implementation +// manipulates to emulate half-precision floating-point behavior. +// +// - BIsRepresentationT: data type which is used by built-in functions. It is +// distinguished from StorageT, because on host, we can still operate on the +// wrapper itself and there is no sense in direct usage of underlying data +// type (too many changes required for BIs implementation without any +// foreseeable profits) +// +// - VecElemT: representation of each element in the vector. On device it is +// the same as StorageT to carry a native vector representation, while on +// host it stores the sycl::half implementation directly. +// +// - VecNStorageT: representation of N-element vector of halfs. Follows the +// same logic as VecElemT. +#ifdef __SYCL_DEVICE_ONLY__ +using StorageT = _Float16; +using BIsRepresentationT = _Float16; +using VecElemT = _Float16; +#else // SYCL_DEVICE_ONLY +using StorageT = uint16_t; +// No need to extract underlying data type for built-in functions operating on +// host +using BIsRepresentationT = half; +using VecElemT = half; +#endif // SYCL_DEVICE_ONLY +} // namespace detail::half_impl +using half = detail::half_impl::half; + +} // namespace _V1 +} // namespace sycl diff --git a/sycl/include/sycl/detail/generic_type_traits.hpp b/sycl/include/sycl/detail/generic_type_traits.hpp index 984a05ace06be..d1f2caad67a97 100644 --- a/sycl/include/sycl/detail/generic_type_traits.hpp +++ b/sycl/include/sycl/detail/generic_type_traits.hpp @@ -8,14 +8,11 @@ #pragma once -#include // for decorated, address_space -#include // for half, cl_char, cl_double -#include // for marray -#include // for is_gen_based_on_type_s... -#include // for BIsRepresentationT -#include // for multi_ptr, address_spa... - -#include // for bfloat16 storage type. +#include +#include +#include +#include +#include #include // for byte #include // for uint8_t @@ -24,6 +21,9 @@ namespace sycl { inline namespace _V1 { +namespace ext::oneapi { +class bfloat16; +} namespace detail { template using is_byte = typename @@ -166,13 +166,16 @@ template auto convertToOpenCLType(T &&x) { static_assert(sizeof(OpenCLType) == sizeof(T)); return static_cast(x); } else if constexpr (std::is_same_v) { - using OpenCLType = sycl::detail::half_impl::BIsRepresentationT; + // Make it template-param-dependent to compile with incomplete `half`: + using OpenCLType = + std::enable_if_t, + sycl::detail::half_impl::BIsRepresentationT>; static_assert(sizeof(OpenCLType) == sizeof(T)); return static_cast(x); } else if constexpr (std::is_same_v) { // On host, don't interpret BF16 as uint16. #ifdef __SYCL_DEVICE_ONLY__ - using OpenCLType = sycl::ext::oneapi::bfloat16::Bfloat16StorageT; + using OpenCLType = typename no_ref::Bfloat16StorageT; return sycl::bit_cast(x); #else return std::forward(x); diff --git a/sycl/include/sycl/detail/spirv.hpp b/sycl/include/sycl/detail/spirv.hpp index a441e5429d457..671e4758a268d 100644 --- a/sycl/include/sycl/detail/spirv.hpp +++ b/sycl/include/sycl/detail/spirv.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #if defined(__NVPTX__) diff --git a/sycl/include/sycl/detail/usm_impl.hpp b/sycl/include/sycl/detail/usm_impl.hpp index fd1a4350f520a..a37e7b3e19c2a 100644 --- a/sycl/include/sycl/detail/usm_impl.hpp +++ b/sycl/include/sycl/detail/usm_impl.hpp @@ -14,6 +14,7 @@ namespace sycl { inline namespace _V1 { class device; +class context; namespace detail::usm { diff --git a/sycl/include/sycl/detail/vector_convert.hpp b/sycl/include/sycl/detail/vector_convert.hpp index 8f4ff466c04f9..544250aff82ac 100644 --- a/sycl/include/sycl/detail/vector_convert.hpp +++ b/sycl/include/sycl/detail/vector_convert.hpp @@ -58,7 +58,8 @@ #include // for errc #include -#include // bfloat16 +#include +#include #include #ifndef __SYCL_DEVICE_ONLY__ diff --git a/sycl/include/sycl/ext/oneapi/experimental/group_load_store.hpp b/sycl/include/sycl/ext/oneapi/experimental/group_load_store.hpp index 5ee3e1d1d0591..4bba7b980b5c1 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/group_load_store.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/group_load_store.hpp @@ -11,6 +11,7 @@ #pragma once #include +#include #include #include #include diff --git a/sycl/include/sycl/ext/oneapi/experimental/prefetch.hpp b/sycl/include/sycl/ext/oneapi/experimental/prefetch.hpp index a10ac625acfc4..aa93dd2c789d5 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/prefetch.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/prefetch.hpp @@ -9,7 +9,9 @@ #pragma once #include +#include #include +#include #include namespace sycl { diff --git a/sycl/include/sycl/half_type.hpp b/sycl/include/sycl/half_type.hpp index 11e1fb388cb1b..c33898a589ee7 100644 --- a/sycl/include/sycl/half_type.hpp +++ b/sycl/include/sycl/half_type.hpp @@ -10,6 +10,7 @@ #include // for bit_cast #include // for __SYCL_EXPORT +#include #ifdef __SYCL_DEVICE_ONLY__ #include @@ -154,36 +155,6 @@ inline __SYCL_CONSTEXPR_HALF float half2Float(const uint16_t &Val) { namespace half_impl { class half; -// Several aliases are defined below: -// - StorageT: actual representation of half data type. It is used by scalar -// half values. On device side, it points to some native half data type, while -// on host it is represented by a 16-bit integer that the implementation -// manipulates to emulate half-precision floating-point behavior. -// -// - BIsRepresentationT: data type which is used by built-in functions. It is -// distinguished from StorageT, because on host, we can still operate on the -// wrapper itself and there is no sense in direct usage of underlying data -// type (too many changes required for BIs implementation without any -// foreseeable profits) -// -// - VecElemT: representation of each element in the vector. On device it is -// the same as StorageT to carry a native vector representation, while on -// host it stores the sycl::half implementation directly. -// -// - VecNStorageT: representation of N-element vector of halfs. Follows the -// same logic as VecElemT. -#ifdef __SYCL_DEVICE_ONLY__ -using StorageT = _Float16; -using BIsRepresentationT = _Float16; -using VecElemT = _Float16; -#else // SYCL_DEVICE_ONLY -using StorageT = uint16_t; -// No need to extract underlying data type for built-in functions operating on -// host -using BIsRepresentationT = half; -using VecElemT = half; -#endif // SYCL_DEVICE_ONLY - // Creation token to disambiguate constructors. struct RawHostHalfToken { constexpr explicit RawHostHalfToken(uint16_t Val) : Value{Val} {} diff --git a/sycl/include/sycl/vector.hpp b/sycl/include/sycl/vector.hpp index 17ba1ee38a22e..c5a8deb9ba8f1 100644 --- a/sycl/include/sycl/vector.hpp +++ b/sycl/include/sycl/vector.hpp @@ -31,10 +31,11 @@ #error "SYCL device compiler is built without ext_vector_type support" #endif -#include // for decorated, address_space -#include // for half, cl_char, cl_int -#include // for ArrayCreator -#include // for __SYCL2020_DEPRECATED +#include // for decorated, address_space +#include // for half, cl_char, cl_int +#include // for ArrayCreator +#include // for __SYCL2020_DEPRECATED +#include #include // for is_sigeninteger, is_s... #include // for memcpy #include diff --git a/sycl/test/include_deps/sycl_accessor.hpp.cpp b/sycl/test/include_deps/sycl_accessor.hpp.cpp index 2901a4fbc0c7a..d29a575a728e7 100644 --- a/sycl/test/include_deps/sycl_accessor.hpp.cpp +++ b/sycl/test/include_deps/sycl_accessor.hpp.cpp @@ -43,18 +43,18 @@ // CHECK-NEXT: detail/accessor_iterator.hpp // CHECK-NEXT: detail/generic_type_traits.hpp // CHECK-NEXT: aliases.hpp +// CHECK-NEXT: bit_cast.hpp +// CHECK-NEXT: detail/fwd/half.hpp // CHECK-NEXT: detail/type_traits.hpp // CHECK-NEXT: detail/type_traits/vec_marray_traits.hpp // CHECK-NEXT: detail/fwd/multi_ptr.hpp +// CHECK-NEXT: detail/handler_proxy.hpp +// CHECK-NEXT: multi_ptr.hpp +// CHECK-NEXT: detail/address_space_cast.hpp // CHECK-NEXT: half_type.hpp -// CHECK-NEXT: bit_cast.hpp // CHECK-NEXT: aspects.hpp // CHECK-NEXT: info/aspects.def // CHECK-NEXT: info/aspects_deprecated.def -// CHECK-NEXT: multi_ptr.hpp -// CHECK-NEXT: detail/address_space_cast.hpp -// CHECK-NEXT: ext/oneapi/bfloat16.hpp -// CHECK-NEXT: detail/handler_proxy.hpp // CHECK-NEXT: pointers.hpp // CHECK-NEXT: properties/accessor_properties.hpp // CHECK-NEXT: properties/runtime_accessor_properties.def @@ -67,6 +67,7 @@ // CHECK-NEXT: ext/oneapi/experimental/device_architecture.def // CHECK-NEXT: ext/oneapi/experimental/forward_progress.hpp // CHECK-NEXT: ext/oneapi/matrix/query-types.hpp +// CHECK-NEXT: ext/oneapi/bfloat16.hpp // CHECK-NEXT: ext/oneapi/matrix/matrix-unified-utils.hpp // CHECK-NEXT: info/platform_traits.def // CHECK-NEXT: info/context_traits.def diff --git a/sycl/test/include_deps/sycl_detail_core.hpp.cpp b/sycl/test/include_deps/sycl_detail_core.hpp.cpp index a87fb75117f27..f3a91fe6199d4 100644 --- a/sycl/test/include_deps/sycl_detail_core.hpp.cpp +++ b/sycl/test/include_deps/sycl_detail_core.hpp.cpp @@ -44,18 +44,18 @@ // CHECK-NEXT: detail/accessor_iterator.hpp // CHECK-NEXT: detail/generic_type_traits.hpp // CHECK-NEXT: aliases.hpp +// CHECK-NEXT: bit_cast.hpp +// CHECK-NEXT: detail/fwd/half.hpp // CHECK-NEXT: detail/type_traits.hpp // CHECK-NEXT: detail/type_traits/vec_marray_traits.hpp // CHECK-NEXT: detail/fwd/multi_ptr.hpp +// CHECK-NEXT: detail/handler_proxy.hpp +// CHECK-NEXT: multi_ptr.hpp +// CHECK-NEXT: detail/address_space_cast.hpp // CHECK-NEXT: half_type.hpp -// CHECK-NEXT: bit_cast.hpp // CHECK-NEXT: aspects.hpp // CHECK-NEXT: info/aspects.def // CHECK-NEXT: info/aspects_deprecated.def -// CHECK-NEXT: multi_ptr.hpp -// CHECK-NEXT: detail/address_space_cast.hpp -// CHECK-NEXT: ext/oneapi/bfloat16.hpp -// CHECK-NEXT: detail/handler_proxy.hpp // CHECK-NEXT: pointers.hpp // CHECK-NEXT: properties/accessor_properties.hpp // CHECK-NEXT: properties/runtime_accessor_properties.def @@ -68,6 +68,7 @@ // CHECK-NEXT: ext/oneapi/experimental/device_architecture.def // CHECK-NEXT: ext/oneapi/experimental/forward_progress.hpp // CHECK-NEXT: ext/oneapi/matrix/query-types.hpp +// CHECK-NEXT: ext/oneapi/bfloat16.hpp // CHECK-NEXT: ext/oneapi/matrix/matrix-unified-utils.hpp // CHECK-NEXT: info/platform_traits.def // CHECK-NEXT: info/context_traits.def