File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff 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```
You can’t perform that action at this time.
0 commit comments