4
4
// RUN: %ACC_RUN_PLACEHOLDER %t.out
5
5
6
6
// TODO: The test irregularly reports incorrect.
7
- // UNSUPPORTED : TEMPORARY_DISABLED
7
+ // REQUIRES : TEMPORARY_DISABLED
8
8
9
9
// This test checks handling of parallel_for() accepting nd_range and
10
10
// two or more reductions.
11
11
12
12
#include " reduction_utils.hpp"
13
13
14
- #include < CL/sycl.hpp>
15
-
16
- #include < cassert>
17
- #include < cmath>
18
- #include < cstdint>
19
- #include < cstdio>
20
- #include < cstdlib>
21
- #include < numeric>
22
- #include < string>
23
-
24
14
using namespace cl ::sycl;
25
15
26
16
template <typename ... Ts> class KNameGroup ;
@@ -29,22 +19,15 @@ template <typename T, bool B> class KName;
29
19
constexpr access::mode RW = access::mode::read_write;
30
20
constexpr access::mode DW = access::mode::discard_write;
31
21
32
- template <typename T>
33
- bool cherkResultIsExpected (int TestCaseNum, T Expected, T Computed,
34
- bool IsSYCL2020) {
35
- bool Success;
36
- if (!std::is_floating_point<T>::value)
37
- Success = (Expected == Computed);
38
- else
39
- Success = std::abs ((Expected / Computed) - 1 ) < 0.5 ;
40
-
41
- if (!Success) {
42
- std::cerr << " Is SYCL2020 mode: " << IsSYCL2020 << std::endl;
43
- std::cerr << TestCaseNum << " : Expected value = " << Expected
44
- << " , Computed value = " << Computed << " \n " ;
45
- }
46
-
47
- return Success;
22
+ template <typename RangeT>
23
+ void printNVarsTestLabel (bool IsSYCL2020, const RangeT &Range,
24
+ bool ToCERR = false ) {
25
+ std::ostream &OS = ToCERR ? std::cerr : std::cout;
26
+ std::string Mode = IsSYCL2020 ? " SYCL2020" : " ONEAPI " ;
27
+ OS << (ToCERR ? " Error" : " Start" ) << " : Mode=" << Mode
28
+ << " , Range=" << Range;
29
+ if (!ToCERR)
30
+ OS << std::endl;
48
31
}
49
32
50
33
// Returns 0 if the test case passed. Otherwise, some non-zero value.
@@ -58,6 +41,10 @@ int testOne(queue &Q, T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
58
41
T3 IdentityVal3, T3 InitVal3, BinaryOperation3 BOp3,
59
42
T4 IdentityVal4, T3 InitVal4, BinaryOperation4 BOp4,
60
43
usm::alloc AllocType4, size_t NWorkItems, size_t WGSize) {
44
+
45
+ auto NDR = nd_range<1 >{range<1 >(NWorkItems), range<1 >{WGSize}};
46
+ printNVarsTestLabel<>(IsSYCL2020, NDR);
47
+
61
48
buffer<T1, 1 > InBuf1 (NWorkItems);
62
49
buffer<T2, 1 > InBuf2 (NWorkItems);
63
50
buffer<T3, 1 > InBuf3 (NWorkItems);
@@ -120,64 +107,33 @@ int testOne(queue &Q, T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
120
107
}
121
108
}
122
109
123
- auto NDR = nd_range<1 >{range<1 >(NWorkItems), range<1 >{WGSize}};
124
- if constexpr (IsSYCL2020) {
125
- Q.submit ([&](handler &CGH) {
126
- auto In1 = InBuf1.template get_access <access::mode::read>(CGH);
127
- auto In2 = InBuf2.template get_access <access::mode::read>(CGH);
128
- auto In3 = InBuf3.template get_access <access::mode::read>(CGH);
129
- auto In4 = InBuf4.template get_access <access::mode::read>(CGH);
130
-
131
- auto Redu1 = sycl::reduction (OutBuf1, CGH, IdentityVal1, BOp1,
132
- getPropertyList<Mode1>());
133
- auto Redu2 = sycl::reduction (OutBuf2, CGH, IdentityVal2, BOp2,
134
- getPropertyList<Mode2>());
135
- auto Redu3 = sycl::reduction (OutBuf3, CGH, IdentityVal3, BOp3,
136
- getPropertyList<Mode3>());
137
- auto Redu4 =
138
- sycl::reduction (Out4, IdentityVal4, BOp4, getPropertyList<Mode4>());
139
-
140
- auto Lambda = [=](nd_item<1 > NDIt, auto &Sum1, auto &Sum2, auto &Sum3,
141
- auto &Sum4) {
142
- size_t I = NDIt.get_global_id (0 );
143
- Sum1.combine (In1[I]);
144
- Sum2.combine (In2[I]);
145
- Sum3.combine (In3[I]);
146
- Sum4.combine (In4[I]);
147
- };
148
- CGH.parallel_for <Name>(NDR, Redu1, Redu2, Redu3, Redu4, Lambda);
149
- }).wait ();
150
- } else {
151
- // Test ONEAPI reductions
152
- Q.submit ([&](handler &CGH) {
153
- auto In1 = InBuf1.template get_access <access::mode::read>(CGH);
154
- auto In2 = InBuf2.template get_access <access::mode::read>(CGH);
155
- auto In3 = InBuf3.template get_access <access::mode::read>(CGH);
156
- auto In4 = InBuf4.template get_access <access::mode::read>(CGH);
157
-
158
- auto Out1 = OutBuf1.template get_access <Mode1>(CGH);
159
- auto Out2 = OutBuf2.template get_access <Mode2>(CGH);
160
- accessor<T3, 0 , Mode3, access::target::global_buffer> Out3 (OutBuf3, CGH);
161
-
162
- auto Redu1 = ONEAPI::reduction (Out1, IdentityVal1, BOp1);
163
- auto Redu2 = ONEAPI::reduction (Out2, IdentityVal2, BOp2);
164
- auto Redu3 = ONEAPI::reduction (Out3, IdentityVal3, BOp3);
165
- auto Redu4 = ONEAPI::reduction (Out4, IdentityVal4, BOp4);
166
-
167
- auto Lambda = [=](nd_item<1 > NDIt, auto &Sum1, auto &Sum2, auto &Sum3,
168
- auto &Sum4) {
169
- size_t I = NDIt.get_global_id (0 );
170
- Sum1.combine (In1[I]);
171
- Sum2.combine (In2[I]);
172
- Sum3.combine (In3[I]);
173
- Sum4.combine (In4[I]);
174
- };
175
- CGH.parallel_for <Name>(NDR, Redu1, Redu2, Redu3, Redu4, Lambda);
176
- }).wait ();
177
- }
110
+ Q.submit ([&](handler &CGH) {
111
+ auto In1 = InBuf1.template get_access <access::mode::read>(CGH);
112
+ auto In2 = InBuf2.template get_access <access::mode::read>(CGH);
113
+ auto In3 = InBuf3.template get_access <access::mode::read>(CGH);
114
+ auto In4 = InBuf4.template get_access <access::mode::read>(CGH);
115
+
116
+ auto Redu1 =
117
+ createReduction<IsSYCL2020, Mode1>(OutBuf1, CGH, IdentityVal1, BOp1);
118
+ auto Redu2 =
119
+ createReduction<IsSYCL2020, Mode2>(OutBuf2, CGH, IdentityVal2, BOp2);
120
+ auto Redu3 =
121
+ createReduction<IsSYCL2020, Mode3>(OutBuf3, CGH, IdentityVal3, BOp3);
122
+ auto Redu4 = createReduction<IsSYCL2020, Mode4>(Out4, IdentityVal4, BOp4);
123
+
124
+ auto Lambda = [=](nd_item<1 > NDIt, auto &Sum1, auto &Sum2, auto &Sum3,
125
+ auto &Sum4) {
126
+ size_t I = NDIt.get_global_id (0 );
127
+ Sum1.combine (In1[I]);
128
+ Sum2.combine (In2[I]);
129
+ Sum3.combine (In3[I]);
130
+ Sum4.combine (In4[I]);
131
+ };
132
+ CGH.parallel_for <Name>(NDR, Redu1, Redu2, Redu3, Redu4, Lambda);
133
+ }).wait ();
178
134
179
135
// Check the results and free memory.
180
- int Error = 0 ;
136
+ int NumErrors = 0 ;
181
137
{
182
138
auto Out1 = OutBuf1.template get_access <access::mode::read>();
183
139
auto Out2 = OutBuf2.template get_access <access::mode::read>();
@@ -195,22 +151,23 @@ int testOne(queue &Q, T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
195
151
Out4Val = *Out4;
196
152
}
197
153
198
- Error += cherkResultIsExpected (1 , CorrectOut1, Out1[0 ], IsSYCL2020) ? 0 : 1 ;
199
- Error += cherkResultIsExpected (2 , CorrectOut2, Out2[0 ], IsSYCL2020) ? 0 : 1 ;
200
- Error += cherkResultIsExpected (3 , CorrectOut3, Out3[0 ], IsSYCL2020) ? 0 : 1 ;
201
- Error += cherkResultIsExpected (4 , CorrectOut4, Out4Val, IsSYCL2020) ? 0 : 1 ;
154
+ std::string AddInfo = " TestCase=" ;
155
+ NumErrors += checkResults (Q, IsSYCL2020, BOp1, NDR, Out1[0 ], CorrectOut1,
156
+ AddInfo + std::to_string (1 ));
157
+ NumErrors += checkResults (Q, IsSYCL2020, BOp2, NDR, Out2[0 ], CorrectOut2,
158
+ AddInfo + std::to_string (2 ));
159
+ NumErrors += checkResults (Q, IsSYCL2020, BOp3, NDR, Out3[0 ], CorrectOut3,
160
+ AddInfo + std::to_string (3 ));
161
+ NumErrors += checkResults (Q, IsSYCL2020, BOp4, NDR, Out4Val, CorrectOut4,
162
+ AddInfo + std::to_string (4 ));
202
163
free (Out4, Q.get_context ());
203
164
}
204
165
205
- if (Error)
206
- std::cerr << " The test failed for nd_range(" << NWorkItems << " ," << WGSize
207
- << " )\n\n " ;
208
-
209
- return Error;
166
+ return NumErrors;
210
167
}
211
168
212
169
// Tests both implementations of reduction:
213
- // sycl::reduction and sycl::ONEAPI ::reduction
170
+ // sycl::reduction and sycl::ext::oneapi ::reduction
214
171
template <class Name , typename T1, access::mode Mode1, typename T2,
215
172
access::mode Mode2, typename T3, access::mode Mode3, typename T4,
216
173
access::mode Mode4, class BinaryOperation1 , class BinaryOperation2 ,
@@ -236,18 +193,16 @@ int testBoth(queue &Q, T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
236
193
237
194
int main () {
238
195
queue Q;
196
+ printDeviceInfo (Q);
239
197
int Error = testBoth<class Case1 , float , DW, int , RW, short , RW, int , RW>(
240
- Q, 0 , 1000 , std::plus<float >{}, 0 , 2000 , std::plus<>{}, 0 , 4000 ,
198
+ Q, 0 , 1000 , std::plus<>{}, 0 , 2000 , std::plus<>{}, 0 , 4000 ,
241
199
std::bit_or<>{}, 0 , 8000 , std::bit_xor<>{}, usm::alloc::shared, 16 , 16 );
242
200
243
201
auto Add = [](auto x, auto y) { return (x + y); };
244
202
Error += testBoth<class Case2 , float , RW, int , RW, short , DW, int , DW>(
245
- Q, 0 , 1000 , std::plus<float >{}, 0 , 2000 , std::plus<>{}, 0 , 4000 , Add, 0 ,
246
- 8000 , std::plus<>{}, usm::alloc::device, 5 * (256 + 1 ), 5 );
203
+ Q, 0 , 1000 , std::plus<>{}, 0 , 2000 , std::plus<>{}, 0 , 4000 , Add, 0 , 8000 ,
204
+ std::plus<>{}, usm::alloc::device, 5 * (256 + 1 ), 5 );
247
205
248
- if (!Error)
249
- std::cout << " Test passed\n " ;
250
- else
251
- std::cerr << Error << " test-cases failed\n " ;
206
+ printFinalStatus (Error);
252
207
return Error;
253
208
}
0 commit comments