diff --git a/opencl/source/mem_obj/image.cpp b/opencl/source/mem_obj/image.cpp index 467b3d6b4a..439ad875da 100644 --- a/opencl/source/mem_obj/image.cpp +++ b/opencl/source/mem_obj/image.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -245,7 +245,7 @@ Image *Image::create(Context *context, allocationInfo[rootDeviceIndex].zeroCopyAllowed = false; Gmm *gmm = nullptr; - auto hwInfo = (&memoryManager->peekExecutionEnvironment())->rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo(); + auto &hwInfo = *memoryManager->peekExecutionEnvironment().rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo(); auto &hwHelper = HwHelper::get((&memoryManager->peekExecutionEnvironment())->rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo()->platform.eRenderCoreFamily); auto clientContext = (&memoryManager->peekExecutionEnvironment())->rootDeviceEnvironments[rootDeviceIndex]->getGmmClientContext(); @@ -287,7 +287,7 @@ Image *Image::create(Context *context, if (!context->isSharedContext) { AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(rootDeviceIndex, imgInfo, false, // allocateMemory - memoryProperties, *hwInfo, + memoryProperties, hwInfo, context->getDeviceBitfieldForAllocation(rootDeviceIndex)); allocationInfo[rootDeviceIndex].memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, hostPtr); @@ -323,7 +323,7 @@ Image *Image::create(Context *context, } else { AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(rootDeviceIndex, imgInfo, true, // allocateMemory - memoryProperties, *hwInfo, + memoryProperties, hwInfo, context->getDeviceBitfieldForAllocation(rootDeviceIndex)); allocationInfo[rootDeviceIndex].memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties); @@ -373,9 +373,9 @@ Image *Image::create(Context *context, for (auto &rootDeviceIndex : context->getRootDeviceIndices()) { - auto hwInfo = (&memoryManager->peekExecutionEnvironment())->rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo(); + auto &hwInfo = *memoryManager->peekExecutionEnvironment().rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo(); - if (context->isProvidingPerformanceHints() && HwHelper::renderCompressedImagesSupported(*hwInfo)) { + if (context->isProvidingPerformanceHints() && HwHelper::renderCompressedImagesSupported(hwInfo)) { if (allocationInfo[rootDeviceIndex].memory->getDefaultGmm()) { if (allocationInfo[rootDeviceIndex].memory->getDefaultGmm()->isRenderCompressed) { context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_NEUTRAL_INTEL, IMAGE_IS_COMPRESSED, image); @@ -422,7 +422,10 @@ Image *Image::create(Context *context, copyRegion = {{imageWidth, imageHeight, std::max(imageDepth, imageCount)}}; } - if (!imgInfo.linearStorage || !MemoryPool::isSystemMemoryPool(allocationInfo[rootDeviceIndex].memory->getMemoryPool())) { + bool isCpuTransferPreferrred = imgInfo.linearStorage && + (MemoryPool::isSystemMemoryPool(allocationInfo[rootDeviceIndex].memory->getMemoryPool()) || + defaultHwHelper.isCpuImageTransferPreferred(hwInfo)); + if (!isCpuTransferPreferrred) { auto cmdQ = context->getSpecialQueue(rootDeviceIndex); if (IsNV12Image(&image->getImageFormat())) { @@ -433,9 +436,23 @@ Image *Image::create(Context *context, hostPtr, allocationInfo[rootDeviceIndex].mapAllocation, 0, nullptr, nullptr); } } else { + auto isNotInSystemMemory = !MemoryPool::isSystemMemoryPool(allocationInfo[rootDeviceIndex].memory->getMemoryPool()); + auto &allocations = image->getMultiGraphicsAllocation().getGraphicsAllocations(); + if (isNotInSystemMemory) { + for (auto &pAllocation : allocations) { + context->getMemoryManager()->lockResource(pAllocation); + } + } + image->transferData(allocationInfo[rootDeviceIndex].memory->getUnderlyingBuffer(), imgInfo.rowPitch, imgInfo.slicePitch, const_cast(hostPtr), hostPtrRowPitch, hostPtrSlicePitch, copyRegion, copyOrigin); + + if (isNotInSystemMemory) { + for (auto &pAllocation : allocations) { + context->getMemoryManager()->unlockResource(pAllocation); + } + } } } diff --git a/opencl/test/unit_test/helpers/hw_helper_tests.cpp b/opencl/test/unit_test/helpers/hw_helper_tests.cpp index ab05e4726b..ad4efdea90 100644 --- a/opencl/test/unit_test/helpers/hw_helper_tests.cpp +++ b/opencl/test/unit_test/helpers/hw_helper_tests.cpp @@ -18,6 +18,7 @@ #include "shared/test/unit_test/cmd_parse/gen_cmd_parse.h" #include "shared/test/unit_test/helpers/debug_manager_state_restore.h" #include "shared/test/unit_test/helpers/variable_backup.h" +#include "shared/test/unit_test/test_macros/test_checks_shared.h" #include "opencl/source/helpers/cl_hw_helper.h" #include "opencl/source/helpers/dispatch_info.h" @@ -1181,3 +1182,9 @@ HWCMDTEST_F(IGFX_GEN8_CORE, HwHelperTest, givenHwHelperWhenAdditionalKernelExecI EXPECT_FALSE(helper.additionalKernelExecInfoSupported(*defaultHwInfo)); } + +TEST_F(HwHelperTest, WhenGettingIsCpuImageTransferPreferredThenFalseIsReturned) { + REQUIRE_IMAGES_OR_SKIP(defaultHwInfo); + auto &hwHelper = HwHelper::get(renderCoreFamily); + EXPECT_FALSE(hwHelper.isCpuImageTransferPreferred(*defaultHwInfo)); +} diff --git a/shared/source/helpers/hw_helper.h b/shared/source/helpers/hw_helper.h index 050f0f18e4..1cd9abd418 100644 --- a/shared/source/helpers/hw_helper.h +++ b/shared/source/helpers/hw_helper.h @@ -127,6 +127,7 @@ class HwHelper { virtual void adjustAddressWidthForCanonize(uint32_t &addressWidth) const = 0; virtual bool isSipWANeeded(const HardwareInfo &hwInfo) const = 0; virtual bool additionalKernelExecInfoSupported(const HardwareInfo &hwInfo) const = 0; + virtual bool isCpuImageTransferPreferred(const HardwareInfo &hwInfo) const = 0; static uint32_t getSubDevicesCount(const HardwareInfo *pHwInfo); static uint32_t getEnginesCount(const HardwareInfo &hwInfo); @@ -322,6 +323,8 @@ class HwHelperHw : public HwHelper { bool additionalKernelExecInfoSupported(const HardwareInfo &hwInfo) const override; + bool isCpuImageTransferPreferred(const HardwareInfo &hwInfo) const override; + protected: LocalMemoryAccessMode getDefaultLocalMemoryAccessMode(const HardwareInfo &hwInfo) const override; diff --git a/shared/source/helpers/hw_helper_bdw_plus.inl b/shared/source/helpers/hw_helper_bdw_plus.inl index 2a5d9c1e04..6d494d0fba 100644 --- a/shared/source/helpers/hw_helper_bdw_plus.inl +++ b/shared/source/helpers/hw_helper_bdw_plus.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 Intel Corporation + * Copyright (C) 2019-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -98,6 +98,11 @@ 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) { }