@@ -211,7 +211,7 @@ class vector
211
211
}
212
212
213
213
// / Creates a new vector and copies the values from \p other.
214
- vector (const vector &other, bool blocking = false )
214
+ explicit vector (const vector &other, bool blocking = false )
215
215
: m_queue (other.m_queue ),
216
216
m_size (other.m_size )
217
217
{
@@ -230,24 +230,38 @@ class vector
230
230
copy (other, m_queue, blocking);
231
231
}
232
232
else {
233
- copy (other, other.get_queue (), m_queue, blocking);
233
+ command_queue other_queue = other.get_queue ();
234
+ copy (other, other_queue, m_queue);
234
235
}
235
236
}
236
237
238
+ // / Creates a new vector and copies the values from \p other
239
+ // / with \p queue.
240
+ template <class OtherAlloc >
241
+ vector (const vector<T, weight, OtherAlloc> &other,
242
+ bool blocking = false )
243
+ : m_queue (other.m_queue ),
244
+ m_size (other.m_size )
245
+ {
246
+ allocate_memory (m_size);
247
+ copy (other, m_queue, blocking);
248
+ }
249
+
237
250
// / Creates a new vector and copies the values from \p other.
238
251
template <class OtherAlloc >
239
252
vector (const vector<T, weight, OtherAlloc> &other,
240
253
command_queue &queue,
241
254
bool blocking = false )
242
255
: m_queue (queue),
243
- m_size (other.m_size )
256
+ m_size (other.size () )
244
257
{
245
258
allocate_memory (m_size);
246
- if (m_queue == other.m_queue ) {
259
+ if (m_queue == other.get_queue () ) {
247
260
copy (other, m_queue, blocking);
248
261
}
249
262
else {
250
- copy (other, other.get_queue (), m_queue, blocking);
263
+ command_queue other_queue = other.get_queue ();
264
+ copy (other, other_queue, m_queue);
251
265
}
252
266
}
253
267
@@ -279,8 +293,8 @@ class vector
279
293
template <class OtherAlloc >
280
294
vector& operator =(const vector<T, weight, OtherAlloc> &other)
281
295
{
282
- m_queue = other.m_queue ;
283
- m_size = other.m_size ;
296
+ m_queue = other.get_queue () ;
297
+ m_size = other.size () ;
284
298
allocate_memory (m_size);
285
299
copy (other, m_queue, false );
286
300
return *this ;
@@ -490,7 +504,12 @@ class vector
490
504
return m_data[n].get_buffer ();
491
505
}
492
506
493
- const command_queue& get_queue () const
507
+ // const command_queue& get_queue() const
508
+ // {
509
+ // return m_queue;
510
+ // }
511
+
512
+ command_queue get_queue () const
494
513
{
495
514
return m_queue;
496
515
}
@@ -585,8 +604,9 @@ class vector
585
604
586
605
// device -> device (copying distributed vector)
587
606
// both vectors must have the same command_queue
607
+ template <class OtherAlloc >
588
608
inline wait_list
589
- copy_async (vector& other, command_queue &queue)
609
+ copy_async (const vector<T, weight, OtherAlloc> & other, command_queue &queue)
590
610
{
591
611
wait_list events;
592
612
events.reserve (m_data.size ());
@@ -606,8 +626,9 @@ class vector
606
626
607
627
// device -> device (copying distributed vector)
608
628
// both vectors must have the same command_queue
629
+ template <class OtherAlloc >
609
630
inline void
610
- copy (vector& other, command_queue &queue, bool blocking)
631
+ copy (const vector<T, weight, OtherAlloc> & other, command_queue &queue, bool blocking)
611
632
{
612
633
if (blocking) {
613
634
copy_async (other, queue).wait ();
@@ -617,62 +638,30 @@ class vector
617
638
}
618
639
619
640
// device -> device (copying distributed vector)
620
- inline wait_list
621
- copy_async (vector& other, command_queue &other_queue, command_queue &queue)
641
+ template <class OtherAlloc >
642
+ inline void
643
+ copy (const vector<T, weight, OtherAlloc> &other,
644
+ command_queue &other_queue,
645
+ command_queue &queue)
622
646
{
623
647
wait_list events;
624
648
events.reserve (m_data.size ());
625
- ::boost::compute::context other_part_context ;
626
- ::boost::compute::context part_context ;
627
- for (size_t i = 0 ; i < m_data. size (); i++)
649
+ std::vector<T> host (other. size ()) ;
650
+ typename std::vector<T>::iterator host_iter = host. begin () ;
651
+ for (size_t i = 0 ; i < other. parts (); i++)
628
652
{
629
- other_part_context = other.get_buffer (i).get_context ();
630
- part_context = get_buffer (i).get_context ();
631
- if (part_context == other_part_context) {
632
- std::vector<T> host (other.part_size (i));
633
- events.safe_insert (
634
- ::boost::compute::copy_async (
635
- other.begin(i),
636
- other.end(i),
637
- host.begin(),
638
- other_queue.get(i)
639
- )
640
- );
641
- events.safe_insert (
642
- ::boost::compute::copy_async (
643
- host.begin(),
644
- host.end(),
645
- begin(i),
646
- queue.get(i)
647
- )
648
- );
649
- }
650
- else {
651
- events.safe_insert (
652
- ::boost::compute::copy_async (
653
- other.begin(i),
654
- other.end(i),
655
- begin(i),
656
- queue.get(i)
657
- )
658
- );
659
- }
660
- }
661
- return events;
662
- }
663
-
664
- // device -> device (copying distributed vector)
665
- inline void
666
- copy (vector& other,
667
- command_queue &other_queue,
668
- command_queue &queue,
669
- bool blocking)
670
- {
671
- if (blocking) {
672
- copy_async (other, other_queue, queue).wait ();
673
- } else {
674
- copy_async (other, other_queue, queue);
653
+ events.safe_insert (
654
+ ::boost::compute::copy_async (
655
+ other.begin(i),
656
+ other.end(i),
657
+ host_iter,
658
+ other_queue.get(i)
659
+ )
660
+ );
661
+ host_iter += other.part_size (i);
675
662
}
663
+ events.wait ();
664
+ copy_async (host.begin (), host.end (), queue).wait ();
676
665
}
677
666
678
667
private:
0 commit comments