From 60049bfde15ad78ef7cfd8783a02b98c8971003e Mon Sep 17 00:00:00 2001 From: "Romanov, Vlad" Date: Wed, 24 Aug 2022 06:59:00 -0700 Subject: [PATCH 1/2] [SYCL] Fix image::get_size method --- sycl/source/buffer.cpp | 2 +- sycl/source/detail/buffer_impl.cpp | 5 +++-- sycl/source/detail/image_impl.cpp | 6 +++--- sycl/source/detail/plugin.hpp | 1 + .../source/detail/scheduler/graph_builder.cpp | 5 +++-- sycl/source/detail/sycl_mem_obj_i.hpp | 2 +- sycl/source/detail/sycl_mem_obj_t.hpp | 4 ++-- sycl/source/image.cpp | 2 +- sycl/unittests/buffer/CMakeLists.txt | 1 + sycl/unittests/buffer/Image.cpp | 21 +++++++++++++++++++ .../scheduler/LinkedAllocaDependencies.cpp | 2 +- 11 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 sycl/unittests/buffer/Image.cpp diff --git a/sycl/source/buffer.cpp b/sycl/source/buffer.cpp index 3152346ee8249..823e1a19b338f 100644 --- a/sycl/source/buffer.cpp +++ b/sycl/source/buffer.cpp @@ -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) diff --git a/sycl/source/detail/buffer_impl.cpp b/sycl/source/detail/buffer_impl.cpp index 0a29b153ef293..550d803f5086e 100644 --- a/sycl/source/detail/buffer_impl.cpp +++ b/sycl/source/detail/buffer_impl.cpp @@ -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, diff --git a/sycl/source/detail/image_impl.cpp b/sycl/source/detail/image_impl.cpp index 324dbf574985b..f20dbc450039e 100644 --- a/sycl/source/detail/image_impl.cpp +++ b/sycl/source/detail/image_impl.cpp @@ -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, diff --git a/sycl/source/detail/plugin.hpp b/sycl/source/detail/plugin.hpp index b2ed64d591218..e8da5c3e9f3f1 100644 --- a/sycl/source/detail/plugin.hpp +++ b/sycl/source/detail/plugin.hpp @@ -174,6 +174,7 @@ class plugin { // If arguments need to be captured, then a data structure can be sent in // the per_instance_user_data field. const char *PIFnName = PiCallInfo.getFuncName(); + printf("%s\n", PIFnName); uint64_t CorrelationID = pi::emitFunctionBeginTrace(PIFnName); uint64_t CorrelationIDWithArgs = 0; unsigned char *ArgsDataPtr = nullptr; diff --git a/sycl/source/detail/scheduler/graph_builder.cpp b/sycl/source/detail/scheduler/graph_builder.cpp index 10ae8d5aa0d57..e4a609566d4cc 100644 --- a/sycl/source/detail/scheduler/graph_builder.cpp +++ b/sycl/source/detail/scheduler/graph_builder.cpp @@ -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; @@ -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, diff --git a/sycl/source/detail/sycl_mem_obj_i.hpp b/sycl/source/detail/sycl_mem_obj_i.hpp index d2688d3fab4c7..e3dfa11fe35a1 100644 --- a/sycl/source/detail/sycl_mem_obj_i.hpp +++ b/sycl/source/detail/sycl_mem_obj_i.hpp @@ -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. diff --git a/sycl/source/detail/sycl_mem_obj_t.hpp b/sycl/source/detail/sycl_mem_obj_t.hpp index cc49509c98975..69335f5ab72dc 100644 --- a/sycl/source/detail/sycl_mem_obj_t.hpp +++ b/sycl/source/detail/sycl_mem_obj_t.hpp @@ -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 bool has_property() const noexcept { diff --git a/sycl/source/image.cpp b/sycl/source/image.cpp index f8f6cb53e2531..781ff97e47e57 100644 --- a/sycl/source/image.cpp +++ b/sycl/source/image.cpp @@ -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(); } diff --git a/sycl/unittests/buffer/CMakeLists.txt b/sycl/unittests/buffer/CMakeLists.txt index d8123f31f0982..f5dabae23f6df 100644 --- a/sycl/unittests/buffer/CMakeLists.txt +++ b/sycl/unittests/buffer/CMakeLists.txt @@ -1,3 +1,4 @@ add_sycl_unittest(BufferTests OBJECT BufferLocation.cpp + Image.cpp ) diff --git a/sycl/unittests/buffer/Image.cpp b/sycl/unittests/buffer/Image.cpp new file mode 100644 index 0000000000000..9b8c642f7540d --- /dev/null +++ b/sycl/unittests/buffer/Image.cpp @@ -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 + +#include + +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()); +} diff --git a/sycl/unittests/scheduler/LinkedAllocaDependencies.cpp b/sycl/unittests/scheduler/LinkedAllocaDependencies.cpp index f4639fb850205..431285b40ca2b 100644 --- a/sycl/unittests/scheduler/LinkedAllocaDependencies.cpp +++ b/sycl/unittests/scheduler/LinkedAllocaDependencies.cpp @@ -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; } }; From 3e1688245c5eb3c9938f418f13434ce94d2d9c93 Mon Sep 17 00:00:00 2001 From: "Romanov, Vlad" Date: Wed, 24 Aug 2022 10:56:35 -0700 Subject: [PATCH 2/2] Remove leftover --- sycl/source/detail/plugin.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/sycl/source/detail/plugin.hpp b/sycl/source/detail/plugin.hpp index e8da5c3e9f3f1..b2ed64d591218 100644 --- a/sycl/source/detail/plugin.hpp +++ b/sycl/source/detail/plugin.hpp @@ -174,7 +174,6 @@ class plugin { // If arguments need to be captured, then a data structure can be sent in // the per_instance_user_data field. const char *PIFnName = PiCallInfo.getFuncName(); - printf("%s\n", PIFnName); uint64_t CorrelationID = pi::emitFunctionBeginTrace(PIFnName); uint64_t CorrelationIDWithArgs = 0; unsigned char *ArgsDataPtr = nullptr;