Skip to content

Commit f7df423

Browse files
committed
Add test for kernel fusion with math function
Signed-off-by: Lukas Sommer <[email protected]>
1 parent a8afe1d commit f7df423

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -fsycl-embed-ir %s -o %t.out
2+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
3+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
4+
// UNSUPPORTED: hip
5+
// REQUIRES: fusion
6+
7+
// Test fusion of a kernel using a math function.
8+
9+
#include <sycl/sycl.hpp>
10+
11+
using namespace sycl;
12+
13+
int main() {
14+
constexpr size_t dataSize = 512;
15+
float in1[dataSize], in2[dataSize], tmp[dataSize], out[dataSize];
16+
17+
for (size_t i = 0; i < dataSize; ++i) {
18+
in1[i] = 1;
19+
in2[i] = i * 3;
20+
tmp[i] = -1;
21+
out[i] = -1;
22+
}
23+
24+
queue q{ext::codeplay::experimental::property::queue::enable_fusion{}};
25+
26+
{
27+
buffer<float> bIn1{in1, range{dataSize}};
28+
buffer<float> bIn2{in2, range{dataSize}};
29+
buffer<float> bTmp{tmp, range{dataSize}};
30+
buffer<float> bOut{out, range{dataSize}};
31+
32+
ext::codeplay::experimental::fusion_wrapper fw{q};
33+
fw.start_fusion();
34+
35+
assert(fw.is_in_fusion_mode() && "Queue should be in fusion mode");
36+
37+
q.submit([&](handler &cgh) {
38+
auto accIn1 = bIn1.get_access(cgh);
39+
auto accTmp = bTmp.get_access(cgh);
40+
cgh.parallel_for<class KernelOne>(
41+
dataSize, [=](id<1> i) { accTmp[i] = sycl::cospi(accIn1[i]); });
42+
});
43+
44+
q.submit([&](handler &cgh) {
45+
auto accTmp = bTmp.get_access(cgh);
46+
auto accIn2 = bIn2.get_access(cgh);
47+
auto accOut = bOut.get_access(cgh);
48+
cgh.parallel_for<class KernelTwo>(
49+
dataSize, [=](id<1> i) { accOut[i] = accTmp[i] * accIn2[i]; });
50+
});
51+
52+
fw.complete_fusion({ext::codeplay::experimental::property::no_barriers{}});
53+
54+
assert(!fw.is_in_fusion_mode() &&
55+
"Queue should not be in fusion mode anymore");
56+
}
57+
58+
// Check the results
59+
for (size_t i = 0; i < dataSize; ++i) {
60+
assert(out[i] == (-1.0 * static_cast<float>(i*3)) && "Computation error");
61+
}
62+
63+
return 0;
64+
}

0 commit comments

Comments
 (0)