From 089a5cc4ad1cbf5c26e4cac8a4ea3f937e85fb01 Mon Sep 17 00:00:00 2001 From: German Andryeyev Date: Fri, 30 Oct 2020 12:10:05 -0400 Subject: [PATCH] Add image view allocation If deferred allocation is disabled, then make sure the image view is created without a delay. Also reset the allocation state, since create() method isn't called for a view creation. Change-Id: I7aa22a62bff18289ade83e56b5d3305ba68c715b --- rocclr/platform/memory.cpp | 24 +++++++++++++++++++++--- rocclr/platform/memory.hpp | 2 ++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/rocclr/platform/memory.cpp b/rocclr/platform/memory.cpp index 857af62400..454b0c131c 100644 --- a/rocclr/platform/memory.cpp +++ b/rocclr/platform/memory.cpp @@ -160,6 +160,15 @@ void Memory::initDeviceMemory() { memset(deviceMemories_, 0, NumDevicesWithP2P() * sizeof(DeviceMemory)); } +// ================================================================================================ +void Memory::resetAllocationState() { + // Reset device memory allocation state + for (size_t i = 0; i < context_().devices().size(); i++) { + deviceAlloced_[context_().devices()[i]].store(AllocInit, std::memory_order_relaxed); + } +} + +// ================================================================================================ void* Memory::operator new(size_t size, const Context& context) { uint32_t devices = context.devices().size(); if (devices == 1) { @@ -1150,9 +1159,10 @@ bool Image::Format::isSupported(const Context& context, cl_mem_object_type image return false; } +// ================================================================================================ Image* Image::createView(const Context& context, const Format& format, device::VirtualDevice* vDev, uint baseMipLevel, cl_mem_flags flags) { - Image* view = NULL; + Image* view = nullptr; // Find the image dimensions and create a corresponding object view = new (context) Image(format, *this, baseMipLevel, flags); @@ -1160,14 +1170,22 @@ Image* Image::createView(const Context& context, const Format& format, device::V // Set GPU virtual device for this view view->setVirtualDevice(vDev); - if (view != NULL) { - // Initialize view + if (view != nullptr) { + view->resetAllocationState(); + + // Initialize array of the device memory pointers view->initDeviceMemory(); + + // Check if runtime has to allocate memory + if ((context.devices().size() == 1) || DISABLE_DEFERRED_ALLOC) { + device::Memory* mem = view->getDeviceMemory(*context.devices()[0]); + } } return view; } +// ================================================================================================ bool Image::isEntirelyCovered(const Coord3D& origin, const Coord3D& region) const { return (origin[0] == 0 && origin[1] == 0 && origin[2] == 0 && region[0] == getWidth() && region[1] == getHeight() && region[2] == getDepth()) diff --git a/rocclr/platform/memory.hpp b/rocclr/platform/memory.hpp index 39d4569379..c134056365 100644 --- a/rocclr/platform/memory.hpp +++ b/rocclr/platform/memory.hpp @@ -215,6 +215,8 @@ class Memory : public amd::RuntimeObject { void setSize(size_t size) { size_ = size; } void setInteropObj(InteropObject* obj) { interopObj_ = obj; } + void resetAllocationState(); + public: //! Placement new operator. void* operator new(size_t size, //!< Original allocation size