Skip to content

Commit

Permalink
[SYCL] Fix vec class alignment on windows platform (#4953)
Browse files Browse the repository at this point in the history
Currently the sycl::vec type can be copied in the way which doesn't
preserve the default alignment on windows. This can causes crashes
since the sycl:;vec code expects the vector to be aligned and uses
vector instructions. We used default alignment because we cannot
set correct alignment in all cases. The patch adds alignment of
vector types, if alignment required is larger than 64, it is limited to 64.
  • Loading branch information
dongkyunahn-intel authored Nov 23, 2021
1 parent 23ca24b commit 826c569
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
21 changes: 12 additions & 9 deletions sycl/include/CL/sycl/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,13 @@ using vec_data_t = typename detail::vec_helper<T>::RetType;
// For information on calling conventions for x64 processors, see
// Calling Convention
// (https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention).
#pragma message ("Alignment of class vec is not in accordance with SYCL \
#pragma message("Alignment of class vec is not in accordance with SYCL \
specification requirements, a limitation of the MSVC compiler(Error C2719).\
Applied default alignment.")
#define __SYCL_ALIGNAS(x)
Requested alignment applied, limited at 64.")
#define __SYCL_ALIGNED_VAR(type, x, var) \
type __declspec(align((x < 64) ? x : 64)) var
#else
#define __SYCL_ALIGNAS(N) alignas(N)
#define __SYCL_ALIGNED_VAR(type, x, var) alignas(x) type var
#endif

/// Provides a cross-patform vector class template that works efficiently on
Expand Down Expand Up @@ -1363,12 +1364,14 @@ template <typename Type, int NumElements> class vec {
}

// fields
// Used "__SYCL_ALIGNAS" instead "alignas" to handle MSVC compiler.
// Used "__SYCL_ALIGNED_VAR" instead "alignas" to handle MSVC compiler.
// For MSVC compiler max alignment is 64, e.g. vec<double, 16> required
// alignment of 128 and MSVC compiler cann't align a parameter with requested
// alignment of 128.
__SYCL_ALIGNAS((detail::vector_alignment<DataT, NumElements>::value))
DataType m_Data;
// alignment of 128. For alignment request larger than 64, 64-alignment
// is applied
__SYCL_ALIGNED_VAR(DataType,
(detail::vector_alignment<DataT, NumElements>::value),
m_Data);

// friends
template <typename T1, typename T2, typename T3, template <typename> class T4,
Expand Down Expand Up @@ -2497,4 +2500,4 @@ struct CheckDeviceCopyable<
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)

#undef __SYCL_ALIGNAS
#undef __SYCL_ALIGNED_VAR
3 changes: 1 addition & 2 deletions sycl/test/basic_tests/stdcpp_compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
// warning_extension-warning@* 0-1 {{#warning is a language extension}}
//
// The next warning is emitted for windows only
// expected-warning@* 0-1 {{Alignment of class vec is not in accordance with SYCL specification requirements, a limitation of the MSVC compiler(Error C2719).Applied default alignment.}}

// expected-warning@* 0-1 {{Alignment of class vec is not in accordance with SYCL specification requirements, a limitation of the MSVC compiler(Error C2719).Requested alignment applied, limited at 64.}}

class KernelName1;

Expand Down

0 comments on commit 826c569

Please sign in to comment.