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
@@ -36,25 +27,29 @@ constexpr access::mode RW = access::mode::read_write;
36
27
constexpr access::mode DW = access::mode::discard_write;
37
28
38
29
template <typename T>
39
- bool cherkResultIsExpected (int TestCaseNum, T Expected, T Computed) {
30
+ bool cherkResultIsExpected (int TestCaseNum, T Expected, T Computed,
31
+ bool IsSYCL2020) {
40
32
bool Success;
41
33
if (!std::is_floating_point<T>::value)
42
34
Success = (Expected == Computed);
43
35
else
44
36
Success = std::abs ((Expected / Computed) - 1 ) < 0.5 ;
45
37
46
- if (!Success)
47
- std::cout << TestCaseNum << " : Expected value = " << Expected
38
+ if (!Success) {
39
+ std::cerr << " Is SYCL2020 mode: " << IsSYCL2020 << std::endl;
40
+ std::cerr << TestCaseNum << " : Expected value = " << Expected
48
41
<< " , Computed value = " << Computed << " \n " ;
42
+ }
49
43
50
44
return Success;
51
45
}
52
46
53
47
// Returns 0 if the test case passed. Otherwise, some non-zero value.
54
- template <class Name , bool IsSYCL2020Mode , typename T1, access::mode Mode1,
48
+ template <class Name , bool IsSYCL2020 , typename T1, access::mode Mode1,
55
49
typename T2, access::mode Mode2, typename T3, access::mode Mode3,
56
- typename T4, class BinaryOperation1 , class BinaryOperation2 ,
57
- class BinaryOperation3 , class BinaryOperation4 >
50
+ typename T4, access::mode Mode4, class BinaryOperation1 ,
51
+ class BinaryOperation2 , class BinaryOperation3 ,
52
+ class BinaryOperation4 >
58
53
int testOne (T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
59
54
T2 IdentityVal2, T2 InitVal2, BinaryOperation2 BOp2,
60
55
T3 IdentityVal3, T3 InitVal3, BinaryOperation3 BOp3,
@@ -100,8 +95,9 @@ int testOne(T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
100
95
CorrectOut2 = BOp2 (CorrectOut2, InitVal2);
101
96
if (Mode3 == access ::mode::read_write)
102
97
CorrectOut3 = BOp3 (CorrectOut3, InitVal3);
103
- // 4th reduction is USM and this is read_write.
104
- CorrectOut4 = BOp4 (CorrectOut4, InitVal4);
98
+ // discard_write mode for USM reductions is available only SYCL2020.
99
+ if (Mode4 == access ::mode::read_write || !IsSYCL2020)
100
+ CorrectOut4 = BOp4 (CorrectOut4, InitVal4);
105
101
106
102
// Inititialize data.
107
103
{
@@ -123,17 +119,21 @@ int testOne(T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
123
119
}
124
120
125
121
auto NDR = nd_range<1 >{range<1 >(NWorkItems), range<1 >{WGSize}};
126
- if constexpr (IsSYCL2020Mode ) {
122
+ if constexpr (IsSYCL2020 ) {
127
123
Q.submit ([&](handler &CGH) {
128
124
auto In1 = InBuf1.template get_access <access ::mode::read >(CGH);
129
125
auto In2 = InBuf2.template get_access <access ::mode::read >(CGH);
130
126
auto In3 = InBuf3.template get_access <access ::mode::read >(CGH);
131
127
auto In4 = InBuf4.template get_access <access ::mode::read >(CGH);
132
128
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);
129
+ auto Redu1 = sycl::reduction (OutBuf1, CGH, IdentityVal1, BOp1,
130
+ getPropertyList<Mode1>());
131
+ auto Redu2 = sycl::reduction (OutBuf2, CGH, IdentityVal2, BOp2,
132
+ getPropertyList<Mode2>());
133
+ auto Redu3 = sycl::reduction (OutBuf3, CGH, IdentityVal3, BOp3,
134
+ getPropertyList<Mode3>());
135
+ auto Redu4 =
136
+ sycl::reduction (Out4, IdentityVal4, BOp4, getPropertyList<Mode4>());
137
137
138
138
auto Lambda = [=](nd_item<1 > NDIt, auto &Sum1, auto &Sum2, auto &Sum3,
139
139
auto &Sum4) {
@@ -193,10 +193,10 @@ int testOne(T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
193
193
Out4Val = *Out4;
194
194
}
195
195
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 ;
196
+ Error += cherkResultIsExpected (1 , CorrectOut1, Out1[0 ], IsSYCL2020 ) ? 0 : 1 ;
197
+ Error += cherkResultIsExpected (2 , CorrectOut2, Out2[0 ], IsSYCL2020 ) ? 0 : 1 ;
198
+ Error += cherkResultIsExpected (3 , CorrectOut3, Out3[0 ], IsSYCL2020 ) ? 0 : 1 ;
199
+ Error += cherkResultIsExpected (4 , CorrectOut4, Out4Val, IsSYCL2020 ) ? 0 : 1 ;
200
200
free (Out4, Q.get_context ());
201
201
}
202
202
@@ -211,45 +211,39 @@ int testOne(T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
211
211
// sycl::reduction and sycl::ONEAPI::reduction
212
212
template <class Name , typename T1, access::mode Mode1, typename T2,
213
213
access::mode Mode2, typename T3, access::mode Mode3, typename T4,
214
- class BinaryOperation1 , class BinaryOperation2 ,
214
+ access::mode Mode4, class BinaryOperation1 , class BinaryOperation2 ,
215
215
class BinaryOperation3 , class BinaryOperation4 >
216
216
int testBoth (T1 IdentityVal1, T1 InitVal1, BinaryOperation1 BOp1,
217
217
T2 IdentityVal2, T2 InitVal2, BinaryOperation2 BOp2,
218
218
T3 IdentityVal3, T3 InitVal3, BinaryOperation3 BOp3,
219
219
T4 IdentityVal4, T3 InitVal4, BinaryOperation4 BOp4,
220
220
usm::alloc AllocType4, size_t NWorkItems, size_t WGSize) {
221
221
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;
232
- 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);
222
+ testOne<KName<Name, false >, false , T1, Mode1, T2, Mode2, T3, Mode3, T4,
223
+ Mode4>(IdentityVal1, InitVal1, BOp1, IdentityVal2, InitVal2, BOp2,
224
+ IdentityVal3, InitVal3, BOp3, IdentityVal4, InitVal4, BOp4,
225
+ AllocType4, NWorkItems, WGSize);
226
+
227
+ Error += testOne<KName<Name, true >, true , T1, Mode1, T2, Mode2, T3, Mode3, T4,
228
+ Mode4>(IdentityVal1, InitVal1, BOp1, IdentityVal2, InitVal2,
229
+ BOp2, IdentityVal3, InitVal3, BOp3, IdentityVal4,
230
+ InitVal4, BOp4, AllocType4, NWorkItems, WGSize);
237
231
return Error;
238
232
}
239
233
240
234
int main () {
241
- int Error = testBoth<class FP32Plus16x16 , float , DW, int , RW, short , RW, int >(
235
+ int Error = testBoth<class Case1 , float , DW, int , RW, short , RW, int , RW >(
242
236
0 , 1000 , std::plus<float >{}, 0 , 2000 , std::plus<>{}, 0 , 4000 ,
243
237
std::bit_or<>{}, 0 , 8000 , std::bit_xor<>{}, usm::alloc::shared, 16 , 16 );
244
238
245
239
auto Add = [](auto x, auto y) { return (x + y); };
246
- Error += testBoth<class FP32Plus5x257 , float , RW, int , RW, short , DW, int >(
240
+ Error += testBoth<class Case2 , float , RW, int , RW, short , DW, int , DW >(
247
241
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 );
242
+ 8000 , std::plus< >{}, usm::alloc::device, 5 * (256 + 1 ), 5 );
249
243
250
244
if (!Error)
251
245
std::cout << " Test passed\n " ;
252
246
else
253
- std::cout << Error << " test-cases failed\n " ;
247
+ std::cerr << Error << " test-cases failed\n " ;
254
248
return Error;
255
249
}
0 commit comments