Skip to content

Commit cdb0dfd

Browse files
authored
[SYCL] Fix image::get_size method (#6637)
#6600 changed behavior of sycl::image::get_size() to return number of elements rather than number of bytes which an image uses. This is not correct. Changing it back and ename the internal method so it's more clear about what it returns.
1 parent 7fa607f commit cdb0dfd

File tree

10 files changed

+37
-13
lines changed

10 files changed

+37
-13
lines changed

sycl/source/buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void buffer_plain::addOrReplaceAccessorProperties(
119119
impl->addOrReplaceAccessorProperties(PropertyList);
120120
}
121121

122-
size_t buffer_plain::getSize() const { return impl->getSize(); }
122+
size_t buffer_plain::getSize() const { return impl->getSizeInBytes(); }
123123

124124
} // namespace detail
125125
} // __SYCL_INLINE_VER_NAMESPACE(_V1)

sycl/source/detail/buffer_impl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ void *buffer_impl::allocateMem(ContextImplPtr Context, bool InitFromUserData,
2828
"Internal error. Allocating memory on the host "
2929
"while having use_host_ptr property");
3030
return MemoryManager::allocateMemBuffer(
31-
std::move(Context), this, HostPtr, HostPtrReadOnly, BaseT::getSize(),
32-
BaseT::MInteropEvent, BaseT::MInteropContext, MProps, OutEventToWait);
31+
std::move(Context), this, HostPtr, HostPtrReadOnly,
32+
BaseT::getSizeInBytes(), BaseT::MInteropEvent, BaseT::MInteropContext,
33+
MProps, OutEventToWait);
3334
}
3435
void buffer_impl::constructorNotification(const detail::code_location &CodeLoc,
3536
void *UserObj, const void *HostObj,

sycl/source/detail/image_impl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,9 @@ void *image_impl::allocateMem(ContextImplPtr Context, bool InitFromUserData,
311311
"The check an image format failed.");
312312

313313
return MemoryManager::allocateMemImage(
314-
std::move(Context), this, HostPtr, HostPtrReadOnly, BaseT::getSize(),
315-
Desc, Format, BaseT::MInteropEvent, BaseT::MInteropContext, MProps,
316-
OutEventToWait);
314+
std::move(Context), this, HostPtr, HostPtrReadOnly,
315+
BaseT::getSizeInBytes(), Desc, Format, BaseT::MInteropEvent,
316+
BaseT::MInteropContext, MProps, OutEventToWait);
317317
}
318318

319319
bool image_impl::checkImageDesc(const RT::PiMemImageDesc &Desc,

sycl/source/detail/scheduler/graph_builder.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,8 @@ AllocaCommandBase *Scheduler::GraphBuilder::findAllocaForReq(
638638
const Requirement *TmpReq = AllocaCmd->getRequirement();
639639
Res &= AllocaCmd->getType() == Command::CommandType::ALLOCA_SUB_BUF;
640640
Res &= TmpReq->MOffsetInBytes == Req->MOffsetInBytes;
641-
Res &= TmpReq->MSYCLMemObj->getSize() == Req->MSYCLMemObj->getSize();
641+
Res &= TmpReq->MSYCLMemObj->getSizeInBytes() ==
642+
Req->MSYCLMemObj->getSizeInBytes();
642643
Res &= AllowConst || !AllocaCmd->MIsConst;
643644
}
644645
return Res;
@@ -678,7 +679,7 @@ AllocaCommandBase *Scheduler::GraphBuilder::getOrCreateAllocaForReq(
678679
if (IsSuitableSubReq(Req)) {
679680
// Get parent requirement. It's hard to get right parents' range
680681
// so full parent requirement has range represented in bytes
681-
range<3> ParentRange{Req->MSYCLMemObj->getSize(), 1, 1};
682+
range<3> ParentRange{Req->MSYCLMemObj->getSizeInBytes(), 1, 1};
682683
Requirement ParentRequirement(/*Offset*/ {0, 0, 0}, ParentRange,
683684
ParentRange, access::mode::read_write,
684685
Req->MSYCLMemObj, /*Dims*/ 1,

sycl/source/detail/sycl_mem_obj_i.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class SYCLMemObjI {
5959
virtual void releaseHostMem(void *Ptr) = 0;
6060

6161
// Returns size of object in bytes
62-
virtual size_t getSize() const = 0;
62+
virtual size_t getSizeInBytes() const = 0;
6363

6464
// Returns the context which is passed if a memory object is created using
6565
// interoperability constructor, nullptr otherwise.

sycl/source/detail/sycl_mem_obj_t.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ class __SYCL_EXPORT SYCLMemObjT : public SYCLMemObjI {
8282

8383
const plugin &getPlugin() const;
8484

85-
size_t getSize() const override { return MSizeInBytes; }
85+
size_t getSizeInBytes() const override { return MSizeInBytes; }
8686
__SYCL2020_DEPRECATED("get_count() is deprecated, please use size() instead")
8787
size_t get_count() const { return size(); }
8888
size_t size() const noexcept {
8989
size_t AllocatorValueSize = MAllocator->getValueSize();
90-
return (getSize() + AllocatorValueSize - 1) / AllocatorValueSize;
90+
return (getSizeInBytes() + AllocatorValueSize - 1) / AllocatorValueSize;
9191
}
9292

9393
template <typename propertyT> bool has_property() const noexcept {

sycl/source/image.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ range<3> image_plain::get_range() const { return impl->get_range(); }
111111

112112
range<2> image_plain::get_pitch() const { return impl->get_pitch(); }
113113

114-
size_t image_plain::get_size() const { return impl->size(); }
114+
size_t image_plain::get_size() const { return impl->getSizeInBytes(); }
115115

116116
size_t image_plain::get_count() const { return impl->get_count(); }
117117

sycl/unittests/buffer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
add_sycl_unittest(BufferTests OBJECT
22
BufferLocation.cpp
3+
Image.cpp
34
)

sycl/unittests/buffer/Image.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//==-------- buffer_location.cpp --- check buffer_location property --------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
#define SYCL2020_DISABLE_DEPRECATION_WARNINGS
9+
10+
#include <sycl/sycl.hpp>
11+
12+
#include <gtest/gtest.h>
13+
14+
TEST(ImageTest, ImageGetSize) {
15+
constexpr size_t ElementsCount = 4;
16+
constexpr size_t ChannelsCount = 4;
17+
sycl::image<1> Image(sycl::image_channel_order::rgba,
18+
sycl::image_channel_type::fp32, sycl::range<1>(ElementsCount));
19+
20+
EXPECT_EQ(ElementsCount * ChannelsCount * sizeof(float), Image.get_size());
21+
}

sycl/unittests/scheduler/LinkedAllocaDependencies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MemObjMock : public sycl::detail::SYCLMemObjI {
3131
void *allocateHostMem() { return nullptr; }
3232
void releaseMem(ContextImplPtr, void *) {}
3333
void releaseHostMem(void *) {}
34-
size_t getSize() const override { return 10; }
34+
size_t getSizeInBytes() const override { return 10; }
3535
detail::ContextImplPtr getInteropContext() const override { return nullptr; }
3636
};
3737

0 commit comments

Comments
 (0)