From 068f6a912a2eed74acb096b4d3fca291596feba2 Mon Sep 17 00:00:00 2001 From: Vyacheslav N Klochkov Date: Tue, 28 Jul 2020 12:32:29 -0700 Subject: [PATCH] Additional fix in reduction LIT test to be in sync with patch enabling lambdas for reduction Signed-off-by: Vyacheslav N Klochkov --- sycl/test/reduction/reduction_ctor.cpp | 93 +++++++++----------------- 1 file changed, 33 insertions(+), 60 deletions(-) diff --git a/sycl/test/reduction/reduction_ctor.cpp b/sycl/test/reduction/reduction_ctor.cpp index 7f8e8e9726e59..4bac1dac9cb9f 100644 --- a/sycl/test/reduction/reduction_ctor.cpp +++ b/sycl/test/reduction/reduction_ctor.cpp @@ -23,13 +23,12 @@ void test_reducer(Reduction &Redu, T A, T B) { "Wrong result of binary operation."); } -template -void test_reducer(Reduction &Redu, T Identity, T A, T B) { - typename Reduction::reducer_type Reducer(Identity); +template +void test_reducer(Reduction &Redu, T Identity, BinaryOperation BOp, T A, T B) { + typename Reduction::reducer_type Reducer(Identity, BOp); Reducer.combine(A); Reducer.combine(B); - typename Reduction::binary_operation BOp; T ExpectedValue = BOp(A, B); assert(ExpectedValue == Reducer.MValue && "Wrong result of binary operation."); @@ -40,35 +39,8 @@ class Known; template class Unknown; -template -struct Point { - Point() : X(0), Y(0) {} - Point(T X, T Y) : X(X), Y(Y) {} - Point(T V) : X(V), Y(V) {} - bool operator==(const Point &P) const { - return P.X == X && P.Y == Y; - } - T X; - T Y; -}; - -template -bool operator==(const Point &A, const Point &B) { - return A.X == B.X && A.Y == B.Y; -} - -template -struct PointPlus { - using P = Point; - P operator()(const P &A, const P &B) const { - return P(A.X + B.X, A.Y + B.Y); - } -}; - template -void testKnown(T Identity, T A, T B) { - - BinaryOperation BOp; +void testKnown(T Identity, BinaryOperation BOp, T A, T B) { buffer ReduBuf(1); queue Q; @@ -81,17 +53,15 @@ void testKnown(T Identity, T A, T B) { assert(Redu.getIdentity() == Identity && "Failed getIdentity() check()."); test_reducer(Redu, A, B); - test_reducer(Redu, Identity, A, B); + test_reducer(Redu, Identity, BOp, A, B); // Command group must have at least one task in it. Use an empty one. CGH.single_task>([=]() {}); }); } -template -void testUnknown(T Identity, T A, T B) { - - BinaryOperation BOp; +template +void testUnknown(T Identity, BinaryOperation BOp, T A, T B) { buffer ReduBuf(1); queue Q; Q.submit([&](handler &CGH) { @@ -102,38 +72,41 @@ void testUnknown(T Identity, T A, T B) { auto Redu = intel::reduction(ReduAcc, Identity, BOp); assert(Redu.getIdentity() == Identity && "Failed getIdentity() check()."); - test_reducer(Redu, Identity, A, B); + test_reducer(Redu, Identity, BOp, A, B); // Command group must have at least one task in it. Use an empty one. - CGH.single_task>([=]() {}); + CGH.single_task([=]() {}); }); } template -void testBoth(T Identity, T A, T B) { - testKnown(Identity, A, B); - testKnown(Identity, A, B); - testUnknown(Identity, A, B); - testUnknown(Identity, A, B); +void testBoth(T Identity, BinaryOperation BOp, T A, T B) { + testKnown(Identity, BOp, A, B); + testKnown(Identity, BOp, A, B); + testUnknown>(Identity, BOp, A, B); + testUnknown>(Identity, BOp, A, B); } int main() { - // testKnown does not pass identity to reduction ctor. - testBoth>(0, 1, 7); - testBoth>(1, 1, 7); - testBoth>(0, 1, 8); - testBoth>(0, 7, 3); - testBoth>(~0, 7, 3); - testBoth>((std::numeric_limits::max)(), 7, 3); - testBoth>((std::numeric_limits::min)(), 7, 3); - - testBoth>(0, 1, 7); - testBoth>(1, 1, 7); - testBoth>(getMaximumFPValue(), 7, 3); - testBoth>(getMinimumFPValue(), 7, 3); - - testUnknown, 0, PointPlus>(Point(0), Point(1), Point(7)); - testUnknown, 1, PointPlus>(Point(0), Point(1), Point(7)); + testBoth(0, intel::plus(), 1, 7); + testBoth(1, std::multiplies(), 1, 7); + testBoth(0, intel::bit_or(), 1, 8); + testBoth(0, intel::bit_xor(), 7, 3); + testBoth(~0, intel::bit_and(), 7, 3); + testBoth((std::numeric_limits::max)(), intel::minimum(), 7, 3); + testBoth((std::numeric_limits::min)(), intel::maximum(), 7, 3); + + testBoth(0, intel::plus(), 1, 7); + testBoth(1, std::multiplies(), 1, 7); + testBoth(getMaximumFPValue(), intel::minimum(), 7, 3); + testBoth(getMinimumFPValue(), intel::maximum(), 7, 3); + + testUnknown, 0, Unknown, 0, CustomVecPlus>>( + CustomVec(0), CustomVecPlus(), CustomVec(1), CustomVec(7)); + testUnknown, 1, Unknown, 1, CustomVecPlus>>( + CustomVec(0), CustomVecPlus(), CustomVec(1), CustomVec(7)); + + testUnknown(0, [](auto a, auto b) { return a | b; }, 1, 8); std::cout << "Test passed\n"; return 0;