From 5618d4dfa4367d1339a5021748c5a871b6220a5d Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Mon, 1 Feb 2021 14:27:48 +0000 Subject: [PATCH] Correct image initialization for linear storage allocations 2/2 Signed-off-by: Filip Hazubski --- opencl/source/mem_obj/image.cpp | 12 ++++-------- opencl/source/mem_obj/image.h | 6 +++--- .../command_queue/multiple_map_image_tests.cpp | 7 ++++--- opencl/test/unit_test/mocks/mock_memory_manager.h | 5 ++++- shared/source/helpers/hw_helper_base.inl | 5 +++++ shared/source/helpers/hw_helper_bdw_plus.inl | 5 ----- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/opencl/source/mem_obj/image.cpp b/opencl/source/mem_obj/image.cpp index 439ad875da..f100c7c4c9 100644 --- a/opencl/source/mem_obj/image.cpp +++ b/opencl/source/mem_obj/image.cpp @@ -436,22 +436,18 @@ Image *Image::create(Context *context, hostPtr, allocationInfo[rootDeviceIndex].mapAllocation, 0, nullptr, nullptr); } } else { + void *pDestinationAddress = allocationInfo[rootDeviceIndex].memory->getUnderlyingBuffer(); auto isNotInSystemMemory = !MemoryPool::isSystemMemoryPool(allocationInfo[rootDeviceIndex].memory->getMemoryPool()); - auto &allocations = image->getMultiGraphicsAllocation().getGraphicsAllocations(); if (isNotInSystemMemory) { - for (auto &pAllocation : allocations) { - context->getMemoryManager()->lockResource(pAllocation); - } + pDestinationAddress = context->getMemoryManager()->lockResource(allocationInfo[rootDeviceIndex].memory); } - image->transferData(allocationInfo[rootDeviceIndex].memory->getUnderlyingBuffer(), imgInfo.rowPitch, imgInfo.slicePitch, + image->transferData(pDestinationAddress, imgInfo.rowPitch, imgInfo.slicePitch, const_cast(hostPtr), hostPtrRowPitch, hostPtrSlicePitch, copyRegion, copyOrigin); if (isNotInSystemMemory) { - for (auto &pAllocation : allocations) { - context->getMemoryManager()->unlockResource(pAllocation); - } + context->getMemoryManager()->unlockResource(allocationInfo[rootDeviceIndex].memory); } } } diff --git a/opencl/source/mem_obj/image.h b/opencl/source/mem_obj/image.h index 68297807e7..0b6f702467 100644 --- a/opencl/source/mem_obj/image.h +++ b/opencl/source/mem_obj/image.h @@ -219,9 +219,9 @@ class Image : public MemObj { void getOsSpecificImageInfo(const cl_mem_info ¶mName, size_t *srcParamSize, void **srcParam); - void transferData(void *dst, size_t dstRowPitch, size_t dstSlicePitch, - void *src, size_t srcRowPitch, size_t srcSlicePitch, - std::array copyRegion, std::array copyOrigin); + MOCKABLE_VIRTUAL void transferData(void *dst, size_t dstRowPitch, size_t dstSlicePitch, + void *src, size_t srcRowPitch, size_t srcSlicePitch, + std::array copyRegion, std::array copyOrigin); cl_image_format imageFormat; cl_image_desc imageDesc; diff --git a/opencl/test/unit_test/command_queue/multiple_map_image_tests.cpp b/opencl/test/unit_test/command_queue/multiple_map_image_tests.cpp index 7ca9be0c4b..e338e73d54 100644 --- a/opencl/test/unit_test/command_queue/multiple_map_image_tests.cpp +++ b/opencl/test/unit_test/command_queue/multiple_map_image_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -41,8 +41,9 @@ struct MultipleMapImageTest : public ClDeviceFixture, public ::testing::Test { const ClSurfaceFormatInfo *surfaceFormatInfo, const SurfaceOffsets *surfaceOffsets) { auto memoryStorage = multiGraphicsAllocation.getDefaultGraphicsAllocation()->getUnderlyingBuffer(); - return new MockImage(context, memoryProperties, flags, flagsIntel, size, memoryStorage, hostPtr, imageFormat, imageDesc, zeroCopy, multiGraphicsAllocation, - isObjectRedescribed, baseMipLevel, mipCount, *surfaceFormatInfo, surfaceOffsets); + return new MockImage(context, memoryProperties, flags, flagsIntel, size, memoryStorage, hostPtr, imageFormat, imageDesc, + zeroCopy, std::move(multiGraphicsAllocation), isObjectRedescribed, baseMipLevel, mipCount, + *surfaceFormatInfo, surfaceOffsets); }; void transferDataToHostPtr(MemObjSizeArray ©Size, MemObjOffsetArray ©Offset) override { diff --git a/opencl/test/unit_test/mocks/mock_memory_manager.h b/opencl/test/unit_test/mocks/mock_memory_manager.h index faca91800c..c4fb3c9fbc 100644 --- a/opencl/test/unit_test/mocks/mock_memory_manager.h +++ b/opencl/test/unit_test/mocks/mock_memory_manager.h @@ -83,7 +83,9 @@ class MockMemoryManager : public MemoryManagerCreate { void *lockResourceImpl(GraphicsAllocation &gfxAllocation) override { lockResourceCalled++; - return OsAgnosticMemoryManager::lockResourceImpl(gfxAllocation); + auto pLockedMemory = OsAgnosticMemoryManager::lockResourceImpl(gfxAllocation); + lockResourcePointers.push_back(pLockedMemory); + return pLockedMemory; } void unlockResourceImpl(GraphicsAllocation &gfxAllocation) override { @@ -121,6 +123,7 @@ class MockMemoryManager : public MemoryManagerCreate { uint32_t freeGraphicsMemoryCalled = 0u; uint32_t unlockResourceCalled = 0u; uint32_t lockResourceCalled = 0u; + std::vector lockResourcePointers; uint32_t handleFenceCompletionCalled = 0u; uint32_t waitForEnginesCompletionCalled = 0u; bool allocationCreated = false; diff --git a/shared/source/helpers/hw_helper_base.inl b/shared/source/helpers/hw_helper_base.inl index 47448f5247..970ca16472 100644 --- a/shared/source/helpers/hw_helper_base.inl +++ b/shared/source/helpers/hw_helper_base.inl @@ -495,6 +495,11 @@ bool HwHelperHw::useSystemMemoryPlacementForISA(const HardwareInfo &h return !getEnableLocalMemory(hwInfo); } +template +bool HwHelperHw::isCpuImageTransferPreferred(const HardwareInfo &hwInfo) const { + return false; +} + template bool MemorySynchronizationCommands::isPipeControlPriorToPipelineSelectWArequired(const HardwareInfo &hwInfo) { return false; diff --git a/shared/source/helpers/hw_helper_bdw_plus.inl b/shared/source/helpers/hw_helper_bdw_plus.inl index 6d494d0fba..5e44b57f5e 100644 --- a/shared/source/helpers/hw_helper_bdw_plus.inl +++ b/shared/source/helpers/hw_helper_bdw_plus.inl @@ -98,11 +98,6 @@ uint64_t HwHelperHw::getGpuTimeStampInNS(uint64_t timeStamp, double f return static_cast(timeStamp * frequency); } -template -bool HwHelperHw::isCpuImageTransferPreferred(const HardwareInfo &hwInfo) const { - return false; -} - template inline void MemorySynchronizationCommands::addPipeControlWA(LinearStream &commandStream, uint64_t gpuAddress, const HardwareInfo &hwInfo) { }