|
| 1 | +// RUN: %clangxx -fsycl %s -o %t.out |
| 2 | +// RUN: env SYCL_DEVICE_TYPE=HOST %t.out |
| 3 | +// RUN: %CPU_RUN_PLACEHOLDER %t.out |
| 4 | +// RUN: %GPU_RUN_PLACEHOLDER %t.out |
| 5 | +// RUN: %ACC_RUN_PLACEHOLDER %t.out |
| 6 | +//==--- handler_copy_with_offset.cpp - SYCL handler copy with offset test --==// |
| 7 | +// |
| 8 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 9 | +// See https://llvm.org/LICENSE.txt for license information. |
| 10 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 11 | +// |
| 12 | +//===----------------------------------------------------------------------===// |
| 13 | + |
| 14 | +#include <CL/sycl.hpp> |
| 15 | + |
| 16 | +#include <cassert> |
| 17 | +#include <exception> |
| 18 | +#include <memory> |
| 19 | +#include <numeric> |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +using namespace cl::sycl; |
| 23 | +constexpr access::mode read = access::mode::read; |
| 24 | +constexpr access::mode write = access::mode::write; |
| 25 | +constexpr access::target global_buffer = access::target::global_buffer; |
| 26 | + |
| 27 | +int main() { |
| 28 | + { |
| 29 | + constexpr size_t Size = 8; |
| 30 | + |
| 31 | + vector_class<char> DataRaw(Size, 'x'); |
| 32 | + { |
| 33 | + buffer<char> Buffer{DataRaw.data(), range<1>{Size}}; |
| 34 | + |
| 35 | + vector_class<char> DataGold(Size); |
| 36 | + std::iota(DataGold.begin(), DataGold.end(), '0'); |
| 37 | + |
| 38 | + queue Queue; |
| 39 | + Queue.submit([&](handler &CGH) { |
| 40 | + range<1> AccessRange{4}; |
| 41 | + id<1> AccessOffset{2}; |
| 42 | + auto Accessor = Buffer.get_access<write, global_buffer>( |
| 43 | + CGH, AccessRange, AccessOffset); |
| 44 | + CGH.copy(DataGold.data(), Accessor); |
| 45 | + }); |
| 46 | + Queue.wait(); |
| 47 | + } |
| 48 | + |
| 49 | + vector_class<char> Expected{'x', 'x', '0', '1', '2', '3', 'x', 'x'}; |
| 50 | + if (DataRaw != Expected) |
| 51 | + throw std::runtime_error("Check of hadler.copy(ptr, acc) was failed"); |
| 52 | + } |
| 53 | + |
| 54 | + { |
| 55 | + constexpr size_t Size = 8; |
| 56 | + vector_class<char> DataRaw(Size, 'x'); |
| 57 | + { |
| 58 | + vector_class<char> DataGold(Size); |
| 59 | + std::iota(DataGold.begin(), DataGold.end(), '0'); |
| 60 | + buffer<char> Buffer{DataGold.data(), range<1>{Size}}; |
| 61 | + |
| 62 | + queue Queue; |
| 63 | + Queue.submit([&](handler &CGH) { |
| 64 | + range<1> AccessRange{4}; |
| 65 | + id<1> AccessOffset{2}; |
| 66 | + auto Accessor = Buffer.get_access<read, global_buffer>(CGH, AccessRange, |
| 67 | + AccessOffset); |
| 68 | + CGH.copy(Accessor, DataRaw.data()); |
| 69 | + }); |
| 70 | + Queue.wait(); |
| 71 | + } |
| 72 | + vector_class<char> Expected{'2', '3', '4', '5', 'x', 'x', 'x', 'x'}; |
| 73 | + if (DataRaw != Expected) |
| 74 | + throw std::runtime_error("Check of hadler.copy(acc, ptr) was failed"); |
| 75 | + } |
| 76 | + return 0; |
| 77 | +} |
0 commit comments