From fba461ffe569e08543a509b5c5c49084a782ba9d Mon Sep 17 00:00:00 2001
From: foreman
Date: Wed, 3 Dec 2014 19:02:40 -0500
Subject: [PATCH] P4 to Git Change 1102328 by gandryey@gera-dev-w7 on
2014/12/03 18:56:06
EPR #410736 - [CQE OCL][ISV][QR][G] FFMPEG app generating corrupted video output; Faulty CL:1101352
- Add detection for AHP allocation.
FFmpeg uses AHP allocations with CL_MAP_READ flag, but actually performs CPU write into the buffer. With indirect map runtime executes useless transfer on map and doesn't write updated memory on unmap, because a wrong flag sent by the app.
Affected files ...
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpumemory.cpp#113 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpumemory.hpp#44 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.cpp#341 edit
... //depot/stg/opencl/drivers/opencl/tests/ocltst/module/perf/TestList.cpp#40 edit
[ROCm/clr commit: f9f5df731ed6c0818b6c56192e1b106e6c9ce195]
---
projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp | 4 ++--
projects/clr/rocclr/runtime/device/gpu/gpumemory.hpp | 9 +++++++++
projects/clr/rocclr/runtime/device/gpu/gpuvirtual.cpp | 8 ++------
3 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp b/projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp
index ba32590eb4..e70cc0b60b 100644
--- a/projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp
+++ b/projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp
@@ -923,7 +923,7 @@ Memory::allocMapTarget(
// If host memory exists, use it
if ((owner()->getHostMem() != NULL) &&
- (isCacheable() || !isHostMemDirectAccess() || !(mapFlags & CL_MAP_READ))) {
+ isDirectMap(mapFlags)) {
mapAddress = reinterpret_cast(owner()->getHostMem());
}
// If resource is a persistent allocation, we can use it directly
@@ -1249,7 +1249,7 @@ Image::allocMapTarget(
// If host memory exists, use it
if ((owner()->getHostMem() != NULL) &&
- (isCacheable() || !isHostMemDirectAccess() || !(mapFlags & CL_MAP_READ))) {
+ isDirectMap(mapFlags)) {
useRemoteResource = false;
mapAddress = reinterpret_cast(owner()->getHostMem());
amd::Image* amdImage = owner()->asImage();
diff --git a/projects/clr/rocclr/runtime/device/gpu/gpumemory.hpp b/projects/clr/rocclr/runtime/device/gpu/gpumemory.hpp
index fbcd63d0d7..3709091a1a 100644
--- a/projects/clr/rocclr/runtime/device/gpu/gpumemory.hpp
+++ b/projects/clr/rocclr/runtime/device/gpu/gpumemory.hpp
@@ -200,6 +200,15 @@ public:
//! Returns the interop resource for this memory object
const Memory* parent() const { return parent_; }
+ //! Returns TRUE if direct map is acceaptable
+ //! The method detects forced USWC memory on APU and
+ //! will cause a switch to indirect map for MAP_READ operations
+ bool isDirectMap(uint mapFlags)
+ {
+ return (isCacheable() || (owner()->getMemFlags() & CL_MEM_ALLOC_HOST_PTR) ||
+ !isHostMemDirectAccess() || !(mapFlags & CL_MAP_READ));
+ }
+
protected:
//! Decrement map count
void decIndMapCount();
diff --git a/projects/clr/rocclr/runtime/device/gpu/gpuvirtual.cpp b/projects/clr/rocclr/runtime/device/gpu/gpuvirtual.cpp
index 4e1cb76edf..d4085903d2 100644
--- a/projects/clr/rocclr/runtime/device/gpu/gpuvirtual.cpp
+++ b/projects/clr/rocclr/runtime/device/gpu/gpuvirtual.cpp
@@ -1091,9 +1091,7 @@ VirtualGPU::submitMapMemory(amd::MapMemoryCommand& vcmd)
// If we have host memory, use it
if ((memory->owner()->getHostMem() != NULL) &&
- (memory->isCacheable() ||
- !memory->isHostMemDirectAccess() ||
- !(vcmd.mapFlags() & CL_MAP_READ))) {
+ memory->isDirectMap(vcmd.mapFlags())) {
if (!memory->isHostMemDirectAccess()) {
// Make sure GPU finished operation before
// synchronization with the backing store
@@ -1179,9 +1177,7 @@ VirtualGPU::submitUnmapMemory(amd::UnmapMemoryCommand& vcmd)
// We used host memory
if ((owner->getHostMem() != NULL) &&
- (memory->isCacheable() ||
- !memory->isHostMemDirectAccess() ||
- !memory->isUnmapRead())) {
+ memory->isDirectMap(memory->isUnmapRead() ? CL_MAP_READ : 0)) {
if (memory->isUnmapWrite()) {
// Target is the backing store, so sync
owner->signalWrite(NULL);