Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 97caea0

Browse files
authored
[SYCL] Add 1 test for reduction initialized by early destroyed accessor (#222)
The corresponding change in SYCL RT: intel/llvm#3498 Signed-off-by: Vyacheslav N Klochkov <[email protected]>
1 parent cd95be7 commit 97caea0

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

SYCL/Reduction/reduction_nd_lambda.cpp

+21-12
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,20 @@
1212

1313
using namespace cl::sycl;
1414

15+
// Note that this function is created only to test that if the accessor
16+
// object passed to ONEAPI::reduction is destroyed right after
17+
// ONEAPI::reduction creation, then the reduction still works properly,
18+
// i.e. it holds a COPY of user's accessor.
19+
template <typename T, typename BOpT>
20+
auto createReduction(sycl::buffer<T, 1> Buffer, handler &CGH, T Identity,
21+
BOpT BOp) {
22+
auto Acc = Buffer.template get_access<access::mode::discard_write>(CGH);
23+
return ONEAPI::reduction(Acc, Identity, BOp);
24+
}
25+
1526
template <class KernelName, typename T, class BinaryOperation>
16-
void test(T Identity, BinaryOperation BOp, size_t WGSize, size_t NWItems) {
27+
void test(queue &Q, T Identity, BinaryOperation BOp, size_t WGSize,
28+
size_t NWItems) {
1729
buffer<T, 1> InBuf(NWItems);
1830
buffer<T, 1> OutBuf(1);
1931

@@ -22,15 +34,11 @@ void test(T Identity, BinaryOperation BOp, size_t WGSize, size_t NWItems) {
2234
initInputData(InBuf, CorrectOut, Identity, BOp, NWItems);
2335

2436
// Compute.
25-
queue Q;
2637
Q.submit([&](handler &CGH) {
2738
auto In = InBuf.template get_access<access::mode::read>(CGH);
28-
auto Out = OutBuf.template get_access<access::mode::discard_write>(CGH);
29-
auto Redu = ONEAPI::reduction(Out, Identity, BOp);
39+
auto Redu = createReduction(OutBuf, CGH, Identity, BOp);
3040

31-
range<1> GlobalRange(NWItems);
32-
range<1> LocalRange(WGSize);
33-
nd_range<1> NDRange(GlobalRange, LocalRange);
41+
nd_range<1> NDRange(range<1>{NWItems}, range<1>{WGSize});
3442
CGH.parallel_for<KernelName>(NDRange, Redu,
3543
[=](nd_item<1> NDIt, auto &Sum) {
3644
Sum.combine(In[NDIt.get_global_linear_id()]);
@@ -41,22 +49,23 @@ void test(T Identity, BinaryOperation BOp, size_t WGSize, size_t NWItems) {
4149
auto Out = OutBuf.template get_access<access::mode::read>();
4250
T ComputedOut = *(Out.get_pointer());
4351
if (ComputedOut != CorrectOut) {
44-
std::cout << "NWItems = " << NWItems << ", WGSize = " << WGSize << "\n";
45-
std::cout << "Computed value: " << ComputedOut
52+
std::cerr << "NWItems = " << NWItems << ", WGSize = " << WGSize << "\n";
53+
std::cerr << "Computed value: " << ComputedOut
4654
<< ", Expected value: " << CorrectOut << "\n";
4755
assert(0 && "Wrong value.");
4856
}
4957
}
5058

5159
int main() {
60+
queue Q;
5261
test<class AddTestName, int>(
53-
0, [](auto x, auto y) { return (x + y); }, 1, 1024);
62+
Q, 0, [](auto x, auto y) { return (x + y); }, 1, 1024);
5463
test<class MulTestName, int>(
55-
0, [](auto x, auto y) { return (x * y); }, 8, 32);
64+
Q, 0, [](auto x, auto y) { return (x * y); }, 8, 32);
5665

5766
// Check with CUSTOM type.
5867
test<class CustomAddTestname, CustomVec<long long>>(
59-
CustomVec<long long>(0),
68+
Q, CustomVec<long long>(0),
6069
[](auto x, auto y) {
6170
CustomVecPlus<long long> BOp;
6271
return BOp(x, y);

0 commit comments

Comments
 (0)