14
14
15
15
#include < cassert>
16
16
#include < iostream>
17
+ #include < numeric>
17
18
18
19
using namespace cl ::sycl;
19
20
@@ -22,8 +23,10 @@ template <typename T> struct point {
22
23
point (T x, T y) : x(x), y(y) {}
23
24
point (T v) : x(v), y(v) {}
24
25
point () : x(0 ), y(0 ) {}
25
- bool operator ==(const T &rhs) { return rhs == x && rhs == y; }
26
- bool operator ==(const point<T> &rhs) { return rhs.x == x && rhs.y == y; }
26
+ bool operator ==(const T &rhs) const { return rhs == x && rhs == y; }
27
+ bool operator ==(const point<T> &rhs) const {
28
+ return rhs.x == x && rhs.y == y;
29
+ }
27
30
T x;
28
31
T y;
29
32
};
@@ -38,6 +41,12 @@ template <typename T> void test_copy_acc_acc();
38
41
template <typename T> void test_update_host ();
39
42
template <typename T> void test_2D_copy_acc_acc ();
40
43
template <typename T> void test_3D_copy_acc_acc ();
44
+ template <typename T> void test_1D2D_copy_acc_acc ();
45
+ template <typename T> void test_1D3D_copy_acc_acc ();
46
+ template <typename T> void test_2D1D_copy_acc_acc ();
47
+ template <typename T> void test_2D3D_copy_acc_acc ();
48
+ template <typename T> void test_3D1D_copy_acc_acc ();
49
+ template <typename T> void test_3D2D_copy_acc_acc ();
41
50
42
51
int main () {
43
52
// handler.fill
@@ -126,6 +135,59 @@ int main() {
126
135
test_3D_copy_acc_acc<point<float >>();
127
136
}
128
137
138
+ // handler.copy(acc, acc) 1D to 2D
139
+ {
140
+ test_1D2D_copy_acc_acc<int >();
141
+ test_1D2D_copy_acc_acc<int >();
142
+ test_1D2D_copy_acc_acc<point<int >>();
143
+ test_1D2D_copy_acc_acc<point<int >>();
144
+ test_1D2D_copy_acc_acc<point<float >>();
145
+ }
146
+
147
+ // handler.copy(acc, acc) 1D to 3D
148
+ {
149
+ test_1D3D_copy_acc_acc<int >();
150
+ test_1D3D_copy_acc_acc<int >();
151
+ test_1D3D_copy_acc_acc<point<int >>();
152
+ test_1D3D_copy_acc_acc<point<int >>();
153
+ test_1D3D_copy_acc_acc<point<float >>();
154
+ }
155
+
156
+ // handler.copy(acc, acc) 2D to 1D
157
+ {
158
+ test_2D1D_copy_acc_acc<int >();
159
+ test_2D1D_copy_acc_acc<int >();
160
+ test_2D1D_copy_acc_acc<point<int >>();
161
+ test_2D1D_copy_acc_acc<point<int >>();
162
+ test_2D1D_copy_acc_acc<point<float >>();
163
+ }
164
+
165
+ // handler.copy(acc, acc) 2D to 3D
166
+ {
167
+ test_2D3D_copy_acc_acc<int >();
168
+ test_2D3D_copy_acc_acc<int >();
169
+ test_2D3D_copy_acc_acc<point<int >>();
170
+ test_2D3D_copy_acc_acc<point<int >>();
171
+ test_2D3D_copy_acc_acc<point<float >>();
172
+ }
173
+
174
+ // handler.copy(acc, acc) 3D to 1D
175
+ {
176
+ test_3D1D_copy_acc_acc<int >();
177
+ test_3D1D_copy_acc_acc<int >();
178
+ test_3D1D_copy_acc_acc<point<int >>();
179
+ test_3D1D_copy_acc_acc<point<int >>();
180
+ test_3D1D_copy_acc_acc<point<float >>();
181
+ }
182
+
183
+ // handler.copy(acc, acc) 3D to 2D
184
+ {
185
+ test_3D2D_copy_acc_acc<int >();
186
+ test_3D2D_copy_acc_acc<int >();
187
+ test_3D2D_copy_acc_acc<point<int >>();
188
+ test_3D2D_copy_acc_acc<point<int >>();
189
+ test_3D2D_copy_acc_acc<point<float >>();
190
+ }
129
191
std::cout << " finish" << std::endl;
130
192
return 0 ;
131
193
}
@@ -365,3 +427,123 @@ template <typename T> void test_3D_copy_acc_acc() {
365
427
}
366
428
}
367
429
}
430
+
431
+ template <typename T> void test_1D2D_copy_acc_acc () {
432
+ const size_t Size = 20 ;
433
+ std::vector<T> Data (Size);
434
+ std::iota (Data.begin (), Data.end (), 0 );
435
+ std::vector<T> Values (Size, T{});
436
+ {
437
+ buffer<T, 1 > BufferFrom (&Data[0 ], range<1 >(Size));
438
+ buffer<T, 2 > BufferTo (&Values[0 ], range<2 >(Size / 2 , 2 ));
439
+ queue Queue;
440
+ Queue.submit ([&](handler &Cgh) {
441
+ accessor<T, 1 , access::mode::read, access::target::global_buffer>
442
+ AccessorFrom (BufferFrom, Cgh, range<1 >(Size));
443
+ accessor<T, 2 , access::mode::write, access::target::global_buffer>
444
+ AccessorTo (BufferTo, Cgh, range<2 >(Size / 2 , 2 ));
445
+ Cgh.copy (AccessorFrom, AccessorTo);
446
+ });
447
+ }
448
+ assert (Data == Values);
449
+ }
450
+
451
+ template <typename T> void test_1D3D_copy_acc_acc () {
452
+ const size_t Size = 20 ;
453
+ std::vector<T> Data (Size);
454
+ std::iota (Data.begin (), Data.end (), 0 );
455
+ std::vector<T> Values (Size, T{});
456
+ {
457
+ buffer<T, 1 > BufferFrom (&Data[0 ], range<1 >(Size));
458
+ buffer<T, 3 > BufferTo (&Values[0 ], range<3 >(Size / 4 , 2 , 2 ));
459
+ queue Queue;
460
+ Queue.submit ([&](handler &Cgh) {
461
+ accessor<T, 1 , access::mode::read, access::target::global_buffer>
462
+ AccessorFrom (BufferFrom, Cgh, range<1 >(Size));
463
+ accessor<T, 3 , access::mode::write, access::target::global_buffer>
464
+ AccessorTo (BufferTo, Cgh, range<3 >(Size / 4 , 2 , 2 ));
465
+ Cgh.copy (AccessorFrom, AccessorTo);
466
+ });
467
+ }
468
+ assert (Data == Values);
469
+ }
470
+
471
+ template <typename T> void test_2D1D_copy_acc_acc () {
472
+ const size_t Size = 20 ;
473
+ std::vector<T> Data (Size);
474
+ std::iota (Data.begin (), Data.end (), 0 );
475
+ std::vector<T> Values (Size, T{});
476
+ {
477
+ buffer<T, 2 > BufferFrom (&Data[0 ], range<2 >(Size / 2 , 2 ));
478
+ buffer<T, 1 > BufferTo (&Values[0 ], range<1 >(Size));
479
+ queue Queue;
480
+ Queue.submit ([&](handler &Cgh) {
481
+ accessor<T, 2 , access::mode::read, access::target::global_buffer>
482
+ AccessorFrom (BufferFrom, Cgh, range<2 >(Size / 2 , 2 ));
483
+ accessor<T, 1 , access::mode::write, access::target::global_buffer>
484
+ AccessorTo (BufferTo, Cgh, range<1 >(Size));
485
+ Cgh.copy (AccessorFrom, AccessorTo);
486
+ });
487
+ }
488
+ assert (Data == Values);
489
+ }
490
+
491
+ template <typename T> void test_2D3D_copy_acc_acc () {
492
+ const size_t Size = 20 ;
493
+ std::vector<T> Data (Size);
494
+ std::iota (Data.begin (), Data.end (), 0 );
495
+ std::vector<T> Values (Size, T{});
496
+ {
497
+ buffer<T, 2 > BufferFrom (&Data[0 ], range<2 >(Size / 2 , 2 ));
498
+ buffer<T, 3 > BufferTo (&Values[0 ], range<3 >(Size / 4 , 2 , 2 ));
499
+ queue Queue;
500
+ Queue.submit ([&](handler &Cgh) {
501
+ accessor<T, 2 , access::mode::read, access::target::global_buffer>
502
+ AccessorFrom (BufferFrom, Cgh, range<2 >(Size / 2 , 2 ));
503
+ accessor<T, 3 , access::mode::write, access::target::global_buffer>
504
+ AccessorTo (BufferTo, Cgh, range<3 >(Size / 4 , 2 , 2 ));
505
+ Cgh.copy (AccessorFrom, AccessorTo);
506
+ });
507
+ }
508
+ assert (Data == Values);
509
+ }
510
+
511
+ template <typename T> void test_3D1D_copy_acc_acc () {
512
+ const size_t Size = 20 ;
513
+ std::vector<T> Data (Size);
514
+ std::iota (Data.begin (), Data.end (), 0 );
515
+ std::vector<T> Values (Size, T{});
516
+ {
517
+ buffer<T, 3 > BufferFrom (&Data[0 ], range<3 >(Size / 4 , 2 , 2 ));
518
+ buffer<T, 1 > BufferTo (&Values[0 ], range<1 >(Size));
519
+ queue Queue;
520
+ Queue.submit ([&](handler &Cgh) {
521
+ accessor<T, 3 , access::mode::read, access::target::global_buffer>
522
+ AccessorFrom (BufferFrom, Cgh, range<3 >(Size / 4 , 2 , 2 ));
523
+ accessor<T, 1 , access::mode::write, access::target::global_buffer>
524
+ AccessorTo (BufferTo, Cgh, range<1 >(Size));
525
+ Cgh.copy (AccessorFrom, AccessorTo);
526
+ });
527
+ }
528
+ assert (Data == Values);
529
+ }
530
+
531
+ template <typename T> void test_3D2D_copy_acc_acc () {
532
+ const size_t Size = 20 ;
533
+ std::vector<T> Data (Size);
534
+ std::iota (Data.begin (), Data.end (), 0 );
535
+ std::vector<T> Values (Size, T{});
536
+ {
537
+ buffer<T, 3 > BufferFrom (&Data[0 ], range<3 >(Size / 4 , 2 , 2 ));
538
+ buffer<T, 2 > BufferTo (&Values[0 ], range<2 >(Size / 2 , 2 ));
539
+ queue Queue;
540
+ Queue.submit ([&](handler &Cgh) {
541
+ accessor<T, 3 , access::mode::read, access::target::global_buffer>
542
+ AccessorFrom (BufferFrom, Cgh, range<3 >(Size / 4 , 2 , 2 ));
543
+ accessor<T, 2 , access::mode::write, access::target::global_buffer>
544
+ AccessorTo (BufferTo, Cgh, range<2 >(Size / 2 , 2 ));
545
+ Cgh.copy (AccessorFrom, AccessorTo);
546
+ });
547
+ }
548
+ assert (Data == Values);
549
+ }
0 commit comments