Skip to content

Commit 803a77f

Browse files
authored
[SYCL][ESIMD] Add more stringent compile time checks for accessor versions of block_load/block_store, gather/scatter API (#11145)
1 parent 87ff465 commit 803a77f

File tree

6 files changed

+342
-164
lines changed

6 files changed

+342
-164
lines changed

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

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,11 @@ class [[__sycl_detail__::__uses_aspects__(
330330
/// argument.
331331
/// @param acc The accessor to read from.
332332
/// @param offset offset in bytes of the first element.
333-
template <typename AccessorT, typename Flags = element_aligned_tag,
334-
typename = std::enable_if_t<
335-
(sycl::detail::acc_properties::is_local_accessor_v<AccessorT> ||
336-
detail::is_sycl_accessor_with<
337-
AccessorT, accessor_mode_cap::can_read,
338-
sycl::access::target::device>::value) &&
339-
is_simd_flag_type_v<Flags>>>
333+
template <
334+
typename AccessorT, typename Flags = element_aligned_tag,
335+
typename = std::enable_if_t<
336+
detail::is_accessor_with_v<AccessorT, accessor_mode_cap::can_read> &&
337+
is_simd_flag_type_v<Flags>>>
340338
simd_obj_impl(AccessorT acc,
341339
#ifdef __ESIMD_FORCE_STATELESS_MEM
342340
uint64_t offset,
@@ -744,8 +742,7 @@ class [[__sycl_detail__::__uses_aspects__(
744742
template <typename AccessorT, typename Flags = element_aligned_tag,
745743
int ChunkSize = 32,
746744
typename = std::enable_if_t<is_simd_flag_type_v<Flags>>>
747-
ESIMD_INLINE EnableIfAccessor<AccessorT, accessor_mode_cap::can_read,
748-
sycl::access::target::device, void>
745+
ESIMD_INLINE EnableIfAccessor<AccessorT, accessor_mode_cap::can_read, void>
749746
copy_from(AccessorT acc,
750747
#ifdef __ESIMD_FORCE_STATELESS_MEM
751748
uint64_t offset,
@@ -754,6 +751,25 @@ class [[__sycl_detail__::__uses_aspects__(
754751
#endif
755752
Flags = {}) SYCL_ESIMD_FUNCTION;
756753

754+
/// Copy a contiguous block of data from memory into this simd_obj_impl
755+
/// object. The amount of memory copied equals the total size of vector
756+
/// elements in this object. Source memory location is represented via a
757+
/// local accessor and offset.
758+
/// None of the template parameters except documented ones can/should be
759+
/// specified by callers.
760+
/// @tparam AccessorT Type of the accessor (auto-deduced).
761+
/// @tparam Flags Alignment control for the copy operation.
762+
/// See @ref sycl_esimd_core_align for more info.
763+
/// @param acc accessor to copy from.
764+
/// @param offset offset to copy from (in bytes).
765+
template <typename AccessorT, typename Flags = element_aligned_tag,
766+
int ChunkSize = 32,
767+
typename = std::enable_if_t<is_simd_flag_type_v<Flags>>>
768+
ESIMD_INLINE std::enable_if_t<
769+
detail::is_local_accessor_with_v<AccessorT, accessor_mode_cap::can_read>,
770+
void>
771+
copy_from(AccessorT acc, uint32_t offset, Flags = {}) SYCL_ESIMD_FUNCTION;
772+
757773
/// Copy all vector elements of this object into a contiguous block in memory.
758774
/// None of the template parameters should be be specified by callers.
759775
/// @tparam Flags Alignment control for the copy operation.
@@ -776,8 +792,7 @@ class [[__sycl_detail__::__uses_aspects__(
776792
template <typename AccessorT, typename Flags = element_aligned_tag,
777793
int ChunkSize = 32,
778794
typename = std::enable_if_t<is_simd_flag_type_v<Flags>>>
779-
ESIMD_INLINE EnableIfAccessor<AccessorT, accessor_mode_cap::can_write,
780-
sycl::access::target::device, void>
795+
ESIMD_INLINE EnableIfAccessor<AccessorT, accessor_mode_cap::can_write, void>
781796
copy_to(AccessorT acc,
782797
#ifdef __ESIMD_FORCE_STATELESS_MEM
783798
uint64_t offset,
@@ -786,6 +801,23 @@ class [[__sycl_detail__::__uses_aspects__(
786801
#endif
787802
Flags = {}) const SYCL_ESIMD_FUNCTION;
788803

804+
/// Copy all vector elements of this object into a contiguous block in memory.
805+
/// Destination memory location is represented via a local accessor and
806+
/// offset.
807+
/// None of the template parameters should be be specified by callers.
808+
/// @tparam AccessorT Type of the accessor (auto-deduced).
809+
/// @tparam Flags Alignment control for the copy operation.
810+
/// See @ref sycl_esimd_core_align for more info.
811+
/// @param acc accessor to copy from.
812+
/// @param offset offset to copy from.
813+
template <typename AccessorT, typename Flags = element_aligned_tag,
814+
int ChunkSize = 32,
815+
typename = std::enable_if_t<is_simd_flag_type_v<Flags>>>
816+
ESIMD_INLINE std::enable_if_t<
817+
detail::is_local_accessor_with_v<AccessorT, accessor_mode_cap::can_write>,
818+
void>
819+
copy_to(AccessorT acc, uint32_t offset, Flags = {}) const SYCL_ESIMD_FUNCTION;
820+
789821
// Unary operations.
790822

791823
/// Per-element bitwise inversion, available in all subclasses, but only for
@@ -916,6 +948,13 @@ class [[__sycl_detail__::__uses_aspects__(
916948
// The underlying data for this vector.
917949
raw_vector_type M_data;
918950

951+
template <int ChunkSize, typename Flags, typename AccessorT, typename TOffset>
952+
ESIMD_INLINE void copy_to_impl(AccessorT acc,
953+
TOffset offset) const SYCL_ESIMD_FUNCTION;
954+
template <int ChunkSize, typename Flags, typename AccessorT, typename TOffset>
955+
ESIMD_INLINE void copy_from_impl(AccessorT acc,
956+
TOffset offset) SYCL_ESIMD_FUNCTION;
957+
919958
protected:
920959
// The test proxy if enabled
921960
__ESIMD_DECLARE_TEST_PROXY

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

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,51 @@ constexpr bool accessor_mode_has_capability() {
6363
(Mode == sycl::access::mode::read);
6464
}
6565

66+
template <typename T> struct local_accessor_access_mode {
67+
static constexpr sycl::access::mode mode =
68+
static_cast<sycl::access::mode>(-1);
69+
};
70+
71+
template <typename DataT, int Dimensions>
72+
struct local_accessor_access_mode<local_accessor<DataT, Dimensions>> {
73+
static constexpr sycl::access::mode mode =
74+
sycl::detail::accessModeFromConstness<DataT>();
75+
};
76+
6677
// Checks that given type is a SYCL accessor type with given capability and
6778
// target.
68-
template <typename T, accessor_mode_cap_val_t Capability,
69-
sycl::access::target AccessTarget>
70-
struct is_sycl_accessor_with
79+
template <typename T, accessor_mode_cap_val_t Capability>
80+
struct is_device_accessor_with
7181
: public std::conditional_t<
7282
accessor_mode_has_capability<is_sycl_accessor<T>::mode,
7383
Capability>() &&
74-
(is_sycl_accessor<T>::target == AccessTarget),
84+
(is_sycl_accessor<T>::target == sycl::access::target::device),
7585
std::true_type, std::false_type> {};
7686

77-
template <typename T, accessor_mode_cap_val_t Capability,
78-
sycl::access::target AccessTarget, typename RetT>
79-
using EnableIfAccessor = std::enable_if_t<
80-
detail::is_sycl_accessor_with<T, Capability, AccessTarget>::value ||
81-
sycl::detail::acc_properties::is_local_accessor_v<T>,
82-
RetT>;
87+
template <typename T, accessor_mode_cap_val_t Capability>
88+
struct is_local_accessor_with
89+
: public std::conditional_t<
90+
sycl::detail::acc_properties::is_local_accessor_v<T> &&
91+
accessor_mode_has_capability<local_accessor_access_mode<T>::mode,
92+
Capability>(),
93+
std::true_type, std::false_type> {};
94+
95+
template <typename T, accessor_mode_cap_val_t Capability>
96+
inline constexpr bool is_local_accessor_with_v =
97+
is_local_accessor_with<T, Capability>::value;
98+
99+
template <typename T, accessor_mode_cap_val_t Capability>
100+
inline constexpr bool is_device_accessor_with_v =
101+
is_device_accessor_with<T, Capability>::value;
102+
103+
template <typename T, accessor_mode_cap_val_t Capability>
104+
inline constexpr bool is_accessor_with_v =
105+
is_device_accessor_with_v<T, Capability> ||
106+
is_local_accessor_with_v<T, Capability>;
107+
108+
template <typename T, accessor_mode_cap_val_t Capability, typename RetT>
109+
using EnableIfAccessor =
110+
std::enable_if_t<detail::is_device_accessor_with_v<T, Capability>, RetT>;
83111

84112
template <typename T, int Dimensions>
85113
__ESIMD_API uint32_t localAccessorToOffset(local_accessor<T, Dimensions> acc) {

0 commit comments

Comments
 (0)