|
9 | 9 | #pragma once
|
10 | 10 |
|
11 | 11 | #include <CL/sycl/access/access.hpp>
|
12 |
| -#include <CL/sycl/detail/aligned_allocator.hpp> |
13 | 12 | #include <CL/sycl/detail/export.hpp>
|
14 | 13 | #include <CL/sycl/detail/sycl_mem_obj_i.hpp>
|
15 | 14 | #include <CL/sycl/id.hpp>
|
@@ -178,22 +177,35 @@ class __SYCL_EXPORT LocalAccessorImplHost {
|
178 | 177 | sycl::range<3> MSize;
|
179 | 178 | int MDims;
|
180 | 179 | int MElemSize;
|
181 |
| - std::vector<char, aligned_allocator<char>> MMem; |
| 180 | + std::vector<char> MMem; |
182 | 181 | };
|
183 | 182 |
|
184 | 183 | using LocalAccessorImplPtr = std::shared_ptr<LocalAccessorImplHost>;
|
185 | 184 |
|
186 | 185 | class LocalAccessorBaseHost {
|
187 | 186 | public:
|
188 | 187 | LocalAccessorBaseHost(sycl::range<3> Size, int Dims, int ElemSize) {
|
| 188 | + // Allocate ElemSize more data to have sufficient padding to enforce |
| 189 | + // alignment. |
189 | 190 | impl = std::shared_ptr<LocalAccessorImplHost>(
|
190 |
| - new LocalAccessorImplHost(Size, Dims, ElemSize)); |
| 191 | + new LocalAccessorImplHost(Size + ElemSize, Dims, ElemSize)); |
191 | 192 | }
|
192 | 193 | sycl::range<3> &getSize() { return impl->MSize; }
|
193 | 194 | const sycl::range<3> &getSize() const { return impl->MSize; }
|
194 |
| - void *getPtr() { return impl->MMem.data(); } |
| 195 | + void *getPtr() { |
| 196 | + // Const cast this in order to call the const getPtr. |
| 197 | + return const_cast<const LocalAccessorBaseHost *>(this)->getPtr(); |
| 198 | + } |
195 | 199 | void *getPtr() const {
|
196 |
| - return const_cast<void *>(reinterpret_cast<void *>(impl->MMem.data())); |
| 200 | + char *ptr = impl->MMem.data(); |
| 201 | + |
| 202 | + // Align the pointer to MElemSize. |
| 203 | + size_t val = reinterpret_cast<size_t>(ptr); |
| 204 | + if (val % impl->MElemSize != 0) { |
| 205 | + ptr += impl->MElemSize - val % impl->MElemSize; |
| 206 | + } |
| 207 | + |
| 208 | + return ptr; |
197 | 209 | }
|
198 | 210 |
|
199 | 211 | int getNumOfDims() { return impl->MDims; }
|
|
0 commit comments