|
| 1 | +// RUN: %clangxx -fsycl -fsyntax-only %s |
| 2 | + |
| 3 | +// Tests reduction parallel_for can use SYCL 2020 range deduction guides. |
| 4 | + |
| 5 | +#include <sycl/sycl.hpp> |
| 6 | + |
| 7 | +template <class T> struct PlusWithoutIdentity { |
| 8 | + T operator()(const T &A, const T &B) const { return A + B; } |
| 9 | +}; |
| 10 | + |
| 11 | +int main() { |
| 12 | + sycl::queue Q; |
| 13 | + |
| 14 | + int *ScalarMem = sycl::malloc_shared<int>(1, Q); |
| 15 | + int *SpanMem = sycl::malloc_shared<int>(8, Q); |
| 16 | + auto ScalarRed1 = sycl::reduction(ScalarMem, std::plus<int>{}); |
| 17 | + auto ScalarRed2 = sycl::reduction(ScalarMem, PlusWithoutIdentity<int>{}); |
| 18 | + auto SpanRed1 = |
| 19 | + sycl::reduction(sycl::span<int, 8>{SpanMem, 8}, std::plus<int>{}); |
| 20 | + auto SpanRed2 = sycl::reduction(sycl::span<int, 8>{SpanMem, 8}, |
| 21 | + PlusWithoutIdentity<int>{}); |
| 22 | + |
| 23 | + // Shortcut and range<1> deduction from integer. |
| 24 | + Q.parallel_for(1024, ScalarRed1, [=](sycl::item<1>, auto &) {}); |
| 25 | + Q.parallel_for(1024, SpanRed1, [=](sycl::item<1>, auto &) {}); |
| 26 | + Q.parallel_for(1024, ScalarRed1, ScalarRed2, |
| 27 | + [=](sycl::item<1>, auto &, auto &) {}); |
| 28 | + Q.parallel_for(1024, SpanRed1, SpanRed2, |
| 29 | + [=](sycl::item<1>, auto &, auto &) {}); |
| 30 | + Q.parallel_for(1024, ScalarRed1, SpanRed1, ScalarRed2, SpanRed2, |
| 31 | + [=](sycl::item<1>, auto &, auto &, auto &, auto &) {}); |
| 32 | + |
| 33 | + // Shortcut and range<1> deduction from initializer. |
| 34 | + Q.parallel_for({1024}, ScalarRed1, [=](sycl::item<1>, auto &) {}); |
| 35 | + Q.parallel_for({1024}, SpanRed1, [=](sycl::item<1>, auto &) {}); |
| 36 | + Q.parallel_for({1024}, ScalarRed1, ScalarRed2, |
| 37 | + [=](sycl::item<1>, auto &, auto &) {}); |
| 38 | + Q.parallel_for({1024}, SpanRed1, SpanRed2, |
| 39 | + [=](sycl::item<1>, auto &, auto &) {}); |
| 40 | + Q.parallel_for({1024}, ScalarRed1, SpanRed1, ScalarRed2, SpanRed2, |
| 41 | + [=](sycl::item<1>, auto &, auto &, auto &, auto &) {}); |
| 42 | + |
| 43 | + // Shortcut and range<2> deduction from initializer. |
| 44 | + Q.parallel_for({1024, 1024}, ScalarRed1, [=](sycl::item<2>, auto &) {}); |
| 45 | + Q.parallel_for({1024, 1024}, SpanRed1, [=](sycl::item<2>, auto &) {}); |
| 46 | + Q.parallel_for({1024, 1024}, ScalarRed1, ScalarRed2, |
| 47 | + [=](sycl::item<2>, auto &, auto &) {}); |
| 48 | + Q.parallel_for({1024, 1024}, SpanRed1, SpanRed2, |
| 49 | + [=](sycl::item<2>, auto &, auto &) {}); |
| 50 | + Q.parallel_for({1024, 1024}, ScalarRed1, SpanRed1, ScalarRed2, SpanRed2, |
| 51 | + [=](sycl::item<2>, auto &, auto &, auto &, auto &) {}); |
| 52 | + |
| 53 | + // Shortcut and range<3> deduction from initializer. |
| 54 | + Q.parallel_for({1024, 1024, 1024}, ScalarRed1, [=](sycl::item<3>, auto &) {}); |
| 55 | + Q.parallel_for({1024, 1024, 1024}, SpanRed1, [=](sycl::item<3>, auto &) {}); |
| 56 | + Q.parallel_for({1024, 1024, 1024}, ScalarRed1, ScalarRed2, |
| 57 | + [=](sycl::item<3>, auto &, auto &) {}); |
| 58 | + Q.parallel_for({1024, 1024, 1024}, SpanRed1, SpanRed2, |
| 59 | + [=](sycl::item<3>, auto &, auto &) {}); |
| 60 | + Q.parallel_for({1024, 1024, 1024}, ScalarRed1, SpanRed1, ScalarRed2, SpanRed2, |
| 61 | + [=](sycl::item<3>, auto &, auto &, auto &, auto &) {}); |
| 62 | + |
| 63 | + // Submission and range<1> deduction from integer. |
| 64 | + Q.submit([&](sycl::handler &CGH) { |
| 65 | + CGH.parallel_for(1024, ScalarRed1, [=](sycl::item<1>, auto &) {}); |
| 66 | + }); |
| 67 | + Q.submit([&](sycl::handler &CGH) { |
| 68 | + CGH.parallel_for(1024, SpanRed1, [=](sycl::item<1>, auto &) {}); |
| 69 | + }); |
| 70 | + Q.submit([&](sycl::handler &CGH) { |
| 71 | + CGH.parallel_for(1024, ScalarRed1, ScalarRed2, |
| 72 | + [=](sycl::item<1>, auto &, auto &) {}); |
| 73 | + }); |
| 74 | + Q.submit([&](sycl::handler &CGH) { |
| 75 | + CGH.parallel_for(1024, SpanRed1, SpanRed2, |
| 76 | + [=](sycl::item<1>, auto &, auto &) {}); |
| 77 | + }); |
| 78 | + Q.submit([&](sycl::handler &CGH) { |
| 79 | + CGH.parallel_for(1024, ScalarRed1, SpanRed1, ScalarRed2, SpanRed2, |
| 80 | + [=](sycl::item<1>, auto &, auto &, auto &, auto &) {}); |
| 81 | + }); |
| 82 | + |
| 83 | + // Submission and range<1> deduction from initializer. |
| 84 | + Q.submit([&](sycl::handler &CGH) { |
| 85 | + CGH.parallel_for({1024}, ScalarRed1, [=](sycl::item<1>, auto &) {}); |
| 86 | + }); |
| 87 | + Q.submit([&](sycl::handler &CGH) { |
| 88 | + CGH.parallel_for({1024}, SpanRed1, [=](sycl::item<1>, auto &) {}); |
| 89 | + }); |
| 90 | + Q.submit([&](sycl::handler &CGH) { |
| 91 | + CGH.parallel_for({1024}, ScalarRed1, ScalarRed2, |
| 92 | + [=](sycl::item<1>, auto &, auto &) {}); |
| 93 | + }); |
| 94 | + Q.submit([&](sycl::handler &CGH) { |
| 95 | + CGH.parallel_for({1024}, SpanRed1, SpanRed2, |
| 96 | + [=](sycl::item<1>, auto &, auto &) {}); |
| 97 | + }); |
| 98 | + Q.submit([&](sycl::handler &CGH) { |
| 99 | + CGH.parallel_for({1024}, ScalarRed1, SpanRed1, ScalarRed2, SpanRed2, |
| 100 | + [=](sycl::item<1>, auto &, auto &, auto &, auto &) {}); |
| 101 | + }); |
| 102 | + |
| 103 | + // Submission and range<2> deduction from initializer. |
| 104 | + Q.submit([&](sycl::handler &CGH) { |
| 105 | + CGH.parallel_for({1024, 1024}, ScalarRed1, [=](sycl::item<2>, auto &) {}); |
| 106 | + }); |
| 107 | + Q.submit([&](sycl::handler &CGH) { |
| 108 | + CGH.parallel_for({1024, 1024}, SpanRed1, [=](sycl::item<2>, auto &) {}); |
| 109 | + }); |
| 110 | + Q.submit([&](sycl::handler &CGH) { |
| 111 | + CGH.parallel_for({1024, 1024}, ScalarRed1, ScalarRed2, |
| 112 | + [=](sycl::item<2>, auto &, auto &) {}); |
| 113 | + }); |
| 114 | + Q.submit([&](sycl::handler &CGH) { |
| 115 | + CGH.parallel_for({1024, 1024}, SpanRed1, SpanRed2, |
| 116 | + [=](sycl::item<2>, auto &, auto &) {}); |
| 117 | + }); |
| 118 | + Q.submit([&](sycl::handler &CGH) { |
| 119 | + CGH.parallel_for({1024, 1024}, ScalarRed1, SpanRed1, ScalarRed2, SpanRed2, |
| 120 | + [=](sycl::item<2>, auto &, auto &, auto &, auto &) {}); |
| 121 | + }); |
| 122 | + |
| 123 | + // Submission and range<3> deduction from initializer. |
| 124 | + Q.submit([&](sycl::handler &CGH) { |
| 125 | + CGH.parallel_for({1024, 1024, 1024}, ScalarRed1, |
| 126 | + [=](sycl::item<3>, auto &) {}); |
| 127 | + }); |
| 128 | + Q.submit([&](sycl::handler &CGH) { |
| 129 | + CGH.parallel_for({1024, 1024, 1024}, SpanRed1, |
| 130 | + [=](sycl::item<3>, auto &) {}); |
| 131 | + }); |
| 132 | + Q.submit([&](sycl::handler &CGH) { |
| 133 | + CGH.parallel_for({1024, 1024, 1024}, ScalarRed1, ScalarRed2, |
| 134 | + [=](sycl::item<3>, auto &, auto &) {}); |
| 135 | + }); |
| 136 | + Q.submit([&](sycl::handler &CGH) { |
| 137 | + CGH.parallel_for({1024, 1024, 1024}, SpanRed1, SpanRed2, |
| 138 | + [=](sycl::item<3>, auto &, auto &) {}); |
| 139 | + }); |
| 140 | + Q.submit([&](sycl::handler &CGH) { |
| 141 | + CGH.parallel_for({1024, 1024, 1024}, ScalarRed1, SpanRed1, ScalarRed2, |
| 142 | + SpanRed2, |
| 143 | + [=](sycl::item<3>, auto &, auto &, auto &, auto &) {}); |
| 144 | + }); |
| 145 | + |
| 146 | + return 0; |
| 147 | +} |
0 commit comments