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

[SYCL] Add identityless reduction test cases #1640

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SYCL/Reduction/reduction_big_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int test(queue &Q, T Identity) {
// Initialize.
BinaryOperation BOp;
T CorrectOut;
initInputData(InBuf, CorrectOut, Identity, BOp, NWorkItems);
initInputData(InBuf, CorrectOut, BOp, NWorkItems);

// Compute.
Q.submit([&](handler &CGH) {
Expand Down
20 changes: 11 additions & 9 deletions SYCL/Reduction/reduction_ctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

// This performs basic checks such as reduction creation, getIdentity() method,
// This performs basic checks such as reduction creation, identity methods,
// and the combine() method of the aux class 'reducer'.
// Note: This test relies on non-standard implementation details.

Expand All @@ -27,8 +27,9 @@ void test_reducer(Reduction &Redu, T A, T B) {
T ExpectedValue = BOp(A, B);
assert(ExpectedValue == detail::ReducerAccess{Reducer}.getElement(0) &&
"Wrong result of binary operation.");
assert(toBool(Reducer.identity() == Redu.getIdentity()) &&
"Failed identity() check().");
assert(
toBool(Reducer.identity() == Redu.getIdentityContainer().getIdentity()) &&
"Failed identity() check().");
}

template <typename T, typename Reduction, typename BinaryOperation>
Expand All @@ -41,8 +42,9 @@ void test_reducer(Reduction &Redu, T Identity, BinaryOperation BOp, T A, T B) {
assert(
toBool(ExpectedValue == detail::ReducerAccess{Reducer}.getElement(0)) &&
"Wrong result of binary operation.");
assert(toBool(Reducer.identity() == Redu.getIdentity()) &&
"Failed identity() check().");
assert(
toBool(Reducer.identity() == Redu.getIdentityContainer().getIdentity()) &&
"Failed identity() check().");
}

template <typename... Ts> class KernelNameGroup;
Expand All @@ -65,8 +67,8 @@ void testKnown(T Identity, BinaryOperation BOp, T A, T B) {
auto Redu = sycl::reduction(ReduBuf, CGH, BOp);
auto ReduUSM = sycl::reduction(ReduUSMPtr, BOp);

assert(toBool(Redu.getIdentity() == Identity) &&
toBool(ReduUSM.getIdentity() == Identity) &&
assert(toBool(Redu.getIdentityContainer().getIdentity() == Identity) &&
toBool(ReduUSM.getIdentityContainer().getIdentity() == Identity) &&
toBool(known_identity<BinaryOperation, T>::value == Identity) &&
"Failed getIdentity() check().");
test_reducer(Redu, A, B);
Expand Down Expand Up @@ -96,8 +98,8 @@ void testUnknown(T Identity, BinaryOperation BOp, T A, T B) {
ReduDWAcc(ReduBuf, CGH);
auto Redu = sycl::reduction(ReduBuf, CGH, Identity, BOp);
auto ReduUSM = sycl::reduction(ReduUSMPtr, Identity, BOp);
assert(toBool(Redu.getIdentity() == Identity) &&
toBool(ReduUSM.getIdentity() == Identity) &&
assert(toBool(Redu.getIdentityContainer().getIdentity() == Identity) &&
toBool(ReduUSM.getIdentityContainer().getIdentity() == Identity) &&
"Failed getIdentity() check().");
test_reducer(Redu, Identity, BOp, A, B);
test_reducer(ReduUSM, Identity, BOp, A, B);
Expand Down
2 changes: 1 addition & 1 deletion SYCL/Reduction/reduction_nd_N_vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct Red {
}

void init() {
initInputData(InBuf, CorrectOut, IdentityVal, BOp, NWorkItems);
initInputData(InBuf, CorrectOut, BOp, NWorkItems);
if (!PropList.template has_property<
property::reduction::initialize_to_identity>())
CorrectOut = BOp(CorrectOut, InitVal);
Expand Down
18 changes: 18 additions & 0 deletions SYCL/Reduction/reduction_nd_rw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ void tests(queue &Q, T Identity, T Init, BinaryOperation BOp, size_t WGSize,
NumErrors += test<Name>(Q, Identity, Init, BOp, NDRange);
}

template <typename Name, typename T, class BinaryOperation>
void tests(queue &Q, T Init, BinaryOperation BOp, size_t WGSize,
size_t NWItems) {
nd_range<1> NDRange(range<1>{NWItems}, range<1>{WGSize});
NumErrors += test<Name>(Q, Init, BOp, NDRange);
}

int main() {
queue Q;
printDeviceInfo(Q);
Expand Down Expand Up @@ -52,6 +59,17 @@ int main() {
// Check with CUSTOM type.
using CV = CustomVec<long long>;
tests<class D1, CV>(Q, CV(0), CV(-199), CustomVecPlus<long long>{}, 8, 256);
tests<class D2, CV>(Q, CV(-199), CustomVecPlus<long long>{}, 8, 256);

// Check non power-of-two work-group sizes without identity.
tests<class E1, int>(Q, 99, PlusWithoutIdentity<int>{}, 1, 7);
tests<class E2, int>(Q, -99, PlusWithoutIdentity<int>{}, 49, 49 * 5);

// Try some power-of-two work-group sizes without identity.
tests<class F1, int>(Q, 99, PlusWithoutIdentity<int>{}, 2, 32);
tests<class F2, int>(Q, 199, PlusWithoutIdentity<int>{}, 32, 32);
tests<class F3, int>(Q, 299, PlusWithoutIdentity<int>{}, 128, 256);
tests<class F4, int>(Q, 399, PlusWithoutIdentity<int>{}, 256, 256);

printFinalStatus(NumErrors);
return NumErrors;
Expand Down
55 changes: 36 additions & 19 deletions SYCL/Reduction/reduction_range_1d_rw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ using namespace sycl;

int NumErrors = 0;

template <typename Name, typename T, typename... ArgTys>
void tests(ArgTys &&...Args) {
NumErrors += test<Name, T>(std::forward<ArgTys>(Args)...);
}

int main() {
queue Q;
printDeviceInfo(Q);
Expand All @@ -20,29 +25,41 @@ int main() {

constexpr access::mode RW = access::mode::read_write;
// Fast-reduce and Fast-atomics. Try various range types/sizes.
test<class A1, int>(Q, 0, 99, std::plus<int>{}, range<1>(1));
test<class A2, int>(Q, 0, 99, std::plus<>{}, range<1>(2));
test<class A3, int>(Q, 0, 99, std::plus<>{}, range<1>(7));
test<class A4, int>(Q, 0, 99, std::plus<>{}, range<1>(64));
test<class A5, int>(Q, 0, 99, std::plus<>{}, range<1>(MaxWGSize * 2));
test<class A6, int>(Q, 0, 99, std::plus<>{}, range<1>(MaxWGSize * 2 + 5));
tests<class A1, int>(Q, 0, 99, std::plus<int>{}, range<1>(1));
tests<class A2, int>(Q, 0, 99, std::plus<>{}, range<1>(2));
tests<class A3, int>(Q, 0, 99, std::plus<>{}, range<1>(7));
tests<class A4, int>(Q, 0, 99, std::plus<>{}, range<1>(64));
tests<class A5, int>(Q, 0, 99, std::plus<>{}, range<1>(MaxWGSize * 2));
tests<class A6, int>(Q, 0, 99, std::plus<>{}, range<1>(MaxWGSize * 2 + 5));

// Try various types & ranges.
test<class B1, int>(Q, ~0, ~0, std::bit_and<>{}, range<1>(8));
test<class B2, int>(Q, 0, 0x12340000, std::bit_xor<>{}, range<1>(16));
test<class B3, int>(Q, 0, 0x3400, std::bit_or<>{}, range<1>(MaxWGSize * 3));
test<class B4, uint64_t>(Q, 1, 2, std::multiplies<>{}, range<1>(16));
test<class B5, float>(Q, 1, 3, std::multiplies<>{}, range<1>(11));
test<class B6, int>(Q, (std::numeric_limits<int>::max)(), -99,
ext::oneapi::minimum<>{}, range<1>(MaxWGSize * 2));
test<class B7, int>(Q, (std::numeric_limits<int>::min)(), 99,
ext::oneapi::maximum<>{}, range<1>(8));
tests<class B1, int>(Q, ~0, ~0, std::bit_and<>{}, range<1>(8));
tests<class B2, int>(Q, 0, 0x12340000, std::bit_xor<>{}, range<1>(16));
tests<class B3, int>(Q, 0, 0x3400, std::bit_or<>{}, range<1>(MaxWGSize * 3));
tests<class B4, uint64_t>(Q, 1, 2, std::multiplies<>{}, range<1>(16));
tests<class B5, float>(Q, 1, 3, std::multiplies<>{}, range<1>(11));
tests<class B6, int>(Q, (std::numeric_limits<int>::max)(), -99,
ext::oneapi::minimum<>{}, range<1>(MaxWGSize * 2));
tests<class B7, int>(Q, (std::numeric_limits<int>::min)(), 99,
ext::oneapi::maximum<>{}, range<1>(8));

// Check with CUSTOM type.
using CV = CustomVec<long long>;
test<class C1>(Q, CV(0), CV(99), CustomVecPlus<long long>{}, range<1>(256));
test<class C2>(Q, CV(0), CV(99), CustomVecPlus<long long>{},
range<1>(MaxWGSize * 3));
tests<class C1, CustomVec<long long>>(Q, 0, 99, CustomVecPlus<long long>{},
range<1>(256));
tests<class C2, CustomVec<long long>>(Q, 0, 99, CustomVecPlus<long long>{},
range<1>(MaxWGSize * 3));
tests<class C3, CustomVec<long long>>(Q, 99, CustomVecPlus<long long>{},
range<1>(72));

// Check with identityless operations.
tests<class D1, int>(Q, 99, PlusWithoutIdentity<int>{}, range<1>(1));
tests<class D2, int>(Q, 99, PlusWithoutIdentity<int>{}, range<1>(2));
tests<class D3, int>(Q, 99, PlusWithoutIdentity<int>{}, range<1>(7));
tests<class D4, int>(Q, 99, PlusWithoutIdentity<int>{}, range<1>(64));
tests<class D5, int>(Q, 99, PlusWithoutIdentity<int>{},
range<1>(MaxWGSize * 2));
tests<class D6, int>(Q, 99, PlusWithoutIdentity<int>{},
range<1>(MaxWGSize * 2 + 5));

printFinalStatus(NumErrors);
return NumErrors;
Expand Down
26 changes: 21 additions & 5 deletions SYCL/Reduction/reduction_range_2d_rw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ using namespace sycl;

int NumErrors = 0;

template <typename Name, typename T, class BinaryOperation>
void tests(queue &Q, T Identity, T Init, BinaryOperation BOp, range<2> Range) {
NumErrors += test<Name>(Q, Identity, Init, BOp, Range);
template <typename Name, typename T, typename... ArgTys>
void tests(ArgTys &&...Args) {
NumErrors += test<Name, T>(std::forward<ArgTys>(Args)...);
}

int main() {
Expand Down Expand Up @@ -46,8 +46,24 @@ int main() {
ext::oneapi::maximum<>{}, range<2>{3, 3});
tests<class B8, float>(Q, 1, 99, std::multiplies<>{}, range<2>{3, 3});

tests<class C1>(Q, CustomVec<long long>(0), CustomVec<long long>(99),
CustomVecPlus<long long>{}, range<2>{33, MaxWGSize});
tests<class C1, CustomVec<long long>>(Q, 0, 99, CustomVecPlus<long long>{},
range<2>{33, MaxWGSize});
tests<class C2, CustomVec<long long>>(Q, 99, CustomVecPlus<long long>{},
range<2>{33, MaxWGSize});

tests<class D1, int>(Q, 99, PlusWithoutIdentity<int>{}, range<2>{1, 1});
tests<class D2, int>(Q, 99, PlusWithoutIdentity<int>{}, range<2>{2, 2});
tests<class D3, int>(Q, 99, PlusWithoutIdentity<int>{}, range<2>{2, 3});
tests<class D4, int>(Q, 99, PlusWithoutIdentity<int>{},
range<2>{MaxWGSize, 1});
tests<class D5, int64_t>(Q, 99, PlusWithoutIdentity<int64_t>{},
range<2>{1, MaxWGSize});
tests<class D6, int64_t>(Q, 99, PlusWithoutIdentity<int64_t>{},
range<2>{2, MaxWGSize * 2});
tests<class D7, int64_t>(Q, 99, PlusWithoutIdentity<int64_t>{},
range<2>{MaxWGSize * 3, 7});
tests<class D8, int64_t>(Q, 99, PlusWithoutIdentity<int64_t>{},
range<2>{3, MaxWGSize * 3});

printFinalStatus(NumErrors);
return NumErrors;
Expand Down
10 changes: 5 additions & 5 deletions SYCL/Reduction/reduction_range_3d_dw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ using namespace sycl;

int NumErrors = 0;

template <typename Name, typename T, class BinaryOperation>
void tests(queue &Q, T Identity, T Init, BinaryOperation BOp, range<3> Range) {
NumErrors += test<Name>(Q, Identity, Init, BOp, Range, init_to_identity());
template <typename Name, typename T, typename... ArgTys>
void tests(ArgTys &&...Args) {
NumErrors += test<Name, T>(std::forward<ArgTys>(Args)..., init_to_identity());
}

int main() {
Expand Down Expand Up @@ -59,8 +59,8 @@ int main() {
ext::oneapi::maximum<>{}, range<3>{3, MaxWGSize, 3});
tests<class B8, float>(Q, 1, 99, std::multiplies<>{}, range<3>{3, 3, 5});

tests<class C1>(Q, CustomVec<long long>(0), CustomVec<long long>(99),
CustomVecPlus<long long>{}, range<3>{2, 33, MaxWGSize});
tests<class C1, CustomVec<long long>>(Q, 0, 99, CustomVecPlus<long long>{},
range<3>{2, 33, MaxWGSize});

printFinalStatus(NumErrors);
return NumErrors;
Expand Down
32 changes: 27 additions & 5 deletions SYCL/Reduction/reduction_range_3d_rw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ using namespace sycl;

int NumErrors = 0;

template <typename Name, typename T, class BinaryOperation>
void tests(queue &Q, T Identity, T Init, BinaryOperation BOp, range<3> Range) {
NumErrors += test<Name>(Q, Identity, Init, BOp, Range);
template <typename Name, typename T, typename... ArgTys>
void tests(ArgTys &&...Args) {
NumErrors += test<Name, T>(std::forward<ArgTys>(Args)...);
}

int main() {
Expand Down Expand Up @@ -58,8 +58,30 @@ int main() {
ext::oneapi::maximum<>{}, range<3>{3, MaxWGSize, 3});
tests<class B8, float>(Q, 1, 99, std::multiplies<>{}, range<3>{3, 3, 4});

tests<class C1>(Q, CustomVec<long long>(0), CustomVec<long long>(99),
CustomVecPlus<long long>{}, range<3>{2, 33, MaxWGSize});
tests<class C1, CustomVec<long long>>(Q, 0, 99, CustomVecPlus<long long>{},
range<3>{2, 33, MaxWGSize});
tests<class C2, CustomVec<long long>>(Q, 99, CustomVecPlus<long long>{},
range<3>{2, 33, MaxWGSize});

tests<class D1, int>(Q, 99, PlusWithoutIdentity<int>{}, range<3>{1, 1, 1});
tests<class D2, int>(Q, 99, PlusWithoutIdentity<int>{}, range<3>{2, 2, 2});
tests<class D3, int>(Q, 99, PlusWithoutIdentity<int>{}, range<3>{2, 3, 4});

/* Temporarily disabled
tests<class D4, int64_t>(Q, 99, PlusWithoutIdentity<int64_t>{},
range<3>{1, 1, MaxWGSize + 1});
tests<class D5, int64_t>(Q, 99, PlusWithoutIdentity<int64_t>{},
range<3>{1, MaxWGSize + 1, 1});
tests<class D6, int64_t>(Q, 99, PlusWithoutIdentity<int64_t>{},
range<3>{MaxWGSize + 1, 1, 1});
*/

tests<class D7, int64_t>(Q, 99, PlusWithoutIdentity<int64_t>{},
range<3>{2, 5, MaxWGSize * 2});
tests<class D8, int64_t>(Q, 99, PlusWithoutIdentity<int64_t>{},
range<3>{3, MaxWGSize * 3, 2});
tests<class D9, int64_t>(Q, 99, PlusWithoutIdentity<int64_t>{},
range<3>{MaxWGSize * 3, 8, 4});

printFinalStatus(NumErrors);
return NumErrors;
Expand Down
2 changes: 1 addition & 1 deletion SYCL/Reduction/reduction_range_N_vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct Red {
}

void init() {
initInputData(InBuf, CorrectOut, IdentityVal, BOp, NWorkItems);
initInputData(InBuf, CorrectOut, BOp, NWorkItems);
if (!PropList.template has_property<
property::reduction::initialize_to_identity>())
CorrectOut = BOp(CorrectOut, InitVal);
Expand Down
62 changes: 34 additions & 28 deletions SYCL/Reduction/reduction_range_lambda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

using namespace sycl;

int NumErrors = 0;

template <typename Name, typename T, typename... ArgTys>
void tests(ArgTys &&...Args) {
NumErrors += test<Name, T>(std::forward<ArgTys>(Args)...);
}

int main() {
queue Q;
printDeviceInfo(Q);
Expand All @@ -18,34 +25,33 @@ int main() {

auto LambdaSum = [](auto x, auto y) { return (x + y); };

int NumErrors = 0;

NumErrors += test<class A1, int>(Q, 0, 99, LambdaSum, range<1>{7});
NumErrors +=
test<class A2, int>(Q, 0, 99, LambdaSum, range<1>{7}, init_to_identity());

NumErrors +=
test<class A3, int>(Q, 0, 99, LambdaSum, range<1>{MaxWGSize + 1});
NumErrors += test<class A4, int>(Q, 0, 99, LambdaSum, range<1>{MaxWGSize + 1},
init_to_identity());

NumErrors += test<class B1, int>(Q, 0, 99, LambdaSum, range<2>{3, 4});
NumErrors += test<class B2, int>(Q, 0, 99, LambdaSum, range<2>{3, 4},
init_to_identity());

NumErrors +=
test<class B3, int>(Q, 0, 99, LambdaSum, range<2>{3, MaxWGSize + 1});
NumErrors += test<class B4, int>(
Q, 0, 99, LambdaSum, range<2>{3, MaxWGSize + 1}, init_to_identity());

NumErrors += test<class C1, int>(Q, 0, 99, LambdaSum, range<3>{2, 3, 4});
NumErrors += test<class C2, int>(Q, 0, 99, LambdaSum, range<3>{2, 3, 4},
init_to_identity());

NumErrors +=
test<class C3, int>(Q, 0, 99, LambdaSum, range<3>{2, 3, MaxWGSize + 1});
NumErrors += test<class C4, int>(
Q, 0, 99, LambdaSum, range<3>{2, 3, MaxWGSize + 1}, init_to_identity());
tests<class A1, int>(Q, 0, 99, LambdaSum, range<1>{7});
tests<class A2, int>(Q, 0, 99, LambdaSum, range<1>{7}, init_to_identity());
tests<class A3, int>(Q, 99, LambdaSum, range<1>{7});

tests<class A4, int>(Q, 0, 99, LambdaSum, range<1>{MaxWGSize + 1});
tests<class A5, int>(Q, 0, 99, LambdaSum, range<1>{MaxWGSize + 1},
init_to_identity());
tests<class A6, int>(Q, 99, LambdaSum, range<1>{MaxWGSize + 1});

tests<class B1, int>(Q, 0, 99, LambdaSum, range<2>{3, 4});
tests<class B2, int>(Q, 0, 99, LambdaSum, range<2>{3, 4}, init_to_identity());
tests<class B3, int>(Q, 99, LambdaSum, range<2>{3, 4});

tests<class B4, int>(Q, 0, 99, LambdaSum, range<2>{3, MaxWGSize + 1});
tests<class B5, int>(Q, 0, 99, LambdaSum, range<2>{3, MaxWGSize + 1},
init_to_identity());
tests<class B6, int>(Q, 99, LambdaSum, range<2>{3, MaxWGSize + 1});

tests<class C1, int>(Q, 0, 99, LambdaSum, range<3>{2, 3, 4});
tests<class C2, int>(Q, 0, 99, LambdaSum, range<3>{2, 3, 4},
init_to_identity());
tests<class C3, int>(Q, 99, LambdaSum, range<3>{2, 3, 4});

tests<class C4, int>(Q, 0, 99, LambdaSum, range<3>{2, 3, MaxWGSize + 1});
tests<class C5, int>(Q, 0, 99, LambdaSum, range<3>{2, 3, MaxWGSize + 1},
init_to_identity());
tests<class C6, int>(Q, 99, LambdaSum, range<3>{2, 3, MaxWGSize + 1});

printFinalStatus(NumErrors);
return NumErrors;
Expand Down
Loading