1010#include < CL/sycl.hpp>
1111#include < iostream>
1212
13+ // Size of an array passing through a pipe
14+ constexpr size_t N = 10 ;
15+
1316// For simple non-blocking pipes with explicit type
1417class some_nb_pipe ;
1518
@@ -140,6 +143,47 @@ int test_multiple_nb_pipe(cl::sycl::queue Queue) {
140143 return 0 ;
141144}
142145
146+ // Test for array passing through a non-blocking pipe
147+ template <int TestNumber>
148+ int test_array_th_nb_pipe (cl::sycl::queue Queue) {
149+ int data[N] = {0 };
150+ using AnotherNbPipe = cl::sycl::pipe<class another_nb_pipe , int >;
151+
152+ Queue.submit ([&](cl::sycl::handler &cgh) {
153+ cgh.single_task <class writer <TestNumber>>([=]() {
154+ bool SuccessCode = false ;
155+ for (size_t i = 0 ; i != N; ++i) {
156+ do {
157+ AnotherNbPipe::write (i, SuccessCode);
158+ } while (!SuccessCode);
159+ }
160+ });
161+ });
162+
163+ cl::sycl::buffer<int , 1 > writeBuf (data, N);
164+ Queue.submit ([&](cl::sycl::handler &cgh) {
165+ auto write_acc = writeBuf.get_access <cl::sycl::access::mode::write>(cgh);
166+ cgh.single_task <class reader <TestNumber>>([=]() {
167+ for (size_t i = 0 ; i != N; ++i) {
168+ bool SuccessCode = false ;
169+ do {
170+ write_acc[i] = AnotherNbPipe::read (SuccessCode);
171+ } while (!SuccessCode);
172+ }
173+ });
174+ });
175+
176+ auto readHostBuffer = writeBuf.get_access <cl::sycl::access::mode::read>();
177+ for (size_t i = 0 ; i != N; ++i) {
178+ if (readHostBuffer[i] != i)
179+ std::cout << " Test: " << TestNumber << " \n Result mismatches "
180+ << readHostBuffer[i] << " Vs expected " << i << std::endl;
181+ return -1 ;
182+ }
183+
184+ return 0 ;
185+ }
186+
143187// Test for simple blocking pipes
144188template <typename PipeName, int TestNumber>
145189int test_simple_bl_pipe (cl::sycl::queue Queue) {
@@ -211,6 +255,39 @@ int test_multiple_bl_pipe(cl::sycl::queue Queue) {
211255 return 0 ;
212256}
213257
258+ // Test for array passing through a blocking pipe
259+ template <int TestNumber>
260+ int test_array_th_bl_pipe (cl::sycl::queue Queue) {
261+ int data[N] = {0 };
262+ using AnotherBlPipe = cl::sycl::pipe<class another_bl_pipe , int >;
263+
264+ Queue.submit ([&](cl::sycl::handler &cgh) {
265+ cgh.single_task <class writer <TestNumber>>([=]() {
266+ for (size_t i = 0 ; i != N; ++i)
267+ AnotherBlPipe::write (i);
268+ });
269+ });
270+
271+ cl::sycl::buffer<int , 1 > writeBuf (data, N);
272+ Queue.submit ([&](cl::sycl::handler &cgh) {
273+ auto write_acc = writeBuf.get_access <cl::sycl::access::mode::write>(cgh);
274+ cgh.single_task <class reader <TestNumber>>([=]() {
275+ for (size_t i = 0 ; i != N; ++i)
276+ write_acc[i] = AnotherBlPipe::read ();
277+ });
278+ });
279+
280+ auto readHostBuffer = writeBuf.get_access <cl::sycl::access::mode::read>();
281+ for (size_t i = 0 ; i != N; ++i) {
282+ if (readHostBuffer[i] != i)
283+ std::cout << " Test: " << TestNumber << " \n Result mismatches "
284+ << readHostBuffer[i] << " Vs expected " << i << std::endl;
285+ return -1 ;
286+ }
287+
288+ return 0 ;
289+ }
290+
214291int main () {
215292 cl::sycl::queue Queue;
216293
@@ -230,5 +307,9 @@ int main() {
230307 Result &= test_simple_bl_pipe<templ_bl_pipe<0 >, /* test number*/ 9 >(Queue);
231308 Result &= test_multiple_bl_pipe</* test number*/ 10 >(Queue);
232309
310+ // Test for an array data passing through a pipe
311+ Result &= test_array_th_nb_pipe</* test number*/ 11 >(Queue);
312+ Result &= test_array_th_bl_pipe</* test number*/ 12 >(Queue);
313+
233314 return Result;
234315}
0 commit comments