diff --git a/rocclr/runtime/device/rocm/rocblit.cpp b/rocclr/runtime/device/rocm/rocblit.cpp index a557565ee8..ba8cf926fd 100644 --- a/rocclr/runtime/device/rocm/rocblit.cpp +++ b/rocclr/runtime/device/rocm/rocblit.cpp @@ -22,10 +22,12 @@ DmaBlitManager::DmaBlitManager(VirtualGPU& gpu, Setup setup) inline void DmaBlitManager::synchronize() const { + // todo TS tracking isn't implemented gpu().releaseGpuMemoryFence(); if (syncOperation_) { // gpu().waitAllEngines(); + gpu().releasePinnedMem(); } } diff --git a/rocclr/runtime/device/rocm/rocdevice.cpp b/rocclr/runtime/device/rocm/rocdevice.cpp index 599b574d7f..bde814d9c9 100644 --- a/rocclr/runtime/device/rocm/rocdevice.cpp +++ b/rocclr/runtime/device/rocm/rocdevice.cpp @@ -1417,6 +1417,7 @@ Device::createMemory(amd::Memory &owner) const amd::Coord3D(0, 0, 0), imageView->getRegion(), 0, 0, true); + owner.setHostMem(nullptr); imageView->release(); } @@ -1564,6 +1565,7 @@ Device::xferQueue() const LogError("Couldn't create the device transfer manager!"); } } + xferQueue_->enableSyncBlit(); return xferQueue_; } diff --git a/rocclr/runtime/device/rocm/rocmemory.cpp b/rocclr/runtime/device/rocm/rocmemory.cpp index 6a7ce7756f..4913a8c768 100644 --- a/rocclr/runtime/device/rocm/rocmemory.cpp +++ b/rocclr/runtime/device/rocm/rocmemory.cpp @@ -43,6 +43,9 @@ Memory::Memory(const roc::Device &dev, size_t size) Memory::~Memory() { dev_.removeVACache(this); + if (nullptr != mapMemory_) { + mapMemory_->release(); + } } bool @@ -62,7 +65,6 @@ Memory::allocateMapMemory(size_t allocationSize) if ((mapMemory == NULL) || (!mapMemory->create())) { LogError("[OCL] Fail to allocate map target object"); - dev_.hostFree(mapData); if (mapMemory) { mapMemory->release(); } @@ -125,9 +127,7 @@ Memory::allocMapTarget( } } - roc::Memory* hsaMapMemory = reinterpret_cast( - mapMemory_->getDeviceMemory(dev_)); - return reinterpret_cast
(hsaMapMemory->getDeviceMemory()) + origin[0]; + return reinterpret_cast
(mapMemory_->getHostMem()) + origin[0]; } void @@ -284,7 +284,7 @@ Buffer::destroy() // if they are identical, the host pointer will be // deallocated later on => avoid double deallocation if (isHostMemDirectAccess()) { - if (memFlags & CL_MEM_USE_HOST_PTR) { + if (memFlags & (CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR)) { if (dev_.agent_profile() != HSA_PROFILE_FULL) { hsa_amd_memory_unlock(owner()->getHostMem()); } @@ -318,12 +318,13 @@ Buffer::create() if(owner()->isInterop()) return createInteropBuffer(GL_ARRAY_BUFFER, 0, NULL, NULL); - if (owner()->parent()) { + if (nullptr != owner()->parent()) { + amd::Memory& parent = *owner()->parent(); // Sub-Buffer creation. - roc::Memory *parentBuffer = - static_cast(owner()->parent()->getDeviceMemory(dev_)); + roc:Memory* parentBuffer = + static_cast(parent.getDeviceMemory(dev_)); - if (parentBuffer == NULL) { + if (parentBuffer == nullptr) { LogError("[OCL] Fail to allocate parent buffer"); return false; } @@ -332,8 +333,19 @@ Buffer::create() deviceMemory_ = parentBuffer->getDeviceMemory() + offset; flags_ |= SubMemoryObject; - flags_ |= - parentBuffer->isHostMemDirectAccess() ? HostMemoryDirectAccess : 0; + flags_ |= parentBuffer->isHostMemDirectAccess() ? + HostMemoryDirectAccess : 0; + + // Explicitly set the host memory location, + // because the parent location could change after reallocation + if (nullptr != parent.getHostMem()) { + owner()->setHostMem( + reinterpret_cast(parent.getHostMem()) + offset); + } + else { + owner()->setHostMem(nullptr); + } + return true; } @@ -383,10 +395,7 @@ Buffer::create() owner()->getHostMem(), *devBufferView, amd::Coord3D(0), amd::Coord3D(size()), true); - if (!ret) { - dev_.memFree(deviceMemory_, size()); - deviceMemory_ = NULL; - } + owner()->setHostMem(nullptr); bufferView->release(); return ret; @@ -420,7 +429,7 @@ Buffer::create() } if (owner()->getSvmPtr() != owner()->getHostMem()) { - if (memFlags & CL_MEM_USE_HOST_PTR) { + if (memFlags & (CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR)) { hsa_agent_t agent = dev_.getBackendDevice(); hsa_status_t status = hsa_amd_memory_lock( owner()->getHostMem(), owner()->getSize(), &agent, 1, &deviceMemory_); diff --git a/rocclr/runtime/device/rocm/rocsettings.cpp b/rocclr/runtime/device/rocm/rocsettings.cpp index cbdccdc700..09c299645b 100644 --- a/rocclr/runtime/device/rocm/rocsettings.cpp +++ b/rocclr/runtime/device/rocm/rocsettings.cpp @@ -73,7 +73,7 @@ Settings::Settings() bool Settings::create(bool fullProfile) { - customHostAllocator_ = true; + customHostAllocator_ = false; if (fullProfile) { pinnedXferSize_ = 0; diff --git a/rocclr/runtime/device/rocm/rocvirtual.cpp b/rocclr/runtime/device/rocm/rocvirtual.cpp index 6fe28dea08..1d7c9f20db 100644 --- a/rocclr/runtime/device/rocm/rocvirtual.cpp +++ b/rocclr/runtime/device/rocm/rocvirtual.cpp @@ -1839,4 +1839,10 @@ VirtualGPU::findPinnedMem(void* addr, size_t size) } return nullptr; } + +void +VirtualGPU::enableSyncBlit() const +{ + blitMgr_->enableSynchronization(); +} } // End of roc namespace diff --git a/rocclr/runtime/device/rocm/rocvirtual.hpp b/rocclr/runtime/device/rocm/rocvirtual.hpp index bbf29929f6..95b6a4337d 100644 --- a/rocclr/runtime/device/rocm/rocvirtual.hpp +++ b/rocclr/runtime/device/rocm/rocvirtual.hpp @@ -212,6 +212,8 @@ public: //! Finds if pinned memory is cached amd::Memory* findPinnedMem(void* addr, size_t size); + void enableSyncBlit() const; + // } roc OpenCL integration private: bool dispatchAqlPacket(