Skip to content

Commit 8f7f4a0

Browse files
alexeyvoronov-intelbader
authored andcommitted
[SYCL] Fix vec<T, 3> the underlying type.
Signed-off-by: Alexey Voronov <[email protected]>
1 parent 333ec8b commit 8f7f4a0

File tree

3 files changed

+81
-15
lines changed

3 files changed

+81
-15
lines changed

sycl/include/CL/sycl/detail/boolean.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,17 @@ template <> struct Assigner<0> {
4343
}
4444
};
4545

46-
template <int N> struct alignas(VectorAlignment<bool, N>::value) Boolean {
46+
template <int N> struct Boolean {
4747
static_assert(((N == 2) || (N == 3) || (N == 4) || (N == 8) || (N == 16)),
4848
"Invalid size");
4949

5050
using element_type = bool;
5151

5252
#ifdef __SYCL_DEVICE_ONLY__
53-
using DataType =
54-
element_type __attribute__((ext_vector_type(VectorLength<N>::value)));
53+
using DataType = element_type __attribute__((ext_vector_type(N)));
5554
using vector_t = DataType;
5655
#else
57-
using DataType = element_type[VectorLength<N>::value];
56+
using DataType = element_type[N];
5857
#endif
5958

6059
Boolean() : value{false} {}
@@ -100,10 +99,10 @@ template <int N> struct alignas(VectorAlignment<bool, N>::value) Boolean {
10099

101100
private:
102101
template <int Num> friend struct Assigner;
103-
DataType value;
102+
alignas(VectorAlignment<bool, N>::value) DataType value;
104103
};
105104

106-
template <> struct alignas(1) Boolean<1> {
105+
template <> struct Boolean<1> {
107106

108107
using element_type = bool;
109108

@@ -136,7 +135,7 @@ template <> struct alignas(1) Boolean<1> {
136135
}
137136

138137
private:
139-
DataType value;
138+
alignas(1) DataType value;
140139
};
141140

142141
} // namespace detail

sycl/include/CL/sycl/types.hpp

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,32 @@ template <typename T, int N> struct VectorAlignment {
317317

318318
} // namespace detail
319319

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+
320339
template <typename Type, int NumElements> class vec {
321340
using DataT = Type;
322341

323342
// This represent type of underlying value. There should be only one field
324343
// 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;
327346

328347
template <bool B, class T, class F>
329348
using conditional_t = typename std::conditional<B, T, F>::type;
@@ -1023,7 +1042,12 @@ template <typename Type, int NumElements> class vec {
10231042
}
10241043

10251044
// 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;
10271051

10281052
// friends
10291053
template <typename T1, typename T2, typename T3, template <typename> class T4,
@@ -1801,15 +1825,14 @@ using cl_schar16 = cl_char16;
18011825
// As a result half values will be converted to the integer and passed as a
18021826
// kernel argument which is expected to be floating point number.
18031827
#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;
18081831
};
18091832

18101833
using __half_t = half;
18111834
using __half2_vec_t = half_vec<2>;
1812-
using __half3_vec_t = half_vec<4>;
1835+
using __half3_vec_t = half_vec<3>;
18131836
using __half4_vec_t = half_vec<4>;
18141837
using __half8_vec_t = half_vec<8>;
18151838
using __half16_vec_t = half_vec<16>;
@@ -2062,3 +2085,5 @@ DECLARE_SYCL_FLOAT_VEC(double)
20622085

20632086
} // namespace sycl
20642087
} // namespace cl
2088+
2089+
#undef SYCL_ALIGNAS

sycl/test/basic_tests/swizzle_op.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,46 @@ int main() {
256256
assert(results[2] == 257);
257257
assert(results[3] == 258);
258258
}
259+
260+
{
261+
int FF[8] = {1, 1, 1, 0, 1, 1, 1, 0};
262+
{
263+
buffer<cl::sycl::int3, 1> b((cl::sycl::int3 *)FF, range<1>(2));
264+
queue myQueue;
265+
myQueue.submit([&](handler &cgh) {
266+
auto B = b.get_access<access::mode::read_write>(cgh);
267+
cgh.parallel_for<class test_10>(
268+
cl::sycl::range<1>{2},
269+
[=](cl::sycl::id<1> ID) { B[ID] = cl::sycl::int3{ID[0]} / B[ID]; });
270+
});
271+
}
272+
assert(FF[0] == 0);
273+
assert(FF[1] == 0);
274+
assert(FF[2] == 0);
275+
assert(FF[4] == 1);
276+
assert(FF[5] == 1);
277+
assert(FF[6] == 1);
278+
}
279+
{
280+
cl::sycl::int3 result = {0, 0, 0};
281+
{
282+
buffer<cl::sycl::int3, 1> b(&result, range<1>(1));
283+
queue myQueue;
284+
myQueue.submit([&](handler &cgh) {
285+
auto B = b.get_access<access::mode::write>(cgh);
286+
cgh.single_task<class test_11>([=]() {
287+
cl::sycl::int3 testVec1 = {2, 2, 2};
288+
cl::sycl::int3 testVec2 = {1, 1, 1};
289+
B[0] = testVec1 / testVec2;
290+
});
291+
});
292+
}
293+
const int r1 = result.x();
294+
const int r2 = result.y();
295+
const int r3 = result.z();
296+
assert(r1 == 2);
297+
assert(r2 == 2);
298+
assert(r3 == 2);
299+
}
300+
return 0;
259301
}

0 commit comments

Comments
 (0)