From 2bd18360498b66a87d0edb9d3e1f4097fff02ae2 Mon Sep 17 00:00:00 2001 From: Alex Xie Date: Fri, 26 Mar 2021 03:31:59 -0400 Subject: [PATCH] SWDEV-276304 - [Navi][OpenCL][Linux]AMF Converter generate corrupted Frames The copy image workaround could be recursively used by ROCclr blit kernel. Avoid such situation by using stack variable. Change-Id: Iadaa8cad9216220194760dd461a9533bb236aea0 --- rocclr/device/rocm/rocvirtual.cpp | 20 +++++++++++--------- rocclr/device/rocm/rocvirtual.hpp | 7 +++---- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/rocclr/device/rocm/rocvirtual.cpp b/rocclr/device/rocm/rocvirtual.cpp index 06e3566917..00aa67fafd 100644 --- a/rocclr/device/rocm/rocvirtual.cpp +++ b/rocclr/device/rocm/rocvirtual.cpp @@ -433,7 +433,8 @@ void VirtualGPU::HwQueueTracker::ResetCurrentSignal() { // ================================================================================================ bool VirtualGPU::processMemObjects(const amd::Kernel& kernel, const_address params, - size_t& ldsAddress, bool cooperativeGroups) { + size_t& ldsAddress, bool cooperativeGroups, bool& imageBufferWrtBack, + std::vector& wrtBackImageBuffer) { Kernel& hsaKernel = const_cast(static_cast(*(kernel.getDeviceKernel(dev())))); const amd::KernelSignature& signature = kernel.signature(); const amd::KernelParameters& kernelParams = kernel.parameters(); @@ -614,8 +615,8 @@ bool VirtualGPU::processMemObjects(const amd::Kernel& kernel, const_address para // If it's not a read only resource, then runtime has to write back if (!desc.info_.readOnly_) { - wrtBackImageBuffer_.push_back(mem->getDeviceMemory(dev())); - imageBufferWrtBack_ = true; + wrtBackImageBuffer.push_back(mem->getDeviceMemory(dev())); + imageBufferWrtBack = true; } } } @@ -2451,10 +2452,14 @@ bool VirtualGPU::submitKernelInternal(const amd::NDRangeContainer& sizes, const device::Kernel* devKernel = const_cast(kernel.getDeviceKernel(dev())); Kernel& gpuKernel = static_cast(*devKernel); size_t ldsUsage = gpuKernel.WorkgroupGroupSegmentByteSize(); + bool imageBufferWrtBack = false; // Image buffer write back is required + std::vector wrtBackImageBuffer; // Array of images for write back + setLastCommandSDMA(false); // Check memory dependency and SVM objects bool coopGroups = (vcmd != nullptr) ? vcmd->cooperativeGroups() : false; - if (!processMemObjects(kernel, parameters, ldsUsage, coopGroups)) { + if (!processMemObjects(kernel, parameters, ldsUsage, coopGroups, + imageBufferWrtBack, wrtBackImageBuffer)) { LogError("Wrong memory objects!"); return false; } @@ -2698,12 +2703,10 @@ bool VirtualGPU::submitKernelInternal(const amd::NDRangeContainer& sizes, const } // Check if image buffer write back is required - if (imageBufferWrtBack_) { - // Avoid recursive write back - imageBufferWrtBack_ = false; + if (imageBufferWrtBack) { // Make sure the original kernel execution is done releaseGpuMemoryFence(); - for (const auto imageBuffer : wrtBackImageBuffer_) { + for (const auto imageBuffer : wrtBackImageBuffer) { Memory* buffer = dev().getGpuMemory(imageBuffer->owner()->parent()); amd::Image* image = imageBuffer->owner()->asImage(); Image* devImage = static_cast(dev().getGpuMemory(imageBuffer->owner())); @@ -2714,7 +2717,6 @@ bool VirtualGPU::submitKernelInternal(const amd::NDRangeContainer& sizes, const offs, image->getRegion(), true, image->getRowPitch(), image->getSlicePitch()); } - wrtBackImageBuffer_.clear(); } return true; } diff --git a/rocclr/device/rocm/rocvirtual.hpp b/rocclr/device/rocm/rocvirtual.hpp index 964bba5338..d8b2a98a8b 100644 --- a/rocclr/device/rocm/rocvirtual.hpp +++ b/rocclr/device/rocm/rocvirtual.hpp @@ -305,7 +305,9 @@ class VirtualGPU : public device::VirtualDevice { bool processMemObjects(const amd::Kernel& kernel, //!< AMD kernel object for execution const_address params, //!< Pointer to the param's store size_t& ldsAddress, //!< LDS usage - bool cooperativeGroups //!< Dispatch with cooperative groups + bool cooperativeGroups, //!< Dispatch with cooperative groups + bool& imageBufferWrtBack, //!< Image buffer write back is required + std::vector& wrtBackImageBuffer //!< images for write back ); //! Adds a stage write buffer into a list @@ -398,7 +400,6 @@ class VirtualGPU : public device::VirtualDevice { union { struct { uint32_t hasPendingDispatch_ : 1; //!< A kernel dispatch is outstanding - uint32_t imageBufferWrtBack_ : 1; //!< Image buffer write back is required uint32_t profiling_ : 1; //!< Profiling is enabled uint32_t cooperative_ : 1; //!< Cooperative launch is enabled uint32_t addSystemScope_ : 1; //!< Insert a system scope to the next aql @@ -407,8 +408,6 @@ class VirtualGPU : public device::VirtualDevice { uint32_t state_; }; - std::vector wrtBackImageBuffer_; //!< Array of images for write back - Timestamp* timestamp_; hsa_agent_t gpu_device_; //!< Physical device hsa_queue_t* gpu_queue_; //!< Queue associated with a gpu