Skip to content

[SYCL] Reduce heap allocations from sycl::local_accessor #17147

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
Feb 27, 2025
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: 0 additions & 2 deletions sycl/include/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2212,8 +2212,6 @@ class __SYCL_SPECIAL_CLASS local_accessor_base :
const auto *this_const = this;
(void)getSize();
(void)this_const->getSize();
(void)getPtr();
(void)this_const->getPtr();
#endif
}

Expand Down
25 changes: 10 additions & 15 deletions sycl/source/accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ AccessorBaseHost::AccessorBaseHost(id<3> Offset, range<3> AccessRange,
bool IsSubBuffer,
const property_list &PropertyList) {
verifyAccessorProps(PropertyList);
impl = std::shared_ptr<AccessorImplHost>(
new AccessorImplHost(Offset, AccessRange, MemoryRange, AccessMode,
(detail::SYCLMemObjI *)SYCLMemObject, Dims, ElemSize,
false, OffsetInBytes, IsSubBuffer, PropertyList));
impl = std::make_shared<AccessorImplHost>(
Offset, AccessRange, MemoryRange, AccessMode,
(detail::SYCLMemObjI *)SYCLMemObject, Dims, ElemSize, false,
OffsetInBytes, IsSubBuffer, PropertyList);
}

AccessorBaseHost::AccessorBaseHost(id<3> Offset, range<3> AccessRange,
Expand Down Expand Up @@ -119,19 +119,14 @@ const sycl::range<3> &LocalAccessorBaseHost::getSize() const {
return impl->MSize;
}
void *LocalAccessorBaseHost::getPtr() {
// Const cast this in order to call the const getPtr.
return const_cast<const LocalAccessorBaseHost *>(this)->getPtr();
// Must not be/isn't called, user-facing APIs do error-checking.
std::abort();
return nullptr;
}
void *LocalAccessorBaseHost::getPtr() const {
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;
// Must not be/isn't called, user-facing APIs do error-checking.
std::abort();
return nullptr;
}
const property_list &LocalAccessorBaseHost::getPropList() const {
return impl->MPropertyList;
Expand Down
2 changes: 0 additions & 2 deletions sycl/source/detail/accessor_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,11 @@ class LocalAccessorImplHost {
LocalAccessorImplHost(sycl::range<3> Size, int Dims, int ElemSize,
const property_list &PropertyList)
: MSize(Size), MDims(Dims), MElemSize(ElemSize),
MMem(Size[0] * Size[1] * Size[2] * ElemSize + ElemSize),
MPropertyList(PropertyList) {}

sycl::range<3> MSize;
int MDims;
int MElemSize;
std::vector<char> MMem;
property_list MPropertyList;
};

Expand Down
Loading