Skip to content

Commit b1c3712

Browse files
authored
Update 03-sycl-advanced.md
1 parent d824a54 commit b1c3712

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

sycl/docs/03-sycl-advanced.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,28 @@ lang: en
7070
</small>
7171
7272
73-
# `malloc_shared`
73+
# AXPY with `malloc_shared`
7474
7575
<small>
7676
```cpp
77+
int a=3;
78+
int* x = malloc_shared<int>(N, q);
7779
int* y = malloc_shared<int>(N, q);
7880
// Initialize from host
7981
for (int i = 0; i < N; i++) {
80-
y[i] = 1;
82+
x[i]=1; y[i] = 2;
8183
}
8284
8385
q.submit([&](handler& cgh) {
8486
cgh.parallel_for(range<1>(N), [=](id<1> idx) {
85-
y[idx] += 1;
87+
y[idx] += a*x[i];
8688
});
8789
}).wait();
8890
8991
// No memcpy needed — host can read directly
9092
for (int i = 0; i < N; i++) {
91-
assert(y[i] == 2);
92-
std::cout << "y[" << i << "] = " << y[i] << "\n";
93+
assert(y[i] == 5);
9394
}
94-
9595
// Free the shared memory
9696
sycl::free(y, q);
9797
```

0 commit comments

Comments
 (0)