Skip to content

Commit 531aabf

Browse files
[SYCL] vec abi unification and trivially copyable (#9492)
adapted from #6816 sycl::vec now uses std::array on host in all cases, but device access is via `ext_vector_type` so as to not lose performance. Alignment is set the same as the size to a maximum of 64 bytes, which aligns with an upcoming spec change proposal. In the cases where the size is greater than 64 we use std::array on the device. We no longer need to emit a pragma on Windows and we can use `alignas()` on all platforms.
1 parent 9c1fe25 commit 531aabf

File tree

10 files changed

+187
-158
lines changed

10 files changed

+187
-158
lines changed

sycl/include/sycl/detail/vector_traits.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@ inline namespace _V1 {
1717
namespace detail {
1818

1919
// 4.10.2.6 Memory layout and alignment
20-
template <typename T, int N>
20+
// due to MSVC the maximum alignment for sycl::vec is 64 and this proposed
21+
// change is being brought to the spec committee.
22+
constexpr size_t MaxVecAlignment = 64;
23+
template <typename T, size_t N>
2124
struct vector_alignment_impl
22-
: std::conditional_t<N == 3, std::integral_constant<int, sizeof(T) * 4>,
23-
std::integral_constant<int, sizeof(T) * N>> {};
25+
: std::conditional_t<
26+
N == 3,
27+
std::integral_constant<size_t,
28+
(std::min)(sizeof(T) * 4, MaxVecAlignment)>,
29+
std::integral_constant<size_t,
30+
(std::min)(sizeof(T) * N, MaxVecAlignment)>> {
31+
};
2432

25-
template <typename T, int N>
33+
template <typename T, size_t N>
2634
struct vector_alignment
2735
: vector_alignment_impl<std::remove_cv_t<std::remove_reference_t<T>>, N> {};
2836
} // namespace detail

sycl/include/sycl/half_type.hpp

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -253,28 +253,12 @@ using BIsRepresentationT = half;
253253
// for vec because they are actually defined as an integer type under the
254254
// hood. As a result half values will be converted to the integer and passed
255255
// as a kernel argument which is expected to be floating point number.
256-
template <int NumElements> struct half_vec {
257-
alignas(
258-
vector_alignment<StorageT, NumElements>::value) StorageT s[NumElements];
259256

260-
__SYCL_CONSTEXPR_HALF half_vec() : s{0.0f} { initialize_data(); }
261-
template <typename... Ts,
262-
typename = std::enable_if_t<(sizeof...(Ts) == NumElements) &&
263-
(std::is_same_v<half, Ts> && ...)>>
264-
__SYCL_CONSTEXPR_HALF half_vec(const Ts &...hs) : s{hs...} {}
265-
266-
constexpr void initialize_data() {
267-
for (size_t i = 0; i < NumElements; ++i) {
268-
s[i] = StorageT(0.0f);
269-
}
270-
}
271-
};
272-
273-
using Vec2StorageT = half_vec<2>;
274-
using Vec3StorageT = half_vec<3>;
275-
using Vec4StorageT = half_vec<4>;
276-
using Vec8StorageT = half_vec<8>;
277-
using Vec16StorageT = half_vec<16>;
257+
using Vec2StorageT = std::array<StorageT, 2>;
258+
using Vec3StorageT = std::array<StorageT, 3>;
259+
using Vec4StorageT = std::array<StorageT, 4>;
260+
using Vec8StorageT = std::array<StorageT, 8>;
261+
using Vec16StorageT = std::array<StorageT, 16>;
278262
#endif
279263

280264
#ifndef __SYCL_DEVICE_ONLY__

0 commit comments

Comments
 (0)