Skip to content

[ESIMD] Provide alternative version of subscript operator #4313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,15 @@ template <typename BaseTy, typename RegionTy> class simd_view_impl {
return v[i];
}

/// Read a single element from a 1D region, by value only.
template <typename T = simd_view_impl,
typename = sycl::detail::enable_if_t<T::is1D()>>
__SYCL_DEPRECATED("use operator[] form.")
element_type operator()(int i) const {
const auto v = read();
return v[i];
}

/// \name Replicate
/// Replicate simd instance given a simd_view
/// @{
Expand Down
10 changes: 10 additions & 0 deletions sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,21 @@ template <typename Ty, int N> class simd {
/// Read single element, return value only (not reference).
Ty operator[](int i) const { return data()[i]; }

/// Read single element, return value only (not reference).
__SYCL_DEPRECATED("use operator[] form.")
Ty operator()(int i) const { return data()[i]; }

/// Return writable view of a single element.
simd_view<simd, region1d_t<Ty, 1, 0>> operator[](int i) {
return select<1, 0>(i);
}

/// Return writable view of a single element.
__SYCL_DEPRECATED("use operator[] form.")
simd_view<simd, region1d_t<Ty, 1, 0>> operator()(int i) {
return select<1, 0>(i);
}

// TODO ESIMD_EXPERIMENTAL
/// Read multiple elements by their indices in vector
template <int Size>
Expand Down
10 changes: 9 additions & 1 deletion sycl/test/esimd/simd_subscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,21 @@ void test_simd_writable_subscript() SYCL_ESIMD_FUNCTION {
simd<int, 4> v = 1;
int val1 = v[0]; // simd_view -> int
v[1] = 0; // returns simd_view

// CHECK: simd_subscript.cpp:69{{.*}}warning: {{.*}} deprecated
// CHECK: sycl/ext/intel/experimental/esimd/simd.hpp:{{.*}} note: {{.*}} has been explicitly marked deprecated here
v(1) = 0;
}

void test_simd_const_subscript() SYCL_ESIMD_FUNCTION {
const simd<int, 4> cv = 1;
int val2 = cv[0]; // returns int instead of simd_view
// CHECK: simd_subscript.cpp:72{{.*}}error: expression is not assignable
// CHECK: simd_subscript.cpp:76{{.*}}error: expression is not assignable
cv[1] = 0;

// CHECK: simd_subscript.cpp:80{{.*}}warning: {{.*}} deprecated
// CHECK: sycl/ext/intel/experimental/esimd/simd.hpp:{{.*}} note: {{.*}} has been explicitly marked deprecated here
int val3 = cv(0);
}

void test_simd_view_assign_op() SYCL_ESIMD_FUNCTION {
Expand Down
11 changes: 10 additions & 1 deletion sycl/test/esimd/simd_view.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %clangxx -fsycl -fsycl-device-only -fsyntax-only -Xclang -verify %s
// expected-no-diagnostics

#include <sycl/ext/intel/experimental/esimd.hpp>
#include <limits>
Expand Down Expand Up @@ -62,3 +61,13 @@ bool test_simd_view_assign3() __attribute__((sycl_device)) {
(g4.row(2) & mask2.bit_cast_view<ushort, 4, 16>().row(0));
return val[0] == 0 && val1[0] == 0;
}

void test_simd_view_subscript() SYCL_ESIMD_FUNCTION {
simd<int, 4> v = 1;
auto vv = v.select<2, 1>(0);

int x = vv[1];
// expected-warning@+2 2 {{deprecated}}
// expected-note@sycl/ext/intel/experimental/esimd/detail/simd_view_impl.hpp:* 2 {{has been explicitly marked deprecated here}}
int y = vv(1);
}