@@ -12,39 +12,62 @@ const size_t N = 10;
12
12
13
13
template <typename T> class init_a ;
14
14
15
- template <typename T> bool test (queue myQueue) {
16
- {
17
- buffer<float , 1 > a (range<1 >{N});
18
- const T test = rand () % 10 ;
19
-
20
- myQueue.submit ([&](handler &cgh) {
21
- auto A = a.get_access <access::mode::write>(cgh);
22
- cgh.parallel_for <init_a<T>>(range<1 >{N},
23
- [=](id<1 > index) { A[index] = test; });
24
- });
25
-
26
- auto A = a.get_access <access::mode::read>();
27
- std::cout << " Result:" << std::endl;
28
- for (size_t i = 0 ; i < N; i++) {
29
- if (A[i] != test) {
30
- std::cout << " ERROR at pos " << i << " expected " << test << " , got "
31
- << A[i] << " \n " ;
32
- return false ;
33
- }
34
- }
15
+ template <typename T, int M>
16
+ bool compare (const sycl::vec<T, M> a, const sycl::vec<T, M> truth) {
17
+ bool res = true ;
18
+ for (int i = 0 ; i < M; i++) {
19
+ res &= a[i] == truth[i];
35
20
}
21
+ return res;
22
+ }
36
23
37
- std::cout << " Good computation!" << std::endl;
24
+ template <typename T> bool compare (const T a, const T truth) {
25
+ return a == truth;
26
+ }
27
+
28
+ template <typename T> bool check (buffer<T, 1 > &result, const T truth) {
29
+ auto A = result.get_host_access ();
30
+ for (size_t i = 0 ; i < N; i++) {
31
+ if (!compare (A[i], truth)) {
32
+ return false ;
33
+ }
34
+ }
38
35
return true ;
39
36
}
40
37
38
+ template <typename T> bool test (queue myQueue) {
39
+ buffer<T, 1 > a (range<1 >{N});
40
+ const T test{42 };
41
+
42
+ myQueue.submit ([&](handler &cgh) {
43
+ auto A = a.template get_access <access::mode::write>(cgh);
44
+ cgh.parallel_for <init_a<T>>(range<1 >{N},
45
+ [=](id<1 > index) { A[index] = test; });
46
+ });
47
+
48
+ return check (a, test);
49
+ }
50
+
41
51
int main () {
42
52
queue q;
43
- int res1 = test<int >(q);
44
- int res2 = test<unsigned >(q);
45
- int res3 = test<float >(q);
46
- int res4 = test<double >(q);
47
- if (!(res1 && res2 && res3 && res4)) {
53
+
54
+ std::vector<bool > res;
55
+ res.push_back (test<int >(q));
56
+ res.push_back (test<unsigned >(q));
57
+ res.push_back (test<float >(q));
58
+ res.push_back (test<double >(q));
59
+ res.push_back (test<sycl::vec<int , 2 >>(q));
60
+ res.push_back (test<sycl::vec<int , 3 >>(q));
61
+ res.push_back (test<sycl::vec<int , 4 >>(q));
62
+ res.push_back (test<sycl::vec<int , 8 >>(q));
63
+ res.push_back (test<sycl::vec<int , 16 >>(q));
64
+ res.push_back (test<sycl::vec<double , 2 >>(q));
65
+ res.push_back (test<sycl::vec<double , 3 >>(q));
66
+ res.push_back (test<sycl::vec<double , 4 >>(q));
67
+ res.push_back (test<sycl::vec<double , 8 >>(q));
68
+ res.push_back (test<sycl::vec<double , 16 >>(q));
69
+
70
+ if (std::any_of (res.begin (), res.end (), [](bool b) { return !b; })) {
48
71
return 1 ;
49
72
}
50
73
return 0 ;
0 commit comments