diff --git a/rocclr/runtime/device/gpu/gpublit.cpp b/rocclr/runtime/device/gpu/gpublit.cpp index 768022a193..ebd13b0885 100644 --- a/rocclr/runtime/device/gpu/gpublit.cpp +++ b/rocclr/runtime/device/gpu/gpublit.cpp @@ -938,6 +938,8 @@ KernelBlitManager::copyBufferToImage( static const bool CopyRect = false; // Flush DMA for ASYNC copy static const bool FlushDMA = true; + size_t imgRowPitch = size[0] * gpuMem(dstMemory).elementSize(); + size_t imgSlicePitch = imgRowPitch * size[1]; if (setup_.disableCopyBufferToImage_) { result = DmaBlitManager::copyBufferToImage( @@ -948,7 +950,9 @@ KernelBlitManager::copyBufferToImage( } // Check if buffer is in system memory with direct access else if (gpuMem(srcMemory).isHostMemDirectAccess() && - (rowPitch == 0) && (slicePitch == 0)) { + (((rowPitch == 0) && (slicePitch == 0)) || + ((rowPitch == imgRowPitch) && + ((slicePitch == 0) || (slicePitch == imgSlicePitch))))) { // First attempt to do this all with DMA, // but there are restriciton with older hardware if (dev().settings().imageDMA_) { @@ -1330,6 +1334,8 @@ KernelBlitManager::copyImageToBuffer( static const bool CopyRect = false; // Flush DMA for ASYNC copy static const bool FlushDMA = true; + size_t imgRowPitch = size[0] * gpuMem(srcMemory).elementSize(); + size_t imgSlicePitch = imgRowPitch * size[1]; if (setup_.disableCopyImageToBuffer_) { result = HostBlitManager::copyImageToBuffer( @@ -1340,7 +1346,9 @@ KernelBlitManager::copyImageToBuffer( } // Check if buffer is in system memory with direct access else if (gpuMem(dstMemory).isHostMemDirectAccess() && - (rowPitch == 0) && (slicePitch == 0)) { + (((rowPitch == 0) && (slicePitch == 0)) || + ((rowPitch == imgRowPitch) && + ((slicePitch == 0) || (slicePitch == imgSlicePitch))))) { // First attempt to do this all with DMA, // but there are restriciton with older hardware if (dev().settings().imageDMA_) { diff --git a/rocclr/runtime/platform/memory.cpp b/rocclr/runtime/platform/memory.cpp index 808dcf31da..a2e5516289 100644 --- a/rocclr/runtime/platform/memory.cpp +++ b/rocclr/runtime/platform/memory.cpp @@ -1226,17 +1226,21 @@ Image::validateRegion(const Coord3D& origin, const Coord3D& region) const } bool -Image::isSliceValid( - const size_t& rowPitch, - const size_t& slice, - const size_t& height) const +Image::isRowSliceValid( + size_t rowPitch, + size_t slice, + size_t width, + size_t height) const { size_t tmpHeight = (getType() == CL_MEM_OBJECT_IMAGE1D_ARRAY) ? 1 : height; + bool valid = (rowPitch == 0) || ((rowPitch != 0) && + (rowPitch >= width * getImageFormat().getElementSize())); + return ((slice == 0) || ((slice != 0) && - (slice >= rowPitch * tmpHeight))) ? true : false; + (slice >= rowPitch * tmpHeight))) ? valid : false; } void diff --git a/rocclr/runtime/platform/memory.hpp b/rocclr/runtime/platform/memory.hpp index a8edbc09d0..441b9d0039 100644 --- a/rocclr/runtime/platform/memory.hpp +++ b/rocclr/runtime/platform/memory.hpp @@ -577,10 +577,11 @@ public: ) const; //! Returns true if the slice value for the image is valid - bool isSliceValid( - const size_t& rowPitch, //!< The row pitch value - const size_t& slicePitch, //!< The slice pitch value - const size_t& height //!< The height of the copy region + bool isRowSliceValid( + size_t rowPitch, //!< The row pitch value + size_t slicePitch, //!< The slice pitch value + size_t width, //!< The width of the copy region + size_t height //!< The height of the copy region ) const; //! Creates a view memory object