|
| 1 | +// REQUIRES: gpu, level_zero |
| 2 | + |
| 3 | +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out |
| 4 | + |
| 5 | +// Check that dynamic batching increases batch size |
| 6 | +// RUN: env SYCL_PI_TRACE=2 ZE_DEBUG=1 %GPU_RUN_PLACEHOLDER %t.out 2>&1 | FileCheck --check-prefixes=CKALL,CKDYNUP %s |
| 7 | + |
| 8 | +// level_zero_dynamic_batch_test.cpp |
| 9 | +// |
| 10 | +// This tests the level zero plugin's kernel dyanmic batch size adjustment |
| 11 | +// code. |
| 12 | +// It starts out by enqueing 40 kernels before it does a wait, and it does |
| 13 | +// this 5 times. That should cause the dynamic batch size adjustment to |
| 14 | +// raise the batch size up several times. |
| 15 | +// |
| 16 | +// Then the test starts enqueueing only 4 kernels before doing a wait, and |
| 17 | +// it does that 5 times as well. That should cause the batch size to |
| 18 | +// be lowered, just once to be less than 4. |
| 19 | +// |
| 20 | +// CKDYN: Raising QueueBatchSize to 3 |
| 21 | +// CKDYN: Raising QueueBatchSize to 4 |
| 22 | +// CKDYN-NOT: Raising QueueBatchSize |
| 23 | +// CKALL: Test Pass |
| 24 | +// CKALL: Test Pass |
| 25 | +// CKALL: Test Pass |
| 26 | +// CKALL: Test Pass |
| 27 | +// CKALL: Test Pass |
| 28 | +// CKALL: Test Pass |
| 29 | +// CKALL: Test Pass |
| 30 | +// CKDYN: Lowering QueueBatchSize to 3 |
| 31 | +// CKDYN-NOT: Lowering QueueBatchSize |
| 32 | +// CKALL: Test Pass |
| 33 | +// CKALL: Test Pass |
| 34 | +// CKALL: Test Pass |
| 35 | +// CKALL: Test Pass |
| 36 | + |
| 37 | +#include "CL/sycl.hpp" |
| 38 | +#include <chrono> |
| 39 | +#include <cmath> |
| 40 | +#include <iostream> |
| 41 | + |
| 42 | +namespace sycl = cl::sycl; |
| 43 | + |
| 44 | +void validate(uint32_t *result, uint32_t *expect, size_t n) { |
| 45 | + int error = 0; |
| 46 | + for (int i = 0; i < n; i++) { |
| 47 | + if (result[i] != expect[i]) { |
| 48 | + error++; |
| 49 | + if (error < 10) { |
| 50 | + printf("Error: %d, expect: %d\n", result[i], expect[i]); |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + error > 0 ? printf("Error: %d\n", error) : printf("Test Pass\n"); |
| 55 | +} |
| 56 | + |
| 57 | +int main(int argc, char *argv[]) { |
| 58 | + size_t M = 65536; |
| 59 | + size_t N = 512 / 4; |
| 60 | + size_t AL = M * N * sizeof(uint32_t); |
| 61 | + |
| 62 | + sycl::queue q(sycl::default_selector{}); |
| 63 | + auto ctx = q.get_context(); |
| 64 | + auto dev = q.get_device(); |
| 65 | + |
| 66 | + uint32_t *Y1 = static_cast<uint32_t *>(sycl::malloc_shared(AL, dev, ctx)); |
| 67 | + uint32_t *Z1 = static_cast<uint32_t *>(sycl::malloc_shared(AL, dev, ctx)); |
| 68 | + uint32_t *Z2 = static_cast<uint32_t *>(sycl::malloc_shared(AL, dev, ctx)); |
| 69 | + uint32_t *Z3 = static_cast<uint32_t *>(sycl::malloc_shared(AL, dev, ctx)); |
| 70 | + uint32_t *Z4 = static_cast<uint32_t *>(sycl::malloc_shared(AL, dev, ctx)); |
| 71 | + uint32_t *Z5 = static_cast<uint32_t *>(sycl::malloc_shared(AL, dev, ctx)); |
| 72 | + uint32_t *Z6 = static_cast<uint32_t *>(sycl::malloc_shared(AL, dev, ctx)); |
| 73 | + uint32_t *Z7 = static_cast<uint32_t *>(sycl::malloc_shared(AL, dev, ctx)); |
| 74 | + uint32_t *Z8 = static_cast<uint32_t *>(sycl::malloc_shared(AL, dev, ctx)); |
| 75 | + |
| 76 | + for (size_t i = 0; i < M * N; i++) { |
| 77 | + Y1[i] = i % 255; |
| 78 | + } |
| 79 | + |
| 80 | + memset(Z1, '\0', AL); |
| 81 | + memset(Z2, '\0', AL); |
| 82 | + memset(Z3, '\0', AL); |
| 83 | + memset(Z4, '\0', AL); |
| 84 | + memset(Z5, '\0', AL); |
| 85 | + memset(Z6, '\0', AL); |
| 86 | + memset(Z7, '\0', AL); |
| 87 | + memset(Z8, '\0', AL); |
| 88 | + |
| 89 | + for (size_t i = 0; i < 5; i++) { |
| 90 | + for (size_t j = 0; j < 5; j++) { |
| 91 | + q.submit([&](sycl::handler &h) { |
| 92 | + h.parallel_for<class u32_copy1>(sycl::range<2>{M, N}, |
| 93 | + [=](sycl::id<2> it) { |
| 94 | + const int m = it[0]; |
| 95 | + const int n = it[1]; |
| 96 | + Z1[m * N + n] = Y1[m * N + n]; |
| 97 | + }); |
| 98 | + }); |
| 99 | + q.submit([&](sycl::handler &h) { |
| 100 | + h.parallel_for<class u32_copy2>(sycl::range<2>{M, N}, |
| 101 | + [=](sycl::id<2> it) { |
| 102 | + const int m = it[0]; |
| 103 | + const int n = it[1]; |
| 104 | + Z2[m * N + n] = Y1[m * N + n]; |
| 105 | + }); |
| 106 | + }); |
| 107 | + q.submit([&](sycl::handler &h) { |
| 108 | + h.parallel_for<class u32_copy3>(sycl::range<2>{M, N}, |
| 109 | + [=](sycl::id<2> it) { |
| 110 | + const int m = it[0]; |
| 111 | + const int n = it[1]; |
| 112 | + Z3[m * N + n] = Y1[m * N + n]; |
| 113 | + }); |
| 114 | + }); |
| 115 | + q.submit([&](sycl::handler &h) { |
| 116 | + h.parallel_for<class u32_copy4>(sycl::range<2>{M, N}, |
| 117 | + [=](sycl::id<2> it) { |
| 118 | + const int m = it[0]; |
| 119 | + const int n = it[1]; |
| 120 | + Z4[m * N + n] = Y1[m * N + n]; |
| 121 | + }); |
| 122 | + }); |
| 123 | + q.submit([&](sycl::handler &h) { |
| 124 | + h.parallel_for<class u32_copy5>(sycl::range<2>{M, N}, |
| 125 | + [=](sycl::id<2> it) { |
| 126 | + const int m = it[0]; |
| 127 | + const int n = it[1]; |
| 128 | + Z5[m * N + n] = Y1[m * N + n]; |
| 129 | + }); |
| 130 | + }); |
| 131 | + q.submit([&](sycl::handler &h) { |
| 132 | + h.parallel_for<class u32_copy6>(sycl::range<2>{M, N}, |
| 133 | + [=](sycl::id<2> it) { |
| 134 | + const int m = it[0]; |
| 135 | + const int n = it[1]; |
| 136 | + Z6[m * N + n] = Y1[m * N + n]; |
| 137 | + }); |
| 138 | + }); |
| 139 | + q.submit([&](sycl::handler &h) { |
| 140 | + h.parallel_for<class u32_copy7>(sycl::range<2>{M, N}, |
| 141 | + [=](sycl::id<2> it) { |
| 142 | + const int m = it[0]; |
| 143 | + const int n = it[1]; |
| 144 | + Z7[m * N + n] = Y1[m * N + n]; |
| 145 | + }); |
| 146 | + }); |
| 147 | + q.submit([&](sycl::handler &h) { |
| 148 | + h.parallel_for<class u32_copy8>(sycl::range<2>{M, N}, |
| 149 | + [=](sycl::id<2> it) { |
| 150 | + const int m = it[0]; |
| 151 | + const int n = it[1]; |
| 152 | + Z8[m * N + n] = Y1[m * N + n]; |
| 153 | + }); |
| 154 | + }); |
| 155 | + } |
| 156 | + q.wait(); |
| 157 | + } |
| 158 | + |
| 159 | + validate(Y1, Z1, M * N); |
| 160 | + validate(Y1, Z2, M * N); |
| 161 | + validate(Y1, Z3, M * N); |
| 162 | + validate(Y1, Z4, M * N); |
| 163 | + validate(Y1, Z5, M * N); |
| 164 | + validate(Y1, Z6, M * N); |
| 165 | + validate(Y1, Z7, M * N); |
| 166 | + validate(Y1, Z8, M * N); |
| 167 | + |
| 168 | + for (size_t i = 0; i < 5; i++) { |
| 169 | + q.submit([&](sycl::handler &h) { |
| 170 | + h.parallel_for<class u32_copy9>(sycl::range<2>{M, N}, |
| 171 | + [=](sycl::id<2> it) { |
| 172 | + const int m = it[0]; |
| 173 | + const int n = it[1]; |
| 174 | + Z1[m * N + n] = Y1[m * N + n]; |
| 175 | + }); |
| 176 | + }); |
| 177 | + q.submit([&](sycl::handler &h) { |
| 178 | + h.parallel_for<class u32_copy10>(sycl::range<2>{M, N}, |
| 179 | + [=](sycl::id<2> it) { |
| 180 | + const int m = it[0]; |
| 181 | + const int n = it[1]; |
| 182 | + Z2[m * N + n] = Y1[m * N + n]; |
| 183 | + }); |
| 184 | + }); |
| 185 | + q.submit([&](sycl::handler &h) { |
| 186 | + h.parallel_for<class u32_copy11>(sycl::range<2>{M, N}, |
| 187 | + [=](sycl::id<2> it) { |
| 188 | + const int m = it[0]; |
| 189 | + const int n = it[1]; |
| 190 | + Z3[m * N + n] = Y1[m * N + n]; |
| 191 | + }); |
| 192 | + }); |
| 193 | + q.submit([&](sycl::handler &h) { |
| 194 | + h.parallel_for<class u32_copy12>(sycl::range<2>{M, N}, |
| 195 | + [=](sycl::id<2> it) { |
| 196 | + const int m = it[0]; |
| 197 | + const int n = it[1]; |
| 198 | + Z4[m * N + n] = Y1[m * N + n]; |
| 199 | + }); |
| 200 | + }); |
| 201 | + q.wait(); |
| 202 | + } |
| 203 | + validate(Y1, Z1, M * N); |
| 204 | + validate(Y1, Z2, M * N); |
| 205 | + validate(Y1, Z3, M * N); |
| 206 | + validate(Y1, Z4, M * N); |
| 207 | + |
| 208 | + sycl::free(Y1, ctx); |
| 209 | + sycl::free(Z1, ctx); |
| 210 | + sycl::free(Z2, ctx); |
| 211 | + sycl::free(Z3, ctx); |
| 212 | + sycl::free(Z4, ctx); |
| 213 | + sycl::free(Z5, ctx); |
| 214 | + sycl::free(Z6, ctx); |
| 215 | + sycl::free(Z7, ctx); |
| 216 | + sycl::free(Z8, ctx); |
| 217 | + |
| 218 | + return 0; |
| 219 | +} |
0 commit comments