Skip to content

Commit f4ed132

Browse files
[SYCL] vec abi changes behind -fpreview-breaking-changes flag (#11697)
sycl::vec was updated earlier to be SYCL 2020 conformant. But those were ABI breaking changes, and the decision has been made to put those changes behind the -fpreview-breaking-changes / __INTEL_PREVIEW_BREAKING_CHANGES flag/macro. This PR restores the old sycl::vec implementation and puts the new conforming one behind the flag/macro.
1 parent 772a8e8 commit f4ed132

19 files changed

+485
-51
lines changed

sycl/include/sycl/buffer.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,13 @@ template <typename T, int dimensions = 1,
168168
typename std::enable_if_t<(dimensions > 0) && (dimensions <= 3)>>
169169
class buffer : public detail::buffer_plain,
170170
public detail::OwnerLessBase<buffer<T, dimensions, AllocatorT>> {
171+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
171172
static_assert(is_device_copyable_v<T>,
172173
"Underlying type of a buffer must be device copyable!");
174+
#else
175+
static_assert(!std::is_same_v<T, std::string>,
176+
"'std::string' is not a device copyable type");
177+
#endif
173178

174179
public:
175180
using value_type = T;

sycl/include/sycl/detail/vector_traits.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ inline namespace _V1 {
1616
namespace detail {
1717

1818
// 4.10.2.6 Memory layout and alignment
19+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
1920
// due to MSVC the maximum alignment for sycl::vec is 64 and this proposed
2021
// change is being brought to the spec committee.
2122
constexpr size_t MaxVecAlignment = 64;
@@ -28,6 +29,12 @@ struct vector_alignment_impl
2829
std::integral_constant<size_t,
2930
(std::min)(sizeof(T) * N, MaxVecAlignment)>> {
3031
};
32+
#else
33+
template <typename T, size_t N>
34+
struct vector_alignment_impl
35+
: std::conditional_t<N == 3, std::integral_constant<int, sizeof(T) * 4>,
36+
std::integral_constant<int, sizeof(T) * N>> {};
37+
#endif
3138

3239
template <typename T, size_t N>
3340
struct vector_alignment

sycl/include/sycl/half_type.hpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ using Vec3StorageT = StorageT __attribute__((ext_vector_type(3)));
249249
using Vec4StorageT = StorageT __attribute__((ext_vector_type(4)));
250250
using Vec8StorageT = StorageT __attribute__((ext_vector_type(8)));
251251
using Vec16StorageT = StorageT __attribute__((ext_vector_type(16)));
252-
#else
252+
#else // SYCL_DEVICE_ONLY
253253
using StorageT = detail::host_half_impl::half;
254254
// No need to extract underlying data type for built-in functions operating on
255255
// host
@@ -259,13 +259,37 @@ using BIsRepresentationT = half;
259259
// for vec because they are actually defined as an integer type under the
260260
// hood. As a result half values will be converted to the integer and passed
261261
// as a kernel argument which is expected to be floating point number.
262-
262+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
263263
using Vec2StorageT = std::array<StorageT, 2>;
264264
using Vec3StorageT = std::array<StorageT, 3>;
265265
using Vec4StorageT = std::array<StorageT, 4>;
266266
using Vec8StorageT = std::array<StorageT, 8>;
267267
using Vec16StorageT = std::array<StorageT, 16>;
268-
#endif
268+
#else // __INTEL_PREVIEW_BREAKING_CHANGES
269+
template <int NumElements> struct half_vec {
270+
alignas(
271+
vector_alignment<StorageT, NumElements>::value) StorageT s[NumElements];
272+
273+
__SYCL_CONSTEXPR_HALF half_vec() : s{0.0f} { initialize_data(); }
274+
template <typename... Ts,
275+
typename = std::enable_if_t<(sizeof...(Ts) == NumElements) &&
276+
(std::is_same_v<half, Ts> && ...)>>
277+
__SYCL_CONSTEXPR_HALF half_vec(const Ts &...hs) : s{hs...} {}
278+
279+
constexpr void initialize_data() {
280+
for (size_t i = 0; i < NumElements; ++i) {
281+
s[i] = StorageT(0.0f);
282+
}
283+
}
284+
};
285+
286+
using Vec2StorageT = half_vec<2>;
287+
using Vec3StorageT = half_vec<3>;
288+
using Vec4StorageT = half_vec<4>;
289+
using Vec8StorageT = half_vec<8>;
290+
using Vec16StorageT = half_vec<16>;
291+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
292+
#endif // SYCL_DEVICE_ONLY
269293

270294
#ifndef __SYCL_DEVICE_ONLY__
271295
class half {

0 commit comments

Comments
 (0)