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