From e11eb46bfff2470a482c37466431e6bc9c13ded2 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Fri, 25 Mar 2022 11:24:00 +0000 Subject: [PATCH] Unify logic for programming mocs in post sync struct Signed-off-by: Mateusz Jablonski --- .../gpgpu_walker_xehp_and_later.inl | 14 ++------ .../command_container/command_encoder.h | 2 ++ .../command_encoder_bdw_and_later.inl | 3 ++ .../command_encoder_xehp_and_later.inl | 25 +++++++++---- .../command_encoder_tests.cpp | 36 +++++++++++++++++++ 5 files changed, 61 insertions(+), 19 deletions(-) diff --git a/opencl/source/command_queue/gpgpu_walker_xehp_and_later.inl b/opencl/source/command_queue/gpgpu_walker_xehp_and_later.inl index ee1cfcb27f..c4d4de03a2 100644 --- a/opencl/source/command_queue/gpgpu_walker_xehp_and_later.inl +++ b/opencl/source/command_queue/gpgpu_walker_xehp_and_later.inl @@ -100,24 +100,14 @@ void GpgpuWalkerHelper::setupTimestampPacket(LinearStream *cmdStream, const RootDeviceEnvironment &rootDeviceEnvironment) { using COMPUTE_WALKER = typename GfxFamily::COMPUTE_WALKER; + const auto &hwInfo = *rootDeviceEnvironment.getHardwareInfo(); auto &postSyncData = walkerCmd->getPostSync(); postSyncData.setDataportPipelineFlush(true); - auto gmmHelper = rootDeviceEnvironment.getGmmHelper(); - - const auto &hwInfo = *rootDeviceEnvironment.getHardwareInfo(); - if (MemorySynchronizationCommands::getDcFlushEnable(true, hwInfo)) { - postSyncData.setMocs(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED)); - } else { - postSyncData.setMocs(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER)); - } + EncodeDispatchKernel::setupPostSyncMocs(*walkerCmd, rootDeviceEnvironment); EncodeDispatchKernel::adjustTimestampPacket(*walkerCmd, hwInfo); - if (DebugManager.flags.OverridePostSyncMocs.get() != -1) { - postSyncData.setMocs(DebugManager.flags.OverridePostSyncMocs.get()); - } - if (DebugManager.flags.UseImmDataWriteModeOnPostSyncOperation.get()) { postSyncData.setOperation(GfxFamily::POSTSYNC_DATA::OPERATION::OPERATION_WRITE_IMMEDIATE_DATA); auto contextEndAddress = TimestampPacketHelper::getContextEndGpuAddress(*timestampPacketNode); diff --git a/shared/source/command_container/command_encoder.h b/shared/source/command_container/command_encoder.h index 6b989a1ce9..4c9b45ac66 100644 --- a/shared/source/command_container/command_encoder.h +++ b/shared/source/command_container/command_encoder.h @@ -93,6 +93,8 @@ struct EncodeDispatchKernel { static void adjustBindingTablePrefetch(INTERFACE_DESCRIPTOR_DATA &interfaceDescriptor, uint32_t samplerCount, uint32_t bindingTableEntryCount); static void adjustTimestampPacket(WALKER_TYPE &walkerCmd, const HardwareInfo &hwInfo); + + static void setupPostSyncMocs(WALKER_TYPE &walkerCmd, const RootDeviceEnvironment &rootDeviceEnvironment); }; template diff --git a/shared/source/command_container/command_encoder_bdw_and_later.inl b/shared/source/command_container/command_encoder_bdw_and_later.inl index a2cf50edf5..ec42c5dfa8 100644 --- a/shared/source/command_container/command_encoder_bdw_and_later.inl +++ b/shared/source/command_container/command_encoder_bdw_and_later.inl @@ -492,4 +492,7 @@ template inline void EncodeMiArbCheck::adjust(MI_ARB_CHECK &miArbCheck) { } +template +void EncodeDispatchKernel::setupPostSyncMocs(WALKER_TYPE &walkerCmd, const RootDeviceEnvironment &rootDeviceEnvironment) {} + } // namespace NEO diff --git a/shared/source/command_container/command_encoder_xehp_and_later.inl b/shared/source/command_container/command_encoder_xehp_and_later.inl index 1bff8f3175..a59391c553 100644 --- a/shared/source/command_container/command_encoder_xehp_and_later.inl +++ b/shared/source/command_container/command_encoder_xehp_and_later.inl @@ -248,13 +248,7 @@ void EncodeDispatchKernel::encode(CommandContainer &container, UNRECOVERABLE_IF(!(isAligned(args.eventAddress))); postSync.setDestinationAddress(args.eventAddress); - auto gmmHelper = args.device->getRootDeviceEnvironment().getGmmHelper(); - if (MemorySynchronizationCommands::getDcFlushEnable(true, hwInfo)) { - postSync.setMocs(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED)); - } else { - postSync.setMocs(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER)); - } - + EncodeDispatchKernel::setupPostSyncMocs(walkerCmd, args.device->getRootDeviceEnvironment()); EncodeDispatchKernel::adjustTimestampPacket(walkerCmd, hwInfo); } @@ -294,6 +288,23 @@ void EncodeDispatchKernel::encode(CommandContainer &container, PreemptionHelper::applyPreemptionWaCmdsEnd(listCmdBufferStream, *args.device); } +template +inline void EncodeDispatchKernel::setupPostSyncMocs(WALKER_TYPE &walkerCmd, const RootDeviceEnvironment &rootDeviceEnvironment) { + auto &postSyncData = walkerCmd.getPostSync(); + auto gmmHelper = rootDeviceEnvironment.getGmmHelper(); + + const auto &hwInfo = *rootDeviceEnvironment.getHardwareInfo(); + if (MemorySynchronizationCommands::getDcFlushEnable(true, hwInfo)) { + postSyncData.setMocs(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED)); + } else { + postSyncData.setMocs(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER)); + } + + if (DebugManager.flags.OverridePostSyncMocs.get() != -1) { + postSyncData.setMocs(DebugManager.flags.OverridePostSyncMocs.get()); + } +} + template inline void EncodeDispatchKernel::encodeAdditionalWalkerFields(const HardwareInfo &hwInfo, WALKER_TYPE &walkerCmd, KernelExecutionType kernelExecutionType) { } diff --git a/shared/test/unit_test/command_container/command_encoder_tests.cpp b/shared/test/unit_test/command_container/command_encoder_tests.cpp index c1a9aeeab2..01c89c3daf 100644 --- a/shared/test/unit_test/command_container/command_encoder_tests.cpp +++ b/shared/test/unit_test/command_container/command_encoder_tests.cpp @@ -7,10 +7,12 @@ #include "shared/source/command_container/command_encoder.h" #include "shared/source/command_stream/linear_stream.h" +#include "shared/source/gmm_helper/gmm_lib.h" #include "shared/source/memory_manager/graphics_allocation.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/default_hw_info.h" #include "shared/test/common/helpers/unit_test_helper.h" +#include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/test_macros/test.h" using namespace NEO; @@ -133,4 +135,38 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, CommandEncoderTests, givenDebugFlagSetWhenProgrammi EXPECT_FALSE(buffer[0].getPreParserDisable()); } } +} + +HWCMDTEST_F(IGFX_GEN8_CORE, CommandEncoderTests, givenPreXeHpPlatformWhenSetupPostSyncMocsThenNothingHappen) { + using WALKER_TYPE = typename FamilyType::WALKER_TYPE; + + WALKER_TYPE walkerCmd{}; + MockExecutionEnvironment executionEnvironment{}; + EXPECT_NO_THROW(EncodeDispatchKernel::setupPostSyncMocs(walkerCmd, *executionEnvironment.rootDeviceEnvironments[0])); +} + +HWCMDTEST_F(IGFX_XE_HP_CORE, CommandEncoderTests, givenAtLeastXeHpPlatformWhenSetupPostSyncMocsThenCorrect) { + using WALKER_TYPE = typename FamilyType::WALKER_TYPE; + + MockExecutionEnvironment executionEnvironment{}; + auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[0]; + rootDeviceEnvironment.initGmm(); + + { + WALKER_TYPE walkerCmd{}; + EncodeDispatchKernel::setupPostSyncMocs(walkerCmd, rootDeviceEnvironment); + + auto gmmHelper = rootDeviceEnvironment.getGmmHelper(); + auto expectedMocs = MemorySynchronizationCommands::getDcFlushEnable(true, *defaultHwInfo) ? gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED) : gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER); + + EXPECT_EQ(expectedMocs, walkerCmd.getPostSync().getMocs()); + } + { + DebugManagerStateRestore restorer{}; + auto expectedMocs = 9u; + DebugManager.flags.OverridePostSyncMocs.set(expectedMocs); + WALKER_TYPE walkerCmd{}; + EncodeDispatchKernel::setupPostSyncMocs(walkerCmd, rootDeviceEnvironment); + EXPECT_EQ(expectedMocs, walkerCmd.getPostSync().getMocs()); + } } \ No newline at end of file