Skip to content

Commit 78613dc

Browse files
[SYCL] Reduce heap allocations from sycl::local_accessor (#17147)
Ideally, there should be zero but we can't fix that without ABI break (both present, and potential future one for unanticipated future changes). Reduce what we can now: - don't allocate memory on host (no host device, APIs accessing memory must be called from inside "command") - Use `std::make_shared` to fold two allocation into one for pImpl idiom
1 parent 35fba19 commit 78613dc

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,8 +2224,6 @@ class __SYCL_SPECIAL_CLASS local_accessor_base :
22242224
const auto *this_const = this;
22252225
(void)getSize();
22262226
(void)this_const->getSize();
2227-
(void)getPtr();
2228-
(void)this_const->getPtr();
22292227
#endif
22302228
}
22312229

sycl/source/accessor.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ AccessorBaseHost::AccessorBaseHost(id<3> Offset, range<3> AccessRange,
5656
bool IsSubBuffer,
5757
const property_list &PropertyList) {
5858
verifyAccessorProps(PropertyList);
59-
impl = std::shared_ptr<AccessorImplHost>(
60-
new AccessorImplHost(Offset, AccessRange, MemoryRange, AccessMode,
61-
(detail::SYCLMemObjI *)SYCLMemObject, Dims, ElemSize,
62-
false, OffsetInBytes, IsSubBuffer, PropertyList));
59+
impl = std::make_shared<AccessorImplHost>(
60+
Offset, AccessRange, MemoryRange, AccessMode,
61+
(detail::SYCLMemObjI *)SYCLMemObject, Dims, ElemSize, false,
62+
OffsetInBytes, IsSubBuffer, PropertyList);
6363
}
6464

6565
AccessorBaseHost::AccessorBaseHost(id<3> Offset, range<3> AccessRange,
@@ -119,19 +119,14 @@ const sycl::range<3> &LocalAccessorBaseHost::getSize() const {
119119
return impl->MSize;
120120
}
121121
void *LocalAccessorBaseHost::getPtr() {
122-
// Const cast this in order to call the const getPtr.
123-
return const_cast<const LocalAccessorBaseHost *>(this)->getPtr();
122+
// Must not be/isn't called, user-facing APIs do error-checking.
123+
std::abort();
124+
return nullptr;
124125
}
125126
void *LocalAccessorBaseHost::getPtr() const {
126-
char *ptr = impl->MMem.data();
127-
128-
// Align the pointer to MElemSize.
129-
size_t val = reinterpret_cast<size_t>(ptr);
130-
if (val % impl->MElemSize != 0) {
131-
ptr += impl->MElemSize - val % impl->MElemSize;
132-
}
133-
134-
return ptr;
127+
// Must not be/isn't called, user-facing APIs do error-checking.
128+
std::abort();
129+
return nullptr;
135130
}
136131
const property_list &LocalAccessorBaseHost::getPropList() const {
137132
return impl->MPropertyList;

sycl/source/detail/accessor_impl.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,11 @@ class LocalAccessorImplHost {
134134
LocalAccessorImplHost(sycl::range<3> Size, int Dims, int ElemSize,
135135
const property_list &PropertyList)
136136
: MSize(Size), MDims(Dims), MElemSize(ElemSize),
137-
MMem(Size[0] * Size[1] * Size[2] * ElemSize + ElemSize),
138137
MPropertyList(PropertyList) {}
139138

140139
sycl::range<3> MSize;
141140
int MDims;
142141
int MElemSize;
143-
std::vector<char> MMem;
144142
property_list MPropertyList;
145143
};
146144

0 commit comments

Comments
 (0)