@@ -33,54 +33,58 @@ class buffer {
33
33
34
34
buffer (const range<dimensions> &bufferRange,
35
35
const property_list &propList = {})
36
- : Range(bufferRange) {
36
+ : Range(bufferRange), MemRange(bufferRange) {
37
37
impl = std::make_shared<detail::buffer_impl<AllocatorT>>(
38
38
get_count () * sizeof (T), propList);
39
39
}
40
40
41
41
buffer (const range<dimensions> &bufferRange, AllocatorT allocator,
42
- const property_list &propList = {}) {
42
+ const property_list &propList = {})
43
+ : Range(bufferRange), MemRange(bufferRange) {
43
44
impl = std::make_shared<detail::buffer_impl<AllocatorT>>(
44
45
get_count () * sizeof (T), propList, allocator);
45
46
}
46
47
47
48
buffer (T *hostData, const range<dimensions> &bufferRange,
48
49
const property_list &propList = {})
49
- : Range(bufferRange) {
50
+ : Range(bufferRange), MemRange(bufferRange) {
50
51
impl = std::make_shared<detail::buffer_impl<AllocatorT>>(
51
52
hostData, get_count () * sizeof (T), propList);
52
53
}
53
54
54
55
buffer (T *hostData, const range<dimensions> &bufferRange,
55
- AllocatorT allocator, const property_list &propList = {}) {
56
+ AllocatorT allocator, const property_list &propList = {})
57
+ : Range(bufferRange), MemRange(bufferRange) {
56
58
impl = std::make_shared<detail::buffer_impl<AllocatorT>>(
57
59
hostData, get_count () * sizeof (T), propList, allocator);
58
60
}
59
61
60
62
buffer (const T *hostData, const range<dimensions> &bufferRange,
61
63
const property_list &propList = {})
62
- : Range(bufferRange) {
64
+ : Range(bufferRange), MemRange(bufferRange) {
63
65
impl = std::make_shared<detail::buffer_impl<AllocatorT>>(
64
66
hostData, get_count () * sizeof (T), propList);
65
67
}
66
68
67
69
buffer (const T *hostData, const range<dimensions> &bufferRange,
68
- AllocatorT allocator, const property_list &propList = {}) {
70
+ AllocatorT allocator, const property_list &propList = {})
71
+ : Range(bufferRange), MemRange(bufferRange) {
69
72
impl = std::make_shared<detail::buffer_impl<AllocatorT>>(
70
73
hostData, get_count () * sizeof (T), propList, allocator);
71
74
}
72
75
73
76
buffer (const shared_ptr_class<T> &hostData,
74
77
const range<dimensions> &bufferRange, AllocatorT allocator,
75
- const property_list &propList = {}) {
78
+ const property_list &propList = {})
79
+ : Range(bufferRange), MemRange(bufferRange) {
76
80
impl = std::make_shared<detail::buffer_impl<AllocatorT>>(
77
81
hostData, get_count () * sizeof (T), propList, allocator);
78
82
}
79
83
80
84
buffer (const shared_ptr_class<T> &hostData,
81
85
const range<dimensions> &bufferRange,
82
86
const property_list &propList = {})
83
- : Range(bufferRange) {
87
+ : Range(bufferRange), MemRange(bufferRange) {
84
88
impl = std::make_shared<detail::buffer_impl<AllocatorT>>(
85
89
hostData, get_count () * sizeof (T), propList);
86
90
}
@@ -89,7 +93,8 @@ class buffer {
89
93
typename = EnableIfOneDimension<N>>
90
94
buffer (InputIterator first, InputIterator last, AllocatorT allocator,
91
95
const property_list &propList = {})
92
- : Range(range<1 >(std::distance(first, last))) {
96
+ : Range(range<1 >(std::distance(first, last))),
97
+ MemRange (range<1 >(std::distance(first, last))) {
93
98
impl = std::make_shared<detail::buffer_impl<AllocatorT>>(
94
99
first, last, get_count () * sizeof (T), propList, allocator);
95
100
}
@@ -98,15 +103,16 @@ class buffer {
98
103
typename = EnableIfOneDimension<N>>
99
104
buffer (InputIterator first, InputIterator last,
100
105
const property_list &propList = {})
101
- : Range(range<1 >(std::distance(first, last))) {
106
+ : Range(range<1 >(std::distance(first, last))),
107
+ MemRange(range<1 >(std::distance(first, last))) {
102
108
impl = std::make_shared<detail::buffer_impl<AllocatorT>>(
103
109
first, last, get_count () * sizeof (T), propList);
104
110
}
105
111
106
- // buffer(buffer<T, dimensions, AllocatorT> b, const id<dimensions>
107
- // &baseIndex, const range<dimensions> &subRange) {
108
- // impl = std::make_shared<detail::buffer_impl>(b, baseIndex, subRange);
109
- // }
112
+ buffer (buffer<T, dimensions, AllocatorT> & b, const id<dimensions> &baseIndex,
113
+ const range<dimensions> &subRange)
114
+ : impl(b.impl), Offset( baseIndex + b.Offset), Range( subRange), MemRange(b.MemRange),
115
+ IsSubBuffer( true ) { }
110
116
111
117
template <int N = dimensions, typename = EnableIfOneDimension<N>>
112
118
buffer (cl_mem MemObject, const context &SyclContext,
@@ -116,6 +122,7 @@ class buffer {
116
122
CHECK_OCL_CODE (clGetMemObjectInfo (MemObject, CL_MEM_SIZE, sizeof (size_t ),
117
123
&BufSize, nullptr ));
118
124
Range[0 ] = BufSize / sizeof (T);
125
+ MemRange[0 ] = BufSize / sizeof (T);
119
126
impl = std::make_shared<detail::buffer_impl<AllocatorT>>(
120
127
MemObject, SyclContext, BufSize, AvailableEvent);
121
128
}
@@ -150,6 +157,9 @@ class buffer {
150
157
access::target target = access::target::global_buffer>
151
158
accessor<T, dimensions, mode, target, access::placeholder::false_t >
152
159
get_access (handler &commandGroupHandler) {
160
+ if (IsSubBuffer)
161
+ return impl->template get_access <T, dimensions, mode, target>(
162
+ *this , commandGroupHandler, Range, Offset);
153
163
return impl->template get_access <T, dimensions, mode, target>(
154
164
*this , commandGroupHandler);
155
165
}
@@ -158,6 +168,9 @@ class buffer {
158
168
accessor<T, dimensions, mode, access::target::host_buffer,
159
169
access::placeholder::false_t >
160
170
get_access () {
171
+ if (IsSubBuffer)
172
+ return impl->template get_access <T, dimensions, mode>(*this , Range,
173
+ Offset);
161
174
return impl->template get_access <T, dimensions, mode>(*this );
162
175
}
163
176
@@ -185,7 +198,7 @@ class buffer {
185
198
186
199
void set_write_back (bool flag = true ) { return impl->set_write_back (flag); }
187
200
188
- // bool is_sub_buffer() const { return impl->is_sub_buffer() ; }
201
+ bool is_sub_buffer () const { return IsSubBuffer ; }
189
202
190
203
template <typename ReinterpretT, int ReinterpretDim>
191
204
buffer<ReinterpretT, ReinterpretDim, AllocatorT>
@@ -212,12 +225,22 @@ class buffer {
212
225
template <class Obj >
213
226
friend decltype (Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
214
227
template <typename A, int dims, typename C> friend class buffer ;
228
+ template <typename DataT, int dims, access::mode mode,
229
+ access::target target, access::placeholder isPlaceholder>
230
+ friend class accessor ;
231
+ // If this buffer is subbuffer - this range represents range of the parent
232
+ // buffer
233
+ range<dimensions> MemRange;
234
+ bool IsSubBuffer = false ;
215
235
range<dimensions> Range;
236
+ // If this buffer is sub-buffer - offset field specifies the origin of the
237
+ // sub-buffer inside the parent buffer
238
+ id<dimensions> Offset;
216
239
217
240
// Reinterpret contructor
218
241
buffer (shared_ptr_class<detail::buffer_impl<AllocatorT>> Impl,
219
242
range<dimensions> reinterpretRange)
220
- : impl(Impl), Range(reinterpretRange){};
243
+ : impl(Impl), Range(reinterpretRange), MemRange(reinterpretRange) {};
221
244
};
222
245
} // namespace sycl
223
246
} // namespace cl
0 commit comments