Skip to content

Commit 17f8939

Browse files
authored
[SYCL][ESIMD] Introduce compile time checks for wrregion API (#10837)
1 parent 445e6fc commit 17f8939

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

sycl/include/sycl/ext/intel/esimd/detail/intrin.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
//
6565
template <typename T, int N, int M, int VStride, int Width, int Stride,
6666
int ParentWidth = 0>
67-
__ESIMD_INTRIN __ESIMD_DNS::vector_type_t<T, M>
67+
__ESIMD_INTRIN __ESIMD_INTRIN std::enable_if_t<(Width > 0) && M % Width == 0,
68+
__ESIMD_DNS::vector_type_t<T, M>>
6869
__esimd_rdregion(__ESIMD_DNS::vector_type_t<T, N> Input, uint16_t Offset);
6970

7071
template <typename T, int N, int M, int ParentWidth = 0>
@@ -121,13 +122,14 @@ __esimd_rdindirect(__ESIMD_DNS::vector_type_t<T, N> Input,
121122
//
122123
template <typename T, int N, int M, int VStride, int Width, int Stride,
123124
int ParentWidth = 0>
124-
__ESIMD_INTRIN __ESIMD_DNS::vector_type_t<T, N>
125+
__ESIMD_INTRIN std::enable_if_t<M <= N && (Width > 0) && M % Width == 0,
126+
__ESIMD_DNS::vector_type_t<T, N>>
125127
__esimd_wrregion(__ESIMD_DNS::vector_type_t<T, N> OldVal,
126128
__ESIMD_DNS::vector_type_t<T, M> NewVal, uint16_t Offset,
127129
__ESIMD_DNS::simd_mask_storage_t<M> Mask = 1);
128130

129131
template <typename T, int N, int M, int ParentWidth = 0>
130-
__ESIMD_INTRIN __ESIMD_DNS::vector_type_t<T, N>
132+
__ESIMD_INTRIN std::enable_if_t<M <= N, __ESIMD_DNS::vector_type_t<T, N>>
131133
__esimd_wrindirect(__ESIMD_DNS::vector_type_t<T, N> OldVal,
132134
__ESIMD_DNS::vector_type_t<T, M> NewVal,
133135
__ESIMD_DNS::vector_type_t<uint16_t, M> Offset,
@@ -262,7 +264,8 @@ __ESIMD_INTRIN uint16_t __esimd_all(__ESIMD_DNS::vector_type_t<T, N> src)
262264
// Implementations of ESIMD intrinsics for the SYCL host device
263265
template <typename T, int N, int M, int VStride, int Width, int Stride,
264266
int ParentWidth>
265-
__ESIMD_INTRIN __ESIMD_DNS::vector_type_t<T, M>
267+
__ESIMD_INTRIN __ESIMD_INTRIN std::enable_if_t<(Width > 0) && M % Width == 0,
268+
__ESIMD_DNS::vector_type_t<T, M>>
266269
__esimd_rdregion(__ESIMD_DNS::vector_type_t<T, N> Input, uint16_t Offset) {
267270
uint16_t EltOffset = Offset / sizeof(T);
268271
assert(Offset % sizeof(T) == 0);
@@ -296,7 +299,8 @@ __esimd_rdindirect(__ESIMD_DNS::vector_type_t<T, N> Input,
296299

297300
template <typename T, int N, int M, int VStride, int Width, int Stride,
298301
int ParentWidth>
299-
__ESIMD_INTRIN __ESIMD_DNS::vector_type_t<T, N>
302+
__ESIMD_INTRIN std::enable_if_t<M <= N && (Width > 0) && M % Width == 0,
303+
__ESIMD_DNS::vector_type_t<T, N>>
300304
__esimd_wrregion(__ESIMD_DNS::vector_type_t<T, N> OldVal,
301305
__ESIMD_DNS::vector_type_t<T, M> NewVal, uint16_t Offset,
302306
__ESIMD_DNS::simd_mask_storage_t<M> Mask) {
@@ -319,7 +323,7 @@ __esimd_wrregion(__ESIMD_DNS::vector_type_t<T, N> OldVal,
319323
}
320324

321325
template <typename T, int N, int M, int ParentWidth>
322-
__ESIMD_INTRIN __ESIMD_DNS::vector_type_t<T, N>
326+
__ESIMD_INTRIN std::enable_if_t<M <= N, __ESIMD_DNS::vector_type_t<T, N>>
323327
__esimd_wrindirect(__ESIMD_DNS::vector_type_t<T, N> OldVal,
324328
__ESIMD_DNS::vector_type_t<T, M> NewVal,
325329
__ESIMD_DNS::vector_type_t<uint16_t, M> Offset,

sycl/test/esimd/simd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ template bool test_format_1d_read<int, short>() SYCL_ESIMD_FUNCTION;
190190
template bool test_format_1d_read<sycl::half, uint8_t>() SYCL_ESIMD_FUNCTION;
191191

192192
template <class T1, class T2> bool test_format_1d_write() SYCL_ESIMD_FUNCTION {
193-
simd<T1, 8> r;
193+
simd<T1, 32> r;
194194
auto rl = r.template bit_cast_view<T2>();
195195
auto rl2 = rl.template select<8, 2>(0);
196196
auto rh = r.template bit_cast_view<T2>();

sycl/test/esimd/wrregion.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %clangxx -fsycl -fsycl-device-only -fsyntax-only -Xclang -verify %s
2+
3+
#include <limits>
4+
#include <sycl/ext/intel/esimd.hpp>
5+
#include <utility>
6+
7+
using namespace sycl::ext::intel::esimd;
8+
9+
// test wrregion size checks.
10+
SYCL_ESIMD_FUNCTION void test_wrregion_size_check() {
11+
simd<int, 16> v16 = 0;
12+
v16.template select<64, 1>(0) = slm_block_load<int, 64>(0);
13+
// expected-error@* {{no matching function for call to '__esimd_wrregion'}}
14+
// expected-note@sycl/ext/intel/esimd/detail/simd_view_impl.hpp:* {{in instantiation of function template specialization}}
15+
// expected-note@sycl/ext/intel/esimd/detail/simd_view_impl.hpp:* {{in instantiation of member function}}
16+
// expected-note@* {{operator=' requested here}}
17+
// expected-note@sycl/ext/intel/esimd/detail/intrin.hpp:* {{candidate template ignored: requirement '64 <= 16' was not satisfied}}
18+
}

0 commit comments

Comments
 (0)