From a4ee15064b43646d67c6aa2dbc07190d504ec9f4 Mon Sep 17 00:00:00 2001
From: foreman
Date: Mon, 30 Oct 2017 15:00:41 -0400
Subject: [PATCH] P4 to Git Change 1476364 by gandryey@gera-w8 on 2017/10/30
14:40:10
SWDEV-79445 - Add logic to handle persistent memory separately from the host memory path
- Some of the optimizations applied to the host memory can't be used for persistent
Affected files ...
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocblit.cpp#20 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocmemory.cpp#30 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocmemory.hpp#10 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocvirtual.cpp#45 edit
[ROCm/clr commit: c2105d8f165ca4777236ad3b69fb69430a342ac8]
---
.../clr/rocclr/runtime/device/rocm/rocblit.cpp | 12 ++++++++----
.../rocclr/runtime/device/rocm/rocmemory.cpp | 17 +++++++++--------
.../rocclr/runtime/device/rocm/rocmemory.hpp | 7 +++++++
.../rocclr/runtime/device/rocm/rocvirtual.cpp | 4 ++++
4 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocblit.cpp b/projects/clr/rocclr/runtime/device/rocm/rocblit.cpp
index 3065f987bc..4fc267d3b7 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocblit.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocblit.cpp
@@ -197,7 +197,8 @@ bool DmaBlitManager::writeBuffer(const void* srcHost, device::Memory& dstMemory,
const amd::Coord3D& origin, const amd::Coord3D& size,
bool entire) const {
// Use host copy if memory has direct access
- if (setup_.disableWriteBuffer_ || dstMemory.isHostMemDirectAccess()) {
+ if (setup_.disableWriteBuffer_ || dstMemory.isHostMemDirectAccess() ||
+ gpuMem(dstMemory).IsPersistentDirectMap()) {
return HostBlitManager::writeBuffer(srcHost, dstMemory, origin, size, entire);
} else {
size_t dstSize = size[0];
@@ -283,7 +284,8 @@ bool DmaBlitManager::writeBufferRect(const void* srcHost, device::Memory& dstMem
const amd::BufferRect& bufRect, const amd::Coord3D& size,
bool entire) const {
// Use host copy if memory has direct access
- if (setup_.disableWriteBufferRect_ || dstMemory.isHostMemDirectAccess()) {
+ if (setup_.disableWriteBufferRect_ || dstMemory.isHostMemDirectAccess() ||
+ gpuMem(dstMemory).IsPersistentDirectMap()) {
return HostBlitManager::writeBufferRect(srcHost, dstMemory, hostRect, bufRect, size, entire);
} else {
Memory& xferBuf = dev().xferWrite().acquire();
@@ -1631,7 +1633,8 @@ bool KernelBlitManager::writeBuffer(const void* srcHost, device::Memory& dstMemo
bool result = false;
// Use host copy if memory has direct access
- if (setup_.disableWriteBuffer_ || dstMemory.isHostMemDirectAccess()) {
+ if (setup_.disableWriteBuffer_ || dstMemory.isHostMemDirectAccess() ||
+ gpuMem(dstMemory).IsPersistentDirectMap()) {
result = HostBlitManager::writeBuffer(srcHost, dstMemory, origin, size, entire);
synchronize();
return result;
@@ -1679,7 +1682,8 @@ bool KernelBlitManager::writeBufferRect(const void* srcHost, device::Memory& dst
bool result = false;
// Use host copy if memory has direct access
- if (setup_.disableWriteBufferRect_ || dstMemory.isHostMemDirectAccess()) {
+ if (setup_.disableWriteBufferRect_ || dstMemory.isHostMemDirectAccess() ||
+ gpuMem(dstMemory).IsPersistentDirectMap()) {
result = HostBlitManager::writeBufferRect(srcHost, dstMemory, hostRect, bufRect, size, entire);
synchronize();
return result;
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocmemory.cpp b/projects/clr/rocclr/runtime/device/rocm/rocmemory.cpp
index d789aea9b4..6281979916 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocmemory.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocmemory.cpp
@@ -33,6 +33,7 @@ Memory::Memory(const roc::Device& dev, amd::Memory& owner)
deviceMemory_(nullptr),
kind_(MEMORY_KIND_NORMAL),
amdImageDesc_(nullptr),
+ persistent_host_ptr_(nullptr),
pinnedMemory_(nullptr) {}
Memory::Memory(const roc::Device& dev, size_t size)
@@ -41,6 +42,7 @@ Memory::Memory(const roc::Device& dev, size_t size)
deviceMemory_(nullptr),
kind_(MEMORY_KIND_NORMAL),
amdImageDesc_(nullptr),
+ persistent_host_ptr_(nullptr),
pinnedMemory_(nullptr) {}
Memory::~Memory() {
@@ -93,15 +95,16 @@ void* Memory::allocMapTarget(const amd::Coord3D& origin, const amd::Coord3D& reg
incIndMapCount();
// If the device backing storage is direct accessible, use it.
- const cl_mem_flags memFlags = owner()->getMemFlags();
- if (isHostMemDirectAccess() || (memFlags & CL_MEM_USE_PERSISTENT_MEM_AMD)) {
+ if (isHostMemDirectAccess()) {
if (owner()->getHostMem() != nullptr) {
return (static_cast(owner()->getHostMem()) + origin[0]);
}
return (static_cast(deviceMemory_) + origin[0]);
}
-
+ if (IsPersistentDirectMap()) {
+ return (static_cast(persistent_host_ptr_) + origin[0]);
+ }
// Otherwise, check for host memory.
void* hostMem = owner()->getHostMem();
if (hostMem != nullptr) {
@@ -150,8 +153,7 @@ void* Memory::cpuMap(device::VirtualDevice& vDev, uint flags, uint startLayer, u
assert(mapTarget != nullptr);
- const cl_mem_flags memFlags = owner()->getMemFlags();
- if (!isHostMemDirectAccess() && !(memFlags & CL_MEM_USE_PERSISTENT_MEM_AMD)) {
+ if (!isHostMemDirectAccess() && !IsPersistentDirectMap()) {
if (!vDev.blitMgr().readBuffer(*this, mapTarget, amd::Coord3D(0), amd::Coord3D(size()), true)) {
decIndMapCount();
return nullptr;
@@ -162,8 +164,7 @@ void* Memory::cpuMap(device::VirtualDevice& vDev, uint flags, uint startLayer, u
}
void Memory::cpuUnmap(device::VirtualDevice& vDev) {
- const cl_mem_flags memFlags = owner()->getMemFlags();
- if (!isHostMemDirectAccess() && !(memFlags & CL_MEM_USE_PERSISTENT_MEM_AMD)) {
+ if (!isHostMemDirectAccess() && !IsPersistentDirectMap()) {
if (!vDev.blitMgr().writeBuffer(mapMemory_->getHostMem(), *this, amd::Coord3D(0),
amd::Coord3D(size()), true)) {
LogError("[OCL] Fail sync the device memory on cpuUnmap");
@@ -650,7 +651,7 @@ bool Buffer::create() {
if (deviceMemory_ == nullptr) {
return false;
}
- owner()->setHostMem(host_ptr);
+ persistent_host_ptr_ = host_ptr;
return true;
}
#endif
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocmemory.hpp b/projects/clr/rocclr/runtime/device/rocm/rocmemory.hpp
index 95c0c35b67..1fd7ae00e4 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocmemory.hpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocmemory.hpp
@@ -85,6 +85,11 @@ class Memory : public device::Memory {
size_t version() const { return version_; }
+ bool IsPersistentDirectMap() const {
+ return ((owner() != nullptr) && (owner()->getMemFlags() & CL_MEM_USE_PERSISTENT_MEM_AMD)); }
+
+ void* PersistentHostPtr() const { return persistent_host_ptr_; }
+
protected:
bool allocateMapMemory(size_t allocationSize);
@@ -110,6 +115,8 @@ class Memory : public device::Memory {
hsa_amd_image_descriptor_t* amdImageDesc_;
+ void* persistent_host_ptr_; //!< Host accessible pointer for persistent memory
+
private:
// Disable copy constructor
Memory(const Memory&);
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp b/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp
index 57a59cfde6..97c0af820d 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp
@@ -1188,6 +1188,8 @@ void VirtualGPU::submitMapMemory(amd::MapMemoryCommand& cmd) {
// Add memory to VA cache, so rutnime can detect direct access to VA
dev().addVACache(devMemory);
}
+ } else if (devMemory->IsPersistentDirectMap()) {
+ // Persistent memory - NOP map
} else if (mapFlag & (CL_MAP_READ | CL_MAP_WRITE)) {
bool result = false;
roc::Memory* hsaMemory = static_cast(devMemory);
@@ -1266,6 +1268,8 @@ void VirtualGPU::submitUnmapMemory(amd::UnmapMemoryCommand& cmd) {
// Remove memory from VA cache
dev().removeVACache(devMemory);
}
+ } else if (devMemory->IsPersistentDirectMap()) {
+ // Persistent memory - NOP unmap
} else if (mapInfo->isUnmapWrite()) {
// Commit the changes made by the user.
if (!devMemory->isHostMemDirectAccess()) {