Skip to content

Commit 3339c45

Browse files
MrSidimsbader
authored andcommitted
[SYCL][FPGA] Fix success code for non-blocking pipes
SYCL pipe built-ins are mapped on SPIR-V pipe instructions. From SPIR-V spec (3.32.23 Pipe Instructions): OpReadPipe Result is 0 if the operation is successful and a negative value if the pipe is empty. Same for OpWritePipe. The bug was that SYCL API was expecting the opposite behaviour. Signed-off-by: Dmitry Sidorov <[email protected]>
1 parent 661da12 commit 3339c45

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

sycl/include/CL/sycl/pipes.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ template <class name, class dataT, int32_t min_capacity = 0> class pipe {
2525
RPipeTy<dataT> RPipe =
2626
__spirv_CreatePipeFromPipeStorage_read<dataT>(&m_Storage);
2727
dataT TempData;
28-
Success = static_cast<bool>(
28+
Success = !static_cast<bool>(
2929
__spirv_ReadPipe(RPipe, &TempData, m_Size, m_Alignment));
3030
return TempData;
3131
#else
@@ -39,7 +39,7 @@ template <class name, class dataT, int32_t min_capacity = 0> class pipe {
3939
#ifdef __SYCL_DEVICE_ONLY__
4040
WPipeTy<dataT> WPipe =
4141
__spirv_CreatePipeFromPipeStorage_write<dataT>(&m_Storage);
42-
Success = static_cast<bool>(
42+
Success = !static_cast<bool>(
4343
__spirv_WritePipe(WPipe, &Data, m_Size, m_Alignment));
4444
#else
4545
assert(!"Pipes are not supported on a host device!");

sycl/test/fpga_tests/fpga_pipes.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
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
1417
class 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 << "\nResult 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
144188
template<typename PipeName, int TestNumber>
145189
int 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 << "\nResult mismatches "
284+
<< readHostBuffer[i] << " Vs expected " << i << std::endl;
285+
return -1;
286+
}
287+
288+
return 0;
289+
}
290+
214291
int 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

Comments
 (0)