@@ -131,10 +131,10 @@ class vector
131
131
: m_queue(context),
132
132
m_size(0 )
133
133
{
134
+ // TODO lazy allocation?
134
135
for (size_t i = 0 ; i < m_queue.size (); i++)
135
136
{
136
137
m_allocators.push_back (Alloc (context.get (i)));
137
- // TODO lazy allocation?
138
138
m_data.push_back (
139
139
m_allocators.back ()
140
140
.allocate (_minimum_capacity ())
@@ -211,90 +211,125 @@ class vector
211
211
}
212
212
213
213
// / Creates a new vector and copies the values from \p other.
214
- vector (const vector &other)
214
+ vector (const vector &other, bool blocking = false )
215
215
: m_queue (other.m_queue ),
216
216
m_size (other.m_size )
217
217
{
218
218
allocate_memory (m_size);
219
- copy (other, m_queue);
219
+ copy (other, m_queue, blocking );
220
220
}
221
221
222
222
// / Creates a new vector and copies the values from \p other
223
223
// / with \p queue.
224
- vector (const vector &other, command_queue &queue)
224
+ vector (const vector &other, command_queue &queue, bool blocking = false )
225
225
: m_queue (queue),
226
226
m_size (other.m_size )
227
227
{
228
228
allocate_memory (m_size);
229
229
if (m_queue == other.m_queue ) {
230
- copy (other, m_queue);
230
+ copy (other, m_queue, blocking );
231
231
}
232
232
else {
233
- copy (other, other.get_queue (), m_queue);
233
+ copy (other, other.get_queue (), m_queue, blocking );
234
234
}
235
235
}
236
236
237
- // /// Creates a new vector and copies the values from \p other.
238
- // template<class OtherAlloc>
239
- // vector(const vector<T, OtherAlloc> &other, command_queue &queue)
240
- // : m_size(other.size())
241
- // {
242
- // }
243
- //
244
- // /// Creates a new vector and copies the values from \p vector.
245
- // template<class OtherAlloc>
246
- // vector(const std::vector<T, OtherAlloc> &vector, command_queue &queue)
247
- // : m_size(vector.size())
248
- // {
249
- //
250
- // }
251
- //
252
- // vector& operator=(const vector &other)
253
- // {
254
- // if(this != &other){
255
- //
256
- // }
257
- // return *this;
258
- // }
259
- //
260
- // template<class OtherAlloc>
261
- // vector& operator=(const vector<T, OtherAlloc> &other)
262
- // {
263
- // return *this;
264
- // }
265
- //
266
- // template<class OtherAlloc>
267
- // vector& operator=(const std::vector<T, OtherAlloc> &vector)
268
- // {
269
- // return *this;
270
- // }
271
- //
272
- // #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
273
- // /// Move-constructs a new vector from \p other.
274
- // vector(vector&& other)
275
- // : m_data(std::move(other.m_data)),
276
- // m_size(other.m_size),
277
- // m_allocator(std::move(other.m_allocator))
278
- // {
279
- // other.m_size = 0;
280
- // }
281
- //
282
- // /// Move-assigns the data from \p other to \c *this.
283
- // vector& operator=(vector&& other)
284
- // {
285
- // if(m_size){
286
- // m_allocator.deallocate(m_data, m_size);
287
- // }
288
- //
289
- // m_data = std::move(other.m_data);
290
- // m_size = other.m_size;
291
- // m_allocator = std::move(other.m_allocator);
292
- //
293
- // other.m_size = 0;
294
- //
295
- // return *this;
296
- // }
297
- // #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
237
+ // / Creates a new vector and copies the values from \p other.
238
+ template <class OtherAlloc >
239
+ vector (const vector<T, weight, OtherAlloc> &other,
240
+ command_queue &queue,
241
+ bool blocking = false )
242
+ : m_queue (queue),
243
+ m_size (other.m_size )
244
+ {
245
+ allocate_memory (m_size);
246
+ if (m_queue == other.m_queue ) {
247
+ copy (other, m_queue, blocking);
248
+ }
249
+ else {
250
+ copy (other, other.get_queue (), m_queue, blocking);
251
+ }
252
+ }
253
+
254
+ // / Creates a new vector and copies the values from \p vector.
255
+ template <class OtherAlloc >
256
+ vector (const std::vector<T, OtherAlloc> &vector,
257
+ command_queue &queue,
258
+ bool blocking = false )
259
+ : m_queue (queue),
260
+ m_size (vector.size ())
261
+ {
262
+ allocate_memory (m_size);
263
+ copy (vector.begin (), vector.end (), m_queue, blocking);
264
+ }
265
+
266
+ // / Copy assignment. This operation is always non-blocking.
267
+ vector& operator =(const vector &other)
268
+ {
269
+ if (this != &other){
270
+ m_queue = other.m_queue ;
271
+ m_size = other.m_size ;
272
+ allocate_memory (m_size);
273
+ copy (other, m_queue, false );
274
+ }
275
+ return *this ;
276
+ }
277
+
278
+ // / Copy assignment. This operation is always non-blocking.
279
+ template <class OtherAlloc >
280
+ vector& operator =(const vector<T, weight, OtherAlloc> &other)
281
+ {
282
+ m_queue = other.m_queue ;
283
+ m_size = other.m_size ;
284
+ allocate_memory (m_size);
285
+ copy (other, m_queue, false );
286
+ return *this ;
287
+ }
288
+
289
+ // / Copy assignment. This operation is always non-blocking.
290
+ template <class OtherAlloc >
291
+ vector& operator =(const std::vector<T, OtherAlloc> &vector)
292
+ {
293
+ m_size = vector.size ();
294
+ allocate_memory (m_size);
295
+ copy (vector.begin (), vector.end (), m_queue, false );
296
+ return *this ;
297
+ }
298
+
299
+ #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
300
+ // / Move-constructs a new vector from \p other.
301
+ vector (vector&& other)
302
+ : m_queue (std::move (m_queue)),
303
+ m_size (other.m_size ),
304
+ m_data (std::move (other.m_data )),
305
+ m_data_sizes (std::move (other.m_data_sizes )),
306
+ m_data_indices (std::move (other.m_data_indices )),
307
+ m_allocators (std::move (other.m_allocators ))
308
+ {
309
+ other.m_size = 0 ;
310
+ }
311
+
312
+ // / Move-assigns the data from \p other to \c *this.
313
+ vector& operator =(vector&& other)
314
+ {
315
+ if (m_size) {
316
+ for (size_t i = 0 ; i < m_allocators.size (); i++) {
317
+ m_allocators[i].deallocate (m_data[i], m_data_sizes[i]);
318
+ }
319
+ }
320
+
321
+ m_queue = std::move (other.m_queue );
322
+ m_size = other.m_size ;
323
+ m_data = std::move (other.m_data );
324
+ m_data_sizes = std::move (other.m_data_sizes );
325
+ m_data_indices = std::move (other.m_data_indices );
326
+ m_allocators = std::move (other.m_allocators );
327
+
328
+ other.m_size = 0 ;
329
+
330
+ return *this ;
331
+ }
332
+ #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
298
333
299
334
// / Destroys the vector object.
300
335
~vector ()
0 commit comments