|
| 1 | +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out |
| 2 | +// RUN: env SYCL_ENABLE_FUSION_CACHING=0 SYCL_RT_WARNING_LEVEL=1 %CPU_RUN_PLACEHOLDER %t.out 2>&1\ |
| 3 | +// RUN: %CPU_CHECK_PLACEHOLDER |
| 4 | +// RUN: env SYCL_ENABLE_FUSION_CACHING=0 SYCL_RT_WARNING_LEVEL=1 %GPU_RUN_PLACEHOLDER %t.out 2>&1\ |
| 5 | +// RUN: %GPU_CHECK_PLACEHOLDER |
| 6 | +// UNSUPPORTED: cuda || hip |
| 7 | +// REQUIRES: fusion |
| 8 | + |
| 9 | +// Test incomplete internalization: Different scenarios causing the JIT compiler |
| 10 | +// to abort internalization due to target or parameter mismatch. Also check that |
| 11 | +// warnings are printed when SYCL_RT_WARNING_LEVEL=1. |
| 12 | + |
| 13 | +#include <sycl/sycl.hpp> |
| 14 | + |
| 15 | +using namespace sycl; |
| 16 | + |
| 17 | +constexpr size_t dataSize = 512; |
| 18 | + |
| 19 | +enum class Internalization { None, Local, Private }; |
| 20 | + |
| 21 | +void performFusion(queue &q, Internalization intKernel1, |
| 22 | + size_t localSizeKernel1, Internalization intKernel2, |
| 23 | + size_t localSizeKernel2, |
| 24 | + bool expectInternalization = false) { |
| 25 | + int in[dataSize], tmp[dataSize], out[dataSize]; |
| 26 | + for (size_t i = 0; i < dataSize; ++i) { |
| 27 | + in[i] = i; |
| 28 | + tmp[i] = -1; |
| 29 | + out[i] = -1; |
| 30 | + } |
| 31 | + { |
| 32 | + buffer<int> bIn{in, range{dataSize}}; |
| 33 | + buffer<int> bTmp{tmp, range{dataSize}}; |
| 34 | + buffer<int> bOut{out, range{dataSize}}; |
| 35 | + |
| 36 | + ext::codeplay::experimental::fusion_wrapper fw{q}; |
| 37 | + fw.start_fusion(); |
| 38 | + |
| 39 | + assert(fw.is_in_fusion_mode() && "Queue should be in fusion mode"); |
| 40 | + |
| 41 | + q.submit([&](handler &cgh) { |
| 42 | + auto accIn = bIn.get_access(cgh); |
| 43 | + property_list properties{}; |
| 44 | + if (intKernel1 == Internalization::Private) { |
| 45 | + properties = { |
| 46 | + sycl::ext::codeplay::experimental::property::promote_private{}}; |
| 47 | + } else if (intKernel1 == Internalization::Local) { |
| 48 | + properties = { |
| 49 | + sycl::ext::codeplay::experimental::property::promote_local{}}; |
| 50 | + } |
| 51 | + accessor<int> accTmp = bTmp.get_access(cgh, properties); |
| 52 | + |
| 53 | + if (localSizeKernel1 > 0) { |
| 54 | + cgh.parallel_for<class Kernel1>( |
| 55 | + nd_range<1>{{dataSize}, {localSizeKernel1}}, |
| 56 | + [=](id<1> i) { accTmp[i] = accIn[i] + 5; }); |
| 57 | + } else { |
| 58 | + cgh.parallel_for<class KernelOne>( |
| 59 | + dataSize, [=](id<1> i) { accTmp[i] = accIn[i] + 5; }); |
| 60 | + } |
| 61 | + }); |
| 62 | + |
| 63 | + q.submit([&](handler &cgh) { |
| 64 | + property_list properties{}; |
| 65 | + if (intKernel2 == Internalization::Private) { |
| 66 | + properties = { |
| 67 | + sycl::ext::codeplay::experimental::property::promote_private{}}; |
| 68 | + } else if (intKernel2 == Internalization::Local) { |
| 69 | + properties = { |
| 70 | + sycl::ext::codeplay::experimental::property::promote_local{}}; |
| 71 | + } |
| 72 | + accessor<int> accTmp = bTmp.get_access(cgh, properties); |
| 73 | + auto accOut = bOut.get_access(cgh); |
| 74 | + if (localSizeKernel2 > 0) { |
| 75 | + cgh.parallel_for<class Kernel2>( |
| 76 | + nd_range<1>{{dataSize}, {localSizeKernel2}}, |
| 77 | + [=](id<1> i) { accOut[i] = accTmp[i] * 2; }); |
| 78 | + } else { |
| 79 | + cgh.parallel_for<class KernelTwo>( |
| 80 | + dataSize, [=](id<1> i) { accOut[i] = accTmp[i] * 2; }); |
| 81 | + } |
| 82 | + }); |
| 83 | + |
| 84 | + fw.complete_fusion({ext::codeplay::experimental::property::no_barriers{}}); |
| 85 | + |
| 86 | + assert(!fw.is_in_fusion_mode() && |
| 87 | + "Queue should not be in fusion mode anymore"); |
| 88 | + } |
| 89 | + |
| 90 | + // Check the results |
| 91 | + size_t numErrors = 0; |
| 92 | + size_t numInternalized = 0; |
| 93 | + for (size_t i = 0; i < dataSize; ++i) { |
| 94 | + if (out[i] != ((i + 5) * 2)) { |
| 95 | + ++numErrors; |
| 96 | + } |
| 97 | + if (tmp[i] == -1) { |
| 98 | + ++numInternalized; |
| 99 | + } |
| 100 | + } |
| 101 | + if (numErrors) { |
| 102 | + std::cout << "COMPUTATION ERROR\n"; |
| 103 | + return; |
| 104 | + } |
| 105 | + if (!expectInternalization && numInternalized) { |
| 106 | + std::cout << "WRONG INTERNALIZATION\n"; |
| 107 | + return; |
| 108 | + } |
| 109 | + std::cout << "COMPUTATION OK\n"; |
| 110 | +} |
| 111 | + |
| 112 | +int main() { |
| 113 | + queue q{ext::codeplay::experimental::property::queue::enable_fusion{}}; |
| 114 | + |
| 115 | + // Scenario: One accessor without internalization, one with local |
| 116 | + // internalization. Should fall back to no internalization and print a |
| 117 | + // warning. |
| 118 | + std::cout << "None, Local(0)\n"; |
| 119 | + performFusion(q, Internalization::None, 0, Internalization::Local, 0); |
| 120 | + // CHECK: None, Local(0) |
| 121 | + // CHECK-NEXT: WARNING: Not performing specified local promotion, due to previous mismatch or because previous accessor specified no promotion |
| 122 | + // CHECK-NEXT: COMPUTATION OK |
| 123 | + |
| 124 | + // Scenario: One accessor without internalization, one with private |
| 125 | + // internalization. Should fall back to no internalization and print a |
| 126 | + // warning. |
| 127 | + std::cout << "None, Private\n"; |
| 128 | + performFusion(q, Internalization::None, 0, Internalization::Private, 0); |
| 129 | + // CHECK-NEXT: None, Private |
| 130 | + // CHECK-NEXT: WARNING: Not performing specified private promotion, due to previous mismatch or because previous accessor specified no promotion |
| 131 | + // CHECK-NEXT: COMPUTATION OK |
| 132 | + |
| 133 | + // Scenario: Both accessor with local promotion, but the second kernel does |
| 134 | + // not specify a work-group size. No promotion should happen and a warning |
| 135 | + // should be printed. |
| 136 | + std::cout << "Local(8), Local(0)\n"; |
| 137 | + performFusion(q, Internalization::Local, 8, Internalization::Local, 0); |
| 138 | + // CHECK-NEXT: Local(8), Local(0) |
| 139 | + // CHECK-NEXT: WARNING: Work-group size for local promotion not specified, not performing internalization |
| 140 | + // CHECK-NEXT: COMPUTATION OK |
| 141 | + |
| 142 | + // Scenario: Both accessor with local promotion, but the first kernel does |
| 143 | + // not specify a work-group size. No promotion should happen and a warning |
| 144 | + // should be printed. |
| 145 | + std::cout << "Local(0), Local(8)\n"; |
| 146 | + performFusion(q, Internalization::Local, 0, Internalization::Local, 8); |
| 147 | + // CHECK-NEXT: Local(0), Local(8) |
| 148 | + // CHECK-NEXT: WARNING: Work-group size for local promotion not specified, not performing internalization |
| 149 | + // CHECK-NEXT: WARNING: Not performing specified local promotion, due to previous mismatch or because previous accessor specified no promotion |
| 150 | + // CHECK-NEXT: WARNING: Cannot fuse kernels with different local size |
| 151 | + // CHECK-NEXT: COMPUTATION OK |
| 152 | + |
| 153 | + // Scenario: Both accessor with local promotion, but the kernels specify |
| 154 | + // different work-group sizes. No promotion should happen and a warning should |
| 155 | + // be printed. |
| 156 | + std::cout << "Local(8), Local(16)\n"; |
| 157 | + performFusion(q, Internalization::Local, 8, Internalization::Local, 16); |
| 158 | + // CHECK-NEXT: Local(8), Local(16) |
| 159 | + // CHECK-NEXT: WARNING: Not performing specified local promotion due to work-group size mismatch |
| 160 | + // CHECK-NEXT: WARNING: Cannot fuse kernels with different local size |
| 161 | + // CHECK-NEXT: COMPUTATION OK |
| 162 | + |
| 163 | + // Scenario: One accessor with local internalization, one with private |
| 164 | + // internalization. Should fall back to local internalization and print a |
| 165 | + // warning. |
| 166 | + std::cout << "Local(8), Private(8)\n"; |
| 167 | + performFusion(q, Internalization::Local, 8, Internalization::Private, 8, |
| 168 | + /* expectInternalization */ true); |
| 169 | + // CHECK-NEXT: Local(8), Private(8) |
| 170 | + // CHECK-NEXT: WARNING: Performing local internalization instead, because previous accessor specified local promotion |
| 171 | + // CHECK-NEXT: COMPUTATION OK |
| 172 | + |
| 173 | + return 0; |
| 174 | +} |
0 commit comments