Skip to content

Commit 56589dd

Browse files
committed
Use CRTP for accessor owner-based ordering
Signed-off-by: Larsen, Steffen <[email protected]>
1 parent ac5c334 commit 56589dd

File tree

4 files changed

+72
-195
lines changed

4 files changed

+72
-195
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 61 additions & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,40 @@ template <int Dims> class AccessorImplDevice {
465465
}
466466
};
467467

468+
// CRTP class supplying a common definition of owner-before ordering for
469+
// accessors.
470+
template <class AccessorT> class AccessorOwnerLessBase {
471+
public:
472+
#ifndef __SYCL_DEVICE_ONLY__
473+
/// Compares the accessor against a weak object using an owner-based
474+
/// implementation-defined ordering.
475+
///
476+
/// \param Other is the weak object to compare ordering against.
477+
/// \return true if this object precedes \param Other and false otherwise.
478+
bool ext_oneapi_owner_before(
479+
const ext::oneapi::detail::weak_object_base<AccessorT> &Other)
480+
const noexcept {
481+
return static_cast<const AccessorT *>(this)->impl.owner_before(
482+
ext::oneapi::detail::getSyclWeakObjImpl(Other));
483+
}
484+
485+
/// Compares the accessor against another accessor using an owner-based
486+
/// implementation-defined ordering.
487+
///
488+
/// \param Other is the object to compare ordering against.
489+
/// \return true if this object precedes \param Other and false otherwise.
490+
bool ext_oneapi_owner_before(const AccessorT &Other) const noexcept {
491+
return static_cast<const AccessorT *>(this)->impl.owner_before(Other.impl);
492+
}
493+
#else
494+
bool ext_oneapi_owner_before(
495+
const ext::oneapi::detail::weak_object_base<AccessorT> &Other)
496+
const noexcept;
497+
498+
bool ext_oneapi_owner_before(const AccessorT &Other) const noexcept;
499+
#endif
500+
};
501+
468502
class AccessorImplHost;
469503

470504
void __SYCL_EXPORT addHostAccessorAndWait(AccessorImplHost *Req);
@@ -543,6 +577,8 @@ class __SYCL_EXPORT LocalAccessorBaseHost {
543577
template <class Obj>
544578
friend Obj detail::createSyclObjFromImpl(decltype(Obj::impl) ImplObj);
545579

580+
template <class AccessorT> friend class AccessorOwnerLessBase;
581+
546582
LocalAccessorImplPtr impl;
547583
};
548584

