8
8
work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>.
9
9
*/
10
10
11
- // #define SYCL_ACADEMY_USING_COMPUTECPP
12
-
13
- #define CATCH_CONFIG_MAIN
14
- #include < catch2/catch.hpp>
15
-
11
+ #include " ../helpers.hpp"
16
12
#include < sycl/sycl.hpp>
17
13
18
14
class kernel_a_1 ;
@@ -22,13 +18,14 @@ class kernel_b_2;
22
18
23
19
int usm_selector (const sycl::device& dev) {
24
20
if (dev.has (sycl::aspect::usm_device_allocations)) {
25
- if (dev.has (sycl::aspect::gpu)) return 2 ;
21
+ if (dev.has (sycl::aspect::gpu))
22
+ return 2 ;
26
23
return 1 ;
27
24
}
28
25
return -1 ;
29
26
}
30
27
31
- TEST_CASE ( " buffer_accessor_temporary_data " , " temporary_data_solution " ) {
28
+ void test_buffer ( ) {
32
29
constexpr size_t dataSize = 1024 ;
33
30
34
31
float in[dataSize], out[dataSize];
@@ -38,31 +35,31 @@ TEST_CASE("buffer_accessor_temporary_data", "temporary_data_solution") {
38
35
}
39
36
40
37
try {
41
- auto gpuQueue = sycl::queue{ sycl::gpu_selector_v};
38
+ auto gpuQueue = sycl::queue { sycl::gpu_selector_v };
42
39
43
- auto bufIn = sycl::buffer{ in, sycl::range{ dataSize} };
44
- auto bufInt = sycl::buffer<float >{ sycl::range{ dataSize} };
45
- auto bufOut = sycl::buffer<float >{ sycl::range{ dataSize} };
40
+ auto bufIn = sycl::buffer { in, sycl::range { dataSize } };
41
+ auto bufInt = sycl::buffer<float > { sycl::range { dataSize } };
42
+ auto bufOut = sycl::buffer<float > { sycl::range { dataSize } };
46
43
47
44
bufIn.set_final_data (nullptr );
48
45
bufOut.set_final_data (out);
49
46
50
47
gpuQueue.submit ([&](sycl::handler& cgh) {
51
- sycl::accessor accIn{ bufIn, cgh, sycl::read_only};
52
- sycl::accessor accOut{ bufInt, cgh, sycl::write_only};
48
+ sycl::accessor accIn { bufIn, cgh, sycl::read_only };
49
+ sycl::accessor accOut { bufInt, cgh, sycl::write_only };
53
50
54
- cgh.parallel_for <kernel_a_1>(sycl::range{dataSize}, [=](sycl::id< 1 > idx) {
55
- accOut[idx] = accIn[idx] * 8 . 0f ;
56
- });
51
+ cgh.parallel_for <kernel_a_1>(
52
+ sycl::range { dataSize },
53
+ [=](sycl::id< 1 > idx) { accOut[idx] = accIn[idx] * 8 . 0f ; });
57
54
});
58
55
59
56
gpuQueue.submit ([&](sycl::handler& cgh) {
60
- sycl::accessor accIn{ bufInt, cgh, sycl::read_only};
61
- sycl::accessor accOut{ bufOut, cgh, sycl::write_only};
57
+ sycl::accessor accIn { bufInt, cgh, sycl::read_only };
58
+ sycl::accessor accOut { bufOut, cgh, sycl::write_only };
62
59
63
- cgh.parallel_for <kernel_b_1>(sycl::range{dataSize}, [=](sycl::id< 1 > idx) {
64
- accOut[idx] = accIn[idx] / 2 . 0f ;
65
- });
60
+ cgh.parallel_for <kernel_b_1>(
61
+ sycl::range { dataSize },
62
+ [=](sycl::id< 1 > idx) { accOut[idx] = accIn[idx] / 2 . 0f ; });
66
63
});
67
64
68
65
gpuQueue.wait_and_throw ();
@@ -71,11 +68,11 @@ TEST_CASE("buffer_accessor_temporary_data", "temporary_data_solution") {
71
68
}
72
69
73
70
for (int i = 0 ; i < dataSize; ++i) {
74
- REQUIRE (out[i] == i * 4 .0f );
71
+ SYCLACADEMY_ASSERT (out[i] == i * 4 .0f );
75
72
}
76
73
}
77
74
78
- TEST_CASE ( " usm_temporary_data " , " temporary_data_solution " ) {
75
+ void test_usm ( ) {
79
76
constexpr size_t dataSize = 1024 ;
80
77
81
78
float in[dataSize], out[dataSize];
@@ -85,7 +82,7 @@ TEST_CASE("usm_temporary_data", "temporary_data_solution") {
85
82
}
86
83
87
84
try {
88
- auto usmQueue = sycl::queue{ usm_selector};
85
+ auto usmQueue = sycl::queue { usm_selector };
89
86
90
87
auto devicePtrIn = sycl::malloc_device<float >(dataSize, usmQueue);
91
88
auto devicePtrInt = sycl::malloc_device<float >(dataSize, usmQueue);
@@ -94,13 +91,13 @@ TEST_CASE("usm_temporary_data", "temporary_data_solution") {
94
91
auto e1 = usmQueue.memcpy (devicePtrIn, in, sizeof (float ) * dataSize);
95
92
96
93
auto e2 = usmQueue.parallel_for <kernel_a_2>(
97
- sycl::range{ dataSize}, e1 , [=](sycl::id<1 > idx) {
94
+ sycl::range { dataSize }, e1 , [=](sycl::id<1 > idx) {
98
95
auto globalId = idx[0 ];
99
96
devicePtrInt[globalId] = devicePtrIn[globalId] * 8 .0f ;
100
97
});
101
98
102
99
auto e3 = usmQueue.parallel_for <kernel_b_2>(
103
- sycl::range{ dataSize}, e2 , [=](sycl::id<1 > idx) {
100
+ sycl::range { dataSize }, e2 , [=](sycl::id<1 > idx) {
104
101
auto globalId = idx[0 ];
105
102
devicePtrOut[globalId] = devicePtrInt[globalId] / 2 .0f ;
106
103
});
@@ -122,6 +119,11 @@ TEST_CASE("usm_temporary_data", "temporary_data_solution") {
122
119
}
123
120
124
121
for (int i = 0 ; i < dataSize; ++i) {
125
- REQUIRE (out[i] == i * 4 .0f );
122
+ SYCLACADEMY_ASSERT (out[i] == i * 4 .0f );
126
123
}
127
124
}
125
+
126
+ int main () {
127
+ test_usm ();
128
+ test_buffer ();
129
+ }
0 commit comments