Skip to content

Commit 28bfa9a

Browse files
[ESIMD] Provide alternative version of subscript operator (#4313)
1 parent b41e8e4 commit 28bfa9a

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

sycl/include/sycl/ext/intel/experimental/esimd/detail/simd_view_impl.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,15 @@ template <typename BaseTy, typename RegionTy> class simd_view_impl {
336336
return v[i];
337337
}
338338

339+
/// Read a single element from a 1D region, by value only.
340+
template <typename T = simd_view_impl,
341+
typename = sycl::detail::enable_if_t<T::is1D()>>
342+
__SYCL_DEPRECATED("use operator[] form.")
343+
element_type operator()(int i) const {
344+
const auto v = read();
345+
return v[i];
346+
}
347+
339348
/// \name Replicate
340349
/// Replicate simd instance given a simd_view
341350
/// @{

sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,21 @@ template <typename Ty, int N> class simd {
195195
/// Read single element, return value only (not reference).
196196
Ty operator[](int i) const { return data()[i]; }
197197

198+
/// Read single element, return value only (not reference).
199+
__SYCL_DEPRECATED("use operator[] form.")
200+
Ty operator()(int i) const { return data()[i]; }
201+
198202
/// Return writable view of a single element.
199203
simd_view<simd, region1d_t<Ty, 1, 0>> operator[](int i) {
200204
return select<1, 0>(i);
201205
}
202206

207+
/// Return writable view of a single element.
208+
__SYCL_DEPRECATED("use operator[] form.")
209+
simd_view<simd, region1d_t<Ty, 1, 0>> operator()(int i) {
210+
return select<1, 0>(i);
211+
}
212+
203213
// TODO ESIMD_EXPERIMENTAL
204214
/// Read multiple elements by their indices in vector
205215
template <int Size>

sycl/test/esimd/simd_subscript.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,21 @@ void test_simd_writable_subscript() SYCL_ESIMD_FUNCTION {
6363
simd<int, 4> v = 1;
6464
int val1 = v[0]; // simd_view -> int
6565
v[1] = 0; // returns simd_view
66+
67+
// CHECK: simd_subscript.cpp:69{{.*}}warning: {{.*}} deprecated
68+
// CHECK: sycl/ext/intel/experimental/esimd/simd.hpp:{{.*}} note: {{.*}} has been explicitly marked deprecated here
69+
v(1) = 0;
6670
}
6771

6872
void test_simd_const_subscript() SYCL_ESIMD_FUNCTION {
6973
const simd<int, 4> cv = 1;
7074
int val2 = cv[0]; // returns int instead of simd_view
71-
// CHECK: simd_subscript.cpp:72{{.*}}error: expression is not assignable
75+
// CHECK: simd_subscript.cpp:76{{.*}}error: expression is not assignable
7276
cv[1] = 0;
77+
78+
// CHECK: simd_subscript.cpp:80{{.*}}warning: {{.*}} deprecated
79+
// CHECK: sycl/ext/intel/experimental/esimd/simd.hpp:{{.*}} note: {{.*}} has been explicitly marked deprecated here
80+
int val3 = cv(0);
7381
}
7482

7583
void test_simd_view_assign_op() SYCL_ESIMD_FUNCTION {

sycl/test/esimd/simd_view.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %clangxx -fsycl -fsycl-device-only -fsyntax-only -Xclang -verify %s
2-
// expected-no-diagnostics
32

43
#include <sycl/ext/intel/experimental/esimd.hpp>
54
#include <limits>
@@ -62,3 +61,13 @@ bool test_simd_view_assign3() __attribute__((sycl_device)) {
6261
(g4.row(2) & mask2.bit_cast_view<ushort, 4, 16>().row(0));
6362
return val[0] == 0 && val1[0] == 0;
6463
}
64+
65+
void test_simd_view_subscript() SYCL_ESIMD_FUNCTION {
66+
simd<int, 4> v = 1;
67+
auto vv = v.select<2, 1>(0);
68+
69+
int x = vv[1];
70+
// expected-warning@+2 2 {{deprecated}}
71+
// expected-note@sycl/ext/intel/experimental/esimd/detail/simd_view_impl.hpp:* 2 {{has been explicitly marked deprecated here}}
72+
int y = vv(1);
73+
}

0 commit comments

Comments
 (0)