Skip to content

Commit 73b24dd

Browse files
authored
[SYCL][NATIVECPU] Fix vector add test (#14620)
Data was not guaranteed to be copied back in `sycl/test/native_cpu/vector-add.cpp`, this PR fixes it.
1 parent d4085bd commit 73b24dd

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

sycl/test/native_cpu/vector-add.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,24 @@ int main() {
3131
C{{0, 0, 0, 0, 0}};
3232
sycl::queue deviceQueue;
3333
sycl::range<1> numOfItems{N};
34-
sycl::buffer<int, 1> bufferA(A.data(), numOfItems);
35-
sycl::buffer<int, 1> bufferB(B.data(), numOfItems);
36-
sycl::buffer<int, 1> bufferC(C.data(), numOfItems);
37-
38-
deviceQueue
39-
.submit([&](sycl::handler &cgh) {
40-
auto accessorA = bufferA.get_access<sycl_read>(cgh);
41-
auto accessorB = bufferB.get_access<sycl_read>(cgh);
42-
auto accessorC = bufferC.get_access<sycl_write>(cgh);
43-
44-
auto kern = [=](sycl::id<1> wiID) {
45-
accessorC[wiID] = accessorA[wiID] + accessorB[wiID];
46-
};
47-
cgh.parallel_for<class SimpleVadd>(numOfItems, kern);
48-
})
49-
.wait();
34+
{
35+
sycl::buffer<int, 1> bufferA(A.data(), numOfItems);
36+
sycl::buffer<int, 1> bufferB(B.data(), numOfItems);
37+
sycl::buffer<int, 1> bufferC(C.data(), numOfItems);
38+
39+
deviceQueue
40+
.submit([&](sycl::handler &cgh) {
41+
auto accessorA = bufferA.get_access<sycl_read>(cgh);
42+
auto accessorB = bufferB.get_access<sycl_read>(cgh);
43+
auto accessorC = bufferC.get_access<sycl_write>(cgh);
44+
45+
auto kern = [=](sycl::id<1> wiID) {
46+
accessorC[wiID] = accessorA[wiID] + accessorB[wiID];
47+
};
48+
cgh.parallel_for<class SimpleVadd>(numOfItems, kern);
49+
})
50+
.wait();
51+
}
5052

5153
for (unsigned int i = 0; i < N; i++) {
5254
std::cout << "C[" << i << "] = " << C[i] << "\n";

0 commit comments

Comments
 (0)