Skip to content

Commit 7ae01c4

Browse files
committed
Try to fix alignment setting
1 parent 100e1e0 commit 7ae01c4

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

sycl/include/sycl/types.hpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,29 @@ template <typename Type, int NumElements> class vec {
14381438

14391439
// Alignment is the same as size, to a maximum size of 64 (with some
14401440
// exceptions, see detail::vector_alignment).
1441-
alignas(detail::vector_alignment<DataT, NumElements>::value) DataType m_Data;
1441+
#if defined(_WIN32) && (_MSC_VER)
1442+
#define __SYCL_ALIGNED_VAR(type, x, var) \
1443+
type __declspec(align((x < MaxVecAlignment) ? x : MaxVecAlignment)) var
1444+
#else
1445+
#define __SYCL_ALIGNED_VAR(type, x, var) alignas(x) type var
1446+
#endif
1447+
// Used "__SYCL_ALIGNED_VAR" instead of "alignas" to handle MSVC compiler.
1448+
//
1449+
// SYCL 2020 spec allows us to have at most 64-byte alignment for vec, but
1450+
// alignas requires that passed alignment is greater or equal to a minumum
1451+
// required alignment for a type. That is 128 bytes for types like
1452+
// vec<double, 16> and MSVC is not able to support that, which makes it
1453+
// impossible to use alignas directly.
1454+
//
1455+
// We have prepared a vec refactoring which changes underlying storage data
1456+
// type so we are able to use alignas directly, but it is hidden under preview
1457+
// breaking changes macro for now.
1458+
// FIXME: we should be able to drop the macro and directly use alignas once
1459+
// functionality under preview breaking changes macro is promoted.
1460+
__SYCL_ALIGNED_VAR(DataType,
1461+
(detail::vector_alignment<DataT, NumElements>::value),
1462+
m_Data);
1463+
#undef __SYCL_ALIGNED_VAR
14421464

14431465
// friends
14441466
template <typename T1, typename T2, typename T3, template <typename> class T4,

0 commit comments

Comments
 (0)