Skip to content

[SYCL] Fix host device local accessor alignment #5554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 1, 2022
Merged
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
19 changes: 16 additions & 3 deletions sycl/include/CL/sycl/detail/accessor_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ class AccessorBaseHost {

class __SYCL_EXPORT LocalAccessorImplHost {
public:
// Allocate ElemSize more data to have sufficient padding to enforce
// alignment.
LocalAccessorImplHost(sycl::range<3> Size, int Dims, int ElemSize)
: MSize(Size), MDims(Dims), MElemSize(ElemSize),
MMem(Size[0] * Size[1] * Size[2] * ElemSize) {}
MMem(Size[0] * Size[1] * Size[2] * ElemSize + ElemSize) {}

sycl::range<3> MSize;
int MDims;
Expand All @@ -190,9 +192,20 @@ class LocalAccessorBaseHost {
}
sycl::range<3> &getSize() { return impl->MSize; }
const sycl::range<3> &getSize() const { return impl->MSize; }
void *getPtr() { return impl->MMem.data(); }
void *getPtr() {
// Const cast this in order to call the const getPtr.
return const_cast<const LocalAccessorBaseHost *>(this)->getPtr();
}
void *getPtr() const {
return const_cast<void *>(reinterpret_cast<void *>(impl->MMem.data()));
char *ptr = impl->MMem.data();

// Align the pointer to MElemSize.
size_t val = reinterpret_cast<size_t>(ptr);
if (val % impl->MElemSize != 0) {
ptr += impl->MElemSize - val % impl->MElemSize;
}

return ptr;
}

int getNumOfDims() { return impl->MDims; }
Expand Down