Skip to content

Commit ff59e41

Browse files
committed
Make common base class for owner-less methods
Signed-off-by: Larsen, Steffen <[email protected]>
1 parent bfb344e commit ff59e41

17 files changed

+172
-305
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <sycl/detail/handler_proxy.hpp>
2020
#include <sycl/detail/image_accessor_util.hpp>
2121
#include <sycl/detail/image_ocl_types.hpp>
22+
#include <sycl/detail/owner_less_base.hpp>
2223
#include <sycl/device.hpp>
2324
#include <sycl/exception.hpp>
2425
#include <sycl/ext/oneapi/accessor_property_list.hpp>
@@ -465,40 +466,6 @@ template <int Dims> class AccessorImplDevice {
465466
}
466467
};
467468

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-
502469
class AccessorImplHost;
503470

504471
void __SYCL_EXPORT addHostAccessorAndWait(AccessorImplHost *Req);
@@ -577,8 +544,6 @@ class __SYCL_EXPORT LocalAccessorBaseHost {
577544
template <class Obj>
578545
friend Obj detail::createSyclObjFromImpl(decltype(Obj::impl) ImplObj);
579546

580-
template <class AccessorT> friend class AccessorOwnerLessBase;
581-
582547
LocalAccessorImplPtr impl;
583548
};
584549

