Skip to content

Commit 3bb85e7

Browse files
authored
[ESIMD] Fix public simd and simd_view APIs. (#5465)
- Remove simd::copy_to(RawTy (&&Arr)[N1]), as it does not make sense - Remove simd_view_impl(BaseTy &&Base, RegionTy Region), as it does not make sense - simd::copy_from(const RawTy (&&Arr)[N1]) -> ... Ty ..., as user APIs must not use raw types - Replace "operator const simd::raw_vector_type &() const &" and "explicit operator raw_vector_type &() &" with "operator simd::raw_vector_type() const" - to avoid publishing references to internal state Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent 52fad5a commit 3bb85e7

File tree

3 files changed

+25
-33
lines changed

3 files changed

+25
-33
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class simd_mask_impl
4949
/// Construct from an array. To allow e.g. simd_mask<N> m({1,0,0,1,...}).
5050
template <int N1, class = std::enable_if_t<N1 == N>>
5151
simd_mask_impl(const raw_element_type (&&Arr)[N1]) {
52-
base_type::init_from_array(std::move(Arr));
52+
base_type::template init_from_array<false>(std::move(Arr));
5353
}
5454

5555
/// Implicit conversion from simd.

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

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,21 @@ class simd_obj_impl {
153153
static constexpr int length = N;
154154

155155
protected:
156+
template <bool UseSet = true>
156157
void init_from_array(const Ty (&&Arr)[N]) noexcept {
158+
raw_vector_type tmp;
159+
157160
if constexpr (is_wrapper_elem_type_v<Ty>) {
158161
for (auto I = 0; I < N; ++I) {
159-
M_data[I] = bitcast_to_raw_type(Arr[I]);
162+
tmp[I] = bitcast_to_raw_type(Arr[I]);
160163
}
161164
} else {
162-
M_data = make_vector(std::move(Arr));
165+
tmp = make_vector(std::move(Arr));
166+
}
167+
if constexpr (UseSet) {
168+
set(std::move(tmp));
169+
} else {
170+
M_data = std::move(tmp);
163171
}
164172
}
165173

@@ -216,7 +224,13 @@ class simd_obj_impl {
216224
template <int N1, class = std::enable_if_t<N1 == N>>
217225
simd_obj_impl(const Ty (&&Arr)[N1]) noexcept {
218226
__esimd_dbg_print(simd_obj_impl(const Ty(&&Arr)[N1]));
219-
init_from_array(std::move(Arr));
227+
init_from_array<false /*init M_data w/o using set(...)*/>(std::move(Arr));
228+
// It is OK not to mark a write to M_data with __esimd_vstore (via 'set')
229+
// here because:
230+
// - __esimd_vstore/vload are need only to mark ESIMD_PRIVATE variable
231+
// access for the VC BE to generate proper code for them.
232+
// - initializers are not allowed for ESIMD_PRIVATE vars, so only the
233+
// default ctor can be used for them
220234
}
221235

222236
/// Load constructor.
@@ -239,34 +253,15 @@ class simd_obj_impl {
239253
copy_from(acc, offset, Flags{});
240254
}
241255

242-
// Load the object's value from array.
243-
template <int N1>
244-
std::enable_if_t<N1 == N> copy_from(const RawTy (&&Arr)[N1]) {
245-
__esimd_dbg_print(copy_from(const RawTy(&&Arr)[N1]));
246-
raw_vector_type Tmp;
247-
for (auto I = 0; I < N; ++I) {
248-
Tmp[I] = Arr[I];
249-
}
250-
set(Tmp);
251-
}
252-
253-
// Store the object's value to array.
254-
template <int N1> std::enable_if_t<N1 == N> copy_to(RawTy (&&Arr)[N1]) const {
255-
__esimd_dbg_print(copy_to(RawTy(&&Arr)[N1]));
256-
for (auto I = 0; I < N; ++I) {
257-
Arr[I] = data()[I];
258-
}
256+
// Load the object's value from an rvalue array.
257+
template <int N1> std::enable_if_t<N1 == N> copy_from(const Ty (&&Arr)[N1]) {
258+
__esimd_dbg_print(copy_from(const Ty(&&Arr)[N1]));
259+
init_from_array(std::move(Arr));
259260
}
260261

261-
/// @{
262-
/// Conversion operators.
263-
explicit operator const raw_vector_type &() const & {
264-
__esimd_dbg_print(explicit operator const raw_vector_type &() const &);
265-
return M_data;
266-
}
267-
explicit operator raw_vector_type &() & {
268-
__esimd_dbg_print(explicit operator raw_vector_type &() &);
269-
return M_data;
262+
explicit operator raw_vector_type() const {
263+
__esimd_dbg_print(explicit operator raw_vector_type());
264+
return data();
270265
}
271266

272267
/// Type conversion into a scalar:
@@ -277,7 +272,6 @@ class simd_obj_impl {
277272
__esimd_dbg_print(operator Ty());
278273
return bitcast_to_wrapper_type<Ty>(data()[0]);
279274
}
280-
/// @}
281275

282276
raw_vector_type data() const {
283277
__esimd_dbg_print(raw_vector_type data());

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ class simd_view_impl {
6868
protected:
6969
simd_view_impl(BaseTy &Base, RegionTy Region)
7070
: M_base(Base), M_region(Region) {}
71-
simd_view_impl(BaseTy &&Base, RegionTy Region)
72-
: M_base(Base), M_region(Region) {}
7371

7472
simd_view_impl(BaseTy &Base) : M_base(Base), M_region(RegionTy(0)) {}
7573

0 commit comments

Comments
 (0)