Skip to content

Commit 08907a3

Browse files
authored
[SYCL] Limit decorations to init function for annotated_arg/ptr classes (#11881)
annotated_arg/annotated_ptr are special classes and arguments of the __init() member function become kernel arguments. The classes have decorated_global_ptr or other such type applied on the class members to indicate that these must be in global address-space (or other address space as indicated by the applied type). The goal of applying the type on the member was to ensure that class member gets captured as a global address space pointer when set as kernel argument. However, the type was applied on class constructor arguments as well. This PR restricts the type to only be present on the __init member function argument, otherwise the presence of the type on constructors causes functional errors on certain backends when objects are constructed in the kernel body. The object constructed inside kernel body also gets a global address space cast generated by the compiler when the decorated_global_ptr type is applied on ctor arguments. This is problematic for example when the object is constructed from a pointer to some array defined inside the kernel.
1 parent 984efcf commit 08907a3

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,15 @@ class __SYCL_SPECIAL_CLASS
6666
__SYCL_TYPE(annotated_arg) annotated_arg<T *, detail::properties_t<Props...>> {
6767
using property_list_t = detail::properties_t<Props...>;
6868

69-
#ifdef __SYCL_DEVICE_ONLY__
70-
using global_pointer_t = typename decorated_global_ptr<T>::pointer;
71-
#else
72-
using global_pointer_t = T *;
73-
#endif
74-
75-
global_pointer_t obj;
69+
T *obj;
7670

7771
template <typename T2, typename PropertyListT> friend class annotated_arg;
7872

7973
#ifdef __SYCL_DEVICE_ONLY__
8074
void __init([[__sycl_detail__::add_ir_attributes_kernel_parameter(
8175
detail::PropertyMetaInfo<Props>::name...,
82-
detail::PropertyMetaInfo<Props>::value...)]] global_pointer_t _obj) {
76+
detail::PropertyMetaInfo<Props>::value...)]]
77+
typename decorated_global_ptr<T>::pointer _obj) {
8378
obj = _obj;
8479
}
8580
#endif
@@ -91,7 +86,7 @@ __SYCL_TYPE(annotated_arg) annotated_arg<T *, detail::properties_t<Props...>> {
9186

9287
annotated_arg(T *_ptr,
9388
const property_list_t &PropList = properties{}) noexcept
94-
: obj(global_pointer_t(_ptr)) {
89+
: obj(_ptr) {
9590
(void)PropList;
9691
}
9792

@@ -100,8 +95,7 @@ __SYCL_TYPE(annotated_arg) annotated_arg<T *, detail::properties_t<Props...>> {
10095
// variadic properties. The same property in `Props...` and
10196
// `PropertyValueTs...` must have the same property value.
10297
template <typename... PropertyValueTs>
103-
annotated_arg(T *_ptr, const PropertyValueTs &...props) noexcept
104-
: obj(global_pointer_t(_ptr)) {
98+
annotated_arg(T *_ptr, const PropertyValueTs &...props) noexcept : obj(_ptr) {
10599
static constexpr bool has_same_properties = std::is_same<
106100
property_list_t,
107101
detail::merged_properties_t<property_list_t,

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr<T, detail::properties_t<Props...>> {
190190
using reference = sycl::ext::oneapi::experimental::annotated_ref<
191191
T, typename unpack<filtered_properties>::type>;
192192

193-
#ifdef __SYCL_DEVICE_ONLY__
194193
#ifdef __ENABLE_USM_ADDR_SPACE__
195194
using global_pointer_t = std::conditional_t<
196195
detail::IsUsmKindDevice<property_list_t>::value,
@@ -202,11 +201,8 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr<T, detail::properties_t<Props...>> {
202201
#else
203202
using global_pointer_t = typename decorated_global_ptr<T>::pointer;
204203
#endif // __ENABLE_USM_ADDR_SPACE__
205-
#else
206-
using global_pointer_t = T *;
207-
#endif // __SYCL_DEVICE_ONLY__
208204

209-
global_pointer_t m_Ptr;
205+
T *m_Ptr;
210206

211207
template <typename T2, typename PropertyListT> friend class annotated_ptr;
212208

@@ -225,15 +221,15 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr<T, detail::properties_t<Props...>> {
225221

226222
explicit annotated_ptr(T *Ptr,
227223
const property_list_t & = properties{}) noexcept
228-
: m_Ptr(global_pointer_t(Ptr)) {}
224+
: m_Ptr(Ptr) {}
229225

230226
// Constructs an annotated_ptr object from a raw pointer and variadic
231227
// properties. The new property set contains all properties of the input
232228
// variadic properties. The same property in `Props...` and
233229
// `PropertyValueTs...` must have the same property value.
234230
template <typename... PropertyValueTs>
235231
explicit annotated_ptr(T *Ptr, const PropertyValueTs &...props) noexcept
236-
: m_Ptr(global_pointer_t(Ptr)) {
232+
: m_Ptr(Ptr) {
237233
static constexpr bool has_same_properties = std::is_same<
238234
property_list_t,
239235
detail::merged_properties_t<property_list_t,

0 commit comments

Comments
 (0)