@@ -1025,7 +990,7 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
1025990
#endif
1026991
public detail::accessor_common<DataT, Dimensions, AccessMode, AccessTarget,
1027992
IsPlaceholder, PropertyListT>,
1028-
public detail::AccessorOwnerLessBase<
993+
public detail::OwnerLessBase<
1029994
accessor<DataT, Dimensions, AccessMode, AccessTarget, IsPlaceholder,
1030995
PropertyListT>> {
1031996
protected:
@@ -2690,7 +2655,7 @@ template <typename DataT, int Dimensions, access::mode AccessMode,
26902655
class __SYCL_SPECIAL_CLASS accessor<DataT, Dimensions, AccessMode,
26912656
access::target::local, IsPlaceholder>
26922657
: public local_accessor_base<DataT, Dimensions, AccessMode, IsPlaceholder>,
2693-
public detail::AccessorOwnerLessBase<
2658+
public detail::OwnerLessBase<
26942659
accessor<DataT, Dimensions, AccessMode, access::target::local,
26952660
IsPlaceholder>> {
26962661

@@ -2728,7 +2693,7 @@ template <typename DataT, int Dimensions = 1>
27282693
class __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor
27292694
: public local_accessor_base<DataT, Dimensions, access::mode::read_write,
27302695
access::placeholder::false_t>,
2731-
public detail::AccessorOwnerLessBase<local_accessor<DataT, Dimensions>> {
2696+
public detail::OwnerLessBase<local_accessor<DataT, Dimensions>> {
27322697

27332698
using local_acc =
27342699
local_accessor_base<DataT, Dimensions, access::mode::read_write,
@@ -2825,7 +2790,7 @@ __SYCL_TYPE(accessor) accessor<DataT, Dimensions, AccessMode,
28252790
access::target::image, IsPlaceholder>
28262791
: public detail::image_accessor<DataT, Dimensions, AccessMode,
28272792
access::target::image, IsPlaceholder>,
2828-
public detail::AccessorOwnerLessBase<
2793+
public detail::OwnerLessBase<
28292794
accessor<DataT, Dimensions, AccessMode, access::target::image,
28302795
IsPlaceholder>> {
28312796
private:
@@ -2890,7 +2855,7 @@ class accessor<DataT, Dimensions, AccessMode, access::target::host_image,
28902855
IsPlaceholder>
28912856
: public detail::image_accessor<DataT, Dimensions, AccessMode,
28922857
access::target::host_image, IsPlaceholder>,
2893-
public detail::AccessorOwnerLessBase<
2858+
public detail::OwnerLessBase<
28942859
accessor<DataT, Dimensions, AccessMode, access::target::host_image,
28952860
IsPlaceholder>> {
28962861
public:
@@ -2925,7 +2890,7 @@ __SYCL_TYPE(accessor) accessor<DataT, Dimensions, AccessMode,
29252890
access::target::image_array, IsPlaceholder>
29262891
: public detail::image_accessor<DataT, Dimensions + 1, AccessMode,
29272892
access::target::image, IsPlaceholder>,
2928-
public detail::AccessorOwnerLessBase<
2893+
public detail::OwnerLessBase<
29292894
accessor<DataT, Dimensions, AccessMode, access::target::image_array,
29302895
IsPlaceholder>> {
29312896
#ifdef __SYCL_DEVICE_ONLY__
@@ -2983,7 +2948,7 @@ template <typename DataT, int Dimensions = 1,
29832948
class host_accessor
29842949
: public accessor<DataT, Dimensions, AccessMode, target::host_buffer,
29852950
access::placeholder::false_t>,
2986-
public detail::AccessorOwnerLessBase<
2951+
public detail::OwnerLessBase<
29872952
host_accessor<DataT, Dimensions, AccessMode>> {
29882953
protected:
29892954
using AccessorT = accessor<DataT, Dimensions, AccessMode, target::host_buffer,

sycl/include/sycl/buffer.hpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#pragma once
1010

1111
#include <sycl/detail/common.hpp>
12+
#include <sycl/detail/owner_less_base.hpp>
1213
#include <sycl/detail/stl_type_traits.hpp>
1314
#include <sycl/detail/sycl_mem_obj_allocator.hpp>
1415
#include <sycl/event.hpp>
@@ -141,7 +142,8 @@ template <typename T, int dimensions = 1,
141142
typename AllocatorT = buffer_allocator<std::remove_const_t<T>>,
142143
typename __Enabled = typename detail::enable_if_t<(dimensions > 0) &&
143144
(dimensions <= 3)>>
144-
class buffer : public detail::buffer_plain {
145+
class buffer : public detail::buffer_plain,
146+
public detail::OwnerLessBase<buffer<T, dimensions, AllocatorT>> {
145147
// TODO check is_device_copyable<T>::value after converting sycl::vec into a
146148
// trivially copyable class.
147149
static_assert(!std::is_same<T, std::string>::value,
@@ -687,16 +689,6 @@ class buffer : public detail::buffer_plain {
687689
return buffer_plain::template get_property<propertyT>();
688690
}
689691

690-
bool ext_oneapi_owner_before(
691-
const ext::oneapi::detail::weak_object_base<buffer> &Other)
692-
const noexcept {
693-
return impl.owner_before(ext::oneapi::detail::getSyclWeakObjImpl(Other));
694-
}
695-
696-
bool ext_oneapi_owner_before(const buffer &Other) const noexcept {
697-
return impl.owner_before(Other.impl);
698-
}
699-
700692
protected:
701693
bool isOutOfBounds(const id<dimensions> &offset,
702694
const range<dimensions> &newRange,

sycl/include/sycl/context.hpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <sycl/detail/common.hpp>
1414
#include <sycl/detail/export.hpp>
1515
#include <sycl/detail/info_desc_helpers.hpp>
16+
#include <sycl/detail/owner_less_base.hpp>
1617
#include <sycl/detail/stl_type_traits.hpp>
1718
#include <sycl/exception_list.hpp>
1819
#include <sycl/ext/oneapi/weak_object_base.hpp>
@@ -37,7 +38,7 @@ auto get_native(const SyclT &Obj) -> backend_return_t<Backend, SyclT>;
3738
/// be executed.
3839
///
3940
/// \ingroup sycl_api
40-
class __SYCL_EXPORT context {
41+
class __SYCL_EXPORT context : public detail::OwnerLessBase<context> {
4142
public:
4243
/// Constructs a SYCL context instance using an instance of default_selector.
4344
///
@@ -220,26 +221,6 @@ class __SYCL_EXPORT context {
220221
/// \return a vector of valid SYCL device instances.
221222
std::vector<device> get_devices() const;
222223

223-
/// Compares the context against a weak object using an owner-based
224-
/// implementation-defined ordering.
225-
///
226-
/// \param Other is the weak object to compare ordering against.
227-
/// \return true if this object precedes \param Other and false otherwise.
228-
bool ext_oneapi_owner_before(
229-
const ext::oneapi::detail::weak_object_base<context> &Other)
230-
const noexcept {
231-
return impl.owner_before(ext::oneapi::detail::getSyclWeakObjImpl(Other));
232-
}
233-
234-
/// Compares the context against another context using an owner-based
235-
/// implementation-defined ordering.
236-
///
237-
/// \param Other is the object to compare ordering against.
238-
/// \return true if this object precedes \param Other and false otherwise.
239-
bool ext_oneapi_owner_before(const context &Other) const noexcept {
240-
return impl.owner_before(Other.impl);
241-
}
242-
243224
private:
244225
/// Constructs a SYCL context object from a valid context_impl instance.
245226
context(std::shared_ptr<detail::context_impl> Impl);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//==-- owner_less_base.hpp --- Common base class for owner-based ordering --==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <sycl/detail/common.hpp>
12+
#include <sycl/detail/defines_elementary.hpp>
13+
#include <sycl/ext/oneapi/weak_object_base.hpp>
14+
15+
namespace sycl {
16+
__SYCL_INLINE_VER_NAMESPACE(_V1) {
17+
namespace detail {
18+
19+
// Common CRTP base class supplying a common definition of owner-before ordering
20+
// for SYCL objects.
21+
template <class SyclObjT> class OwnerLessBase {
22+
public:
23+
#ifndef __SYCL_DEVICE_ONLY__
24+
/// Compares the object against a weak object using an owner-based
25+
/// implementation-defined ordering.
26+
///
27+
/// \param Other is the weak object to compare ordering against.
28+
/// \return true if this object precedes \param Other and false otherwise.
29+
bool ext_oneapi_owner_before(
30+
const ext::oneapi::detail::weak_object_base<SyclObjT> &Other)
31+
const noexcept {
32+
return getSyclObjImpl(*static_cast<const SyclObjT *>(this))
33+
.owner_before(ext::oneapi::detail::getSyclWeakObjImpl(Other));
34+
}
35+
36+
/// Compares the object against another object using an owner-based
37+
/// implementation-defined ordering.
38+
///
39+
/// \param Other is the object to compare ordering against.
40+
/// \return true if this object precedes \param Other and false otherwise.
41+
bool ext_oneapi_owner_before(const SyclObjT &Other) const noexcept {
42+
return getSyclObjImpl(*static_cast<const SyclObjT *>(this))
43+
.owner_before(Other.impl);
44+
}
45+
#else
46+
bool ext_oneapi_owner_before(
47+
const ext::oneapi::detail::weak_object_base<SyclObjT> &Other)
48+
const noexcept;
49+
50+
bool ext_oneapi_owner_before(const SyclObjT &Other) const noexcept;
51+
#endif
52+
};
53+
54+
} // namespace detail
55+
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
56+
} // namespace sycl

sycl/include/sycl/device.hpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <sycl/detail/common.hpp>
1515
#include <sycl/detail/export.hpp>
1616
#include <sycl/detail/info_desc_helpers.hpp>
17+
#include <sycl/detail/owner_less_base.hpp>
1718
#include <sycl/ext/oneapi/weak_object_base.hpp>
1819
#include <sycl/info/info_desc.hpp>
1920
#include <sycl/platform.hpp>
@@ -45,7 +46,7 @@ class filter_selector;
4546
/// may be executed.
4647
///
4748
/// \ingroup sycl_api
48-
class __SYCL_EXPORT device {
49+
class __SYCL_EXPORT device : public detail::OwnerLessBase<device> {
4950
public:
5051
/// Constructs a SYCL device instance using the default device.
5152
device();
@@ -219,26 +220,6 @@ class __SYCL_EXPORT device {
219220
/// \return true if the SYCL device has the given feature.
220221
bool has(aspect Aspect) const;
221222

222-
/// Compares the device against a weak object using an owner-based
223-
/// implementation-defined ordering.
224-
///
225-
/// \param Other is the weak object to compare ordering against.
226-
/// \return true if this object precedes \param Other and false otherwise.
227-
bool ext_oneapi_owner_before(
228-
const ext::oneapi::detail::weak_object_base<device> &Other)
229-
const noexcept {
230-
return impl.owner_before(ext::oneapi::detail::getSyclWeakObjImpl(Other));
231-
}
232-
233-
/// Compares the device against another device using an owner-based
234-
/// implementation-defined ordering.
235-
///
236-
/// \param Other is the object to compare ordering against.
237-
/// \return true if this object precedes \param Other and false otherwise.
238-
bool ext_oneapi_owner_before(const device &Other) const noexcept {
239-
return impl.owner_before(Other.impl);
240-
}
241-
242223
private:
243224
std::shared_ptr<detail::device_impl> impl;
244225
device(std::shared_ptr<detail::device_impl> impl) : impl(impl) {}

sycl/include/sycl/event.hpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <sycl/detail/common.hpp>
1414
#include <sycl/detail/export.hpp>
1515
#include <sycl/detail/info_desc_helpers.hpp>
16+
#include <sycl/detail/owner_less_base.hpp>
1617
#include <sycl/ext/oneapi/weak_object_base.hpp>
1718
#include <sycl/info/info_desc.hpp>
1819
#include <sycl/stl.hpp>
@@ -36,7 +37,7 @@ class event_impl;
3637
/// kernels and signaling barriers.
3738
///
3839
/// \ingroup sycl_api
39-
class __SYCL_EXPORT event {
40+
class __SYCL_EXPORT event : public detail::OwnerLessBase<event> {
4041
public:
4142
/// Constructs a ready SYCL event.
4243
///
@@ -130,26 +131,6 @@ class __SYCL_EXPORT event {
130131
/// \return the backend associated with this platform
131132
backend get_backend() const noexcept;
132133

133-
/// Compares the event against a weak object using an owner-based
134-
/// implementation-defined ordering.
135-
///
136-
/// \param Other is the weak object to compare ordering against.
137-
/// \return true if this object precedes \param Other and false otherwise.
138-
bool ext_oneapi_owner_before(
139-
const ext::oneapi::detail::weak_object_base<event> &Other)
140-
const noexcept {
141-
return impl.owner_before(ext::oneapi::detail::getSyclWeakObjImpl(Other));
142-
}
143-
144-
/// Compares the event against another event using an owner-based
145-
/// implementation-defined ordering.
146-
///
147-
/// \param Other is the object to compare ordering against.
148-
/// \return true if this object precedes \param Other and false otherwise.
149-
bool ext_oneapi_owner_before(const event &Other) const noexcept {
150-
return impl.owner_before(Other.impl);
151-
}
152-
153134
private:
154135
event(std::shared_ptr<detail::event_impl> EventImpl);
155136

sycl/include/sycl/kernel.hpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <sycl/detail/common.hpp>
1313
#include <sycl/detail/export.hpp>
1414
#include <sycl/detail/info_desc_helpers.hpp>
15+
#include <sycl/detail/owner_less_base.hpp>
1516
#include <sycl/detail/pi.h>
1617
#include <sycl/ext/oneapi/weak_object_base.hpp>
1718
#include <sycl/info/info_desc.hpp>
@@ -67,7 +68,7 @@ template <typename Type> struct get_kernel_name_t<detail::auto_name, Type> {
6768
/// \sa queue
6869
///
6970
/// \ingroup sycl_api
70-
class __SYCL_EXPORT kernel {
71+
class __SYCL_EXPORT kernel : public detail::OwnerLessBase<kernel> {
7172
public:
7273
/// Constructs a SYCL kernel instance from an OpenCL cl_kernel
7374
///
@@ -156,26 +157,6 @@ class __SYCL_EXPORT kernel {
156157
typename detail::is_kernel_device_specific_info_desc<Param>::return_type
157158
get_info(const device &Device, const range<3> &WGSize) const;
158159

159-
/// Compares the kernel against a weak object using an owner-based
160-
/// implementation-defined ordering.
161-
///
162-
/// \param Other is the weak object to compare ordering against.
163-
/// \return true if this object precedes \param Other and false otherwise.
164-
bool ext_oneapi_owner_before(
165-
const ext::oneapi::detail::weak_object_base<kernel> &Other)
166-
const noexcept {
167-
return impl.owner_before(ext::oneapi::detail::getSyclWeakObjImpl(Other));
168-
}
169-
170-
/// Compares the kernel against another kernel using an owner-based
171-
/// implementation-defined ordering.
172-
///
173-
/// \param Other is the object to compare ordering against.
174-
/// \return true if this object precedes \param Other and false otherwise.
175-
bool ext_oneapi_owner_before(const kernel &Other) const noexcept {
176-
return impl.owner_before(Other.impl);
177-
}
178-
179160
private:
180161
/// Constructs a SYCL kernel object from a valid kernel_impl instance.
181162
kernel(std::shared_ptr<detail::kernel_impl> Impl);

0 commit comments

Comments
 (0)