@@ -988,7 +1024,10 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
9881024
public detail::AccessorBaseHost,
9891025
#endif
9901026
public detail::accessor_common<DataT, Dimensions, AccessMode, AccessTarget,
991-
IsPlaceholder, PropertyListT> {
1027+
IsPlaceholder, PropertyListT>,
1028+
public detail::AccessorOwnerLessBase<
1029+
accessor<DataT, Dimensions, AccessMode, AccessTarget, IsPlaceholder,
1030+
PropertyListT>> {
9921031
protected:
9931032
static_assert((AccessTarget == access::target::global_buffer ||
9941033
AccessTarget == access::target::constant_buffer ||
@@ -2145,34 +2184,6 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
21452184
bool operator==(const accessor &Rhs) const { return impl == Rhs.impl; }
21462185
bool operator!=(const accessor &Rhs) const { return !(*this == Rhs); }
21472186

2148-
#ifndef __SYCL_DEVICE_ONLY__
2149-
/// Compares the accessor against a weak object using an owner-based
2150-
/// implementation-defined ordering.
2151-
///
2152-
/// \param Other is the weak object to compare ordering against.
2153-
/// \return true if this object precedes \param Other and false otherwise.
2154-
bool ext_oneapi_owner_before(
2155-
const ext::oneapi::detail::weak_object_base<accessor> &Other)
2156-
const noexcept {
2157-
return impl.owner_before(ext::oneapi::detail::getSyclWeakObjImpl(Other));
2158-
}
2159-
2160-
/// Compares the accessor against another accessor using an owner-based
2161-
/// implementation-defined ordering.
2162-
///
2163-
/// \param Other is the object to compare ordering against.
2164-
/// \return true if this object precedes \param Other and false otherwise.
2165-
bool ext_oneapi_owner_before(const accessor &Other) const noexcept {
2166-
return impl.owner_before(Other.impl);
2167-
}
2168-
#else
2169-
bool ext_oneapi_owner_before(
2170-
const ext::oneapi::detail::weak_object_base<accessor> &Other)
2171-
const noexcept;
2172-
2173-
bool ext_oneapi_owner_before(const accessor &Other) const noexcept;
2174-
#endif
2175-
21762187
iterator begin() const noexcept {
21772188
return iterator::getBegin(
21782189
get_pointer(),
@@ -2678,7 +2689,10 @@ template <typename DataT, int Dimensions, access::mode AccessMode,
26782689
access::placeholder IsPlaceholder>
26792690
class __SYCL_SPECIAL_CLASS accessor<DataT, Dimensions, AccessMode,
26802691
access::target::local, IsPlaceholder>
2681-
: public local_accessor_base<DataT, Dimensions, AccessMode, IsPlaceholder> {
2692+
: public local_accessor_base<DataT, Dimensions, AccessMode, IsPlaceholder>,
2693+
public detail::AccessorOwnerLessBase<
2694+
accessor<DataT, Dimensions, AccessMode, access::target::local,
2695+
IsPlaceholder>> {
26822696

26832697
using local_acc =
26842698
local_accessor_base<DataT, Dimensions, AccessMode, IsPlaceholder>;
@@ -2704,44 +2718,17 @@ class __SYCL_SPECIAL_CLASS accessor<DataT, Dimensions, AccessMode,
27042718
range>::template get<0>();
27052719
}
27062720

2707-
bool ext_oneapi_owner_before(
2708-
const ext::oneapi::detail::weak_object_base<accessor> &Other)
2709-
const noexcept;
2710-
bool ext_oneapi_owner_before(const accessor &Other) const noexcept;
2711-
27122721
#else
27132722
private:
27142723
accessor(const detail::AccessorImplPtr &Impl) : local_acc{Impl} {}
2715-
2716-
public:
2717-
/// Compares the accessor against a weak object using an owner-based
2718-
/// implementation-defined ordering.
2719-
///
2720-
/// \param Other is the weak object to compare ordering against.
2721-
/// \return true if this object precedes \param Other and false otherwise.
2722-
bool ext_oneapi_owner_before(
2723-
const ext::oneapi::detail::weak_object_base<accessor> &Other)
2724-
const noexcept {
2725-
return local_acc::impl.owner_before(
2726-
ext::oneapi::detail::getSyclWeakObjImpl(Other));
2727-
}
2728-
2729-
/// Compares the accessor against another accessor using an owner-based
2730-
/// implementation-defined ordering.
2731-
///
2732-
/// \param Other is the object to compare ordering against.
2733-
/// \return true if this object precedes \param Other and false otherwise.
2734-
bool ext_oneapi_owner_before(const accessor &Other) const noexcept {
2735-
return local_acc::impl.owner_before(Other.impl);
2736-
}
2737-
27382724
#endif
27392725
};
27402726

27412727
template <typename DataT, int Dimensions = 1>
27422728
class __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor
27432729
: public local_accessor_base<DataT, Dimensions, access::mode::read_write,
2744-
access::placeholder::false_t> {
2730+
access::placeholder::false_t>,
2731+
public detail::AccessorOwnerLessBase<local_accessor<DataT, Dimensions>> {
27452732

27462733
using local_acc =
27472734
local_accessor_base<DataT, Dimensions, access::mode::read_write,
@@ -2768,35 +2755,8 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor
27682755
range>::template get<0>();
27692756
}
27702757

2771-
bool ext_oneapi_owner_before(
2772-
const ext::oneapi::detail::weak_object_base<local_accessor> &Other)
2773-
const noexcept;
2774-
bool ext_oneapi_owner_before(const local_accessor &Other) const noexcept;
2775-
27762758
#else
27772759
local_accessor(const detail::AccessorImplPtr &Impl) : local_acc{Impl} {}
2778-
2779-
public:
2780-
/// Compares the local_accessor against a weak object using an owner-based
2781-
/// implementation-defined ordering.
2782-
///
2783-
/// \param Other is the weak object to compare ordering against.
2784-
/// \return true if this object precedes \param Other and false otherwise.
2785-
bool ext_oneapi_owner_before(
2786-
const ext::oneapi::detail::weak_object_base<local_accessor> &Other)
2787-
const noexcept {
2788-
return local_acc::impl.owner_before(
2789-
ext::oneapi::detail::getSyclWeakObjImpl(Other));
2790-
}
2791-
2792-
/// Compares the local_accessor against another local_accessor using an
2793-
/// owner-based implementation-defined ordering.
2794-
///
2795-
/// \param Other is the object to compare ordering against.
2796-
/// \return true if this object precedes \param Other and false otherwise.
2797-
bool ext_oneapi_owner_before(const local_accessor &Other) const noexcept {
2798-
return local_acc::impl.owner_before(Other.impl);
2799-
}
28002760
#endif
28012761

28022762
public:
@@ -2864,7 +2824,10 @@ class __SYCL_SPECIAL_CLASS
28642824
__SYCL_TYPE(accessor) accessor<DataT, Dimensions, AccessMode,
28652825
access::target::image, IsPlaceholder>
28662826
: public detail::image_accessor<DataT, Dimensions, AccessMode,
2867-
access::target::image, IsPlaceholder> {
2827+
access::target::image, IsPlaceholder>,
2828+
public detail::AccessorOwnerLessBase<
2829+
accessor<DataT, Dimensions, AccessMode, access::target::image,
2830+
IsPlaceholder>> {
28682831
private:
28692832
accessor(const detail::AccessorImplPtr &Impl)
28702833
: detail::image_accessor<DataT, Dimensions, AccessMode,
@@ -2911,34 +2874,6 @@ __SYCL_TYPE(accessor) accessor<DataT, Dimensions, AccessMode,
29112874
public:
29122875
// Default constructor for objects later initialized with __init member.
29132876
accessor() = default;
2914-
2915-
bool ext_oneapi_owner_before(
2916-
const ext::oneapi::detail::weak_object_base<accessor> &Other)
2917-
const noexcept;
2918-
bool ext_oneapi_owner_before(const accessor &Other) const noexcept;
2919-
#else
2920-
public:
2921-
/// Compares the accessor against a weak object using an owner-based
2922-
/// implementation-defined ordering.
2923-
///
2924-
/// \param Other is the weak object to compare ordering against.
2925-
/// \return true if this object precedes \param Other and false otherwise.
2926-
bool ext_oneapi_owner_before(
2927-
const ext::oneapi::detail::weak_object_base<accessor> &Other)
2928-
const noexcept {
2929-
return detail::AccessorBaseHost::impl.owner_before(
2930-
ext::oneapi::detail::getSyclWeakObjImpl(Other));
2931-
}
2932-
2933-
/// Compares the accessor against another accessor using an
2934-
/// owner-based implementation-defined ordering.
2935-
///
2936-
/// \param Other is the object to compare ordering against.
2937-
/// \return true if this object precedes \param Other and false otherwise.
2938-
bool ext_oneapi_owner_before(const accessor &Other) const noexcept {
2939-
return detail::AccessorBaseHost::impl.owner_before(Other.impl);
2940-
}
2941-
29422877
#endif
29432878
};
29442879

@@ -2954,7 +2889,10 @@ template <typename DataT, int Dimensions, access::mode AccessMode,
29542889
class accessor<DataT, Dimensions, AccessMode, access::target::host_image,
29552890
IsPlaceholder>
29562891
: public detail::image_accessor<DataT, Dimensions, AccessMode,
2957-
access::target::host_image, IsPlaceholder> {
2892+
access::target::host_image, IsPlaceholder>,
2893+
public detail::AccessorOwnerLessBase<
2894+
accessor<DataT, Dimensions, AccessMode, access::target::host_image,
2895+
IsPlaceholder>> {
29582896
public:
29592897
template <typename AllocatorT>
29602898
accessor(sycl::image<Dimensions, AllocatorT> &Image)
@@ -2970,34 +2908,6 @@ class accessor<DataT, Dimensions, AccessMode, access::target::host_image,
29702908
Image, Image.getElementSize()) {
29712909
(void)propList;
29722910
}
2973-
2974-
#ifndef __SYCL_DEVICE_ONLY__
2975-
/// Compares the accessor against a weak object using an owner-based
2976-
/// implementation-defined ordering.
2977-
///
2978-
/// \param Other is the weak object to compare ordering against.
2979-
/// \return true if this object precedes \param Other and false otherwise.
2980-
bool ext_oneapi_owner_before(
2981-
const ext::oneapi::detail::weak_object_base<accessor> &Other)
2982-
const noexcept {
2983-
return detail::AccessorBaseHost::impl.owner_before(
2984-
ext::oneapi::detail::getSyclWeakObjImpl(Other));
2985-
}
2986-
2987-
/// Compares the accessor against another accessor using an
2988-
/// owner-based implementation-defined ordering.
2989-
///
2990-
/// \param Other is the object to compare ordering against.
2991-
/// \return true if this object precedes \param Other and false otherwise.
2992-
bool ext_oneapi_owner_before(const accessor &Other) const noexcept {
2993-
return detail::AccessorBaseHost::impl.owner_before(Other.impl);
2994-
}
2995-
#else
2996-
bool ext_oneapi_owner_before(
2997-
const ext::oneapi::detail::weak_object_base<accessor> &Other)
2998-
const noexcept;
2999-
bool ext_oneapi_owner_before(const accessor &Other) const noexcept;
3000-
#endif
30012911
};
30022912

30032913
/// Image array accessor.
@@ -3014,7 +2924,10 @@ class __SYCL_SPECIAL_CLASS
30142924
__SYCL_TYPE(accessor) accessor<DataT, Dimensions, AccessMode,
30152925
access::target::image_array, IsPlaceholder>
30162926
: public detail::image_accessor<DataT, Dimensions + 1, AccessMode,
3017-
access::target::image, IsPlaceholder> {
2927+
access::target::image, IsPlaceholder>,
2928+
public detail::AccessorOwnerLessBase<
2929+
accessor<DataT, Dimensions, AccessMode, access::target::image_array,
2930+
IsPlaceholder>> {
30182931
#ifdef __SYCL_DEVICE_ONLY__
30192932
private:
30202933
using OCLImageTy =
@@ -3063,41 +2976,15 @@ __SYCL_TYPE(accessor) accessor<DataT, Dimensions, AccessMode,
30632976
return detail::__image_array_slice__<DataT, Dimensions, AccessMode,
30642977
IsPlaceholder>(*this, Index);
30652978
}
3066-
3067-
#ifndef __SYCL_DEVICE_ONLY__
3068-
/// Compares the accessor against a weak object using an owner-based
3069-
/// implementation-defined ordering.
3070-
///
3071-
/// \param Other is the weak object to compare ordering against.
3072-
/// \return true if this object precedes \param Other and false otherwise.
3073-
bool ext_oneapi_owner_before(
3074-
const ext::oneapi::detail::weak_object_base<accessor> &Other)
3075-
const noexcept {
3076-
return detail::AccessorBaseHost::impl.owner_before(
3077-
ext::oneapi::detail::getSyclWeakObjImpl(Other));
3078-
}
3079-
3080-
/// Compares the accessor against another accessor using an
3081-
/// owner-based implementation-defined ordering.
3082-
///
3083-
/// \param Other is the object to compare ordering against.
3084-
/// \return true if this object precedes \param Other and false otherwise.
3085-
bool ext_oneapi_owner_before(const accessor &Other) const noexcept {
3086-
return detail::AccessorBaseHost::impl.owner_before(Other.impl);
3087-
}
3088-
#else
3089-
bool ext_oneapi_owner_before(
3090-
const ext::oneapi::detail::weak_object_base<accessor> &Other)
3091-
const noexcept;
3092-
bool ext_oneapi_owner_before(const accessor &Other) const noexcept;
3093-
#endif
30942979
};
30952980

30962981
template <typename DataT, int Dimensions = 1,
30972982
access_mode AccessMode = access_mode::read_write>
30982983
class host_accessor
30992984
: public accessor<DataT, Dimensions, AccessMode, target::host_buffer,
3100-
access::placeholder::false_t> {
2985+
access::placeholder::false_t>,
2986+
public detail::AccessorOwnerLessBase<
2987+
host_accessor<DataT, Dimensions, AccessMode>> {
31012988
protected:
31022989
using AccessorT = accessor<DataT, Dimensions, AccessMode, target::host_buffer,
31032990
access::placeholder::false_t>;
@@ -3293,27 +3180,6 @@ class host_accessor
32933180
PropertyList, CodeLoc) {}
32943181

32953182
#endif
3296-
3297-
/// Compares the host_accessor against a weak object using an owner-based
3298-
/// implementation-defined ordering.
3299-
///
3300-
/// \param Other is the weak object to compare ordering against.
3301-
/// \return true if this object precedes \param Other and false otherwise.
3302-
bool ext_oneapi_owner_before(
3303-
const ext::oneapi::detail::weak_object_base<host_accessor> &Other)
3304-
const noexcept {
3305-
return detail::AccessorBaseHost::impl.owner_before(
3306-
ext::oneapi::detail::getSyclWeakObjImpl(Other));
3307-
}
3308-
3309-
/// Compares the host_accessor against another host_accessor using an
3310-
/// owner-based implementation-defined ordering.
3311-
///
3312-
/// \param Other is the object to compare ordering against.
3313-
/// \return true if this object precedes \param Other and false otherwise.
3314-
bool ext_oneapi_owner_before(const host_accessor &Other) const noexcept {
3315-
return detail::AccessorBaseHost::impl.owner_before(Other.impl);
3316-
}
33173183
};
33183184

33193185
#if __cplusplus >= 201703L

0 commit comments

Comments
 (0)