@@ -317,13 +317,32 @@ template <typename T, int N> struct VectorAlignment {
317
317
318
318
} // namespace detail
319
319
320
+ #if defined(_WIN32) && (_MSC_VER)
321
+ // MSVC Compiler doesn't allow using of function arguments with alignment
322
+ // requirements. MSVC Compiler Error C2719: 'parameter': formal parameter with
323
+ // __declspec(align('#')) won't be aligned. The align __declspec modifier
324
+ // is not permitted on function parameters. Function parameter alignment
325
+ // is controlled by the calling convention used.
326
+ // For more information, see Calling Conventions
327
+ // (https://docs.microsoft.com/en-us/cpp/cpp/calling-conventions).
328
+ // For information on calling conventions for x64 processors, see
329
+ // Calling Convention
330
+ // (https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention).
331
+ #pragma message ("Alignment of class vec is not in accordance with SYCL \
332
+ specification requirements, a limitation of the MSVC compiler (Error C2719).\
333
+ Applied default alignment.")
334
+ #define SYCL_ALIGNAS (x )
335
+ #else
336
+ #define SYCL_ALIGNAS (N ) alignas (N)
337
+ #endif
338
+
320
339
template <typename Type, int NumElements> class vec {
321
340
using DataT = Type;
322
341
323
342
// This represent type of underlying value. There should be only one field
324
343
// in the class, so vec<float, 16> should be equal to float16 in memory.
325
- using DataType = typename detail::BaseCLTypeConverter<
326
- DataT, detail::VectorLength< NumElements>::value >::DataType;
344
+ using DataType =
345
+ typename detail::BaseCLTypeConverter<DataT, NumElements>::DataType;
327
346
328
347
template <bool B, class T , class F >
329
348
using conditional_t = typename std::conditional<B, T, F>::type;
@@ -1023,7 +1042,12 @@ template <typename Type, int NumElements> class vec {
1023
1042
}
1024
1043
1025
1044
// fields
1026
- DataType m_Data;
1045
+ // Used "SYCL_ALIGNAS" instead "alignas" to handle MSVC compiler.
1046
+ // For MSVC compiler max alignment is 64, e.g. vec<double, 16> required
1047
+ // alignment of 128 and MSVC compiler cann't align a parameter with requested
1048
+ // alignment of 128.
1049
+ SYCL_ALIGNAS ((detail::VectorAlignment<DataT, NumElements>::value))
1050
+ DataType m_Data;
1027
1051
1028
1052
// friends
1029
1053
template <typename T1, typename T2, typename T3, template <typename > class T4 ,
@@ -1801,15 +1825,14 @@ using cl_schar16 = cl_char16;
1801
1825
// As a result half values will be converted to the integer and passed as a
1802
1826
// kernel argument which is expected to be floating point number.
1803
1827
#ifndef __SYCL_DEVICE_ONLY__
1804
- template <int NumElements>
1805
- struct alignas (
1806
- cl::sycl::detail::VectorAlignment<half, NumElements>::value) half_vec {
1807
- std::array<half, cl::sycl::detail::VectorLength<NumElements>::value> s;
1828
+ template <int NumElements> struct half_vec {
1829
+ alignas (cl::sycl::detail::VectorAlignment<half, NumElements>::value)
1830
+ std::array<half, NumElements> s;
1808
1831
};
1809
1832
1810
1833
using __half_t = half;
1811
1834
using __half2_vec_t = half_vec<2 >;
1812
- using __half3_vec_t = half_vec<4 >;
1835
+ using __half3_vec_t = half_vec<3 >;
1813
1836
using __half4_vec_t = half_vec<4 >;
1814
1837
using __half8_vec_t = half_vec<8 >;
1815
1838
using __half16_vec_t = half_vec<16 >;
@@ -2062,3 +2085,5 @@ DECLARE_SYCL_FLOAT_VEC(double)
2062
2085
2063
2086
} // namespace sycl
2064
2087
} // namespace cl
2088
+
2089
+ #undef SYCL_ALIGNAS
0 commit comments