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

Commit 4dd294a

Browse files
authored
[SYCL][Fusion] Test non-internalization if the pointer is stored (#1600)
Test internalization is not performed when the argument to be internalized is stored. The new `abort_internalization_stored_ptr.cpp` passes an `accessor` holding the input pointer to a `noinline` function, thus forcing the input pointer argument to be stored in an `accessor` struct being passed to such function. --------- Signed-off-by: Victor Perez <[email protected]>
1 parent de7dc0a commit 4dd294a

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// RUN: env SYCL_RT_WARNING_LEVEL=1 %CPU_RUN_PLACEHOLDER %t.out 2>&1\
3+
// RUN: %CPU_CHECK_PLACEHOLDER --implicit-check-not "Computation error" --implicit-check-not "Internalized"
4+
// RUN: env SYCL_RT_WARNING_LEVEL=1 %GPU_RUN_PLACEHOLDER %t.out 2>&1\
5+
// RUN: %GPU_CHECK_PLACEHOLDER --implicit-check-not "Computation error" --implicit-check-not "Internalized"
6+
// UNSUPPORTED: cuda || hip
7+
// REQUIRES: fusion
8+
9+
// Test pointers being stored are not internalized.
10+
11+
// CHECK: Unable to perform all promotions for function {{.*}}. Detailed information:
12+
// CHECK-NEXT: Failed to promote argument 0 of function {{.*}}: It is not safe to promote values being stored to another pointer
13+
14+
#include <sycl/sycl.hpp>
15+
16+
#include <array>
17+
18+
using namespace sycl;
19+
20+
// Pointer will be stored in an accessor struct before being passed here.
21+
__attribute__((noinline)) void
22+
kernel_one_impl(accessor<int, 1, access::mode::read_write> acc, std::size_t i,
23+
int lhs, int rhs) {
24+
acc[i] = lhs + rhs;
25+
}
26+
27+
int main() {
28+
constexpr size_t dataSize = 512;
29+
30+
std::array<int, dataSize> in1, in2, in3, tmp, out;
31+
32+
for (size_t i = 0; i < dataSize; ++i) {
33+
in1[i] = i * 2;
34+
in2[i] = i * 3;
35+
in3[i] = i * 4;
36+
tmp[i] = -1;
37+
out[i] = -1;
38+
}
39+
40+
queue q{ext::codeplay::experimental::property::queue::enable_fusion{}};
41+
42+
{
43+
buffer<int> bIn1{in1};
44+
buffer<int> bIn2{in2};
45+
buffer<int> bIn3{in3};
46+
buffer<int> bTmp{tmp};
47+
buffer<int> bOut{out};
48+
49+
ext::codeplay::experimental::fusion_wrapper fw{q};
50+
fw.start_fusion();
51+
52+
assert(fw.is_in_fusion_mode() && "Queue should be in fusion mode");
53+
54+
q.submit([&](handler &cgh) {
55+
auto accIn1 = bIn1.get_access(cgh);
56+
auto accIn2 = bIn2.get_access(cgh);
57+
auto accTmp = bTmp.get_access(
58+
cgh, sycl::ext::codeplay::experimental::property::promote_private{});
59+
cgh.parallel_for<class KernelOne>(dataSize, [=](id<1> i) {
60+
kernel_one_impl(accTmp, i, accIn1[i], accIn2[i]);
61+
});
62+
});
63+
64+
q.submit([&](handler &cgh) {
65+
auto accTmp = bTmp.get_access(
66+
cgh, sycl::ext::codeplay::experimental::property::promote_private{});
67+
auto accIn3 = bIn3.get_access(cgh);
68+
auto accOut = bOut.get_access(cgh);
69+
cgh.parallel_for<class KernelTwo>(
70+
dataSize, [=](id<1> i) { accOut[i] = accTmp[i] * accIn3[i]; });
71+
});
72+
73+
fw.complete_fusion({ext::codeplay::experimental::property::no_barriers{}});
74+
75+
assert(!fw.is_in_fusion_mode() &&
76+
"Queue should not be in fusion mode anymore");
77+
}
78+
79+
// Check the results
80+
for (size_t i = 0; i < dataSize; ++i) {
81+
assert(out[i] == (20 * i * i) && "Computation error");
82+
assert(tmp[i] == (5 * i) && "Internalized");
83+
}
84+
}

0 commit comments

Comments
 (0)