Skip to content

[SYCL] Replace constant address space with global #576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion sycl/include/CL/sycl/access/access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ struct PtrValueType<ElementType, access::address_space::global_space> {

template <typename ElementType>
struct PtrValueType<ElementType, access::address_space::constant_space> {
using type = SYCL_CONSTANT_AS ElementType;
// 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, global address space is used here
// instead of constant to avoid incorrect address space casts in the produced
// device code. "const" qualifier is not used here because multi_ptr interface
// contains function members which return pure ElementType without qualifiers
// and adding const qualifier here will require adding const casts to
// multi_ptr methods to remove const qualifiers from underlying pointer type.
using type = SYCL_GLOBAL_AS ElementType;
};

template <typename ElementType>
Expand Down
24 changes: 6 additions & 18 deletions sycl/include/CL/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,8 @@ class accessor_common {
constexpr static bool IsAccessReadWrite =
AccessMode == access::mode::read_write;

using RefType = typename std::conditional<
AS == access::address_space::constant_space,
typename detail::PtrValueType<DataT, AS>::type &, DataT &>::type;
using PtrType = typename std::conditional<
AS == access::address_space::constant_space,
typename detail::PtrValueType<DataT, AS>::type *, DataT *>::type;
using RefType = DataT &;
using PtrType = DataT *;

using AccType =
accessor<DataT, Dimensions, AccessMode, AccessTarget, IsPlaceholder>;
Expand Down Expand Up @@ -673,13 +669,9 @@ class accessor :
using AccessorSubscript =
typename AccessorCommonT::template AccessorSubscript<Dims>;

using RefType = typename std::conditional<
AS == access::address_space::constant_space,
typename detail::PtrValueType<DataT, AS>::type &, DataT &>::type;
using RefType = DataT &;
using ConcreteASPtrType = typename detail::PtrValueType<DataT, AS>::type *;
using PtrType =
typename std::conditional<AS == access::address_space::constant_space,
ConcreteASPtrType, DataT *>::type;
using PtrType = DataT *;

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

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

using RefType = typename std::conditional<
AS == access::address_space::constant_space,
typename detail::PtrValueType<DataT, AS>::type &, DataT &>::type;
using RefType = DataT &;
using ConcreteASPtrType = typename detail::PtrValueType<DataT, AS>::type *;
using PtrType =
typename std::conditional<AS == access::address_space::constant_space,
ConcreteASPtrType, DataT *>::type;
using PtrType = DataT *;

#ifdef __SYCL_DEVICE_ONLY__
detail::LocalAccessorBaseDevice<AdjustedDim> impl;
Expand Down
12 changes: 0 additions & 12 deletions sycl/include/CL/sycl/multi_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,9 @@ template <typename ElementType, access::address_space Space> class multi_ptr {
return *this;
}

#ifdef __SYCL_ENABLE_INFER_AS__
using ReturnPtr =
typename std::conditional<Space == access::address_space::constant_space,
pointer_t, ElementType *>::type;
using ReturnRef =
typename std::conditional<Space == access::address_space::constant_space,
reference_t, ElementType &>::type;
using ReturnConstRef =
typename std::conditional<Space == access::address_space::constant_space,
const_reference_t, const ElementType &>::type;
#else
using ReturnPtr = ElementType *;
using ReturnRef = ElementType &;
using ReturnConstRef = const ElementType &;
#endif

ReturnRef operator*() const {
return *reinterpret_cast<ReturnPtr>(m_Pointer);
Expand Down