From be97bf3aaf5eede697d1e08655fa03d19f99edbb Mon Sep 17 00:00:00 2001 From: foreman Date: Wed, 23 Nov 2016 17:20:51 -0500 Subject: [PATCH] P4 to Git Change 1345399 by cpaquot@hog-ocl on 2016/11/23 17:13:30 SWDEV-107558 - Wrong path for map/unmap images If mapMemory is allocated, we shouldn't use the read/writeImage path since they lock/unlock the host pointer which in this case, is mapped to GPU memory already. ReviewBoardURL = http://ocltc.amd.com/reviews/r/11891/diff/ Affected files ... ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocvirtual.cpp#20 edit [ROCm/clr commit: 45bf0e3ba6d9625c75716ab897f345051c74bd28] --- .../rocclr/runtime/device/rocm/rocvirtual.cpp | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp b/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp index 77792eb789..431cdf53f3 100644 --- a/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp +++ b/projects/clr/rocclr/runtime/device/rocm/rocvirtual.cpp @@ -1169,10 +1169,19 @@ void VirtualGPU::submitMapMemory(amd::MapMemoryCommand &cmd) } else if (type == CL_COMMAND_MAP_IMAGE) { amd::Image* image = cmd.memory().asImage(); - result = blitMgr().readImage( - *hsaMemory, hostPtr, amd::Coord3D(0), - image->getRegion(), image->getRowPitch(), - image->getSlicePitch(), true); + if (mapMemory != nullptr) { + roc::Memory *mapMemory = static_cast( + devMemory->mapMemory()->getDeviceMemory(dev(), false)); + result = blitMgr().copyImageToBuffer( + *hsaMemory, *mapMemory, cmd.origin(), + cmd.origin(), cmd.size(), true); + } + else { + result = blitMgr().readImage( + *hsaMemory, hostPtr, amd::Coord3D(0), + image->getRegion(), image->getRowPitch(), + image->getSlicePitch(), true); + } } else { ShouldNotReachHere(); @@ -1217,14 +1226,23 @@ void VirtualGPU::submitUnmapMemory(amd::UnmapMemoryCommand &cmd) if (cmd.memory().asImage() && !imageBuffer) { amd::Image *image = cmd.memory().asImage(); amd::Memory* mapMemory = devMemory->mapMemory(); - void *hostPtr = mapMemory == NULL ? - devMemory->owner()->getHostMem() : - mapMemory->getHostMem(); + if (devMemory->mapMemory() != nullptr) { + roc::Memory *mapMemory = static_cast( + devMemory->mapMemory()->getDeviceMemory(dev(), false)); + result = blitMgr().copyBufferToImage( + *mapMemory, *devMemory, mapInfo->origin_, + mapInfo->origin_, mapInfo->region_, true); + } + else { + void *hostPtr = mapMemory == NULL ? + devMemory->owner()->getHostMem() : + mapMemory->getHostMem(); - result = blitMgr().writeImage( - hostPtr, *devMemory, - amd::Coord3D(0), image->getRegion(), - image->getRowPitch(), image->getSlicePitch(), true); + result = blitMgr().writeImage( + hostPtr, *devMemory, + amd::Coord3D(0), image->getRegion(), + image->getRowPitch(), image->getSlicePitch(), true); + } } else { amd::Coord3D origin(mapInfo->origin_[0]);