Skip to content

Commit bddfeb9

Browse files
authored
[SYCL][NFC] Do not use std::exclusive_scan/inclusive_scan/reduce in tests (#11529)
To adhere to [LLVM host compiler requirements](https://github.com/intel/llvm/blob/sycl/llvm/docs/GettingStarted.rst#host-c-toolchain-both-compiler-and-standard-library), this PR removes uses of std::exclusive_scan/inclusive_scan/reduce in some end to end tests, as they are not supported in GCC 7.4
1 parent e5d01d2 commit bddfeb9

File tree

8 files changed

+50
-80
lines changed

8 files changed

+50
-80
lines changed

sycl/test-e2e/GroupAlgorithm/SYCL2020/exclusive_scan.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %{build} -I . -o %t.out
22
// RUN: %{run} %t.out
33

4+
#include "../../helpers.hpp"
45
#include "support.h"
56
#include <algorithm>
67
#include <cassert>
@@ -14,23 +15,6 @@ using namespace sycl;
1415
template <class SpecializationKernelName, int TestNumber>
1516
class exclusive_scan_kernel;
1617

17-
// std::exclusive_scan isn't implemented yet, so use serial implementation
18-
// instead
19-
namespace emu {
20-
template <typename InputIterator, typename OutputIterator,
21-
class BinaryOperation, typename T>
22-
OutputIterator exclusive_scan(InputIterator first, InputIterator last,
23-
OutputIterator result, T init,
24-
BinaryOperation binary_op) {
25-
T partial = init;
26-
for (InputIterator it = first; it != last; ++it) {
27-
*(result++) = partial;
28-
partial = binary_op(partial, *it);
29-
}
30-
return result;
31-
}
32-
} // namespace emu
33-
3418
template <typename SpecializationKernelName, typename InputContainer,
3519
typename OutputContainer, class BinaryOperation>
3620
void test(queue q, InputContainer input, OutputContainer output,

sycl/test-e2e/GroupAlgorithm/SYCL2020/inclusive_scan.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %{build} -I . -o %t.out
22
// RUN: %{run} %t.out
33

4+
#include "../../helpers.hpp"
45
#include "support.h"
56
#include <algorithm>
67
#include <cassert>
@@ -14,23 +15,6 @@ using namespace sycl;
1415
template <class SpecializationKernelName, int TestNumber>
1516
class inclusive_scan_kernel;
1617

17-
// std::inclusive_scan isn't implemented yet, so use serial implementation
18-
// instead
19-
namespace emu {
20-
template <typename InputIterator, typename OutputIterator,
21-
class BinaryOperation, typename T>
22-
OutputIterator inclusive_scan(InputIterator first, InputIterator last,
23-
OutputIterator result, BinaryOperation binary_op,
24-
T init) {
25-
T partial = init;
26-
for (InputIterator it = first; it != last; ++it) {
27-
partial = binary_op(partial, *it);
28-
*(result++) = partial;
29-
}
30-
return result;
31-
}
32-
} // namespace emu
33-
3418
template <typename SpecializationKernelName, typename InputContainer,
3519
typename OutputContainer, class BinaryOperation>
3620
void test(queue q, InputContainer input, OutputContainer output,

sycl/test-e2e/GroupAlgorithm/different_types.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %{build} -fsycl-device-code-split=per_kernel -I . -o %t.out
22
// RUN: %{run} %t.out
33

4+
#include "../helpers.hpp"
45
#include <complex>
56
#include <cstdint>
67
#include <limits>
@@ -46,7 +47,7 @@ void test(queue &q, const InputContainer &input, InitT init,
4647
host_accessor a_reduce_out(b_reduce_out);
4748
host_accessor a_scan_out(b_scan_out);
4849

49-
const auto r = std::reduce(input.begin(), input.end(), init, binary_op);
50+
const auto r = std::accumulate(input.begin(), input.end(), init, binary_op);
5051
assert(r == a_reduce_out[0]);
5152
assert(r == a_reduce_out[1]);
5253
assert(r == a_reduce_out[2]);
@@ -55,14 +56,14 @@ void test(queue &q, const InputContainer &input, InitT init,
5556
return std::equal(C1.begin(), C1.end(), C2.begin());
5657
};
5758
std::vector<OutT> escan_ref(N);
58-
std::exclusive_scan(input.begin(), input.end(), escan_ref.begin(), init,
59+
emu::exclusive_scan(input.begin(), input.end(), escan_ref.begin(), init,
5960
binary_op);
6061
assert(equal(escan_ref, span(&a_scan_out[0][0], N)));
6162
assert(equal(escan_ref, span(&a_scan_out[1][0], N)));
6263
assert(equal(escan_ref, span(&a_scan_out[2][0], N)));
6364

6465
std::vector<OutT> iscan_ref(N);
65-
std::inclusive_scan(input.begin(), input.end(), iscan_ref.begin(), binary_op,
66+
emu::inclusive_scan(input.begin(), input.end(), iscan_ref.begin(), binary_op,
6667
init);
6768
assert(equal(iscan_ref, span(&a_scan_out[3][0], N)));
6869
assert(equal(iscan_ref, span(&a_scan_out[4][0], N)));

sycl/test-e2e/GroupAlgorithm/exclusive_scan_sycl2020.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %{build} -fsycl-device-code-split=per_kernel -I . -o %t.out
33
// RUN: %{run} %t.out
44

5+
#include "../helpers.hpp"
56
#include "support.h"
67
#include <algorithm>
78
#include <cassert>
@@ -16,24 +17,6 @@ using namespace sycl;
1617
template <class SpecializationKernelName, int TestNumber>
1718
class exclusive_scan_kernel;
1819

19-
// std::exclusive_scan isn't implemented yet, so use serial implementation
20-
// instead
21-
// TODO: use std::exclusive_scan when it will be supported
22-
namespace emu {
23-
template <typename InputIterator, typename OutputIterator,
24-
class BinaryOperation, typename T>
25-
OutputIterator exclusive_scan(InputIterator first, InputIterator last,
26-
OutputIterator result, T init,
27-
BinaryOperation binary_op) {
28-
T partial = init;
29-
for (InputIterator it = first; it != last; ++it) {
30-
*(result++) = partial;
31-
partial = binary_op(partial, *it);
32-
}
33-
return result;
34-
}
35-
} // namespace emu
36-
3720
queue q;
3821

3922
template <typename SpecializationKernelName, typename InputContainer,

sycl/test-e2e/GroupAlgorithm/inclusive_scan_sycl2020.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %{build} -fsycl-device-code-split=per_kernel -I . -o %t.out
33
// RUN: %{run} %t.out
44

5+
#include "../helpers.hpp"
56
#include "support.h"
67
#include <algorithm>
78
#include <cassert>
@@ -18,24 +19,6 @@ queue q;
1819
template <class SpecializationKernelName, int TestNumber>
1920
class inclusive_scan_kernel;
2021

21-
// std::inclusive_scan isn't implemented yet, so use serial implementation
22-
// instead
23-
// TODO: use std::inclusive_scan when it will be supported
24-
namespace emu {
25-
template <typename InputIterator, typename OutputIterator,
26-
class BinaryOperation, typename T>
27-
OutputIterator inclusive_scan(InputIterator first, InputIterator last,
28-
OutputIterator result, BinaryOperation binary_op,
29-
T init) {
30-
T partial = init;
31-
for (InputIterator it = first; it != last; ++it) {
32-
partial = binary_op(partial, *it);
33-
*(result++) = partial;
34-
}
35-
return result;
36-
}
37-
} // namespace emu
38-
3922
template <typename SpecializationKernelName, typename InputContainer,
4023
class BinaryOperation>
4124
void test(const InputContainer &input, BinaryOperation binary_op,

sycl/test-e2e/Regression/exclusive-scan-char-short.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// This test ensures the result computed by exclusive_scan_over_group
55
// for the first work item when given a short or char argument with
66
// the maximum or minimum operator is computed correctly.
7+
#include "../helpers.hpp"
78
#include <numeric>
89
#include <sycl/sycl.hpp>
910

@@ -18,7 +19,7 @@ template <typename T, typename OpT> void test() {
1819
auto *p = malloc_shared<T>(1, q);
1920
*p = 0;
2021
T ref;
21-
std::exclusive_scan(p, p + 1, &ref, init, op);
22+
emu::exclusive_scan(p, p + 1, &ref, init, op);
2223
range r(1);
2324
q.parallel_for(nd_range(r, r), [=](nd_item<1> it) {
2425
auto g = it.get_group();

sycl/test-e2e/UserDefinedReductions/user_defined_reductions.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,16 @@ void test(queue q, InputContainer input, OutputContainer output,
145145
});
146146
q.wait();
147147
}
148-
assert(output[0] == std::reduce(input.begin(), input.begin() + workgroup_size,
149-
identity, binary_op));
150-
assert(output[1] == std::reduce(input.begin(), input.begin() + workgroup_size,
151-
init, binary_op));
148+
assert(output[0] == std::accumulate(input.begin(),
149+
input.begin() + workgroup_size, identity,
150+
binary_op));
151+
assert(output[1] == std::accumulate(input.begin(),
152+
input.begin() + workgroup_size, init,
153+
binary_op));
152154
assert(output[2] ==
153-
std::reduce(input.begin(), input.end(), identity, binary_op));
154-
assert(output[3] == std::reduce(input.begin(), input.end(), init, binary_op));
155+
std::accumulate(input.begin(), input.end(), identity, binary_op));
156+
assert(output[3] ==
157+
std::accumulate(input.begin(), input.end(), init, binary_op));
155158
}
156159

157160
int main() {

sycl/test-e2e/helpers.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,34 @@ class TestQueue : public sycl::queue {
7171

7272
~TestQueue() { wait_and_throw(); }
7373
};
74+
75+
namespace emu {
76+
77+
// std::exclusive_scan/inclusive_scan are not supported GCC 7.4,
78+
// so use our own implementations
79+
template <typename InputIterator, typename OutputIterator,
80+
class BinaryOperation, typename T>
81+
OutputIterator exclusive_scan(InputIterator first, InputIterator last,
82+
OutputIterator result, T init,
83+
BinaryOperation binary_op) {
84+
T partial = init;
85+
for (InputIterator it = first; it != last; ++it) {
86+
*(result++) = partial;
87+
partial = binary_op(partial, *it);
88+
}
89+
return result;
90+
}
91+
92+
template <typename InputIterator, typename OutputIterator,
93+
class BinaryOperation, typename T>
94+
OutputIterator inclusive_scan(InputIterator first, InputIterator last,
95+
OutputIterator result, BinaryOperation binary_op,
96+
T init) {
97+
T partial = init;
98+
for (InputIterator it = first; it != last; ++it) {
99+
partial = binary_op(partial, *it);
100+
*(result++) = partial;
101+
}
102+
return result;
103+
}
104+
} // namespace emu

0 commit comments

Comments
 (0)