File tree 3 files changed +18
-1
lines changed
code/day-1/07_axpy-usm_allocator
3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 24
24
assert (x.size () == y.size ());
25
25
auto sz = x.size ();
26
26
27
+ auto ptrX = x.data ();
28
+ auto ptrY = y.data ();
29
+
27
30
// FIXME allocate output vector
28
31
std::vector z (...);
29
32
// NOTE why do we take the address of the output vector?
Original file line number Diff line number Diff line change 22
22
assert (x.size () == y.size ());
23
23
auto sz = x.size ();
24
24
25
+ auto ptrX = x.data ();
26
+ auto ptrY = y.data ();
27
+
25
28
std::vector z (sz, T { 0.0 }, shared_allocator<T>(Q));
26
29
// get address of z, because we rely on by-copy capture in the kernel lambda.
27
30
// Why?
33
36
Q.submit ([&](handler& cgh) {
34
37
cgh.parallel_for (range { sz }, [=](id<1 > tid) {
35
38
auto i = tid[0 ];
36
- ptrZ[i] = alpha * x [i] + y [i];
39
+ ptrZ[i] = alpha * ptrX [i] + ptrY [i];
37
40
});
38
41
})
39
42
.wait ();
Original file line number Diff line number Diff line change @@ -334,6 +334,17 @@ Implicit
334
334
335
335
A working solution is in the ``solution `` subfolder.
336
336
337
+ .. note ::
338
+
339
+ The fact that we use a device-aware allocator for ``std::vector ``
340
+ does not mean that STL objects will *magically * work within the
341
+ SYCL runtime. Indeed, doing so is absolutely not legal code: it
342
+ might compile and even work in some cases, but is to be considered
343
+ a bug.
344
+ You can read up a complete explanation `here
345
+ <https://github.com/illuhad/hipSYCL/issues/817#issuecomment-1231922115> `_.
346
+
347
+
337
348
338
349
.. keypoints ::
339
350
You can’t perform that action at this time.
0 commit comments