@@ -15,13 +15,11 @@ class AccessorIteratorTest : public ::testing::Test {
15
15
std::iota (reference.begin (), reference.end (), 0 );
16
16
sycl::buffer<T, Dimensions> buffer (reference.data (), shape);
17
17
auto accessor = buffer.template get_access <sycl::access_mode::read_write>();
18
- std::vector<T> copied =
19
- copyThroughIterators<T>(accessor.begin (), accessor.end ());
20
18
21
- ASSERT_EQ (copied. size (), reference. size ());
22
- for ( size_t i = 0 , e = reference. size (); i < e; ++i) {
23
- ASSERT_EQ (copied[i], reference[i]);
24
- }
19
+ ASSERT_NO_FATAL_FAILURE ( checkFullCopyThroughIteratorImpl (
20
+ reference, accessor. begin (), accessor. end ()));
21
+ ASSERT_NO_FATAL_FAILURE ( checkFullCopyThroughIteratorImpl (
22
+ reference, accessor. cbegin (), accessor. cend ()));
25
23
}
26
24
27
25
template <int Dimensions, typename T = int >
@@ -33,49 +31,74 @@ class AccessorIteratorTest : public ::testing::Test {
33
31
std::iota (reference.begin (), reference.end (), 0 );
34
32
sycl::buffer<T, Dimensions> buffer (reference.data (), fullShape);
35
33
std::vector<T> copied;
34
+
36
35
{
37
36
auto accessor = buffer.template get_access <sycl::access_mode::read_write>(
38
37
copyShape, offset);
39
38
copied = copyThroughIterators<T>(accessor.begin (), accessor.end ());
40
39
}
41
-
42
- ASSERT_EQ (copied. size (), copyShape. size ( ));
40
+ ASSERT_NO_FATAL_FAILURE (
41
+ validatePartialCopyThroughIterator (copied, buffer, copyShape, offset ));
43
42
44
43
{
45
- auto fullAccessor = buffer.template get_access <sycl::access_mode::read>();
46
- size_t linearId = 0 ;
47
-
48
- sycl::id<3 > offsetToUse (Dimensions > 2 ? offset[Dimensions - 3 ] : 1 ,
49
- Dimensions > 1 ? offset[Dimensions - 2 ] : 1 ,
50
- offset[Dimensions - 1 ]);
51
-
52
- sycl::id<3 > shapeToCheck (
53
- (Dimensions > 2 ? copyShape[Dimensions - 3 ] : 1 ) + offsetToUse[0 ],
54
- (Dimensions > 1 ? copyShape[Dimensions - 2 ] : 1 ) + offsetToUse[1 ],
55
- copyShape[Dimensions - 1 ] + offsetToUse[2 ]);
56
-
57
- for (size_t z = offsetToUse[0 ]; z < shapeToCheck[0 ]; ++z) {
58
- for (size_t y = offsetToUse[1 ]; y < shapeToCheck[1 ]; ++y) {
59
- for (size_t x = offsetToUse[2 ]; x < shapeToCheck[2 ]; ++x) {
60
- auto value = accessHelper<Dimensions>(fullAccessor, z, y, x);
61
- ASSERT_EQ (copied[linearId], value);
62
- ++linearId;
63
- }
64
- }
65
- }
44
+ auto accessor = buffer.template get_access <sycl::access_mode::read_write>(
45
+ copyShape, offset);
46
+ copied = copyThroughIterators<T>(accessor.cbegin (), accessor.cend ());
66
47
}
48
+ ASSERT_NO_FATAL_FAILURE (
49
+ validatePartialCopyThroughIterator (copied, buffer, copyShape, offset));
67
50
}
68
51
69
52
private:
53
+ template <typename IteratorT, typename T = int >
54
+ void checkFullCopyThroughIteratorImpl (const std::vector<T> &reference,
55
+ IteratorT begin, IteratorT end) {
56
+ std::vector<T> copied = copyThroughIterators<T>(begin, end);
57
+
58
+ ASSERT_EQ (copied.size (), reference.size ());
59
+ for (size_t i = 0 , e = reference.size (); i < e; ++i) {
60
+ ASSERT_EQ (copied[i], reference[i]);
61
+ }
62
+ }
63
+
70
64
template <typename T, typename IteratorT>
71
65
std::vector<T> copyThroughIterators (IteratorT begin, IteratorT end) {
72
66
std::vector<T> copied;
73
- for (auto it = begin; it != end; ++it) {
67
+ for (auto it = begin; it != end; ++it)
74
68
copied.push_back (*it);
75
- }
69
+
76
70
return copied;
77
71
}
78
72
73
+ template <int Dimensions, typename T = int >
74
+ void
75
+ validatePartialCopyThroughIterator (const std::vector<T> &copied,
76
+ sycl::buffer<T, Dimensions> &buffer,
77
+ const sycl::range<Dimensions> ©Shape,
78
+ const sycl::id<Dimensions> &offset = {}) {
79
+ auto fullAccessor = buffer.template get_access <sycl::access_mode::read>();
80
+ size_t linearId = 0 ;
81
+
82
+ sycl::id<3 > offsetToUse (Dimensions > 2 ? offset[Dimensions - 3 ] : 1 ,
83
+ Dimensions > 1 ? offset[Dimensions - 2 ] : 1 ,
84
+ offset[Dimensions - 1 ]);
85
+
86
+ sycl::id<3 > shapeToCheck (
87
+ (Dimensions > 2 ? copyShape[Dimensions - 3 ] : 1 ) + offsetToUse[0 ],
88
+ (Dimensions > 1 ? copyShape[Dimensions - 2 ] : 1 ) + offsetToUse[1 ],
89
+ copyShape[Dimensions - 1 ] + offsetToUse[2 ]);
90
+
91
+ for (size_t z = offsetToUse[0 ]; z < shapeToCheck[0 ]; ++z) {
92
+ for (size_t y = offsetToUse[1 ]; y < shapeToCheck[1 ]; ++y) {
93
+ for (size_t x = offsetToUse[2 ]; x < shapeToCheck[2 ]; ++x) {
94
+ auto value = accessHelper<Dimensions>(fullAccessor, z, y, x);
95
+ ASSERT_EQ (copied[linearId], value);
96
+ ++linearId;
97
+ }
98
+ }
99
+ }
100
+ }
101
+
79
102
template <int TotalDimensions, int CurrentDimension = 3 , typename Container,
80
103
typename ... Indices>
81
104
auto &&accessHelper(Container &&C, int Idx, Indices... Ids) {
0 commit comments