Skip to content

Commit 38c2960

Browse files
Fznamznonbader
authored andcommitted
[SYCL] Replace constant address space with global (#576)
Current implementation of address spaces handling leads to possibility of emitting incorrect (in terms of OpenCL) address space casts from constant to generic (and vise-versa). So, we use global address space instead of constant to implement constant_ptr to avoid incorrect address space casts in the generated device code. Signed-off-by: Mariya Podchishchaeva <[email protected]>
1 parent 863e808 commit 38c2960

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

sycl/include/CL/sycl/access/access.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,15 @@ struct PtrValueType<ElementType, access::address_space::global_space> {
127127

128128
template <typename ElementType>
129129
struct PtrValueType<ElementType, access::address_space::constant_space> {
130-
using type = SYCL_CONSTANT_AS ElementType;
130+
// Current implementation of address spaces handling leads to possibility
131+
// of emitting incorrect (in terms of OpenCL) address space casts from
132+
// constant to generic (and vise-versa). So, global address space is used here
133+
// instead of constant to avoid incorrect address space casts in the produced
134+
// device code. "const" qualifier is not used here because multi_ptr interface
135+
// contains function members which return pure ElementType without qualifiers
136+
// and adding const qualifier here will require adding const casts to
137+
// multi_ptr methods to remove const qualifiers from underlying pointer type.
138+
using type = SYCL_GLOBAL_AS ElementType;
131139
};
132140

133141
template <typename ElementType>

sycl/include/CL/sycl/accessor.hpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,8 @@ class accessor_common {
193193
constexpr static bool IsAccessReadWrite =
194194
AccessMode == access::mode::read_write;
195195

196-
using RefType = typename std::conditional<
197-
AS == access::address_space::constant_space,
198-
typename detail::PtrValueType<DataT, AS>::type &, DataT &>::type;
199-
using PtrType = typename std::conditional<
200-
AS == access::address_space::constant_space,
201-
typename detail::PtrValueType<DataT, AS>::type *, DataT *>::type;
196+
using RefType = DataT &;
197+
using PtrType = DataT *;
202198

203199
using AccType =
204200
accessor<DataT, Dimensions, AccessMode, AccessTarget, IsPlaceholder>;
@@ -673,13 +669,9 @@ class accessor :
673669
using AccessorSubscript =
674670
typename AccessorCommonT::template AccessorSubscript<Dims>;
675671

676-
using RefType = typename std::conditional<
677-
AS == access::address_space::constant_space,
678-
typename detail::PtrValueType<DataT, AS>::type &, DataT &>::type;
672+
using RefType = DataT &;
679673
using ConcreteASPtrType = typename detail::PtrValueType<DataT, AS>::type *;
680-
using PtrType =
681-
typename std::conditional<AS == access::address_space::constant_space,
682-
ConcreteASPtrType, DataT *>::type;
674+
using PtrType = DataT *;
683675

684676
template <int Dims = Dimensions> size_t getLinearIndex(id<Dims> Id) const {
685677

@@ -1012,13 +1004,9 @@ class accessor<DataT, Dimensions, AccessMode, access::target::local,
10121004
using AccessorSubscript =
10131005
typename AccessorCommonT::template AccessorSubscript<Dims>;
10141006

1015-
using RefType = typename std::conditional<
1016-
AS == access::address_space::constant_space,
1017-
typename detail::PtrValueType<DataT, AS>::type &, DataT &>::type;
1007+
using RefType = DataT &;
10181008
using ConcreteASPtrType = typename detail::PtrValueType<DataT, AS>::type *;
1019-
using PtrType =
1020-
typename std::conditional<AS == access::address_space::constant_space,
1021-
ConcreteASPtrType, DataT *>::type;
1009+
using PtrType = DataT *;
10221010

10231011
#ifdef __SYCL_DEVICE_ONLY__
10241012
detail::LocalAccessorBaseDevice<AdjustedDim> impl;

sycl/include/CL/sycl/multi_ptr.hpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,9 @@ template <typename ElementType, access::address_space Space> class multi_ptr {
7070
return *this;
7171
}
7272

73-
#ifdef __SYCL_ENABLE_INFER_AS__
74-
using ReturnPtr =
75-
typename std::conditional<Space == access::address_space::constant_space,
76-
pointer_t, ElementType *>::type;
77-
using ReturnRef =
78-
typename std::conditional<Space == access::address_space::constant_space,
79-
reference_t, ElementType &>::type;
80-
using ReturnConstRef =
81-
typename std::conditional<Space == access::address_space::constant_space,
82-
const_reference_t, const ElementType &>::type;
83-
#else
8473
using ReturnPtr = ElementType *;
8574
using ReturnRef = ElementType &;
8675
using ReturnConstRef = const ElementType &;
87-
#endif
8876

8977
ReturnRef operator*() const {
9078
return *reinterpret_cast<ReturnPtr>(m_Pointer);

0 commit comments

Comments
 (0)