Skip to content

[SYCL] Fix image::get_size method #6637

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 2 commits into from
Aug 24, 2022
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: 1 addition & 1 deletion sycl/source/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void buffer_plain::addOrReplaceAccessorProperties(
impl->addOrReplaceAccessorProperties(PropertyList);
}

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

} // namespace detail
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
Expand Down
5 changes: 3 additions & 2 deletions sycl/source/detail/buffer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ void *buffer_impl::allocateMem(ContextImplPtr Context, bool InitFromUserData,
"Internal error. Allocating memory on the host "
"while having use_host_ptr property");
return MemoryManager::allocateMemBuffer(
std::move(Context), this, HostPtr, HostPtrReadOnly, BaseT::getSize(),
BaseT::MInteropEvent, BaseT::MInteropContext, MProps, OutEventToWait);
std::move(Context), this, HostPtr, HostPtrReadOnly,
BaseT::getSizeInBytes(), BaseT::MInteropEvent, BaseT::MInteropContext,
MProps, OutEventToWait);
}
void buffer_impl::constructorNotification(const detail::code_location &CodeLoc,
void *UserObj, const void *HostObj,
Expand Down
6 changes: 3 additions & 3 deletions sycl/source/detail/image_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ void *image_impl::allocateMem(ContextImplPtr Context, bool InitFromUserData,
"The check an image format failed.");

return MemoryManager::allocateMemImage(
std::move(Context), this, HostPtr, HostPtrReadOnly, BaseT::getSize(),
Desc, Format, BaseT::MInteropEvent, BaseT::MInteropContext, MProps,
OutEventToWait);
std::move(Context), this, HostPtr, HostPtrReadOnly,
BaseT::getSizeInBytes(), Desc, Format, BaseT::MInteropEvent,
BaseT::MInteropContext, MProps, OutEventToWait);
}

bool image_impl::checkImageDesc(const RT::PiMemImageDesc &Desc,
Expand Down
5 changes: 3 additions & 2 deletions sycl/source/detail/scheduler/graph_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,8 @@ AllocaCommandBase *Scheduler::GraphBuilder::findAllocaForReq(
const Requirement *TmpReq = AllocaCmd->getRequirement();
Res &= AllocaCmd->getType() == Command::CommandType::ALLOCA_SUB_BUF;
Res &= TmpReq->MOffsetInBytes == Req->MOffsetInBytes;
Res &= TmpReq->MSYCLMemObj->getSize() == Req->MSYCLMemObj->getSize();
Res &= TmpReq->MSYCLMemObj->getSizeInBytes() ==
Req->MSYCLMemObj->getSizeInBytes();
Res &= AllowConst || !AllocaCmd->MIsConst;
}
return Res;
Expand Down Expand Up @@ -678,7 +679,7 @@ AllocaCommandBase *Scheduler::GraphBuilder::getOrCreateAllocaForReq(
if (IsSuitableSubReq(Req)) {
// Get parent requirement. It's hard to get right parents' range
// so full parent requirement has range represented in bytes
range<3> ParentRange{Req->MSYCLMemObj->getSize(), 1, 1};
range<3> ParentRange{Req->MSYCLMemObj->getSizeInBytes(), 1, 1};
Requirement ParentRequirement(/*Offset*/ {0, 0, 0}, ParentRange,
ParentRange, access::mode::read_write,
Req->MSYCLMemObj, /*Dims*/ 1,
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/sycl_mem_obj_i.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SYCLMemObjI {
virtual void releaseHostMem(void *Ptr) = 0;

// Returns size of object in bytes
virtual size_t getSize() const = 0;
virtual size_t getSizeInBytes() const = 0;

// Returns the context which is passed if a memory object is created using
// interoperability constructor, nullptr otherwise.
Expand Down
4 changes: 2 additions & 2 deletions sycl/source/detail/sycl_mem_obj_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ class __SYCL_EXPORT SYCLMemObjT : public SYCLMemObjI {

const plugin &getPlugin() const;

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

template <typename propertyT> bool has_property() const noexcept {
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ range<3> image_plain::get_range() const { return impl->get_range(); }

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

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

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

Expand Down
1 change: 1 addition & 0 deletions sycl/unittests/buffer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_sycl_unittest(BufferTests OBJECT
BufferLocation.cpp
Image.cpp
)
21 changes: 21 additions & 0 deletions sycl/unittests/buffer/Image.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//==-------- buffer_location.cpp --- check buffer_location property --------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#define SYCL2020_DISABLE_DEPRECATION_WARNINGS

#include <sycl/sycl.hpp>

#include <gtest/gtest.h>

TEST(ImageTest, ImageGetSize) {
constexpr size_t ElementsCount = 4;
constexpr size_t ChannelsCount = 4;
sycl::image<1> Image(sycl::image_channel_order::rgba,
sycl::image_channel_type::fp32, sycl::range<1>(ElementsCount));

EXPECT_EQ(ElementsCount * ChannelsCount * sizeof(float), Image.get_size());
}
2 changes: 1 addition & 1 deletion sycl/unittests/scheduler/LinkedAllocaDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MemObjMock : public sycl::detail::SYCLMemObjI {
void *allocateHostMem() { return nullptr; }
void releaseMem(ContextImplPtr, void *) {}
void releaseHostMem(void *) {}
size_t getSize() const override { return 10; }
size_t getSizeInBytes() const override { return 10; }
detail::ContextImplPtr getInteropContext() const override { return nullptr; }
};

Expand Down