|
| 1 | +// RUN: %clangxx -fsycl -fsycl-unnamed-lambda %s -o %t.out |
| 2 | +// The purpose of this test is to check that the following code can be |
| 3 | +// successfully compiled |
| 4 | +#include <CL/sycl.hpp> |
| 5 | + |
| 6 | +#include <iostream> |
| 7 | + |
| 8 | +int main() { |
| 9 | + auto AsyncHandler = [](cl::sycl::exception_list EL) { |
| 10 | + for (std::exception_ptr const &P : EL) { |
| 11 | + try { |
| 12 | + std::rethrow_exception(P); |
| 13 | + } catch (std::exception const &E) { |
| 14 | + std::cerr << "Caught async SYCL exception: " << E.what() << std::endl; |
| 15 | + } |
| 16 | + } |
| 17 | + }; |
| 18 | + |
| 19 | + cl::sycl::queue Q(AsyncHandler); |
| 20 | + |
| 21 | + constexpr size_t Size = 10; |
| 22 | + const int ReferenceData[Size] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; |
| 23 | + |
| 24 | + cl::sycl::buffer<int> Buf(Size); |
| 25 | + |
| 26 | + Q.submit([&](cl::sycl::handler &CGH) { |
| 27 | + auto Acc = Buf.get_access<cl::sycl::access::mode::write>(CGH); |
| 28 | + CGH.copy(ReferenceData, Acc); |
| 29 | + }); |
| 30 | + |
| 31 | + Q.wait_and_throw(); |
| 32 | + |
| 33 | + auto Acc = Buf.get_access<cl::sycl::access::mode::read>(); |
| 34 | + for (size_t I = 0; I < Size; ++I) { |
| 35 | + if (ReferenceData[I] != Acc[I]) { |
| 36 | + std::cerr << "Incorrect result, got: " << Acc[I] |
| 37 | + << ", expected: " << ReferenceData[I] << std::endl; |
| 38 | + return 1; |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + int CopybackData[Size] = { 0 }; |
| 43 | + Q.submit([&](cl::sycl::handler &CGH) { |
| 44 | + auto Acc = Buf.get_access<cl::sycl::access::mode::read>(CGH); |
| 45 | + CGH.copy(Acc, CopybackData); |
| 46 | + }); |
| 47 | + |
| 48 | + Q.wait_and_throw(); |
| 49 | + |
| 50 | + for (size_t I = 0; I < Size; ++I) { |
| 51 | + if (ReferenceData[I] != CopybackData[I]) { |
| 52 | + std::cerr << "Incorrect result, got: " << Acc[I] |
| 53 | + << ", expected: " << ReferenceData[I] << std::endl; |
| 54 | + return 1; |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + return 0; |
| 59 | +} |
0 commit comments