Skip to content

Commit cb11870

Browse files
authored
Update 03-sycl-advanced.md
1 parent ca717cd commit cb11870

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

sycl/docs/03-sycl-advanced.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,27 @@ lang: en
4141

4242
<small>
4343
```cpp
44-
std::vector<int> y(N, 1);
44+
std::vector<int> y(N, 2), x(N, 1);
45+
int a=3
4546

4647
// Allocate device memory
48+
int* d_x = malloc_device<int>(N, q);
4749
int* d_y = malloc_device<int>(N, q);
4850
// Copy data from host to device
51+
q.memcpy(d_x, x.data(), N * sizeof(int)).wait();
4952
q.memcpy(d_y, y.data(), N * sizeof(int)).wait();
5053

5154
q.submit([&](handler& cgh) {
5255
cgh.parallel_for(range<1>(N), [=](sid<1> id) {
53-
d_y[id] += 1;
56+
d_y[id] += a*x_d[i];
5457
});
5558
}).wait();
5659
// Copy results back to host
5760
q.memcpy(y.data(), d_y, N * sizeof(int)).wait();
5861

5962
// Verify the results
6063
for (int i = 0; i < N; i++) {
61-
assert(y[i] == 2);
64+
assert(y[i] == 5);
6265
}
6366

6467
// Free the device memory

0 commit comments

Comments
 (0)