From b7d5427f017fc876f5ae6d81f0e13c0ef884ebbf Mon Sep 17 00:00:00 2001 From: Slawomir Milczarek Date: Fri, 30 Oct 2020 09:02:18 +0100 Subject: [PATCH] CPU access disallowed mode and blitter amendments Related-To: NEO-4876 Change-Id: I7d6de1a0530e9c4f8bcf302824242033d3ca724a Signed-off-by: Slawomir Milczarek --- opencl/source/command_queue/command_queue.cpp | 8 ++--- .../command_queue/command_queue_tests.cpp | 33 ++++++++++++------ .../enqueue_read_image_tests.cpp | 1 + .../enqueue_write_image_tests.cpp | 1 + .../gen12lp/dg1/hw_helper_tests_dg1.cpp | 16 +++++++++ .../gen12lp/hw_helper_tests_gen12lp.inl | 34 +++++++++++++++++++ .../gen12lp/tgllp/test_hw_helper_tgllp.cpp | 16 +++++++++ shared/source/gen12lp/helpers_gen12lp.cpp | 8 +++++ shared/source/gen12lp/helpers_gen12lp.h | 3 ++ shared/source/gen12lp/helpers_gen12lp_dg1.cpp | 8 +++++ shared/source/gen12lp/hw_helper_gen12lp.cpp | 20 +++++++++++ 11 files changed, 134 insertions(+), 14 deletions(-) diff --git a/opencl/source/command_queue/command_queue.cpp b/opencl/source/command_queue/command_queue.cpp index bd16f23a82..84aa745e7f 100644 --- a/opencl/source/command_queue/command_queue.cpp +++ b/opencl/source/command_queue/command_queue.cpp @@ -637,11 +637,11 @@ bool CommandQueue::queueDependenciesClearRequired() const { } bool CommandQueue::blitEnqueueAllowed(cl_command_type cmdType) const { + auto blitterSupported = device->getHardwareInfo().capabilityTable.blitterOperationsSupported || this->isCopyOnly; - auto blitAllowed = device->getHardwareInfo().capabilityTable.blitterOperationsSupported || this->isCopyOnly; + bool blitEnqueueAllowed = getGpgpuCommandStreamReceiver().peekTimestampPacketWriteEnabled() || this->isCopyOnly; if (DebugManager.flags.EnableBlitterForEnqueueOperations.get() != -1) { - - blitAllowed &= static_cast(DebugManager.flags.EnableBlitterForEnqueueOperations.get()); + blitEnqueueAllowed = DebugManager.flags.EnableBlitterForEnqueueOperations.get(); } switch (cmdType) { @@ -654,7 +654,7 @@ bool CommandQueue::blitEnqueueAllowed(cl_command_type cmdType) const { case CL_COMMAND_SVM_MEMCPY: case CL_COMMAND_READ_IMAGE: case CL_COMMAND_WRITE_IMAGE: - return blitAllowed; + return blitterSupported && blitEnqueueAllowed; default: return false; } diff --git a/opencl/test/unit_test/command_queue/command_queue_tests.cpp b/opencl/test/unit_test/command_queue/command_queue_tests.cpp index fd01754bc8..75d4f62008 100644 --- a/opencl/test/unit_test/command_queue/command_queue_tests.cpp +++ b/opencl/test/unit_test/command_queue/command_queue_tests.cpp @@ -1160,16 +1160,29 @@ TEST(CommandQueue, giveClCommandWhenCallingBlitEnqueueAllowedThenReturnCorrectVa MockCommandQueue queue(&context, context.getDevice(0), 0); hwInfo->capabilityTable.blitterOperationsSupported = true; - EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_READ_BUFFER)); - EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_WRITE_BUFFER)); - EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_COPY_BUFFER)); - EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_READ_BUFFER_RECT)); - EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_WRITE_BUFFER_RECT)); - EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_COPY_BUFFER_RECT)); - EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_SVM_MEMCPY)); - EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_READ_IMAGE)); - EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_WRITE_IMAGE)); - EXPECT_FALSE(queue.blitEnqueueAllowed(CL_COMMAND_COPY_IMAGE)); + if (queue.getGpgpuCommandStreamReceiver().peekTimestampPacketWriteEnabled()) { + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_READ_BUFFER)); + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_WRITE_BUFFER)); + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_COPY_BUFFER)); + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_READ_BUFFER_RECT)); + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_WRITE_BUFFER_RECT)); + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_COPY_BUFFER_RECT)); + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_SVM_MEMCPY)); + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_READ_IMAGE)); + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_WRITE_IMAGE)); + EXPECT_FALSE(queue.blitEnqueueAllowed(CL_COMMAND_COPY_IMAGE)); + } else { + EXPECT_FALSE(queue.blitEnqueueAllowed(CL_COMMAND_READ_BUFFER)); + EXPECT_FALSE(queue.blitEnqueueAllowed(CL_COMMAND_WRITE_BUFFER)); + EXPECT_FALSE(queue.blitEnqueueAllowed(CL_COMMAND_COPY_BUFFER)); + EXPECT_FALSE(queue.blitEnqueueAllowed(CL_COMMAND_READ_BUFFER_RECT)); + EXPECT_FALSE(queue.blitEnqueueAllowed(CL_COMMAND_WRITE_BUFFER_RECT)); + EXPECT_FALSE(queue.blitEnqueueAllowed(CL_COMMAND_COPY_BUFFER_RECT)); + EXPECT_FALSE(queue.blitEnqueueAllowed(CL_COMMAND_SVM_MEMCPY)); + EXPECT_FALSE(queue.blitEnqueueAllowed(CL_COMMAND_READ_IMAGE)); + EXPECT_FALSE(queue.blitEnqueueAllowed(CL_COMMAND_WRITE_IMAGE)); + EXPECT_FALSE(queue.blitEnqueueAllowed(CL_COMMAND_COPY_IMAGE)); + } } TEST(CommandQueue, givenCopySizeAndOffsetWhenCallingBlitEnqueueImageAllowedThenReturnCorrectValue) { diff --git a/opencl/test/unit_test/command_queue/enqueue_read_image_tests.cpp b/opencl/test/unit_test/command_queue/enqueue_read_image_tests.cpp index 3adb673ab1..51b4494922 100644 --- a/opencl/test/unit_test/command_queue/enqueue_read_image_tests.cpp +++ b/opencl/test/unit_test/command_queue/enqueue_read_image_tests.cpp @@ -433,6 +433,7 @@ HWTEST_F(EnqueueReadImageTest, GivenImage1DThatIsZeroCopyWhenReadImageWithTheSam HWTEST_F(EnqueueReadImageTest, givenDeviceWithBlitterSupportWhenEnqueueReadImageThenBlitEnqueueImageAllowedReturnsCorrectResult) { DebugManagerStateRestore restorer; DebugManager.flags.OverrideInvalidEngineWithDefault.set(1); + DebugManager.flags.EnableBlitterForEnqueueOperations.set(1); auto &capabilityTable = pClDevice->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable; capabilityTable.blitterOperationsSupported = true; diff --git a/opencl/test/unit_test/command_queue/enqueue_write_image_tests.cpp b/opencl/test/unit_test/command_queue/enqueue_write_image_tests.cpp index 51385ee6c9..1152c08d8f 100644 --- a/opencl/test/unit_test/command_queue/enqueue_write_image_tests.cpp +++ b/opencl/test/unit_test/command_queue/enqueue_write_image_tests.cpp @@ -205,6 +205,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, EnqueueWriteImageTest, WhenWritingImageThenMediaVfeS HWTEST_F(EnqueueWriteImageTest, givenDeviceWithBlitterSupportWhenEnqueueWriteImageThenBlitEnqueueImageAllowedReturnsCorrectResult) { DebugManagerStateRestore restorer; DebugManager.flags.OverrideInvalidEngineWithDefault.set(1); + DebugManager.flags.EnableBlitterForEnqueueOperations.set(1); auto &capabilityTable = pClDevice->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable; capabilityTable.blitterOperationsSupported = true; diff --git a/opencl/test/unit_test/gen12lp/dg1/hw_helper_tests_dg1.cpp b/opencl/test/unit_test/gen12lp/dg1/hw_helper_tests_dg1.cpp index 823067868c..49c359390d 100644 --- a/opencl/test/unit_test/gen12lp/dg1/hw_helper_tests_dg1.cpp +++ b/opencl/test/unit_test/gen12lp/dg1/hw_helper_tests_dg1.cpp @@ -111,3 +111,19 @@ DG1TEST_F(HwHelperTestDg1, givenDg1WhenSteppingB0ThenIntegerDivisionEmulationIsN auto &helper = HwHelper::get(renderCoreFamily); EXPECT_FALSE(helper.isForceEmuInt32DivRemSPWARequired(hardwareInfo)); } + +DG1TEST_F(HwHelperTestDg1, givenDg1WhenObtainingBlitterPreferenceThenReturnFalse) { + auto &helper = HwHelper::get(renderCoreFamily); + + EXPECT_FALSE(helper.obtainBlitterPreference(hardwareInfo)); +} + +DG1TEST_F(HwHelperTestDg1, givenDg1WhenGettingLocalMemoryAccessModeThenReturnCpuAccessDefault) { + struct MockHwHelper : HwHelperHw { + using HwHelper::getDefaultLocalMemoryAccessMode; + }; + + auto hwHelper = static_cast(HwHelper::get(renderCoreFamily)); + + EXPECT_EQ(LocalMemoryAccessMode::Default, hwHelper.getDefaultLocalMemoryAccessMode(*defaultHwInfo)); +} diff --git a/opencl/test/unit_test/gen12lp/hw_helper_tests_gen12lp.inl b/opencl/test/unit_test/gen12lp/hw_helper_tests_gen12lp.inl index 050178d98e..b7f3baf0a4 100644 --- a/opencl/test/unit_test/gen12lp/hw_helper_tests_gen12lp.inl +++ b/opencl/test/unit_test/gen12lp/hw_helper_tests_gen12lp.inl @@ -12,6 +12,7 @@ #include "opencl/test/unit_test/gen12lp/special_ult_helper_gen12lp.h" #include "opencl/test/unit_test/helpers/hw_helper_tests.h" #include "opencl/test/unit_test/mocks/mock_context.h" +#include "opencl/test/unit_test/mocks/mock_memory_manager.h" #include "opencl/test/unit_test/mocks/mock_platform.h" #include "engine_node.h" @@ -426,6 +427,39 @@ GEN12LPTEST_F(HwHelperTestGen12Lp, givenL1ForceDisabledWhenRequestingMocsThenPro EXPECT_EQ(mocsL3, helper.getMocsIndex(*gmmHelper, true, true)); } +GEN12LPTEST_F(HwHelperTestGen12Lp, givenAllocationTypeWithCpuAccessRequiredWhenCpuAccessIsDisallowedThenSystemMemoryIsRequested) { + DebugManagerStateRestore restore; + DebugManager.flags.ForceLocalMemoryAccessMode.set(static_cast(LocalMemoryAccessMode::CpuAccessDisallowed)); + + const GraphicsAllocation::AllocationType allocationTypesToUseSystemMemory[] = { + GraphicsAllocation::AllocationType::COMMAND_BUFFER, + GraphicsAllocation::AllocationType::CONSTANT_SURFACE, + GraphicsAllocation::AllocationType::GLOBAL_SURFACE, + GraphicsAllocation::AllocationType::INTERNAL_HEAP, + GraphicsAllocation::AllocationType::LINEAR_STREAM, + GraphicsAllocation::AllocationType::PIPE, + GraphicsAllocation::AllocationType::PRINTF_SURFACE, + GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER, + GraphicsAllocation::AllocationType::RING_BUFFER, + GraphicsAllocation::AllocationType::SEMAPHORE_BUFFER}; + + MockMemoryManager mockMemoryManager; + for (auto allocationType : allocationTypesToUseSystemMemory) { + AllocationData allocData{}; + AllocationProperties properties(mockRootDeviceIndex, true, 10, allocationType, false, mockDeviceBitfield); + mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); + + EXPECT_TRUE(allocData.flags.requiresCpuAccess); + EXPECT_TRUE(allocData.flags.useSystemMemory); + } + + AllocationData allocData{}; + AllocationProperties properties(mockRootDeviceIndex, true, 10, GraphicsAllocation::AllocationType::BUFFER, false, mockDeviceBitfield); + mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); + EXPECT_FALSE(allocData.flags.requiresCpuAccess); + EXPECT_FALSE(allocData.flags.useSystemMemory); +} + HWTEST2_F(HwHelperTestGen12Lp, givenRevisionEnumThenProperValueForIsWorkaroundRequiredIsReturned, IsRKL) { std::vector steppings; HardwareInfo hardwareInfo = *defaultHwInfo; diff --git a/opencl/test/unit_test/gen12lp/tgllp/test_hw_helper_tgllp.cpp b/opencl/test/unit_test/gen12lp/tgllp/test_hw_helper_tgllp.cpp index 183ade33bc..e9dae62db2 100644 --- a/opencl/test/unit_test/gen12lp/tgllp/test_hw_helper_tgllp.cpp +++ b/opencl/test/unit_test/gen12lp/tgllp/test_hw_helper_tgllp.cpp @@ -75,3 +75,19 @@ TGLLPTEST_F(HwHelperTestGen12Lp, givenTgllpAndVariousSteppingsWhenGettingIsWorka } } } + +TGLLPTEST_F(HwHelperTestGen12Lp, givenTgllpWhenObtainingBlitterPreferenceThenReturnFalse) { + auto &helper = HwHelper::get(renderCoreFamily); + + EXPECT_FALSE(helper.obtainBlitterPreference(hardwareInfo)); +} + +TGLLPTEST_F(HwHelperTestGen12Lp, givenTgllpWhenGettingLocalMemoryAccessModeThenReturnCpuAccessDefault) { + struct MockHwHelper : HwHelperHw { + using HwHelper::getDefaultLocalMemoryAccessMode; + }; + + auto hwHelper = static_cast(HwHelper::get(renderCoreFamily)); + + EXPECT_EQ(LocalMemoryAccessMode::Default, hwHelper.getDefaultLocalMemoryAccessMode(*defaultHwInfo)); +} diff --git a/shared/source/gen12lp/helpers_gen12lp.cpp b/shared/source/gen12lp/helpers_gen12lp.cpp index 33d60e7b78..15cba8b0a6 100644 --- a/shared/source/gen12lp/helpers_gen12lp.cpp +++ b/shared/source/gen12lp/helpers_gen12lp.cpp @@ -68,5 +68,13 @@ bool forceBlitterUseForGlobalBuffers(const HardwareInfo &hwInfo, GraphicsAllocat return false; } +bool obtainBlitterPreference(const HardwareInfo &hwInfo) { + return false; +} + +LocalMemoryAccessMode getDefaultLocalMemoryAccessMode(const HardwareInfo &hwInfo) { + return LocalMemoryAccessMode::Default; +} + } // namespace Gen12LPHelpers } // namespace NEO diff --git a/shared/source/gen12lp/helpers_gen12lp.h b/shared/source/gen12lp/helpers_gen12lp.h index 0b32c2c1e1..16c125aba3 100644 --- a/shared/source/gen12lp/helpers_gen12lp.h +++ b/shared/source/gen12lp/helpers_gen12lp.h @@ -20,6 +20,7 @@ class GraphicsAllocation; struct HardwareInfo; struct PipelineSelectArgs; class Image; +enum class LocalMemoryAccessMode; namespace Gen12LPHelpers { bool pipeControlWaRequired(PRODUCT_FAMILY productFamily); @@ -38,6 +39,8 @@ bool isOffsetToSkipSetFFIDGPWARequired(const HardwareInfo &hwInfo); bool isForceEmuInt32DivRemSPWARequired(const HardwareInfo &hwInfo); bool is3DPipelineSelectWARequired(const HardwareInfo &hwInfo); bool forceBlitterUseForGlobalBuffers(const HardwareInfo &hwInfo, GraphicsAllocation *allocation); +bool obtainBlitterPreference(const HardwareInfo &hwInfo); +LocalMemoryAccessMode getDefaultLocalMemoryAccessMode(const HardwareInfo &hwInfo); } // namespace Gen12LPHelpers } // namespace NEO diff --git a/shared/source/gen12lp/helpers_gen12lp_dg1.cpp b/shared/source/gen12lp/helpers_gen12lp_dg1.cpp index 6aafc3f68e..db5aefd479 100644 --- a/shared/source/gen12lp/helpers_gen12lp_dg1.cpp +++ b/shared/source/gen12lp/helpers_gen12lp_dg1.cpp @@ -98,5 +98,13 @@ bool forceBlitterUseForGlobalBuffers(const HardwareInfo &hwInfo, GraphicsAllocat return false; } +bool obtainBlitterPreference(const HardwareInfo &hwInfo) { + return false; +} + +LocalMemoryAccessMode getDefaultLocalMemoryAccessMode(const HardwareInfo &hwInfo) { + return LocalMemoryAccessMode::Default; +} + } // namespace Gen12LPHelpers } // namespace NEO diff --git a/shared/source/gen12lp/hw_helper_gen12lp.cpp b/shared/source/gen12lp/hw_helper_gen12lp.cpp index 4e336f2a1d..8f86132aa2 100644 --- a/shared/source/gen12lp/hw_helper_gen12lp.cpp +++ b/shared/source/gen12lp/hw_helper_gen12lp.cpp @@ -288,6 +288,26 @@ bool MemorySynchronizationCommands::isPipeControlPriorToPipelineSel return MemorySynchronizationCommands::isPipeControlWArequired(hwInfo); } +template <> +bool HwHelperHw::obtainBlitterPreference(const HardwareInfo &hwInfo) const { + return Gen12LPHelpers::obtainBlitterPreference(hwInfo); +} + +template <> +inline LocalMemoryAccessMode HwHelperHw::getDefaultLocalMemoryAccessMode(const HardwareInfo &hwInfo) const { + return Gen12LPHelpers::getDefaultLocalMemoryAccessMode(hwInfo); +} + +template <> +void HwHelperHw::setExtraAllocationData(AllocationData &allocationData, const AllocationProperties &properties, const HardwareInfo &hwInfo) const { + HwHelper &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily); + if (hwHelper.getLocalMemoryAccessMode(hwInfo) == LocalMemoryAccessMode::CpuAccessDisallowed) { + if (GraphicsAllocation::isCpuAccessRequired(properties.allocationType)) { + allocationData.flags.useSystemMemory = true; + } + } +} + template class HwHelperHw; template class FlatBatchBufferHelperHw; template struct MemorySynchronizationCommands;