Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 22e0c8d

Browse files
committed
Add tests for accessor version of copy_to
1 parent a54fc0d commit 22e0c8d

File tree

1 file changed

+52
-22
lines changed

1 file changed

+52
-22
lines changed

SYCL/ESIMD/regression/copyto_char_test.cpp

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ using shared_vector = std::vector<DataT, shared_allocator<DataT>>;
2626

2727
using DataT = char;
2828

29-
template <int NumElems> int test_to_copy() {
29+
template <int NumElems, bool IsAcc> int test_to_copy() {
3030
sycl::queue queue;
3131
constexpr int NumSelectedElems = NumElems / 3;
3232
constexpr int Stride = 2;
@@ -47,21 +47,41 @@ template <int NumElems> int test_to_copy() {
4747
ref_data_for_fill[i] =
4848
initial_ref_data[i] + value_for_increase_ref_data_for_fill;
4949
}
50-
queue.submit([&](sycl::handler &cgh) {
51-
DataT *init_ref_ptr = initial_ref_data.data();
52-
DataT *ref_data_for_fill_ptr = ref_data_for_fill.data();
53-
DataT *const out_ptr = result.data();
54-
55-
cgh.single_task([=]() SYCL_ESIMD_KERNEL {
56-
simd<DataT, NumElems> src_simd_obj;
57-
src_simd_obj.copy_from(init_ref_ptr);
58-
simd<DataT, NumSelectedElems> dst_simd_obj;
59-
dst_simd_obj.copy_from(ref_data_for_fill_ptr);
60-
src_simd_obj.template select<NumSelectedElems, Stride>(Offset) =
61-
dst_simd_obj;
62-
src_simd_obj.copy_to(out_ptr);
50+
if constexpr (IsAcc) {
51+
sycl::buffer<DataT> output_buf(result.data(), result.size());
52+
queue.submit([&](sycl::handler &cgh) {
53+
DataT *init_ref_ptr = initial_ref_data.data();
54+
DataT *ref_data_for_fill_ptr = ref_data_for_fill.data();
55+
auto acc =
56+
output_buf.template get_access<sycl::access::mode::read_write>(cgh);
57+
58+
cgh.single_task([=]() SYCL_ESIMD_KERNEL {
59+
simd<DataT, NumElems> src_simd_obj;
60+
src_simd_obj.copy_from(init_ref_ptr);
61+
simd<DataT, NumSelectedElems> dst_simd_obj;
62+
dst_simd_obj.copy_from(ref_data_for_fill_ptr);
63+
src_simd_obj.template select<NumSelectedElems, Stride>(Offset) =
64+
dst_simd_obj;
65+
src_simd_obj.copy_to(acc, 0);
66+
});
6367
});
64-
});
68+
} else {
69+
queue.submit([&](sycl::handler &cgh) {
70+
DataT *init_ref_ptr = initial_ref_data.data();
71+
DataT *ref_data_for_fill_ptr = ref_data_for_fill.data();
72+
DataT *const out_ptr = result.data();
73+
74+
cgh.single_task([=]() SYCL_ESIMD_KERNEL {
75+
simd<DataT, NumElems> src_simd_obj;
76+
src_simd_obj.copy_from(init_ref_ptr);
77+
simd<DataT, NumSelectedElems> dst_simd_obj;
78+
dst_simd_obj.copy_from(ref_data_for_fill_ptr);
79+
src_simd_obj.template select<NumSelectedElems, Stride>(Offset) =
80+
dst_simd_obj;
81+
src_simd_obj.copy_to(out_ptr);
82+
});
83+
});
84+
}
6585
queue.wait_and_throw();
6686

6787
std::vector<size_t> selected_indices;
@@ -114,13 +134,23 @@ template <int NumElems> int test_to_copy() {
114134
int main() {
115135
int test_result = 0;
116136

117-
test_result |= test_to_copy<16>();
118-
test_result |= test_to_copy<32 + 8>();
119-
test_result |= test_to_copy<32 + 10>();
120-
test_result |= test_to_copy<10>();
121-
test_result |= test_to_copy<8>();
122-
test_result |= test_to_copy<7>();
123-
test_result |= test_to_copy<15>();
137+
test_result |= test_to_copy<16, false>();
138+
test_result |= test_to_copy<32 + 8, false>();
139+
test_result |= test_to_copy<32 + 10, false>();
140+
test_result |= test_to_copy<10, false>();
141+
test_result |= test_to_copy<8, false>();
142+
test_result |= test_to_copy<7, false>();
143+
test_result |= test_to_copy<15, false>();
144+
test_result |= test_to_copy<32, false>();
145+
146+
test_result |= test_to_copy<16, true>();
147+
test_result |= test_to_copy<32 + 8, true>();
148+
test_result |= test_to_copy<32 + 10, true>();
149+
test_result |= test_to_copy<10, true>();
150+
test_result |= test_to_copy<8, true>();
151+
test_result |= test_to_copy<7, true>();
152+
test_result |= test_to_copy<15, true>();
153+
test_result |= test_to_copy<32, true>();
124154

125155
if (!test_result) {
126156
std::cout << "Test passed" << std::endl;

0 commit comments

Comments
 (0)