1
- // TODO: level_zero reports an internal error for this test.
2
- // UNSUPPORTED: level_zero
3
-
4
- // TODO: Windows implementation of std::tuple is not trivially copiable and
5
- // thus cannot be passed from HOST to DEVICE. Enable the test on Windows when
6
- // SYCL RT gets new type traits having less strict requirements for objects
7
- // being passed to DEVICE.
8
- // UNSUPPORTED: windows
9
-
10
1
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
11
2
// RUN: %CPU_RUN_PLACEHOLDER %t.out
12
3
// RUN: %GPU_RUN_PLACEHOLDER %t.out
13
4
// RUN: %ACC_RUN_PLACEHOLDER %t.out
14
5
6
+ // TODO: The test irregularly reports incorrect results on CPU.
7
+ // UNSUPPORTED: cpu
8
+
15
9
// This test checks handling of parallel_for() accepting nd_range and
16
10
// two or more reductions.
17
11
@@ -36,26 +30,30 @@ constexpr access::mode RW = access::mode::read_write;
36
30
constexpr access::mode DW = access::mode::discard_write;
37
31
38
32
template <typename T>
39
- bool cherkResultIsExpected (int TestCaseNum, T Expected, T Computed) {
33
+ bool cherkResultIsExpected (int TestCaseNum, T Expected, T Computed,
34
+ bool IsSYCL2020) {
40
35
bool Success;
41
36
if (!std::is_floating_point<T>::value)
42
37
Success = (Expected == Computed);
43
38
else
44
39
Success = std::abs ((Expected / Computed) - 1 ) < 0.5 ;
45
40
46
- if (!Success)
47
- std::cout << TestCaseNum << " : Expected value = " << Expected
41
+ if (!Success) {
42
+ std::cerr << " Is SYCL2020 mode: " << IsSYCL2020 << std::endl;
43
+ std::cerr << TestCaseNum << " : Expected value = " << Expected
48
44
<< " , Computed value = " << Computed << " \n " ;
45
+ }
49
46
50
47
return Success;
51
48
}
52
49
53
50
// Returns 0 if the test case passed. Otherwise, some non-zero value.
54
- template <class Name , bool IsSYCL2020Mode , typename T1, access::mode Mode1,
51
+ template <class Name , bool IsSYCL2020 , typename T1, access::mode Mode1,
55
52
typename T2, access::mode Mode2, typename T3, access::mode Mode3,
56
- typename T4, class BinaryOperation1 , class BinaryOperation2 ,
57
- class BinaryOperation3 , class BinaryOperation4 >
58
- int testOne (T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
53
+ typename T4, access::mode Mode4, class BinaryOperation1 ,
54
+ class BinaryOperation2 , class BinaryOperation3 ,
55
+ class BinaryOperation4 >
56
+ int testOne (queue &Q, T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
59
57
T2 IdentityVal2, T2 InitVal2, BinaryOperation2 BOp2,
60
58
T3 IdentityVal3, T3 InitVal3, BinaryOperation3 BOp3,
61
59
T4 IdentityVal4, T3 InitVal4, BinaryOperation4 BOp4,
@@ -68,7 +66,6 @@ int testOne(T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
68
66
buffer<T2, 1 > OutBuf2 (1 );
69
67
buffer<T3, 1 > OutBuf3 (1 );
70
68
71
- queue Q;
72
69
auto Dev = Q.get_device ();
73
70
if (AllocType4 == usm::alloc::shared &&
74
71
!Dev.get_info <info::device::usm_shared_allocations>())
@@ -100,8 +97,9 @@ int testOne(T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
100
97
CorrectOut2 = BOp2 (CorrectOut2, InitVal2);
101
98
if (Mode3 == access ::mode::read_write)
102
99
CorrectOut3 = BOp3 (CorrectOut3, InitVal3);
103
- // 4th reduction is USM and this is read_write.
104
- CorrectOut4 = BOp4 (CorrectOut4, InitVal4);
100
+ // discard_write mode for USM reductions is available only SYCL2020.
101
+ if (Mode4 == access ::mode::read_write || !IsSYCL2020)
102
+ CorrectOut4 = BOp4 (CorrectOut4, InitVal4);
105
103
106
104
// Inititialize data.
107
105
{
@@ -123,17 +121,21 @@ int testOne(T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
123
121
}
124
122
125
123
auto NDR = nd_range<1 >{range<1 >(NWorkItems), range<1 >{WGSize}};
126
- if constexpr (IsSYCL2020Mode ) {
124
+ if constexpr (IsSYCL2020 ) {
127
125
Q.submit ([&](handler &CGH) {
128
126
auto In1 = InBuf1.template get_access <access ::mode::read >(CGH);
129
127
auto In2 = InBuf2.template get_access <access ::mode::read >(CGH);
130
128
auto In3 = InBuf3.template get_access <access ::mode::read >(CGH);
131
129
auto In4 = InBuf4.template get_access <access ::mode::read >(CGH);
132
130
133
- auto Redu1 = sycl::reduction (OutBuf1, CGH, IdentityVal1, BOp1);
134
- auto Redu2 = sycl::reduction (OutBuf2, CGH, IdentityVal2, BOp2);
135
- auto Redu3 = sycl::reduction (OutBuf3, CGH, IdentityVal3, BOp3);
136
- auto Redu4 = sycl::reduction (Out4, IdentityVal4, BOp4);
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>());
137
139
138
140
auto Lambda = [=](nd_item<1 > NDIt, auto &Sum1, auto &Sum2, auto &Sum3,
139
141
auto &Sum4) {
@@ -193,10 +195,10 @@ int testOne(T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
193
195
Out4Val = *Out4;
194
196
}
195
197
196
- Error += cherkResultIsExpected (1 , CorrectOut1, Out1[0 ]) ? 0 : 1 ;
197
- Error += cherkResultIsExpected (2 , CorrectOut2, Out2[0 ]) ? 0 : 1 ;
198
- Error += cherkResultIsExpected (3 , CorrectOut3, Out3[0 ]) ? 0 : 1 ;
199
- Error += cherkResultIsExpected (4 , CorrectOut4, Out4Val) ? 0 : 1 ;
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 ;
200
202
free (Out4, Q.get_context ());
201
203
}
202
204
@@ -211,45 +213,41 @@ int testOne(T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
211
213
// sycl::reduction and sycl::ONEAPI::reduction
212
214
template <class Name , typename T1, access::mode Mode1, typename T2,
213
215
access::mode Mode2, typename T3, access::mode Mode3, typename T4,
214
- class BinaryOperation1 , class BinaryOperation2 ,
216
+ access::mode Mode4, class BinaryOperation1 , class BinaryOperation2 ,
215
217
class BinaryOperation3 , class BinaryOperation4 >
216
- int testBoth (T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
218
+ int testBoth (queue &Q, T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
217
219
T2 IdentityVal2, T2 InitVal2, BinaryOperation2 BOp2,
218
220
T3 IdentityVal3, T3 InitVal3, BinaryOperation3 BOp3,
219
221
T4 IdentityVal4, T3 InitVal4, BinaryOperation4 BOp4,
220
222
usm::alloc AllocType4, size_t NWorkItems, size_t WGSize) {
221
223
int Error =
222
- testOne<KName<Name, false >, false , T1, Mode1, T2, Mode2, T3, Mode3, T4>(
223
- IdentityVal1, InitVal1, BOp1, IdentityVal2, InitVal2, BOp2,
224
- IdentityVal3, InitVal3, BOp3, IdentityVal4, InitVal4, BOp4,
225
- AllocType4, NWorkItems, WGSize);
226
-
227
- // TODO: property::reduction::initialize_to_identity is not supported yet.
228
- // Thus only read_write mode is tested now.
229
- constexpr access ::mode _Mode1 = (Mode1 == DW) ? RW : Mode1;
230
- constexpr access ::mode _Mode2 = (Mode2 == DW) ? RW : Mode2;
231
- constexpr access ::mode _Mode3 = (Mode3 == DW) ? RW : Mode3;
224
+ testOne<KName<Name, false >, false , T1, Mode1, T2, Mode2, T3, Mode3, T4,
225
+ Mode4>(Q, IdentityVal1, InitVal1, BOp1, IdentityVal2, InitVal2,
226
+ BOp2, IdentityVal3, InitVal3, BOp3, IdentityVal4, InitVal4,
227
+ BOp4, AllocType4, NWorkItems, WGSize);
228
+
232
229
Error +=
233
- testOne<KName<Name, true >, true , T1, _Mode1 , T2, _Mode2 , T3, _Mode3 , T4>(
234
- IdentityVal1, InitVal1, BOp1, IdentityVal2, InitVal2, BOp2 ,
235
- IdentityVal3, InitVal3, BOp3, IdentityVal4, InitVal4, BOp4 ,
236
- AllocType4, NWorkItems, WGSize);
230
+ testOne<KName<Name, true >, true , T1, Mode1 , T2, Mode2 , T3, Mode3 , T4,
231
+ Mode4>(Q, IdentityVal1, InitVal1, BOp1, IdentityVal2, InitVal2,
232
+ BOp2, IdentityVal3, InitVal3, BOp3, IdentityVal4, InitVal4,
233
+ BOp4, AllocType4, NWorkItems, WGSize);
237
234
return Error;
238
235
}
239
236
240
237
int main () {
241
- int Error = testBoth<class FP32Plus16x16 , float , DW, int , RW, short , RW, int >(
242
- 0 , 1000 , std::plus<float >{}, 0 , 2000 , std::plus<>{}, 0 , 4000 ,
238
+ queue Q;
239
+ 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 ,
243
241
std::bit_or<>{}, 0 , 8000 , std::bit_xor<>{}, usm::alloc::shared, 16 , 16 );
244
242
245
243
auto Add = [](auto x, auto y) { return (x + y); };
246
- Error += testBoth<class FP32Plus5x257 , float , RW, int , RW, short , DW, int >(
247
- 0 , 1000 , std::plus<float >{}, 0 , 2000 , std::plus<>{}, 0 , 4000 , Add, 0 ,
248
- 8000 , std::bit_xor< int >{}, usm::alloc::device, 5 * (256 + 1 ), 5 );
244
+ 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 );
249
247
250
248
if (!Error)
251
249
std::cout << " Test passed\n " ;
252
250
else
253
- std::cout << Error << " test-cases failed\n " ;
251
+ std::cerr << Error << " test-cases failed\n " ;
254
252
return Error;
255
253
}
0 commit comments