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