From e56e3ce677b65019d188083626c6d10b1699cd59 Mon Sep 17 00:00:00 2001
From: foreman
Date: Thu, 10 May 2018 14:03:44 -0400
Subject: [PATCH] P4 to Git Change 1553193 by gandryey@gera-lnx-rcf-lc on
2018/05/10 13:55:21
SWDEV-79445 - OCL generic changes and code clean-up
- Following CL#1552596. Add a flag to skip memory allocation. ROCr backend requires access to the parent object in the blit manager, but it's not fully initialized and a view creation is required. However a view creation with not fully initialized object can cause a dead lock if device memory is allocated during the object create.
Affected files ...
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocmemory.cpp#35 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.cpp#132 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.hpp#104 edit
---
rocclr/runtime/device/rocm/rocmemory.cpp | 2 +-
rocclr/runtime/platform/memory.cpp | 8 ++++----
rocclr/runtime/platform/memory.hpp | 6 ++++--
3 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/rocclr/runtime/device/rocm/rocmemory.cpp b/rocclr/runtime/device/rocm/rocmemory.cpp
index 2b68d53143..48bbfee444 100644
--- a/rocclr/runtime/device/rocm/rocmemory.cpp
+++ b/rocclr/runtime/device/rocm/rocmemory.cpp
@@ -708,7 +708,7 @@ bool Buffer::create() {
// data transfer to the view of the buffer.
amd::Buffer* bufferView = new (owner()->getContext())
amd::Buffer(*owner(), 0, owner()->getOrigin(), owner()->getSize());
- bufferView->create();
+ bufferView->create(nullptr, false, true);
roc::Buffer* devBufferView = new roc::Buffer(dev_, *bufferView);
devBufferView->deviceMemory_ = deviceMemory_;
diff --git a/rocclr/runtime/platform/memory.cpp b/rocclr/runtime/platform/memory.cpp
index b17f4032c2..2f00dd8f08 100644
--- a/rocclr/runtime/platform/memory.cpp
+++ b/rocclr/runtime/platform/memory.cpp
@@ -205,7 +205,7 @@ bool Memory::allocHostMemory(void* initFrom, bool allocHostMem, bool forceCopy)
return true;
}
-bool Memory::create(void* initFrom, bool sysMemAlloc) {
+bool Memory::create(void* initFrom, bool sysMemAlloc, bool skipAlloc) {
static const bool forceAllocHostMem = false;
initDeviceMemory();
@@ -238,7 +238,7 @@ bool Memory::create(void* initFrom, bool sysMemAlloc) {
deviceMemories_[i].ref_ = devices[i];
deviceMemories_[i].value_ = NULL;
- if ((devices.size() == 1) || DISABLE_DEFERRED_ALLOC) {
+ if (!skipAlloc && ((devices.size() == 1) || DISABLE_DEFERRED_ALLOC)) {
device::Memory* mem = getDeviceMemory(*devices[i]);
if (NULL == mem) {
LogPrintfError("Can't allocate memory size - 0x%08X bytes!", getSize());
@@ -436,7 +436,7 @@ void Buffer::initDeviceMemory() {
memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory));
}
-bool Buffer::create(void* initFrom, bool sysMemAlloc) {
+bool Buffer::create(void* initFrom, bool sysMemAlloc, bool skipAlloc) {
if ((getMemFlags() & CL_MEM_EXTERNAL_PHYSICAL_AMD) && (initFrom != NULL)) {
busAddress_ = *(reinterpret_cast(initFrom));
initFrom = NULL;
@@ -444,7 +444,7 @@ bool Buffer::create(void* initFrom, bool sysMemAlloc) {
busAddress_.surface_bus_address = 0;
busAddress_.marker_bus_address = 0;
}
- return Memory::create(initFrom, sysMemAlloc);
+ return Memory::create(initFrom, sysMemAlloc, skipAlloc);
}
bool Buffer::isEntirelyCovered(const Coord3D& origin, const Coord3D& region) const {
diff --git a/rocclr/runtime/platform/memory.hpp b/rocclr/runtime/platform/memory.hpp
index 53714d58b2..ec31e4eebe 100644
--- a/rocclr/runtime/platform/memory.hpp
+++ b/rocclr/runtime/platform/memory.hpp
@@ -228,7 +228,8 @@ class Memory : public amd::RuntimeObject {
//! Creates and initializes device (cache) memory for all devices
virtual bool create(void* initFrom = NULL, //!< Pointer to the initialization data
- bool sysMemAlloc = false //!< Allocate device memory in system memory
+ bool sysMemAlloc = false, //!< Allocate device memory in system memory
+ bool skipAlloc = false //!< Skip device memory allocation
);
//! Allocates device (cache) memory for a specific device
@@ -338,7 +339,8 @@ class Buffer : public Memory {
: Memory(parent, flags, origin, size) {}
bool create(void* initFrom = NULL, //!< Pointer to the initialization data
- bool sysMemAlloc = false //!< Allocate device memory in system memory
+ bool sysMemAlloc = false, //!< Allocate device memory in system memory
+ bool skipAlloc = false //!< Skip device memory allocation
);
//! static_cast to Buffer with sanity check