Skip to content

Commit 88fe720

Browse files
committed
code refactor
1 parent 0457819 commit 88fe720

File tree

1 file changed

+57
-37
lines changed

1 file changed

+57
-37
lines changed

sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr.hpp

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,49 @@ template <typename... Ts>
5353
using contains_alignment =
5454
detail::ContainsProperty<alignment_key, std::tuple<Ts...>>;
5555

56+
// properties filter
57+
template <typename property_list, template <class...> typename filter>
58+
using PropertiesFilter =
59+
sycl::detail::boost::mp11::mp_copy_if<property_list, filter>;
60+
61+
// filter properties that are applied on annotations
62+
template <typename... Props>
63+
using annotation_filter = properties<
64+
PropertiesFilter<std::tuple<Props...>, propagateToPtrAnnotation>>;
5665
} // namespace detail
5766

67+
template <typename I, typename P> struct annotationHelper {};
68+
69+
// unpack properties to varadic template
70+
template <typename I, typename... P>
71+
struct annotationHelper<I, detail::properties_t<P...>> {
72+
static I *annotate(I *ptr) {
73+
return __builtin_intel_sycl_ptr_annotation(
74+
ptr, detail::PropertyMetaInfo<P>::name...,
75+
detail::PropertyMetaInfo<P>::value...);
76+
}
77+
78+
// static I load(I *ptr) {
79+
// return *annotate(ptr);
80+
// }
81+
82+
// template <class O> static I store(I *ptr, O &&Obj) {
83+
// return *annotate(ptr) = std::forward<O>(Obj);
84+
// }
85+
86+
static I load(I *ptr) {
87+
return *__builtin_intel_sycl_ptr_annotation(
88+
ptr, detail::PropertyMetaInfo<P>::name...,
89+
detail::PropertyMetaInfo<P>::value...);
90+
}
91+
92+
template <class O> static I store(I *ptr, O &&Obj) {
93+
return *__builtin_intel_sycl_ptr_annotation(
94+
ptr, detail::PropertyMetaInfo<P>::name...,
95+
detail::PropertyMetaInfo<P>::value...) = std::forward<O>(Obj);
96+
}
97+
};
98+
5899
template <typename T, typename... Props>
59100
class annotated_ref<T, detail::properties_t<Props...>> {
60101
using property_list_t = detail::properties_t<Props...>;
@@ -67,44 +108,14 @@ class annotated_ref<T, detail::properties_t<Props...>> {
67108
T *m_Ptr;
68109
explicit annotated_ref(T *Ptr) : m_Ptr(Ptr) {}
69110

70-
// properties filter
71-
template <typename property_list, template <class...> typename filter>
72-
using PropertiesFilter =
73-
sycl::detail::boost::mp11::mp_copy_if<property_list, filter>;
74-
75-
template <typename p>
76-
using annotation_filter = propagateToPtrAnnotation<typename p::key_t>;
77-
78-
// filter properties that are applied on annotations
79-
using property_tuple_t = std::tuple<Props...>;
80-
using annotation_props =
81-
properties<PropertiesFilter<property_tuple_t, annotation_filter>>;
82-
83-
template <typename I, typename P> struct annotationHelper {};
84-
85-
// unpack properties to varadic template
86-
template <typename I, typename... P>
87-
struct annotationHelper<I, detail::properties_t<P...>> {
88-
static I load(I *ptr) {
89-
return *__builtin_intel_sycl_ptr_annotation(
90-
ptr, detail::PropertyMetaInfo<P>::name...,
91-
detail::PropertyMetaInfo<P>::value...);
92-
}
93-
94-
template <class O> static I store(I *ptr, O &&Obj) {
95-
return *__builtin_intel_sycl_ptr_annotation(
96-
ptr, detail::PropertyMetaInfo<P>::name...,
97-
detail::PropertyMetaInfo<P>::value...) = std::forward<O>(Obj);
98-
}
99-
};
100-
101111
public:
102112
annotated_ref(const annotated_ref &) = delete;
103113

104114
// implicit conversion with annotaion
105115
operator T() const {
106116
#ifdef __SYCL_DEVICE_ONLY__
107-
return annotationHelper<T, annotation_props>::load(m_Ptr);
117+
return annotationHelper<T, detail::annotation_filter<Props...>>::load(
118+
m_Ptr);
108119
#else
109120
return *m_Ptr;
110121
#endif
@@ -114,7 +125,8 @@ class annotated_ref<T, detail::properties_t<Props...>> {
114125
template <class O, typename = std::enable_if_t<!detail::is_ann_ref_v<O>>>
115126
T operator=(O &&Obj) const {
116127
#ifdef __SYCL_DEVICE_ONLY__
117-
return annotationHelper<T, annotation_props>::store(m_Ptr, Obj);
128+
return annotationHelper<T, detail::annotation_filter<Props...>>::store(
129+
m_Ptr, Obj);
118130
#else
119131
return *m_Ptr = std::forward<O>(Obj);
120132
#endif
@@ -126,6 +138,16 @@ class annotated_ref<T, detail::properties_t<Props...>> {
126138
return *this = t2;
127139
}
128140

141+
// address-of operator
142+
T *operator&() const {
143+
#ifdef __SYCL_DEVICE_ONLY__
144+
return annotationHelper<T, detail::annotation_filter<Props...>>::annotate(
145+
m_Ptr);
146+
#else
147+
return *m_Ptr;
148+
#endif
149+
}
150+
129151
// propagate compound operators
130152
#define PROPAGATE_OP(op) \
131153
template <class O, typename = std::enable_if_t<!detail::is_ann_ref_v<O>>> \
@@ -376,12 +398,10 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr<T, detail::properties_t<Props...>> {
376398

377399
operator T *() const noexcept = delete;
378400

379-
// T *get() const noexcept {
380401
T *get() const noexcept {
381402
#ifdef __SYCL_DEVICE_ONLY__
382-
return __builtin_intel_sycl_ptr_annotation(
383-
m_Ptr, detail::PropertyMetaInfo<Props>::name...,
384-
detail::PropertyMetaInfo<Props>::value...);
403+
return annotationHelper<T, detail::annotation_filter<Props...>>::annotate(
404+
m_Ptr);
385405
#else
386406
return m_Ptr;
387407
#endif

0 commit comments

Comments
 (0)