Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sycl/source/detail/sycl_mem_obj_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class __SYCL_EXPORT SYCLMemObjT : public SYCLMemObjI {
bool canReuseHostPtr(void *HostPtr, const size_t RequiredAlign) {
bool Aligned =
(reinterpret_cast<std::uintptr_t>(HostPtr) % RequiredAlign) == 0;
return Aligned || useHostPtr();
return !MHostPtrReadOnly && (Aligned || useHostPtr());
}

void handleHostData(void *HostPtr, const size_t RequiredAlign) {
Expand Down
37 changes: 37 additions & 0 deletions sycl/test-e2e/Basic/host_write_back.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// RUN: %{build} -o %t.out
// RUN: %{run} %t.out

#include <iostream>
#include <sycl/sycl.hpp>

using namespace sycl;

static constexpr int N = 32;

void testAccessor() {
std::vector<int> vec(N, 1);
{
buffer<int, 1> buf(static_cast<const int *>(vec.data()), range<1>{N});
queue q;
q.submit([&](handler &cgh) {
auto acc = buf.get_access<access_mode::read_write>(cgh);
cgh.parallel_for<class Kernel>({N}, [=](id<1> i) { acc[i] += 5; });
});
}
assert(vec[0] == 1);
}

void testHostAcessor() {
std::vector<int> vec(N, 1);
{
buffer<int, 1> buf(static_cast<const int *>(vec.data()), range<1>{N});
auto acc = buf.get_host_access();
acc[0] += 5;
}
assert(vec[0] == 1);
}

int main() {
testAccessor();
testHostAcessor();
}