Skip to content
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

[SYCL] Add buffer dimensions restriction #1147

Merged
merged 6 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
43 changes: 21 additions & 22 deletions sycl/include/CL/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,7 @@ class accessor :
: impl(id<AdjustedDim>(), range<1>{1}, BufferRef.get_range()) {
#else
: AccessorBaseHost(
/*Offset=*/{0, 0, 0},
detail::convertToArrayOfN<3, 1>(range<1>{1}),
/*Offset=*/{0, 0, 0}, detail::convertToArrayOfN<3, 1>(range<1>{1}),
detail::convertToArrayOfN<3, 1>(BufferRef.get_range()), AccessMode,
detail::getSyclObjImpl(BufferRef).get(), AdjustedDim, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
Expand All @@ -773,18 +772,19 @@ class accessor :
#endif
}

template <int Dims = Dimensions, typename AllocatorT>
accessor(buffer<DataT, 1, AllocatorT> &BufferRef,
detail::enable_if_t<Dims == 0 &&
(!IsPlaceH && (IsGlobalBuf || IsConstantBuf)),
handler> &CommandGroupHandler)
template <int Dims = Dimensions, typename AllocatorT,
typename = typename detail::enable_if_t<
(Dims == 0) &&
(!IsPlaceH && (IsGlobalBuf || IsConstantBuf))>
>
accessor(buffer<DataT,1,AllocatorT> &BufferRef,
handler &CommandGroupHandler)
#ifdef __SYCL_DEVICE_ONLY__
: impl(id<AdjustedDim>(), range<1>{1}, BufferRef.get_range()) {
}
#else
: AccessorBaseHost(
/*Offset=*/{0, 0, 0},
detail::convertToArrayOfN<3, 1>(range<1>{1}),
/*Offset=*/{0, 0, 0}, detail::convertToArrayOfN<3, 1>(range<1>{1}),
detail::convertToArrayOfN<3, 1>(BufferRef.get_range()), AccessMode,
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
Expand All @@ -793,11 +793,10 @@ class accessor :
#endif

template <int Dims = Dimensions, typename AllocatorT,
typename detail::enable_if_t<
typename = typename detail::enable_if_t<
(Dims > 0) && ((!IsPlaceH && IsHostBuf) ||
(IsPlaceH && (IsGlobalBuf || IsConstantBuf)))>
* = nullptr>
accessor(buffer<DataT, Dimensions, AllocatorT> &BufferRef)
(IsPlaceH && (IsGlobalBuf || IsConstantBuf)))>>
accessor(buffer<DataT, Dims, AllocatorT> &BufferRef)
#ifdef __SYCL_DEVICE_ONLY__
: impl(id<Dimensions>(), BufferRef.get_range(), BufferRef.get_range()) {
}
Expand All @@ -816,7 +815,7 @@ class accessor :
template <int Dims = Dimensions, typename AllocatorT,
typename = detail::enable_if_t<
(Dims > 0) && (!IsPlaceH && (IsGlobalBuf || IsConstantBuf))>>
accessor(buffer<DataT, Dimensions, AllocatorT> &BufferRef,
accessor(buffer<DataT, Dims, AllocatorT> &BufferRef,
romanovvlad marked this conversation as resolved.
Show resolved Hide resolved
handler &CommandGroupHandler)
#ifdef __SYCL_DEVICE_ONLY__
: impl(id<AdjustedDim>(), BufferRef.get_range(), BufferRef.get_range()) {
Expand All @@ -836,7 +835,7 @@ class accessor :
typename = detail::enable_if_t<
(Dims > 0) && ((!IsPlaceH && IsHostBuf) ||
(IsPlaceH && (IsGlobalBuf || IsConstantBuf)))>>
accessor(buffer<DataT, Dimensions, AllocatorT> &BufferRef,
accessor(buffer<DataT, Dims, AllocatorT> &BufferRef,
range<Dimensions> AccessRange, id<Dimensions> AccessOffset = {})
#ifdef __SYCL_DEVICE_ONLY__
: impl(AccessOffset, AccessRange, BufferRef.get_range()) {
Expand All @@ -856,7 +855,7 @@ class accessor :
template <int Dims = Dimensions, typename AllocatorT,
typename = detail::enable_if_t<
(Dims > 0) && (!IsPlaceH && (IsGlobalBuf || IsConstantBuf))>>
accessor(buffer<DataT, Dimensions, AllocatorT> &BufferRef,
accessor(buffer<DataT, Dims, AllocatorT> &BufferRef,
handler &CommandGroupHandler, range<Dimensions> AccessRange,
id<Dimensions> AccessOffset = {})
#ifdef __SYCL_DEVICE_ONLY__
Expand Down Expand Up @@ -932,17 +931,17 @@ class accessor :
}

template <int Dims = Dimensions>
operator typename std::enable_if<Dims == 0 &&
AccessMode == access::mode::atomic,
atomic<DataT, AS>>::type() const {
operator typename detail::enable_if_t<
Dims == 0 && AccessMode == access::mode::atomic, atomic<DataT, AS>>()
const {
const size_t LinearIndex = getLinearIndex(id<AdjustedDim>());
return atomic<DataT, AS>(
multi_ptr<DataT, AS>(getQualifiedPtr() + LinearIndex));
}

template <int Dims = Dimensions>
typename std::enable_if<(Dims > 0) && AccessMode == access::mode::atomic,
atomic<DataT, AS>>::type
typename detail::enable_if_t<(Dims > 0) && AccessMode == access::mode::atomic,
atomic<DataT, AS>>
operator[](id<Dimensions> Index) const {
const size_t LinearIndex = getLinearIndex(Index);
return atomic<DataT, AS>(
Expand All @@ -951,7 +950,7 @@ class accessor :

template <int Dims = Dimensions>
typename detail::enable_if_t<Dims == 1 && AccessMode == access::mode::atomic,
atomic<DataT, AS>>::type
atomic<DataT, AS>>
operator[](size_t Index) const {
const size_t LinearIndex = getLinearIndex(id<AdjustedDim>(Index));
return atomic<DataT, AS>(
Expand Down
11 changes: 7 additions & 4 deletions sycl/include/CL/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class queue;
template <int dimensions> class range;

template <typename T, int dimensions = 1,
typename AllocatorT = cl::sycl::buffer_allocator>
typename AllocatorT = cl::sycl::buffer_allocator,
typename = typename std::enable_if<(dimensions > 0) &&
(dimensions <= 3)>::type>
class buffer {
public:
using value_type = T;
Expand Down Expand Up @@ -300,9 +302,10 @@ class buffer {
shared_ptr_class<detail::buffer_impl> impl;
template <class Obj>
friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
template <typename A, int dims, typename C> friend class buffer;
template <typename DataT, int dims, access::mode mode,
access::target target, access::placeholder isPlaceholder>
template <typename A, int dims, typename C, typename Enable>
friend class buffer;
template <typename DataT, int dims, access::mode mode, access::target target,
access::placeholder isPlaceholder>
friend class accessor;
range<dimensions> Range;
// Offset field specifies the origin of the sub buffer inside the parent
Expand Down
3 changes: 2 additions & 1 deletion sycl/include/CL/sycl/detail/buffer_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace sycl {
template <typename DataT, int Dimensions, access::mode AccessMode,
access::target AccessTarget, access::placeholder IsPlaceholder>
class accessor;
template <typename T, int Dimensions, typename AllocatorT> class buffer;
template <typename T, int Dimensions, typename AllocatorT, typename Enable>
class buffer;
class handler;

using buffer_allocator = detail::sycl_memory_object_allocator;
Expand Down
3 changes: 2 additions & 1 deletion sycl/include/CL/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ namespace sycl {
// Forward declaration

class handler;
template <typename T, int Dimensions, typename AllocatorT> class buffer;
template <typename T, int Dimensions, typename AllocatorT, typename Enable>
class buffer;
namespace detail {

/// This class is the default KernelName template parameter type for kernel
Expand Down