Skip to content

Commit da6d1dc

Browse files
[SYCL] Fix copyback bug for container based buffers. (#2172)
The C++17 buffers from contiguous containers have a small bug where they don't copy back all the data correctly. This fixes this and adds a test. Signed-off-by: Chris Perkins <[email protected]>
1 parent 0fdeb61 commit da6d1dc

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

sycl/include/CL/sycl/buffer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ class buffer {
170170
const property_list &propList = {})
171171
: Range(range<1>(container.size())) {
172172
impl = std::make_shared<detail::buffer_impl>(
173-
container.data(), container.data() + container.size(),
174-
get_count() * sizeof(T), detail::getNextPowerOfTwo(sizeof(T)), propList,
173+
container.data(), get_count() * sizeof(T),
174+
detail::getNextPowerOfTwo(sizeof(T)), propList,
175175
make_unique_ptr<detail::SYCLMemObjAllocatorHolder<AllocatorT>>(
176176
allocator));
177177
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %clangxx %s -std=c++17 -o %t1.out -lsycl -I %sycl_include
2+
// RUN: env SYCL_DEVICE_TYPE=HOST %t1.out
3+
// RUN: %clangxx -std=c++17 -fsycl -fsycl-targets=%sycl_triple %s -o %t2.out
4+
// RUN: env SYCL_DEVICE_TYPE=HOST %t2.out
5+
// RUN: %CPU_RUN_PLACEHOLDER %t2.out
6+
// RUN: %GPU_RUN_PLACEHOLDER %t2.out
7+
// RUN: %ACC_RUN_PLACEHOLDER %t2.out
8+
9+
#include <CL/sycl.hpp>
10+
11+
using namespace cl::sycl;
12+
13+
int main() {
14+
// buffer created from contiguous container copies back
15+
{
16+
constexpr int num = 10;
17+
std::vector<int> out_data(num, -1);
18+
{
19+
buffer A(out_data);
20+
queue Q;
21+
Q.submit([&](handler &h) {
22+
auto out = A.get_access<access::mode::write>(h);
23+
h.parallel_for<class containerBuffer>(A.get_range(),
24+
[out](id<1> i) { out[i] = 1; });
25+
});
26+
} //~buffer
27+
for (int i = 0; i < num; i++)
28+
assert(out_data[i] == 1);
29+
}
30+
}

0 commit comments

Comments
 (0)