Skip to content

Commit

Permalink
Additional fix in reduction LIT test to be in sync with patch enablin…
Browse files Browse the repository at this point in the history
…g lambdas for reduction

Signed-off-by: Vyacheslav N Klochkov <[email protected]>
  • Loading branch information
v-klochkov committed Jul 28, 2020
1 parent 6e0b92e commit 068f6a9
Showing 1 changed file with 33 additions and 60 deletions.
93 changes: 33 additions & 60 deletions sycl/test/reduction/reduction_ctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ void test_reducer(Reduction &Redu, T A, T B) {
"Wrong result of binary operation.");
}

template <typename T, typename Reduction>
void test_reducer(Reduction &Redu, T Identity, T A, T B) {
typename Reduction::reducer_type Reducer(Identity);
template <typename T, typename Reduction, typename BinaryOperation>
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.");
Expand All @@ -40,35 +39,8 @@ class Known;
template <typename T, int Dim, class BinaryOperation>
class Unknown;

template <typename T>
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 <typename T>
bool operator==(const Point<T> &A, const Point<T> &B) {
return A.X == B.X && A.Y == B.Y;
}

template <class T>
struct PointPlus {
using P = Point<T>;
P operator()(const P &A, const P &B) const {
return P(A.X + B.X, A.Y + B.Y);
}
};

template <typename T, int Dim, class BinaryOperation>
void testKnown(T Identity, T A, T B) {

BinaryOperation BOp;
void testKnown(T Identity, BinaryOperation BOp, T A, T B) {
buffer<T, 1> ReduBuf(1);

queue Q;
Expand All @@ -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<Known<T, Dim, BinaryOperation>>([=]() {});
});
}

template <typename T, int Dim, class BinaryOperation>
void testUnknown(T Identity, T A, T B) {

BinaryOperation BOp;
template <typename T, int Dim, typename KernelName, class BinaryOperation>
void testUnknown(T Identity, BinaryOperation BOp, T A, T B) {
buffer<T, 1> ReduBuf(1);
queue Q;
Q.submit([&](handler &CGH) {
Expand All @@ -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<Unknown<T, Dim, BinaryOperation>>([=]() {});
CGH.single_task<KernelName>([=]() {});
});
}

template <typename T, class BinaryOperation>
void testBoth(T Identity, T A, T B) {
testKnown<T, 0, BinaryOperation>(Identity, A, B);
testKnown<T, 1, BinaryOperation>(Identity, A, B);
testUnknown<T, 0, BinaryOperation>(Identity, A, B);
testUnknown<T, 1, BinaryOperation>(Identity, A, B);
void testBoth(T Identity, BinaryOperation BOp, T A, T B) {
testKnown<T, 0 >(Identity, BOp, A, B);
testKnown<T, 1>(Identity, BOp, A, B);
testUnknown<T, 0, Unknown<T, 0, BinaryOperation>>(Identity, BOp, A, B);
testUnknown<T, 1, Unknown<T, 1, BinaryOperation>>(Identity, BOp, A, B);
}

int main() {
// testKnown does not pass identity to reduction ctor.
testBoth<int, intel::plus<int>>(0, 1, 7);
testBoth<int, std::multiplies<int>>(1, 1, 7);
testBoth<int, intel::bit_or<int>>(0, 1, 8);
testBoth<int, intel::bit_xor<int>>(0, 7, 3);
testBoth<int, intel::bit_and<int>>(~0, 7, 3);
testBoth<int, intel::minimum<int>>((std::numeric_limits<int>::max)(), 7, 3);
testBoth<int, intel::maximum<int>>((std::numeric_limits<int>::min)(), 7, 3);

testBoth<float, intel::plus<float>>(0, 1, 7);
testBoth<float, std::multiplies<float>>(1, 1, 7);
testBoth<float, intel::minimum<float>>(getMaximumFPValue<float>(), 7, 3);
testBoth<float, intel::maximum<float>>(getMinimumFPValue<float>(), 7, 3);

testUnknown<Point<float>, 0, PointPlus<float>>(Point<float>(0), Point<float>(1), Point<float>(7));
testUnknown<Point<float>, 1, PointPlus<float>>(Point<float>(0), Point<float>(1), Point<float>(7));
testBoth<int>(0, intel::plus<int>(), 1, 7);
testBoth<int>(1, std::multiplies<int>(), 1, 7);
testBoth<int>(0, intel::bit_or<int>(), 1, 8);
testBoth<int>(0, intel::bit_xor<int>(), 7, 3);
testBoth<int>(~0, intel::bit_and<int>(), 7, 3);
testBoth<int>((std::numeric_limits<int>::max)(), intel::minimum<int>(), 7, 3);
testBoth<int>((std::numeric_limits<int>::min)(), intel::maximum<int>(), 7, 3);

testBoth<float>(0, intel::plus<float>(), 1, 7);
testBoth<float>(1, std::multiplies<float>(), 1, 7);
testBoth<float>(getMaximumFPValue<float>(), intel::minimum<float>(), 7, 3);
testBoth<float>(getMinimumFPValue<float>(), intel::maximum<float>(), 7, 3);

testUnknown<CustomVec<float>, 0, Unknown<CustomVec<float>, 0, CustomVecPlus<float>>>(
CustomVec<float>(0), CustomVecPlus<float>(), CustomVec<float>(1), CustomVec<float>(7));
testUnknown<CustomVec<float>, 1, Unknown<CustomVec<float>, 1, CustomVecPlus<float>>>(
CustomVec<float>(0), CustomVecPlus<float>(), CustomVec<float>(1), CustomVec<float>(7));

testUnknown<int, 0, class BitOrName>(0, [](auto a, auto b) { return a | b; }, 1, 8);

std::cout << "Test passed\n";
return 0;
Expand Down

0 comments on commit 068f6a9

Please sign in to comment.