|
| 1 | +#include <CL/sycl.hpp> |
| 2 | +#include <cassert> |
| 3 | +#include <iostream> |
| 4 | + |
| 5 | +using namespace cl::sycl; |
| 6 | +using namespace cl::sycl::access; |
| 7 | + |
| 8 | +void kernelFunc1(int *Buf, int wiID) { |
| 9 | + Buf[wiID] = 9; |
| 10 | + assert(Buf[wiID] != 0 && "One shouldn't see this message"); |
| 11 | +} |
| 12 | + |
| 13 | +void assertTest1(queue &Q, buffer<int, 1> &Buf) { |
| 14 | + Q.submit([&](handler &CGH) { |
| 15 | + auto Acc = Buf.template get_access<mode::read_write>(CGH); |
| 16 | + |
| 17 | + CGH.parallel_for<class Kernel_1>( |
| 18 | + Buf.get_range(), |
| 19 | + [=](cl::sycl::id<1> wiID) { kernelFunc1(&Acc[0], wiID); }); |
| 20 | + }); |
| 21 | +} |
| 22 | + |
| 23 | +void kernelFunc2(int *Buf, int wiID) { |
| 24 | + if (wiID % 2 != 0) |
| 25 | + Buf[wiID] = 0; |
| 26 | + assert(Buf[wiID] == 0 && "from assert statement"); |
| 27 | +} |
| 28 | + |
| 29 | +void assertTest2(queue &Q, buffer<int, 1> &Buf) { |
| 30 | + Q.submit([&](handler &CGH) { |
| 31 | + auto Acc = Buf.template get_access<mode::read_write>(CGH); |
| 32 | + |
| 33 | + CGH.parallel_for<class Kernel_2>( |
| 34 | + Buf.get_range(), |
| 35 | + [=](cl::sycl::id<1> wiID) { kernelFunc2(&Acc[0], wiID); }); |
| 36 | + }); |
| 37 | +} |
| 38 | + |
| 39 | +void kernelFunc3(int *Buf, int wiID) { |
| 40 | + if (wiID == 0) |
| 41 | + assert(false && "test aborts earlier, one shouldn't see this message"); |
| 42 | + Buf[wiID] = 9; |
| 43 | +} |
| 44 | + |
| 45 | +void assertTest3(queue &Q, buffer<int, 1> &Buf) { |
| 46 | + Q.submit([&](handler &CGH) { |
| 47 | + auto Acc = Buf.template get_access<mode::read_write>(CGH); |
| 48 | + |
| 49 | + CGH.parallel_for<class Kernel_3>( |
| 50 | + Buf.get_range(), |
| 51 | + [=](cl::sycl::id<1> wiID) { kernelFunc3(&Acc[0], wiID); }); |
| 52 | + }); |
| 53 | +} |
| 54 | + |
| 55 | +int main(int Argc, const char *Argv[]) { |
| 56 | + std::array<int, 4> Vec = {1, 2, 3, 4}; |
| 57 | + cl::sycl::range<1> numOfItems{Vec.size()}; |
| 58 | + cl::sycl::buffer<int, 1> Buf(Vec.data(), numOfItems); |
| 59 | + |
| 60 | + queue Q; |
| 61 | + assertTest1(Q, Buf); |
| 62 | + Q.wait(); |
| 63 | + |
| 64 | + assertTest2(Q, Buf); |
| 65 | + Q.wait(); |
| 66 | + |
| 67 | + assertTest3(Q, Buf); |
| 68 | + Q.wait(); |
| 69 | + |
| 70 | + std::cout << "The test ended." << std::endl; |
| 71 | + return 0; |
| 72 | +} |
0 commit comments