Skip to content

Commit 866d634

Browse files
v-klochkovromanovvlad
authored andcommitted
[SYCL] Fix memory deallocation size, fix 2 CTS test fails on Windows
Signed-off-by: Vyacheslav N Klochkov <vyacheslav.n.klochkov@intel.com>
1 parent a47fae3 commit 866d634

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

sycl/include/CL/sycl/detail/sycl_mem_obj_t.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ template <typename AllocatorT> class SYCLMemObjT : public SYCLMemObjI {
101101
}
102102

103103
size_t get_size() const { return MSizeInBytes; }
104+
size_t get_count() const {
105+
auto constexpr AllocatorValueSize =
106+
sizeof(allocator_value_type_t<AllocatorT>);
107+
return (get_size() + AllocatorValueSize - 1) / AllocatorValueSize;
108+
}
104109

105110
template <typename propertyT> bool has_property() const {
106111
return MProps.has_property<propertyT>();
@@ -112,16 +117,11 @@ template <typename AllocatorT> class SYCLMemObjT : public SYCLMemObjI {
112117

113118
AllocatorT get_allocator() const { return MAllocator; }
114119

115-
void *allocateHostMem() override {
116-
size_t AllocatorValueSize = sizeof(allocator_value_type_t<AllocatorT>);
117-
size_t AllocationSize = get_size() / AllocatorValueSize;
118-
AllocationSize += (get_size() % AllocatorValueSize) ? 1 : 0;
119-
return MAllocator.allocate(AllocationSize);
120-
}
120+
void *allocateHostMem() override { return MAllocator.allocate(get_count()); }
121121

122122
void releaseHostMem(void *Ptr) override {
123123
if (Ptr)
124-
MAllocator.deallocate(allocator_pointer_t<AllocatorT>(Ptr), get_size());
124+
MAllocator.deallocate(allocator_pointer_t<AllocatorT>(Ptr), get_count());
125125
}
126126

127127
void releaseMem(ContextImplPtr Context, void *MemAllocation) override {

sycl/test/basic_tests/buffer/buffer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,13 @@ int main() {
643643
b.set_final_data(voidPtr);
644644
}
645645

646+
{
647+
std::allocator<float8> buf_alloc;
648+
cl::sycl::shared_ptr_class<float8> data(new float8[8]);
649+
cl::sycl::buffer<float8, 1, std::allocator<float8>>
650+
b(data, cl::sycl::range<1>(8), buf_alloc);
651+
}
652+
646653
// TODO tests with mutex property
647654
return failed;
648655
}

0 commit comments

Comments
 (0)