diff --git a/shared/test/common/cmd_parse/CMakeLists.txt b/shared/test/common/cmd_parse/CMakeLists.txt index 9d6e3b863b..6b6c8cb543 100644 --- a/shared/test/common/cmd_parse/CMakeLists.txt +++ b/shared/test/common/cmd_parse/CMakeLists.txt @@ -28,5 +28,11 @@ if(TESTS_XEHP_AND_LATER) ) endif() +if(TESTS_PVC_AND_LATER) + list(APPEND NEO_SHARED_TESTS_CMD_PARSE + ${CMAKE_CURRENT_SOURCE_DIR}/cmd_parse_pvc_and_later.inl + ) +endif() + add_subdirectories() set_property(GLOBAL PROPERTY NEO_SHARED_TESTS_CMD_PARSE ${NEO_SHARED_TESTS_CMD_PARSE}) diff --git a/shared/test/common/cmd_parse/cmd_parse_pvc_and_later.inl b/shared/test/common/cmd_parse/cmd_parse_pvc_and_later.inl new file mode 100644 index 0000000000..32c2062c54 --- /dev/null +++ b/shared/test/common/cmd_parse/cmd_parse_pvc_and_later.inl @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/program/kernel_info.h" +#include "shared/test/common/cmd_parse/cmd_parse_3d_state_btd.inl" +#include "shared/test/common/cmd_parse/cmd_parse_base.inl" +#include "shared/test/common/cmd_parse/cmd_parse_compute_mi_arb.inl" +#include "shared/test/common/cmd_parse/cmd_parse_compute_mode.inl" +#include "shared/test/common/cmd_parse/cmd_parse_compute_walker.inl" +#include "shared/test/common/cmd_parse/hw_parse.h" +#include "shared/test/common/cmd_parse/hw_parse.inl" + +#include "gtest/gtest.h" + +using STATE_SIP = GenStruct::STATE_SIP; + +template <> +STATE_SIP *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return STATE_SIP::COMMAND_TYPE_GFXPIPE == pCmd->TheStructure.Common.CommandType && + STATE_SIP::COMMAND_SUBTYPE_GFXPIPE_COMMON == pCmd->TheStructure.Common.CommandSubtype && + STATE_SIP::_3D_COMMAND_OPCODE_GFXPIPE_NONPIPELINED == pCmd->TheStructure.Common._3DCommandOpcode && + STATE_SIP::_3D_COMMAND_SUB_OPCODE_STATE_SIP == pCmd->TheStructure.Common._3DCommandSubOpcode + ? pCmd + : nullptr; +} + +template <> +size_t CmdParse::getCommandLengthHwSpecific(void *cmd) { + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return pCmd->TheStructure.Common.DwordLength + 2; + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return pCmd->TheStructure.Common.DwordLength + 2; + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return pCmd->TheStructure.Common.DwordLength + 2; + } + { + auto pCmd = genCmdCast<_3DSTATE_BINDING_TABLE_POOL_ALLOC *>(cmd); + if (pCmd) + return pCmd->TheStructure.Common.DwordLength + 2; + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return 1; + } + { + auto pCmd = genCmdCast<_3DSTATE_BTD *>(cmd); + if (pCmd) + return pCmd->TheStructure.Common.DwordLength + 2; + } + { + auto pCmd = genCmdCast(cmd); + if (pCmd) + return pCmd->TheStructure.Common.DwordLength + 2; + } + + return 0; +} + +template <> +const char *CmdParse::getCommandNameHwSpecific(void *cmd) { + if (nullptr != genCmdCast(cmd)) { + return "STATE_COMPUTE_MODE"; + } + + if (nullptr != genCmdCast(cmd)) { + return "COMPUTE_WALKER"; + } + + if (nullptr != genCmdCast(cmd)) { + return "CFE_STATE"; + } + + if (nullptr != genCmdCast<_3DSTATE_BINDING_TABLE_POOL_ALLOC *>(cmd)) { + return "_3DSTATE_BINDING_TABLE_POOL_ALLOC"; + } + + if (nullptr != genCmdCast(cmd)) { + return "MI_SET_PREDICATE"; + } + + if (nullptr != genCmdCast<_3DSTATE_BTD *>(cmd)) { + return "_3DSTATE_BTD"; + } + + if (nullptr != genCmdCast(cmd)) { + return "STATE_SIP"; + } + + return "UNKNOWN"; +} + +template struct CmdParse; + +namespace NEO { + +template <> +void HardwareParse::findHardwareCommands(IndirectHeap *dsh) { + typedef typename GenGfxFamily::COMPUTE_WALKER COMPUTE_WALKER; + typedef typename GenGfxFamily::CFE_STATE CFE_STATE; + typedef typename GenGfxFamily::PIPELINE_SELECT PIPELINE_SELECT; + typedef typename GenGfxFamily::STATE_BASE_ADDRESS STATE_BASE_ADDRESS; + typedef typename GenGfxFamily::INTERFACE_DESCRIPTOR_DATA INTERFACE_DESCRIPTOR_DATA; + typedef typename GenGfxFamily::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START; + typedef typename GenGfxFamily::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM; + + itorWalker = find(cmdList.begin(), cmdList.end()); + if (itorWalker != cmdList.end()) { + cmdWalker = *itorWalker; + } + + itorBBStartAfterWalker = find(itorWalker, cmdList.end()); + if (itorBBStartAfterWalker != cmdList.end()) { + cmdBBStartAfterWalker = *itorBBStartAfterWalker; + } + for (auto it = cmdList.begin(); it != cmdList.end(); it++) { + auto lri = genCmdCast(*it); + if (lri) { + lriList.push_back(*it); + } + } + + if (parsePipeControl) { + for (auto it = cmdList.begin(); it != cmdList.end(); it++) { + auto pipeControl = genCmdCast(*it); + if (pipeControl) { + pipeControlList.push_back(*it); + } + } + } + + itorPipelineSelect = find(cmdList.begin(), itorWalker); + if (itorPipelineSelect != itorWalker) { + cmdPipelineSelect = *itorPipelineSelect; + } + + itorMediaVfeState = find(itorPipelineSelect, itorWalker); + if (itorMediaVfeState != itorWalker) { + cmdMediaVfeState = *itorMediaVfeState; + } + + STATE_BASE_ADDRESS *cmdSBA = nullptr; + uint64_t dynamicStateHeap = 0; + itorStateBaseAddress = find(cmdList.begin(), itorWalker); + if (itorStateBaseAddress != itorWalker) { + cmdSBA = (STATE_BASE_ADDRESS *)*itorStateBaseAddress; + cmdStateBaseAddress = *itorStateBaseAddress; + + // Extract the dynamicStateHeap + dynamicStateHeap = cmdSBA->getDynamicStateBaseAddress(); + if (dsh && (dsh->getHeapGpuBase() == dynamicStateHeap)) { + dynamicStateHeap = reinterpret_cast(dsh->getCpuBase()); + } + ASSERT_NE(0u, dynamicStateHeap); + } + + // interfaceDescriptorData should be located within COMPUTE_WALKER + if (cmdWalker) { + // Extract the interfaceDescriptorData + INTERFACE_DESCRIPTOR_DATA &idd = reinterpret_cast(cmdWalker)->getInterfaceDescriptor(); + cmdInterfaceDescriptorData = &idd; + } +} + +template <> +const void *HardwareParse::getStatelessArgumentPointer(const KernelInfo &kernelInfo, uint32_t indexArg, IndirectHeap &ioh, uint32_t rootDeviceIndex) { + typedef typename GenGfxFamily::COMPUTE_WALKER COMPUTE_WALKER; + typedef typename GenGfxFamily::STATE_BASE_ADDRESS STATE_BASE_ADDRESS; + + auto cmdWalker = (COMPUTE_WALKER *)this->cmdWalker; + EXPECT_NE(nullptr, cmdWalker); + auto inlineInComputeWalker = cmdWalker->getInlineDataPointer(); + + auto cmdSBA = (STATE_BASE_ADDRESS *)cmdStateBaseAddress; + EXPECT_NE(nullptr, cmdSBA); + auto argOffset = std::numeric_limits::max(); + // Determine where the argument is + const auto &arg = kernelInfo.getArgDescriptorAt(indexArg); + if (arg.is() && isValidOffset(arg.as().stateless)) { + argOffset = arg.as().stateless; + } else { + return nullptr; + } + + bool inlineDataActive = kernelInfo.kernelDescriptor.kernelAttributes.flags.passInlineData; + auto inlineDataSize = 32u; + + auto offsetCrossThreadData = cmdWalker->getIndirectDataStartAddress(); + + offsetCrossThreadData -= static_cast(ioh.getGraphicsAllocation()->getGpuAddressToPatch()); + + // Get the base of cross thread + auto pCrossThreadData = ptrOffset( + reinterpret_cast(ioh.getCpuBase()), + offsetCrossThreadData); + + if (inlineDataActive) { + if (argOffset < inlineDataSize) { + return ptrOffset(inlineInComputeWalker, argOffset); + } else { + return ptrOffset(pCrossThreadData, argOffset - inlineDataSize); + } + } + + return ptrOffset(pCrossThreadData, argOffset); +} + +template <> +void HardwareParse::findHardwareCommands() { + findHardwareCommands(nullptr); +} +} // namespace NEO diff --git a/shared/test/common/helpers/CMakeLists.txt b/shared/test/common/helpers/CMakeLists.txt index 828286ad12..33c5986876 100644 --- a/shared/test/common/helpers/CMakeLists.txt +++ b/shared/test/common/helpers/CMakeLists.txt @@ -50,6 +50,13 @@ if(TESTS_DG2_AND_LATER) ) endif() +if(TESTS_PVC_AND_LATER) + list(APPEND NEO_CORE_HELPERS_TESTS + ${CMAKE_CURRENT_SOURCE_DIR}/test_blit_commands_helper_pvc_and_later.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/simd_helper_tests_pvc_and_later.inl + ) +endif() + add_subdirectories() target_sources(${TARGET_NAME} PRIVATE diff --git a/shared/test/common/helpers/includes/test_traits_common.h b/shared/test/common/helpers/includes/test_traits_common.h index e0a82e57d0..432a3d232d 100644 --- a/shared/test/common/helpers/includes/test_traits_common.h +++ b/shared/test/common/helpers/includes/test_traits_common.h @@ -11,4 +11,5 @@ #include "shared/test/common/gen8/test_traits_gen8.h" #include "shared/test/common/gen9/test_traits_gen9.h" #include "shared/test/common/xe_hp_core/test_traits_xe_hp_core.h" -#include "shared/test/common/xe_hpg_core/test_traits_xe_hpg_core.h" +#include "shared/test/common/xe_hpc_core/test_traits_xe_hpc_core.h" +#include "shared/test/common/xe_hpg_core/test_traits_xe_hpg_core.h" \ No newline at end of file diff --git a/shared/test/common/helpers/simd_helper_tests_pvc_and_later.inl b/shared/test/common/helpers/simd_helper_tests_pvc_and_later.inl new file mode 100644 index 0000000000..ed019d2565 --- /dev/null +++ b/shared/test/common/helpers/simd_helper_tests_pvc_and_later.inl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/helpers/simd_helper.h" + +#include "test.h" + +namespace NEO { + +template +class GivenSimdSizeWhenGetSimdConfigCalledThenCorrectEnumReturnedPVCAndLater { + public: + static void TestBodyImpl() { + uint32_t simd = 32; + auto result = getSimdConfig(simd); + EXPECT_EQ(result, WALKER_TYPE::SIMD_SIZE::SIMD_SIZE_SIMT32); + + simd = 16; + result = getSimdConfig(simd); + EXPECT_EQ(result, WALKER_TYPE::SIMD_SIZE::SIMD_SIZE_SIMT16); + + simd = 1; + result = getSimdConfig(simd); + EXPECT_EQ(result, WALKER_TYPE::SIMD_SIZE::SIMD_SIZE_SIMT32); + } +}; +} // namespace NEO diff --git a/shared/test/common/helpers/test_blit_commands_helper_pvc_and_later.cpp b/shared/test/common/helpers/test_blit_commands_helper_pvc_and_later.cpp new file mode 100644 index 0000000000..261ae7b741 --- /dev/null +++ b/shared/test/common/helpers/test_blit_commands_helper_pvc_and_later.cpp @@ -0,0 +1,342 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/gmm_helper/client_context/gmm_client_context.h" +#include "shared/test/common/helpers/blit_commands_helper_tests.inl" +#include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/mocks/mock_gmm.h" + +#include "gtest/gtest.h" + +using BlitTests = Test; + +HWTEST2_F(BlitTests, givenOneBytePatternWhenFillPatternWithBlitThenCommandIsProgrammed, IsPVC) { + using MEM_SET = typename FamilyType::MEM_SET; + uint32_t pattern = 1; + uint32_t streamBuffer[100] = {}; + LinearStream stream(streamBuffer, sizeof(streamBuffer)); + MockGraphicsAllocation mockAllocation(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, + reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), + MemoryPool::System4KBPages, MemoryManager::maxOsContextCount); + BlitCommandsHelper::dispatchBlitMemoryColorFill(&mockAllocation, 0, &pattern, sizeof(uint8_t), stream, mockAllocation.getUnderlyingBufferSize(), *pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]); + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(stream.getCpuBase(), 0), stream.getUsed())); + auto itor = find(cmdList.begin(), cmdList.end()); + EXPECT_NE(cmdList.end(), itor); +} + +HWTEST2_F(BlitTests, givenDeviceWithoutDefaultGmmWhenAppendBlitCommandsForVillBufferThenDstCompressionDisabled, IsPVC) { + using MEM_SET = typename FamilyType::MEM_SET; + uint32_t pattern = 1; + uint32_t streamBuffer[100] = {}; + LinearStream stream(streamBuffer, sizeof(streamBuffer)); + MockGraphicsAllocation mockAllocation(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, + reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), + MemoryPool::System4KBPages, MemoryManager::maxOsContextCount); + BlitCommandsHelper::dispatchBlitMemoryColorFill(&mockAllocation, 0, &pattern, sizeof(uint8_t), stream, mockAllocation.getUnderlyingBufferSize(), *pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]); + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(stream.getCpuBase(), 0), stream.getUsed())); + auto itor = find(cmdList.begin(), cmdList.end()); + EXPECT_NE(cmdList.end(), itor); + { + auto blitCmd = genCmdCast(*itor); + EXPECT_EQ(blitCmd->getDestinationCompressible(), MEM_SET::DESTINATION_COMPRESSIBLE::DESTINATION_COMPRESSIBLE_NOT_COMPRESSIBLE); + } +} + +HWTEST2_F(BlitTests, givenGmmWithDisabledCompresionWhenAppendBlitCommandsForVillBufferThenDstCompressionDisabled, IsPVC) { + using MEM_SET = typename FamilyType::MEM_SET; + auto gmm = std::make_unique(pDevice->getGmmClientContext()); + gmm->isCompressionEnabled = false; + + uint32_t pattern = 1; + uint32_t streamBuffer[100] = {}; + LinearStream stream(streamBuffer, sizeof(streamBuffer)); + MockGraphicsAllocation mockAllocation(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, + reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), + MemoryPool::System4KBPages, MemoryManager::maxOsContextCount); + mockAllocation.setGmm(gmm.get(), 0u); + BlitCommandsHelper::dispatchBlitMemoryColorFill(&mockAllocation, 0, &pattern, sizeof(uint8_t), stream, mockAllocation.getUnderlyingBufferSize(), *pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]); + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(stream.getCpuBase(), 0), stream.getUsed())); + auto itor = find(cmdList.begin(), cmdList.end()); + EXPECT_NE(cmdList.end(), itor); + { + auto blitCmd = genCmdCast(*itor); + EXPECT_EQ(blitCmd->getDestinationCompressible(), MEM_SET::DESTINATION_COMPRESSIBLE::DESTINATION_COMPRESSIBLE_NOT_COMPRESSIBLE); + } +} + +HWTEST2_F(BlitTests, givenGmmWithEnabledCompresionWhenAppendBlitCommandsForVillBufferThenDstCompressionEnabled, IsPVC) { + using MEM_SET = typename FamilyType::MEM_SET; + auto gmm = std::make_unique(pDevice->getGmmClientContext()); + gmm->isCompressionEnabled = true; + + uint32_t pattern = 1; + uint32_t streamBuffer[100] = {}; + LinearStream stream(streamBuffer, sizeof(streamBuffer)); + MockGraphicsAllocation mockAllocation(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, + reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), + MemoryPool::System4KBPages, MemoryManager::maxOsContextCount); + mockAllocation.setGmm(gmm.get(), 0u); + const auto &rootDeviceEnvironment = pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]; + BlitCommandsHelper::dispatchBlitMemoryColorFill(&mockAllocation, 0, &pattern, sizeof(uint8_t), stream, mockAllocation.getUnderlyingBufferSize(), *rootDeviceEnvironment); + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(stream.getCpuBase(), 0), stream.getUsed())); + auto itor = find(cmdList.begin(), cmdList.end()); + EXPECT_NE(cmdList.end(), itor); + { + auto blitCmd = genCmdCast(*itor); + EXPECT_EQ(blitCmd->getDestinationCompressible(), MEM_SET::DESTINATION_COMPRESSIBLE::DESTINATION_COMPRESSIBLE_COMPRESSIBLE); + + auto resourceFormat = gmm->gmmResourceInfo->getResourceFormat(); + auto compressionFormat = rootDeviceEnvironment->getGmmClientContext()->getSurfaceStateCompressionFormat(resourceFormat); + EXPECT_EQ(compressionFormat, blitCmd->getCompressionFormat40()); + } +} + +HWTEST2_F(BlitTests, givenOverridedMocksValueWhenAppendBlitCommandsForVillBufferThenDebugMocksValueIsSet, IsPVC) { + using MEM_SET = typename FamilyType::MEM_SET; + DebugManagerStateRestore dbgRestore; + uint32_t mockValue = 5; + DebugManager.flags.OverrideBlitterMocs.set(mockValue); + + uint32_t pattern = 1; + uint32_t streamBuffer[100] = {}; + LinearStream stream(streamBuffer, sizeof(streamBuffer)); + MockGraphicsAllocation mockAllocation(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, + reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), + MemoryPool::System4KBPages, MemoryManager::maxOsContextCount); + BlitCommandsHelper::dispatchBlitMemoryColorFill(&mockAllocation, 0, &pattern, sizeof(uint8_t), stream, mockAllocation.getUnderlyingBufferSize(), *pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]); + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(stream.getCpuBase(), 0), stream.getUsed())); + auto itor = find(cmdList.begin(), cmdList.end()); + EXPECT_NE(cmdList.end(), itor); + { + auto blitCmd = genCmdCast(*itor); + EXPECT_EQ(blitCmd->getDestinationMOCS(), mockValue); + } +} + +HWTEST2_F(BlitTests, givenEnableStatelessCompressionWithUnifiedMemoryAndSystemMemWhenAppendBlitCommandsForVillBufferThenCompresionDisabled, IsPVC) { + using MEM_SET = typename FamilyType::MEM_SET; + DebugManagerStateRestore dbgRestore; + DebugManager.flags.EnableStatelessCompressionWithUnifiedMemory.set(true); + + uint32_t pattern = 1; + uint32_t streamBuffer[100] = {}; + LinearStream stream(streamBuffer, sizeof(streamBuffer)); + MockGraphicsAllocation mockAllocation(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, + reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), + MemoryPool::System4KBPages, MemoryManager::maxOsContextCount); + BlitCommandsHelper::dispatchBlitMemoryColorFill(&mockAllocation, 0, &pattern, sizeof(uint8_t), stream, mockAllocation.getUnderlyingBufferSize(), *pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]); + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(stream.getCpuBase(), 0), stream.getUsed())); + auto itor = find(cmdList.begin(), cmdList.end()); + EXPECT_NE(cmdList.end(), itor); + { + auto blitCmd = genCmdCast(*itor); + EXPECT_EQ(blitCmd->getDestinationCompressible(), MEM_SET::DESTINATION_COMPRESSIBLE::DESTINATION_COMPRESSIBLE_NOT_COMPRESSIBLE); + } +} + +HWTEST2_F(BlitTests, givenEnableStatelessCompressionWithUnifiedMemoryAndLocalMemWhenAppendBlitCommandsForVillBufferThenCompresionEnabled, IsPVC) { + using MEM_SET = typename FamilyType::MEM_SET; + DebugManagerStateRestore dbgRestore; + DebugManager.flags.EnableStatelessCompressionWithUnifiedMemory.set(true); + + uint32_t pattern = 1; + uint32_t streamBuffer[100] = {}; + LinearStream stream(streamBuffer, sizeof(streamBuffer)); + MockGraphicsAllocation mockAllocation(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, + reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), + MemoryPool::LocalMemory, MemoryManager::maxOsContextCount); + BlitCommandsHelper::dispatchBlitMemoryColorFill(&mockAllocation, 0, &pattern, sizeof(uint8_t), stream, mockAllocation.getUnderlyingBufferSize(), *pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]); + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(stream.getCpuBase(), 0), stream.getUsed())); + auto itor = find(cmdList.begin(), cmdList.end()); + EXPECT_NE(cmdList.end(), itor); + { + auto blitCmd = genCmdCast(*itor); + EXPECT_EQ(blitCmd->getDestinationCompressible(), MEM_SET::DESTINATION_COMPRESSIBLE::DESTINATION_COMPRESSIBLE_COMPRESSIBLE); + EXPECT_EQ(static_cast(DebugManager.flags.FormatForStatelessCompressionWithUnifiedMemory.get()), blitCmd->getCompressionFormat40()); + } +} + +HWTEST2_F(BlitTests, givenMemorySizeBiggerThanMaxWidthButLessThanTwiceMaxWidthWhenFillPatternWithBlitThenHeightIsOne, IsPVC) { + using MEM_SET = typename FamilyType::MEM_SET; + uint32_t pattern = 1; + uint32_t streamBuffer[100] = {}; + LinearStream stream(streamBuffer, sizeof(streamBuffer)); + MockGraphicsAllocation mockAllocation(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, + reinterpret_cast(0x1234), 0x1000, 0, (2 * BlitterConstants::maxBlitSetWidth) - 1, + MemoryPool::System4KBPages, MemoryManager::maxOsContextCount); + BlitCommandsHelper::dispatchBlitMemoryColorFill(&mockAllocation, 0, &pattern, sizeof(uint8_t), stream, mockAllocation.getUnderlyingBufferSize(), *pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]); + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(stream.getCpuBase(), 0), stream.getUsed())); + auto itor = find(cmdList.begin(), cmdList.end()); + EXPECT_NE(cmdList.end(), itor); + { + auto cmd = genCmdCast(*itor); + EXPECT_EQ(cmd->getFillHeight(), 1u); + } +} + +HWTEST2_F(BlitTests, givenMemorySizeTwiceBiggerThanMaxWidthWhenFillPatternWithBlitThenHeightIsTwo, IsPVC) { + using MEM_SET = typename FamilyType::MEM_SET; + uint32_t pattern = 1; + uint32_t streamBuffer[100] = {}; + LinearStream stream(streamBuffer, sizeof(streamBuffer)); + MockGraphicsAllocation mockAllocation(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, + reinterpret_cast(0x1234), 0x1000, 0, (2 * BlitterConstants::maxBlitSetWidth), + MemoryPool::System4KBPages, MemoryManager::maxOsContextCount); + BlitCommandsHelper::dispatchBlitMemoryColorFill(&mockAllocation, 0, &pattern, sizeof(uint8_t), stream, mockAllocation.getUnderlyingBufferSize(), *pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]); + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(stream.getCpuBase(), 0), stream.getUsed())); + auto itor = find(cmdList.begin(), cmdList.end()); + EXPECT_NE(cmdList.end(), itor); + { + auto cmd = genCmdCast(*itor); + EXPECT_EQ(cmd->getFillHeight(), 2u); + } +} + +struct BlitTestsTestPvc : BlitColorTests {}; + +template +class GivenLinearStreamWhenCallDispatchBlitMemoryColorFillThenCorrectDepthIsProgrammedPVC : public GivenLinearStreamWhenCallDispatchBlitMemoryColorFillThenCorrectDepthIsProgrammed { + public: + GivenLinearStreamWhenCallDispatchBlitMemoryColorFillThenCorrectDepthIsProgrammedPVC(Device *device) : GivenLinearStreamWhenCallDispatchBlitMemoryColorFillThenCorrectDepthIsProgrammed(device) {} +}; + +template +typename FamilyType::XY_COLOR_BLT::COLOR_DEPTH getColorDepth(size_t patternSize) { + using COLOR_DEPTH = typename FamilyType::XY_COLOR_BLT::COLOR_DEPTH; + COLOR_DEPTH depth = {}; + switch (patternSize) { + case 1: + depth = COLOR_DEPTH::COLOR_DEPTH_8_BIT_COLOR; + break; + case 2: + depth = COLOR_DEPTH::COLOR_DEPTH_16_BIT_COLOR; + break; + case 4: + depth = COLOR_DEPTH::COLOR_DEPTH_32_BIT_COLOR; + break; + case 8: + depth = COLOR_DEPTH::COLOR_DEPTH_64_BIT_COLOR; + break; + case 16: + depth = COLOR_DEPTH::COLOR_DEPTH_128_BIT_COLOR; + break; + } + return depth; +} + +HWTEST2_P(BlitTestsTestPvc, givenCommandStreamWhenCallToDispatchMemoryFillThenColorDepthAreProgrammedCorrectly, IsXeHpcCore) { + auto patternSize = GetParam(); + auto expecttedDepth = getColorDepth(patternSize); + GivenLinearStreamWhenCallDispatchBlitMemoryColorFillThenCorrectDepthIsProgrammedPVC test(pDevice); + test.TestBodyImpl(patternSize, expecttedDepth); +} + +INSTANTIATE_TEST_CASE_P(size_t, + BlitTestsTestPvc, + testing::Values(2, + 4, + 8, + 16)); + +HWTEST2_F(BlitTests, givenMemoryAndImageWhenDispatchCopyImageCallThenCommandAddedToStream, IsPVC) { + using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; + MockGraphicsAllocation srcAlloc; + MockGraphicsAllocation dstAlloc; + MockGraphicsAllocation clearColorAlloc; + + Vec3 dstOffsets = {0, 0, 0}; + Vec3 srcOffsets = {0, 0, 0}; + + Vec3 copySize = {0x100, 0x40, 0x1}; + Vec3 srcSize = {0x100, 0x40, 0x1}; + Vec3 dstSize = {0x100, 0x40, 0x1}; + + size_t srcRowPitch = srcSize.x; + size_t srcSlicePitch = srcSize.y; + size_t dstRowPitch = dstSize.x; + size_t dstSlicePitch = dstSize.y; + + auto blitProperties = BlitProperties::constructPropertiesForCopy(&dstAlloc, &srcAlloc, + dstOffsets, srcOffsets, copySize, srcRowPitch, srcSlicePitch, + dstRowPitch, dstSlicePitch, &clearColorAlloc); + + uint32_t streamBuffer[100] = {}; + LinearStream stream(streamBuffer, sizeof(streamBuffer)); + blitProperties.bytesPerPixel = 4; + blitProperties.srcSize = srcSize; + blitProperties.dstSize = dstSize; + NEO::BlitCommandsHelper::dispatchBlitCommandsRegion(blitProperties, stream, *pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]); + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(stream.getCpuBase(), 0), stream.getUsed())); + auto itor = find(cmdList.begin(), cmdList.end()); + EXPECT_EQ(cmdList.end(), itor); +} + +HWTEST2_F(BlitTests, givenBlockCopyCommandWhenAppendBlitCommandsForImagesThenNothingChanged, IsPVC) { + using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; + auto bltCmd = FamilyType::cmdInitXyCopyBlt; + auto bltCmdBefore = bltCmd; + BlitProperties properties = {}; + auto srcSlicePitch = static_cast(properties.srcSlicePitch); + auto dstSlicePitch = static_cast(properties.dstSlicePitch); + NEO::BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd, pDevice->getRootDeviceEnvironment(), srcSlicePitch, dstSlicePitch); + EXPECT_EQ(memcmp(&bltCmd, &bltCmdBefore, sizeof(XY_COPY_BLT)), 0); +} +HWTEST2_F(BlitTests, givenBlockCopyCommandWhenAppendColorDepthThenNothingChanged, IsPVC) { + using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; + auto bltCmd = FamilyType::cmdInitXyCopyBlt; + auto bltCmdBefore = bltCmd; + BlitProperties properties = {}; + NEO::BlitCommandsHelper::appendColorDepth(properties, bltCmd); + EXPECT_EQ(memcmp(&bltCmd, &bltCmdBefore, sizeof(XY_COPY_BLT)), 0); +} +HWTEST2_F(BlitTests, givenBlockCopyCommandWhenAppendSliceOffsetThenNothingChanged, IsPVC) { + using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; + auto bltCmd = FamilyType::cmdInitXyCopyBlt; + auto bltCmdBefore = bltCmd; + BlitProperties properties = {}; + auto srcSlicePitch = 0u; + auto dstSlicePitch = 0u; + + NEO::BlitCommandsHelper::appendSliceOffsets(properties, bltCmd, 0, pDevice->getRootDeviceEnvironment(), srcSlicePitch, dstSlicePitch); + EXPECT_EQ(memcmp(&bltCmd, &bltCmdBefore, sizeof(XY_COPY_BLT)), 0); +} +HWTEST2_F(BlitTests, givenBlockCopyCommandWhenAppendSurfaceTypeThenNothingChanged, IsPVC) { + using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; + auto bltCmd = FamilyType::cmdInitXyCopyBlt; + auto bltCmdBefore = bltCmd; + BlitProperties properties = {}; + NEO::BlitCommandsHelper::appendSurfaceType(properties, bltCmd); + EXPECT_EQ(memcmp(&bltCmd, &bltCmdBefore, sizeof(XY_COPY_BLT)), 0); +} +HWTEST2_F(BlitTests, givenBlockCopyCommandWhenAppendTilingTypeThenNothingChanged, IsPVC) { + using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; + auto bltCmd = FamilyType::cmdInitXyCopyBlt; + auto bltCmdBefore = bltCmd; + BlitProperties properties = {}; + NEO::BlitCommandsHelper::appendTilingType(GMM_NOT_TILED, GMM_NOT_TILED, bltCmd); + EXPECT_EQ(memcmp(&bltCmd, &bltCmdBefore, sizeof(XY_COPY_BLT)), 0); +} diff --git a/shared/test/common/libult/xe_hpc_core.cpp b/shared/test/common/libult/xe_hpc_core.cpp new file mode 100644 index 0000000000..8d6d8443de --- /dev/null +++ b/shared/test/common/libult/xe_hpc_core.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/helpers/populate_factory.h" +#include "shared/test/common/libult/ult_command_stream_receiver.h" + +namespace NEO { + +typedef XE_HPC_COREFamily Family; + +static auto gfxCore = IGFX_XE_HPC_CORE; + +extern CommandStreamReceiverCreateFunc commandStreamReceiverFactory[2 * IGFX_MAX_CORE]; + +template <> +void populateFactoryTable>() { + commandStreamReceiverFactory[IGFX_MAX_CORE + gfxCore] = UltCommandStreamReceiver::create; +} + +struct enableXeHpcCore { + enableXeHpcCore() { + populateFactoryTable>(); + } +}; + +static enableXeHpcCore enable; + +template class UltCommandStreamReceiver; +} // namespace NEO diff --git a/shared/test/common/test_configuration/aub_tests/xe_hpc_core/CMakeLists.txt b/shared/test/common/test_configuration/aub_tests/xe_hpc_core/CMakeLists.txt new file mode 100644 index 0000000000..4592a4c9fe --- /dev/null +++ b/shared/test/common/test_configuration/aub_tests/xe_hpc_core/CMakeLists.txt @@ -0,0 +1,15 @@ +# +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +if(TESTS_XE_HPC_CORE) + set(NEO_SHARED_aub_tests_configurations + ${NEO_SHARED_aub_tests_configurations} + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/aub_tests_configuration_xe_hpc_core.cpp + ) + + set(NEO_SHARED_aub_tests_configurations ${NEO_SHARED_aub_tests_configurations} PARENT_SCOPE) +endif() diff --git a/shared/test/common/test_configuration/aub_tests/xe_hpc_core/aub_tests_configuration_xe_hpc_core.cpp b/shared/test/common/test_configuration/aub_tests/xe_hpc_core/aub_tests_configuration_xe_hpc_core.cpp new file mode 100644 index 0000000000..4339de8cc4 --- /dev/null +++ b/shared/test/common/test_configuration/aub_tests/xe_hpc_core/aub_tests_configuration_xe_hpc_core.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/test/common/test_configuration/aub_tests/aub_tests_configuration.h" + +#include "test.h" + +#include "hw_cmds.h" +using namespace NEO; + +template <> +AubTestsConfig GetAubTestsConfig() { + AubTestsConfig aubTestsConfig; + aubTestsConfig.testCanonicalAddress = false; + return aubTestsConfig; +} diff --git a/shared/test/common/xe_hpc_core/CMakeLists.txt b/shared/test/common/xe_hpc_core/CMakeLists.txt new file mode 100644 index 0000000000..64dddc01e8 --- /dev/null +++ b/shared/test/common/xe_hpc_core/CMakeLists.txt @@ -0,0 +1,32 @@ +# +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +if(TESTS_XE_HPC_CORE) + + set(NEO_CORE_TESTS_XE_HPC_CORE + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/simd_helper_tests_xe_hpc_core.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_traits_xe_hpc_core.h + ) + set_property(GLOBAL PROPERTY NEO_CORE_TESTS_XE_HPC_CORE ${NEO_CORE_TESTS_XE_HPC_CORE}) + + add_subdirectories() + + set(IGDRCL_SRCS_tests_xe_hpc_core_excludes + ${CMAKE_CURRENT_SOURCE_DIR}/excludes_xe_hpc_core.cpp + ) + set_property(GLOBAL APPEND PROPERTY IGDRCL_SRCS_tests_excludes ${IGDRCL_SRCS_tests_xe_hpc_core_excludes}) + + target_sources(${TARGET_NAME} PRIVATE + ${IGDRCL_SRCS_tests_xe_hpc_core_excludes} + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/image_surface_state_tests_xe_hpc_core.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_encode_xe_hpc_core.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_preemption_xe_hpc_core.cpp + ${COMPUTE_RUNTIME_ULT_XE_HPC_CORE} + ) + +endif() diff --git a/shared/test/common/xe_hpc_core/cmd_parse_xe_hpc_core.cpp b/shared/test/common/xe_hpc_core/cmd_parse_xe_hpc_core.cpp new file mode 100644 index 0000000000..b33d267b3b --- /dev/null +++ b/shared/test/common/xe_hpc_core/cmd_parse_xe_hpc_core.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/xe_hpc_core/hw_cmds.h" +using GenStruct = NEO::XE_HPC_CORE; +using GenGfxFamily = NEO::XE_HPC_COREFamily; + +#include "shared/test/common/cmd_parse/gen_cmd_parse.h" + +using MI_MEM_FENCE = GenStruct::MI_MEM_FENCE; +using STATE_SYSTEM_MEM_FENCE_ADDRESS = GenStruct::STATE_SYSTEM_MEM_FENCE_ADDRESS; +using STATE_PREFETCH = GenStruct::STATE_PREFETCH; +using MEM_SET = GenStruct::MEM_SET; + +template <> +MI_MEM_FENCE *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return (0x0 == pCmd->TheStructure.Common.MiCommandSubOpcode && + 0x9 == pCmd->TheStructure.Common.MiCommandOpcode && + 0x0 == pCmd->TheStructure.Common.CommandType) + ? pCmd + : nullptr; +} + +template <> +STATE_SYSTEM_MEM_FENCE_ADDRESS *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return (0x1 == pCmd->TheStructure.Common.DwordLength && + 0x9 == pCmd->TheStructure.Common._3DCommandSubOpcode && + 0x1 == pCmd->TheStructure.Common._3DCommandOpcode && + 0x0 == pCmd->TheStructure.Common.CommandSubType && + 0x3 == pCmd->TheStructure.Common.CommandType) + ? pCmd + : nullptr; +} + +template <> +STATE_PREFETCH *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return (0x2 == pCmd->TheStructure.Common.DwordLength && + 0x3 == pCmd->TheStructure.Common._3dCommandSubOpcode && + 0x0 == pCmd->TheStructure.Common._3dCommandOpcode && + 0x0 == pCmd->TheStructure.Common.CommandSubType && + 0x3 == pCmd->TheStructure.Common.CommandType) + ? pCmd + : nullptr; +} + +template <> +MEM_SET *genCmdCast(void *buffer) { + auto pCmd = reinterpret_cast(buffer); + + return (0x5 == pCmd->TheStructure.Common.DwordLength && + 0x5B == pCmd->TheStructure.Common.InstructionTarget_Opcode && + 0x2 == pCmd->TheStructure.Common.Client) + ? pCmd + : nullptr; +} + +template <> +size_t CmdParse::getAdditionalCommandLength(void *cmd) { + { + if (genCmdCast(cmd)) { + return sizeof(MI_MEM_FENCE) / sizeof(uint32_t); + } + } + { + if (genCmdCast(cmd)) { + return sizeof(STATE_SYSTEM_MEM_FENCE_ADDRESS) / sizeof(uint32_t); + } + } + { + if (genCmdCast(cmd)) { + return sizeof(STATE_PREFETCH) / sizeof(uint32_t); + } + } + { + if (genCmdCast(cmd)) { + return sizeof(MEM_SET) / sizeof(uint32_t); + } + } + + return 0; +} + +template <> +const char *CmdParse::getAdditionalCommandName(void *cmd) { + + if (genCmdCast(cmd)) { + return "MI_MEM_FENCE"; + } + if (genCmdCast(cmd)) { + return "STATE_SYSTEM_MEM_FENCE_ADDRESS"; + } + if (genCmdCast(cmd)) { + return "STATE_PREFETCH"; + } + if (genCmdCast(cmd)) { + return "MEM_SET"; + } + + return "UNKNOWN"; +} + +#include "shared/test/common/cmd_parse/cmd_parse_pvc_and_later.inl" diff --git a/shared/test/common/xe_hpc_core/excludes_xe_hpc_core.cpp b/shared/test/common/xe_hpc_core/excludes_xe_hpc_core.cpp new file mode 100644 index 0000000000..0df9e528dd --- /dev/null +++ b/shared/test/common/xe_hpc_core/excludes_xe_hpc_core.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "test.h" + +HWTEST_EXCLUDE_PRODUCT(CommandEncodeStatesTest, givenSlmTotalSizeEqualZeroWhenDispatchingKernelThenSharedMemorySizeIsSetCorrectly, IGFX_XE_HPC_CORE); +HWTEST_EXCLUDE_PRODUCT(CommandEncodeStatesTest, givenOverrideSlmTotalSizeDebugVariableWhenDispatchingKernelThenSharedMemorySizeIsSetCorrectly, IGFX_XE_HPC_CORE); +HWTEST_EXCLUDE_PRODUCT(WalkerPartitionTests, givenMiAtomicWhenItIsProgrammedThenAllFieldsAreSetCorrectly, IGFX_XE_HPC_CORE); +HWTEST_EXCLUDE_PRODUCT(WalkerPartitionTests, givenProgramBatchBufferStartCommandWhenItIsCalledThenCommandIsProgrammedCorrectly, IGFX_XE_HPC_CORE); +HWTEST_EXCLUDE_PRODUCT(XeHPAndLaterPreemptionTests, GivenDebuggerUsedWhenProgrammingStateSipThenStateSipIsAdded, IGFX_XE_HPC_CORE); diff --git a/shared/test/common/xe_hpc_core/image_surface_state_tests_xe_hpc_core.cpp b/shared/test/common/xe_hpc_core/image_surface_state_tests_xe_hpc_core.cpp new file mode 100644 index 0000000000..11f9defaef --- /dev/null +++ b/shared/test/common/xe_hpc_core/image_surface_state_tests_xe_hpc_core.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/test/unit_test/image/image_surface_state_fixture.h" + +using namespace NEO; + +using ImageSurfaceStateTestsXeHpcCore = ImageSurfaceStateTests; + +XE_HPC_CORETEST_F(ImageSurfaceStateTestsXeHpcCore, givenGmmWithMediaCompressedWhenSetFlagsForMediaCompressionThenAuxiliarySurfaceNoneIsSetAndMemoryCompressionEnable) { + auto size = sizeof(typename FamilyType::RENDER_SURFACE_STATE); + auto surfaceState = std::make_unique(size); + auto castSurfaceState = reinterpret_cast(surfaceState.get()); + castSurfaceState->setAuxiliarySurfaceMode(FamilyType::RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_CCS_E); + + mockGmm->gmmResourceInfo->getResourceFlags()->Info.MediaCompressed = false; + EncodeSurfaceState::setFlagsForMediaCompression(castSurfaceState, mockGmm.get()); + EXPECT_EQ(castSurfaceState->getAuxiliarySurfaceMode(), FamilyType::RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_CCS_E); + EXPECT_EQ(castSurfaceState->getMemoryCompressionEnable(), false); + mockGmm->gmmResourceInfo->getResourceFlags()->Info.MediaCompressed = true; + EncodeSurfaceState::setFlagsForMediaCompression(castSurfaceState, mockGmm.get()); + EXPECT_EQ(castSurfaceState->getAuxiliarySurfaceMode(), FamilyType::RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_NONE); + EXPECT_EQ(castSurfaceState->getMemoryCompressionEnable(), true); +} + +XE_HPC_CORETEST_F(ImageSurfaceStateTestsXeHpcCore, givenGmmWhenSetClearColorParamsThenClearValueAddressEnable) { + auto size = sizeof(typename FamilyType::RENDER_SURFACE_STATE); + auto surfaceState = std::make_unique(size); + auto castSurfaceState = reinterpret_cast(surfaceState.get()); + + mockGmm->gmmResourceInfo->getResourceFlags()->Gpu.IndirectClearColor = true; + EncodeSurfaceState::setClearColorParams(castSurfaceState, mockGmm.get()); + EXPECT_EQ(castSurfaceState->getClearValueAddressEnable(), true); +} + +XE_HPC_CORETEST_F(ImageSurfaceStateTestsXeHpcCore, givenGmmWithMediaCompressedWhenSetMipTailStartLodThenMipTailStartLodIsSet) { + auto size = sizeof(typename FamilyType::RENDER_SURFACE_STATE); + auto surfaceState = std::make_unique(size); + auto castSurfaceState = reinterpret_cast(surfaceState.get()); + + setMipTailStartLod(castSurfaceState, nullptr); + + EXPECT_EQ(castSurfaceState->getMipTailStartLod(), 0u); + + setMipTailStartLod(castSurfaceState, mockGmm.get()); + + EXPECT_EQ(castSurfaceState->getMipTailStartLod(), mockGmm->gmmResourceInfo->getMipTailStartLodSurfaceState()); +} diff --git a/shared/test/common/xe_hpc_core/pvc/CMakeLists.txt b/shared/test/common/xe_hpc_core/pvc/CMakeLists.txt new file mode 100644 index 0000000000..974b99c396 --- /dev/null +++ b/shared/test/common/xe_hpc_core/pvc/CMakeLists.txt @@ -0,0 +1,15 @@ +# +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +if(TESTS_PVC) + set(NEO_CORE_TESTS_XE_HPC_CORE_PVC + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/test_encode_dispatch_kernel_pvc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_hw_helper_pvc.cpp + ) + + target_sources(${TARGET_NAME} PRIVATE ${NEO_CORE_TESTS_XE_HPC_CORE_PVC}) +endif() diff --git a/shared/test/common/xe_hpc_core/pvc/test_encode_dispatch_kernel_pvc.cpp b/shared/test/common/xe_hpc_core/pvc/test_encode_dispatch_kernel_pvc.cpp new file mode 100644 index 0000000000..5c15bae7c6 --- /dev/null +++ b/shared/test/common/xe_hpc_core/pvc/test_encode_dispatch_kernel_pvc.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/command_container/command_encoder.h" +#include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/helpers/variable_backup.h" + +#include "test.h" + +#include "hw_cmds.h" + +using namespace NEO; + +using CommandEncodeStatesPvcTest = ::testing::Test; + +PVCTEST_F(CommandEncodeStatesPvcTest, GivenSmallSlmTotalSizesWhenSetAdditionalInfoIsCalledThenCorrectValuesAreSet) { + using INTERFACE_DESCRIPTOR_DATA = typename FamilyType::INTERFACE_DESCRIPTOR_DATA; + using PREFERRED_SLM_SIZE_OVERRIDE = typename INTERFACE_DESCRIPTOR_DATA::PREFERRED_SLM_SIZE_OVERRIDE; + using PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS = typename INTERFACE_DESCRIPTOR_DATA::PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS; + + HardwareInfo hwInfo = *defaultHwInfo; + uint32_t threadsCount = 1; + uint32_t slmTotalSize = 0; + + struct { + unsigned short revisionId; + bool isWaRequired; + } revisionsToTest[] = { + {0x0, true}, + {0x1, true}, + {0x2, true}, + {0x41, true}, + {0x3, false}, + {0x9d, false}, + }; + + for (auto &revisionToTest : revisionsToTest) { + hwInfo.platform.usRevId = revisionToTest.revisionId; + INTERFACE_DESCRIPTOR_DATA idd = FamilyType::cmdInitInterfaceDescriptorData; + EncodeDispatchKernel::appendAdditionalIDDFields(&idd, hwInfo, threadsCount, slmTotalSize, SlmPolicy::SlmPolicyNone); + if (revisionToTest.isWaRequired) { + EXPECT_EQ(PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS::PREFERRED_SLM_SIZE_IS_16K, idd.getPreferredSlmAllocationSizePerDss()); + } else { + EXPECT_EQ(PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS::PREFERRED_SLM_SIZE_IS_0K, idd.getPreferredSlmAllocationSizePerDss()); + } + } +} diff --git a/shared/test/common/xe_hpc_core/pvc/test_hw_helper_pvc.cpp b/shared/test/common/xe_hpc_core/pvc/test_hw_helper_pvc.cpp new file mode 100644 index 0000000000..9819264403 --- /dev/null +++ b/shared/test/common/xe_hpc_core/pvc/test_hw_helper_pvc.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/helpers/hw_helper.h" +#include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/helpers/hw_helper_tests.h" + +#include "test.h" + +using namespace NEO; +using HwHelperTestPvc = ::testing::Test; + +PVCTEST_F(HwHelperTestPvc, givenSlmSizeWhenEncodingThenReturnCorrectValues) { + ComputeSlmTestInput computeSlmValuesPvcAndLaterTestsInput[] = { + {0, 0 * KB}, + {1, 0 * KB + 1}, + {1, 1 * KB}, + {2, 1 * KB + 1}, + {2, 2 * KB}, + {3, 2 * KB + 1}, + {3, 4 * KB}, + {4, 4 * KB + 1}, + {4, 8 * KB}, + {5, 8 * KB + 1}, + {5, 16 * KB}, + {8, 16 * KB + 1}, + {8, 24 * KB}, + {6, 24 * KB + 1}, + {6, 32 * KB}, + {9, 32 * KB + 1}, + {9, 48 * KB}, + {7, 48 * KB + 1}, + {7, 64 * KB}, + {10, 64 * KB + 1}, + {10, 96 * KB}, + {11, 96 * KB + 1}, + {11, 128 * KB}}; + + auto hwInfo = *defaultHwInfo; + auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily); + + for (auto &testInput : computeSlmValuesPvcAndLaterTestsInput) { + EXPECT_EQ(testInput.expected, hwHelper.computeSlmValues(hwInfo, testInput.slmSize)); + } + + EXPECT_THROW(hwHelper.computeSlmValues(hwInfo, 129 * KB), std::exception); +} + +PVCTEST_F(HwHelperTestPvc, WhenGettingIsCpuImageTransferPreferredThenTrueIsReturned) { + auto &hwHelper = HwHelper::get(renderCoreFamily); + EXPECT_TRUE(hwHelper.isCpuImageTransferPreferred(*defaultHwInfo)); +} + +PVCTEST_F(HwHelperTestPvc, givenHwHelperWhenGettingISAPaddingThenCorrectValueIsReturned) { + auto &hwHelper = NEO::HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily); + EXPECT_EQ(hwHelper.getPaddingForISAAllocation(), 3584u); +} diff --git a/shared/test/common/xe_hpc_core/simd_helper_tests_xe_hpc_core.cpp b/shared/test/common/xe_hpc_core/simd_helper_tests_xe_hpc_core.cpp new file mode 100644 index 0000000000..f0cbb63671 --- /dev/null +++ b/shared/test/common/xe_hpc_core/simd_helper_tests_xe_hpc_core.cpp @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/test/common/helpers/simd_helper_tests_pvc_and_later.inl" + +using namespace NEO; + +using TestSimdConfigSet = ::testing::Test; + +XE_HPC_CORETEST_F(TestSimdConfigSet, GivenSimdSizeWhenGetSimdConfigCalledThenCorrectEnumReturnedXeHpcCore) { + GivenSimdSizeWhenGetSimdConfigCalledThenCorrectEnumReturnedPVCAndLater::TestBodyImpl(); +} \ No newline at end of file diff --git a/shared/test/common/xe_hpc_core/test_encode_xe_hpc_core.cpp b/shared/test/common/xe_hpc_core/test_encode_xe_hpc_core.cpp new file mode 100644 index 0000000000..8a805cb514 --- /dev/null +++ b/shared/test/common/xe_hpc_core/test_encode_xe_hpc_core.cpp @@ -0,0 +1,500 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/command_container/command_encoder.h" +#include "shared/source/command_container/memory_fence_encoder.h" +#include "shared/source/command_stream/stream_properties.h" +#include "shared/source/gmm_helper/gmm.h" +#include "shared/source/gmm_helper/gmm_helper.h" +#include "shared/source/kernel/kernel_descriptor.h" +#include "shared/test/common/cmd_parse/gen_cmd_parse.h" +#include "shared/test/common/fixtures/command_container_fixture.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/mocks/mock_dispatch_kernel_encoder_interface.h" + +#include "test.h" + +#include "hw_cmds.h" + +using namespace NEO; + +HWTEST_EXCLUDE_PRODUCT(XeHPAndLaterEncodeMiFlushDWTest, whenMiFlushDwIsProgrammedThenSetFlushCcsAndLlc, IGFX_XE_HPC_CORE); +HWTEST_EXCLUDE_PRODUCT(CommandEncoderTests, whenEncodeMemoryPrefetchCalledThenDoNothing, IGFX_XE_HPC_CORE); + +using CommandEncodeXeHpcCoreTest = ::testing::Test; + +XE_HPC_CORETEST_F(CommandEncodeXeHpcCoreTest, whenMiFlushDwIsProgrammedThenSetAndFlushLlcWithoutCcs) { + using MI_FLUSH_DW = typename FamilyType::MI_FLUSH_DW; + uint8_t buffer[2 * sizeof(MI_FLUSH_DW)] = {}; + LinearStream linearStream(buffer, sizeof(buffer)); + + MiFlushArgs args; + args.commandWithPostSync = true; + EncodeMiFlushDW::programMiFlushDw(linearStream, 0x1230000, 456, args); + auto miFlushDwCmd = reinterpret_cast(buffer); + EXPECT_EQ(0u, miFlushDwCmd->getFlushCcs()); + EXPECT_EQ(1u, miFlushDwCmd->getFlushLlc()); +} + +XE_HPC_CORETEST_F(CommandEncodeXeHpcCoreTest, givenOffsetWhenProgrammingStatePrefetchThenSetCorrectGpuVa) { + using STATE_PREFETCH = typename FamilyType::STATE_PREFETCH; + + HardwareInfo hwInfo = *defaultHwInfo; + hwInfo.platform.usRevId = 0b0011'1000; // [3:5] - BaseDie != A0 + + uint8_t buffer[sizeof(STATE_PREFETCH) * 4] = {}; + auto statePrefetchCmd = reinterpret_cast(buffer); + + constexpr uint64_t gpuVa = 0x100000; + constexpr uint32_t gpuVaOffset = 0x10000; + + const GraphicsAllocation allocation(0, GraphicsAllocation::AllocationType::BUFFER, nullptr, gpuVa, 0, 4096, MemoryPool::LocalMemory, MemoryManager::maxOsContextCount); + + memset(buffer, 0, sizeof(buffer)); + LinearStream linearStream(buffer, sizeof(buffer)); + + uint32_t expectedCmdsCount = 3; + uint32_t alignedSize = MemoryConstants::pageSize64k * expectedCmdsCount; + + EncodeMemoryPrefetch::programMemoryPrefetch(linearStream, allocation, alignedSize, gpuVaOffset, hwInfo); + EXPECT_EQ(sizeof(STATE_PREFETCH) * expectedCmdsCount, linearStream.getUsed()); + + for (uint32_t i = 0; i < expectedCmdsCount; i++) { + uint64_t expectedVa = gpuVa + gpuVaOffset + (i * MemoryConstants::pageSize64k); + EXPECT_EQ(expectedVa, statePrefetchCmd[i].getAddress()); + } +} + +XE_HPC_CORETEST_F(CommandEncodeXeHpcCoreTest, givenDebugVariableSetwhenProgramingStatePrefetchThenSetCorrectFields) { + using STATE_PREFETCH = typename FamilyType::STATE_PREFETCH; + + HardwareInfo hwInfo = *defaultHwInfo; + hwInfo.platform.usRevId = 0b0011'1000; // [3:5] - BaseDie != A0 + + uint8_t buffer[sizeof(STATE_PREFETCH) * 4] = {}; + auto statePrefetchCmd = reinterpret_cast(buffer); + + constexpr uint64_t gpuVa = 0x100000; + constexpr uint32_t mocsIndexForL3 = (2 << 1); + constexpr size_t numCachelines = 3; + + const GraphicsAllocation allocation(0, GraphicsAllocation::AllocationType::BUFFER, nullptr, gpuVa, 0, 4096, MemoryPool::LocalMemory, MemoryManager::maxOsContextCount); + + constexpr std::array expectedSizes = {{ + MemoryConstants::cacheLineSize - 1, + MemoryConstants::cacheLineSize, + MemoryConstants::cacheLineSize + 1, + MemoryConstants::cacheLineSize * numCachelines, + MemoryConstants::pageSize64k - 1, + MemoryConstants::pageSize64k, + (MemoryConstants::pageSize64k * 2) + 1, + }}; + + for (auto expectedSize : expectedSizes) { + memset(buffer, 0, sizeof(buffer)); + LinearStream linearStream(buffer, sizeof(buffer)); + + uint32_t alignedSize = alignUp(expectedSize, MemoryConstants::pageSize64k); + uint32_t expectedCmdsCount = std::max((alignedSize / static_cast(MemoryConstants::pageSize64k)), 1u); + + EXPECT_EQ(sizeof(STATE_PREFETCH) * expectedCmdsCount, EncodeMemoryPrefetch::getSizeForMemoryPrefetch(expectedSize)); + + EncodeMemoryPrefetch::programMemoryPrefetch(linearStream, allocation, expectedSize, 0, hwInfo); + EXPECT_EQ(sizeof(STATE_PREFETCH) * expectedCmdsCount, linearStream.getUsed()); + + for (uint32_t i = 0; i < expectedCmdsCount; i++) { + uint32_t programmedSize = (statePrefetchCmd[i].getPrefetchSize() + 1) * MemoryConstants::cacheLineSize; + + EXPECT_EQ(statePrefetchCmd[i].getAddress(), gpuVa + (i * MemoryConstants::pageSize64k)); + EXPECT_FALSE(statePrefetchCmd[i].getKernelInstructionPrefetch()); + EXPECT_FALSE(statePrefetchCmd[i].getParserStall()); + EXPECT_EQ(mocsIndexForL3, statePrefetchCmd[i].getMemoryObjectControlState()); + + if (programmedSize > expectedSize) { + // cacheline alignemnt + EXPECT_TRUE((programmedSize - expectedSize) < MemoryConstants::cacheLineSize); + expectedSize = 0; + } else { + expectedSize -= programmedSize; + } + } + EXPECT_EQ(0u, expectedSize); + } +} + +XE_HPC_CORETEST_F(CommandEncodeXeHpcCoreTest, givenIsaAllocationWhenProgrammingPrefetchThenSetKernelInstructionPrefetchBit) { + using STATE_PREFETCH = typename FamilyType::STATE_PREFETCH; + + HardwareInfo hwInfo = *defaultHwInfo; + hwInfo.platform.usRevId = 0b0011'1000; // [3:5] - BaseDie != A0 + + uint8_t buffer[sizeof(STATE_PREFETCH)] = {}; + auto statePrefetchCmd = reinterpret_cast(buffer); + + EXPECT_EQ(sizeof(STATE_PREFETCH), EncodeMemoryPrefetch::getSizeForMemoryPrefetch(1)); + + GraphicsAllocation::AllocationType isaTypes[] = {GraphicsAllocation::AllocationType::KERNEL_ISA, GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL}; + + for (uint32_t i = 0; i < 2; i++) { + memset(buffer, 0, sizeof(STATE_PREFETCH)); + LinearStream linearStream(buffer, sizeof(buffer)); + + const GraphicsAllocation allocation(0, isaTypes[i], + nullptr, 1234, 0, 4096, MemoryPool::LocalMemory, MemoryManager::maxOsContextCount); + + EncodeMemoryPrefetch::programMemoryPrefetch(linearStream, allocation, 123, 0, hwInfo); + EXPECT_EQ(sizeof(STATE_PREFETCH), linearStream.getUsed()); + + EXPECT_TRUE(statePrefetchCmd->getKernelInstructionPrefetch()); + } +} + +XE_HPC_CORETEST_F(CommandEncodeXeHpcCoreTest, givenDebugFlagSetWhenProgramPrefetchCalledThenDoPrefetchIfSetToOne) { + using STATE_PREFETCH = typename FamilyType::STATE_PREFETCH; + DebugManagerStateRestore restore; + + HardwareInfo hwInfo = *defaultHwInfo; + hwInfo.platform.usRevId = 0b0011'1000; // [3:5] - BaseDie != A0 + + uint8_t buffer[sizeof(STATE_PREFETCH)] = {}; + + GraphicsAllocation::AllocationType isaTypes[] = {GraphicsAllocation::AllocationType::KERNEL_ISA, GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL}; + + for (uint32_t i = 0; i < 2; i++) { + memset(buffer, 0, sizeof(STATE_PREFETCH)); + const GraphicsAllocation allocation(0, isaTypes[i], + nullptr, 1234, 0, 4096, MemoryPool::LocalMemory, MemoryManager::maxOsContextCount); + + LinearStream linearStream(buffer, sizeof(buffer)); + + DebugManager.flags.EnableMemoryPrefetch.set(0); + EXPECT_EQ(0u, EncodeMemoryPrefetch::getSizeForMemoryPrefetch(100)); + EncodeMemoryPrefetch::programMemoryPrefetch(linearStream, allocation, 100, 0, hwInfo); + EXPECT_EQ(0u, linearStream.getUsed()); + + DebugManager.flags.EnableMemoryPrefetch.set(1); + EncodeMemoryPrefetch::programMemoryPrefetch(linearStream, allocation, 123, 0, hwInfo); + EXPECT_EQ(sizeof(STATE_PREFETCH), linearStream.getUsed()); + auto statePrefetchCmd = reinterpret_cast(buffer); + EXPECT_TRUE(statePrefetchCmd->getKernelInstructionPrefetch()); + } +} + +XE_HPC_CORETEST_F(CommandEncodeXeHpcCoreTest, givenSteppingWhenProgrammingPrefetchThenProgramOnlyAboveAzero) { + using STATE_PREFETCH = typename FamilyType::STATE_PREFETCH; + + HardwareInfo hwInfo = *defaultHwInfo; + hwInfo.platform.usRevId = 0b0100'0111; // [3:5] - BaseDie == A0; + + const GraphicsAllocation allocation(0, GraphicsAllocation::AllocationType::KERNEL_ISA, + nullptr, 1234, 0, 4096, MemoryPool::LocalMemory, MemoryManager::maxOsContextCount); + uint8_t buffer[sizeof(STATE_PREFETCH)] = {}; + + LinearStream linearStream(buffer, sizeof(buffer)); + + EncodeMemoryPrefetch::programMemoryPrefetch(linearStream, allocation, 123, 0, hwInfo); + EXPECT_EQ(0u, linearStream.getUsed()); + + hwInfo.platform.usRevId = 0b0010'1000; // [3:5] - BaseDie != A0 + EncodeMemoryPrefetch::programMemoryPrefetch(linearStream, allocation, 123, 0, hwInfo); + EXPECT_EQ(sizeof(STATE_PREFETCH), linearStream.getUsed()); +} + +XE_HPC_CORETEST_F(CommandEncodeXeHpcCoreTest, givenDebugFlagSetWhenProgrammingPrefetchThenSetParserStall) { + using STATE_PREFETCH = typename FamilyType::STATE_PREFETCH; + + DebugManagerStateRestore restore; + DebugManager.flags.ForceCsStallForStatePrefetch.set(1); + + HardwareInfo hwInfo = *defaultHwInfo; + hwInfo.platform.usRevId = 0b0010'1000; // [3:5] - BaseDie != A0 + + const GraphicsAllocation allocation(0, GraphicsAllocation::AllocationType::BUFFER, + nullptr, 1234, 0, 4096, MemoryPool::LocalMemory, MemoryManager::maxOsContextCount); + uint8_t buffer[sizeof(STATE_PREFETCH)] = {}; + + LinearStream linearStream(buffer, sizeof(buffer)); + + EncodeMemoryPrefetch::programMemoryPrefetch(linearStream, allocation, 123, 0, hwInfo); + + auto statePrefetchCmd = reinterpret_cast(buffer); + + EXPECT_TRUE(statePrefetchCmd->getParserStall()); +} + +XE_HPC_CORETEST_F(CommandEncodeXeHpcCoreTest, whenProgrammingStateComputeModeThenProperFieldsAreSet) { + using STATE_COMPUTE_MODE = typename FamilyType::STATE_COMPUTE_MODE; + using EU_THREAD_SCHEDULING_MODE_OVERRIDE = typename STATE_COMPUTE_MODE::EU_THREAD_SCHEDULING_MODE_OVERRIDE; + uint8_t buffer[64]{}; + + StateComputeModeProperties properties; + auto pLinearStream = std::make_unique(buffer, sizeof(buffer)); + EncodeComputeMode::adjustComputeMode(*pLinearStream, nullptr, properties, *defaultHwInfo); + auto pScm = reinterpret_cast(pLinearStream->getCpuBase()); + EXPECT_EQ(0u, pScm->getMaskBits()); + EXPECT_EQ(STATE_COMPUTE_MODE::FORCE_NON_COHERENT_FORCE_DISABLED, pScm->getForceNonCoherent()); + EXPECT_EQ(EU_THREAD_SCHEDULING_MODE_OVERRIDE::EU_THREAD_SCHEDULING_MODE_OVERRIDE_HW_DEFAULT, pScm->getEuThreadSchedulingModeOverride()); + EXPECT_FALSE(pScm->getLargeGrfMode()); + + properties.isCoherencyRequired.value = 0; + properties.threadArbitrationPolicy.value = ThreadArbitrationPolicy::RoundRobin; + properties.largeGrfMode.value = 1; + pLinearStream = std::make_unique(buffer, sizeof(buffer)); + EncodeComputeMode::adjustComputeMode(*pLinearStream, nullptr, properties, *defaultHwInfo); + pScm = reinterpret_cast(pLinearStream->getCpuBase()); + EXPECT_EQ(0u, pScm->getMaskBits()); + EXPECT_EQ(STATE_COMPUTE_MODE::FORCE_NON_COHERENT_FORCE_DISABLED, pScm->getForceNonCoherent()); + EXPECT_EQ(EU_THREAD_SCHEDULING_MODE_OVERRIDE::EU_THREAD_SCHEDULING_MODE_OVERRIDE_HW_DEFAULT, pScm->getEuThreadSchedulingModeOverride()); + EXPECT_FALSE(pScm->getLargeGrfMode()); + + properties.isCoherencyRequired.isDirty = true; + properties.threadArbitrationPolicy.isDirty = true; + properties.largeGrfMode.isDirty = true; + pLinearStream = std::make_unique(buffer, sizeof(buffer)); + EncodeComputeMode::adjustComputeMode(*pLinearStream, nullptr, properties, *defaultHwInfo); + pScm = reinterpret_cast(pLinearStream->getCpuBase()); + auto expectedMask = FamilyType::stateComputeModeForceNonCoherentMask | FamilyType::stateComputeModeEuThreadSchedulingModeOverrideMask | + FamilyType::stateComputeModeLargeGrfModeMask; + EXPECT_EQ(expectedMask, pScm->getMaskBits()); + EXPECT_EQ(STATE_COMPUTE_MODE::FORCE_NON_COHERENT_FORCE_GPU_NON_COHERENT, pScm->getForceNonCoherent()); + EXPECT_EQ(EU_THREAD_SCHEDULING_MODE_OVERRIDE::EU_THREAD_SCHEDULING_MODE_OVERRIDE_ROUND_ROBIN, pScm->getEuThreadSchedulingModeOverride()); + EXPECT_TRUE(pScm->getLargeGrfMode()); +} + +XE_HPC_CORETEST_F(CommandEncodeXeHpcCoreTest, whenAdjustComputeModeIsCalledThenCorrectPolicyIsProgrammed) { + using STATE_COMPUTE_MODE = typename FamilyType::STATE_COMPUTE_MODE; + using EU_THREAD_SCHEDULING_MODE_OVERRIDE = typename STATE_COMPUTE_MODE::EU_THREAD_SCHEDULING_MODE_OVERRIDE; + + uint8_t buffer[64]{}; + StreamProperties properties{}; + + auto pLinearStream = std::make_unique(buffer, sizeof(buffer)); + properties.stateComputeMode.setProperties(false, 0, ThreadArbitrationPolicy::AgeBased); + EncodeComputeMode::adjustComputeMode(*pLinearStream, nullptr, properties.stateComputeMode, *defaultHwInfo); + auto pScm = reinterpret_cast(pLinearStream->getCpuBase()); + EXPECT_EQ(EU_THREAD_SCHEDULING_MODE_OVERRIDE::EU_THREAD_SCHEDULING_MODE_OVERRIDE_OLDEST_FIRST, pScm->getEuThreadSchedulingModeOverride()); + + pLinearStream = std::make_unique(buffer, sizeof(buffer)); + properties.stateComputeMode.setProperties(false, 0, ThreadArbitrationPolicy::RoundRobin); + EncodeComputeMode::adjustComputeMode(*pLinearStream, nullptr, properties.stateComputeMode, *defaultHwInfo); + pScm = reinterpret_cast(pLinearStream->getCpuBase()); + EXPECT_EQ(EU_THREAD_SCHEDULING_MODE_OVERRIDE::EU_THREAD_SCHEDULING_MODE_OVERRIDE_ROUND_ROBIN, pScm->getEuThreadSchedulingModeOverride()); + + pLinearStream = std::make_unique(buffer, sizeof(buffer)); + properties.stateComputeMode.setProperties(false, 0, ThreadArbitrationPolicy::RoundRobinAfterDependency); + EncodeComputeMode::adjustComputeMode(*pLinearStream, nullptr, properties.stateComputeMode, *defaultHwInfo); + pScm = reinterpret_cast(pLinearStream->getCpuBase()); + EXPECT_EQ(EU_THREAD_SCHEDULING_MODE_OVERRIDE::EU_THREAD_SCHEDULING_MODE_OVERRIDE_STALL_BASED_ROUND_ROBIN, pScm->getEuThreadSchedulingModeOverride()); + + pLinearStream = std::make_unique(buffer, sizeof(buffer)); + properties.stateComputeMode.setProperties(false, 0, ThreadArbitrationPolicy::NotPresent); + EncodeComputeMode::adjustComputeMode(*pLinearStream, nullptr, properties.stateComputeMode, *defaultHwInfo); + pScm = reinterpret_cast(pLinearStream->getCpuBase()); + EXPECT_EQ(EU_THREAD_SCHEDULING_MODE_OVERRIDE::EU_THREAD_SCHEDULING_MODE_OVERRIDE_HW_DEFAULT, pScm->getEuThreadSchedulingModeOverride()); +} + +using EncodeKernelXeHpcCoreTest = Test; + +XE_HPC_CORETEST_F(EncodeKernelXeHpcCoreTest, givenNoFenceAsPostSyncOperationInComputeWalkerWhenEnqueueKernelIsCalledThenDoNotGenerateFenceCommands) { + using WALKER_TYPE = typename FamilyType::WALKER_TYPE; + using MI_MEM_FENCE = typename FamilyType::MI_MEM_FENCE; + DebugManagerStateRestore restore; + DebugManager.flags.ProgramGlobalFenceAsPostSyncOperationInComputeWalker.set(0); + + uint32_t dims[] = {1, 1, 1}; + std::unique_ptr dispatchInterface(new MockDispatchKernelEncoder()); + + EXPECT_CALL(*dispatchInterface.get(), getCrossThreadDataSize()).WillRepeatedly(::testing::Return(0)); + + bool requiresUncachedMocs = false; + uint32_t partitionCount = 0; + EncodeDispatchKernel::encode(*cmdContainer.get(), dims, false, false, dispatchInterface.get(), 0, false, false, + pDevice, NEO::PreemptionMode::Disabled, requiresUncachedMocs, false, partitionCount, + false, false); + + GenCmdList commands; + CmdParse::parseCommandBuffer(commands, ptrOffset(cmdContainer->getCommandStream()->getCpuBase(), 0), cmdContainer->getCommandStream()->getUsed()); + + auto itor = find(commands.begin(), commands.end()); + ASSERT_NE(itor, commands.end()); + + auto walkerCmd = genCmdCast(*itor); + auto &postSyncData = walkerCmd->getPostSync(); + EXPECT_FALSE(postSyncData.getSystemMemoryFenceRequest()); +} + +XE_HPC_CORETEST_F(EncodeKernelXeHpcCoreTest, givenFenceAsPostSyncOperationInComputeWalkerWhenEnqueueKernelIsCalledThenGenerateFenceCommands) { + using WALKER_TYPE = typename FamilyType::WALKER_TYPE; + using MI_MEM_FENCE = typename FamilyType::MI_MEM_FENCE; + DebugManagerStateRestore restore; + DebugManager.flags.ProgramGlobalFenceAsPostSyncOperationInComputeWalker.set(1); + + uint32_t dims[] = {1, 1, 1}; + std::unique_ptr dispatchInterface(new MockDispatchKernelEncoder()); + + EXPECT_CALL(*dispatchInterface.get(), getCrossThreadDataSize()).WillRepeatedly(::testing::Return(0)); + + bool requiresUncachedMocs = false; + uint32_t partitionCount = 0; + EncodeDispatchKernel::encode(*cmdContainer.get(), dims, false, false, dispatchInterface.get(), 0, false, false, + pDevice, NEO::PreemptionMode::Disabled, requiresUncachedMocs, false, partitionCount, + false, false); + + GenCmdList commands; + CmdParse::parseCommandBuffer(commands, ptrOffset(cmdContainer->getCommandStream()->getCpuBase(), 0), cmdContainer->getCommandStream()->getUsed()); + + auto itor = find(commands.begin(), commands.end()); + ASSERT_NE(itor, commands.end()); + + auto walkerCmd = genCmdCast(*itor); + auto &postSyncData = walkerCmd->getPostSync(); + EXPECT_TRUE(postSyncData.getSystemMemoryFenceRequest()); +} + +XE_HPC_CORETEST_F(EncodeKernelXeHpcCoreTest, givenDefaultSettingForFenceAsPostSyncOperationInComputeWalkerWhenEnqueueKernelIsCalledThenDoNotGenerateFenceCommands) { + using WALKER_TYPE = typename FamilyType::WALKER_TYPE; + using MI_MEM_FENCE = typename FamilyType::MI_MEM_FENCE; + DebugManagerStateRestore restore; + DebugManager.flags.ProgramGlobalFenceAsPostSyncOperationInComputeWalker.set(-1); + + uint32_t dims[] = {1, 1, 1}; + std::unique_ptr dispatchInterface(new MockDispatchKernelEncoder()); + + EXPECT_CALL(*dispatchInterface.get(), getCrossThreadDataSize()).WillRepeatedly(::testing::Return(0)); + + bool requiresUncachedMocs = false; + uint32_t partitionCount = 0; + EncodeDispatchKernel::encode(*cmdContainer.get(), dims, false, false, dispatchInterface.get(), 0, false, false, + pDevice, NEO::PreemptionMode::Disabled, requiresUncachedMocs, false, partitionCount, + false, false); + + GenCmdList commands; + CmdParse::parseCommandBuffer(commands, ptrOffset(cmdContainer->getCommandStream()->getCpuBase(), 0), cmdContainer->getCommandStream()->getUsed()); + + auto itor = find(commands.begin(), commands.end()); + ASSERT_NE(itor, commands.end()); + + auto walkerCmd = genCmdCast(*itor); + auto &postSyncData = walkerCmd->getPostSync(); + EXPECT_FALSE(postSyncData.getSystemMemoryFenceRequest()); +} + +XE_HPC_CORETEST_F(EncodeKernelXeHpcCoreTest, givenCleanHeapsAndSlmNotChangedAndUncachedMocsRequestedThenSBAIsProgrammedAndMocsAreSet) { + uint32_t dims[] = {2, 1, 1}; + std::unique_ptr dispatchInterface(new MockDispatchKernelEncoder()); + cmdContainer->slmSize = 1; + EXPECT_CALL(*dispatchInterface.get(), getSlmTotalSize()).WillRepeatedly(::testing::Return(cmdContainer->slmSize)); + cmdContainer->setDirtyStateForAllHeaps(false); + + bool requiresUncachedMocs = true; + uint32_t partitionCount = 0; + EncodeDispatchKernel::encode(*cmdContainer.get(), dims, false, false, dispatchInterface.get(), 0, false, false, + pDevice, NEO::PreemptionMode::Disabled, requiresUncachedMocs, false, partitionCount, + false, false); + + GenCmdList commands; + CmdParse::parseCommandBuffer(commands, ptrOffset(cmdContainer->getCommandStream()->getCpuBase(), 0), cmdContainer->getCommandStream()->getUsed()); + + using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS; + auto itor = find(commands.begin(), commands.end()); + ASSERT_NE(commands.end(), itor); + + auto cmdSba = genCmdCast(*itor); + auto gmmHelper = cmdContainer->getDevice()->getGmmHelper(); + EXPECT_EQ(cmdSba->getStatelessDataPortAccessMemoryObjectControlState(), + (gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED))); +} + +XE_HPC_CORETEST_F(EncodeKernelXeHpcCoreTest, givenStreamWhenEncodingSystemMemoryFenceThenCorrectFenceAddressIsSet) { + using STATE_SYSTEM_MEM_FENCE_ADDRESS = typename FamilyType::STATE_SYSTEM_MEM_FENCE_ADDRESS; + + const GraphicsAllocation allocation(0, GraphicsAllocation::AllocationType::UNKNOWN, + nullptr, 1234, 0, 4096, MemoryPool::System4KBPages, MemoryManager::maxOsContextCount); + + auto before = cmdContainer->getCommandStream()->getUsed(); + auto cmd = reinterpret_cast(cmdContainer->getCommandStream()->getSpace(0)); + EncodeMemoryFence::encodeSystemMemoryFence(*cmdContainer->getCommandStream(), &allocation); + auto after = cmdContainer->getCommandStream()->getUsed(); + + EXPECT_EQ(sizeof(STATE_SYSTEM_MEM_FENCE_ADDRESS), after - before); + + STATE_SYSTEM_MEM_FENCE_ADDRESS expectedCmd = FamilyType::cmdInitStateSystemMemFenceAddress; + expectedCmd.setSystemMemoryFenceAddress(allocation.getGpuAddress()); + + EXPECT_EQ(expectedCmd.getSystemMemoryFenceAddress(), cmd->getSystemMemoryFenceAddress()); + EXPECT_EQ(expectedCmd.TheStructure.RawData[0], cmd->TheStructure.RawData[0]); + EXPECT_EQ(expectedCmd.TheStructure.RawData[1], cmd->TheStructure.RawData[1]); + EXPECT_EQ(expectedCmd.TheStructure.RawData[2], cmd->TheStructure.RawData[2]); +} + +XE_HPC_CORETEST_F(EncodeKernelXeHpcCoreTest, whenSizeForEncodeSystemMemoryFenceQueriedThenCorrectValueIsReturned) { + using STATE_SYSTEM_MEM_FENCE_ADDRESS = typename FamilyType::STATE_SYSTEM_MEM_FENCE_ADDRESS; + + auto size = EncodeMemoryFence::getSystemMemoryFenceSize(); + EXPECT_EQ(sizeof(STATE_SYSTEM_MEM_FENCE_ADDRESS), size); +} + +XE_HPC_CORETEST_F(EncodeKernelXeHpcCoreTest, givenRevisionBAndAboveWhenSpecialModeRequiredThenDontReprogramPipelineSelect) { + bool requiresUncachedMocs = false; + uint32_t partitionCount = 0; + auto hwInfo = pDevice->getRootDeviceEnvironment().getMutableHardwareInfo(); + uint32_t dims[] = {1, 1, 1}; + std::unique_ptr dispatchInterface(new MockDispatchKernelEncoder()); + dispatchInterface->kernelDescriptor.kernelAttributes.flags.usesSpecialPipelineSelectMode = true; + + struct { + unsigned short revId; + bool expectedValue; + } testInputs[] = { + {0x0, true}, + {0x1, true}, + {0x3, true}, + {0x5, false}, + {0x6, false}, + {0x7, false}, + }; + for (auto &testInput : testInputs) { + hwInfo->platform.usRevId = testInput.revId; + cmdContainer->lastPipelineSelectModeRequired = false; + EncodeDispatchKernel::encode(*cmdContainer.get(), dims, false, false, dispatchInterface.get(), 0, false, false, + pDevice, NEO::PreemptionMode::Initial, requiresUncachedMocs, false, partitionCount, false, false); + EXPECT_EQ(testInput.expectedValue, cmdContainer->lastPipelineSelectModeRequired); + } +} + +XE_HPC_CORETEST_F(EncodeKernelXeHpcCoreTest, givenRevisionBAndAboveWhenSpecialModeRequiredAndAdjustPipelineSelectCalledThenDontEnableSystolicMode) { + using PIPELINE_SELECT = typename FamilyType::PIPELINE_SELECT; + auto hwInfo = pDevice->getRootDeviceEnvironment().getMutableHardwareInfo(); + std::unique_ptr dispatchInterface(new MockDispatchKernelEncoder()); + dispatchInterface->kernelDescriptor.kernelAttributes.flags.usesSpecialPipelineSelectMode = true; + + struct { + unsigned short revId; + bool expectedValue; + } testInputs[] = { + {0x0, true}, + {0x1, true}, + {0x3, true}, + {0x5, false}, + {0x6, false}, + {0x7, false}, + }; + for (auto &testInput : testInputs) { + hwInfo->platform.usRevId = testInput.revId; + EncodeComputeMode::adjustPipelineSelect(*cmdContainer.get(), dispatchInterface->kernelDescriptor); + GenCmdList commands; + CmdParse::parseCommandBuffer(commands, ptrOffset(cmdContainer->getCommandStream()->getCpuBase(), 0), cmdContainer->getCommandStream()->getUsed()); + + auto itor = find(commands.begin(), commands.end()); + ASSERT_NE(itor, commands.end()); + + auto pipelineSelectCmd = genCmdCast(*itor); + EXPECT_EQ(testInput.expectedValue, pipelineSelectCmd->getSystolicModeEnable()); + cmdContainer->reset(); + } +} diff --git a/shared/test/common/xe_hpc_core/test_preemption_xe_hpc_core.cpp b/shared/test/common/xe_hpc_core/test_preemption_xe_hpc_core.cpp new file mode 100644 index 0000000000..6fbbf80701 --- /dev/null +++ b/shared/test/common/xe_hpc_core/test_preemption_xe_hpc_core.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/helpers/hw_helper.h" +#include "shared/test/common/fixtures/preemption_fixture.h" + +using namespace NEO; + +template <> +PreemptionTestHwDetails GetPreemptionTestHwDetails() { + PreemptionTestHwDetails ret; + ret.modeToRegValueMap[PreemptionMode::ThreadGroup] = DwordBuilder::build(1, true) | DwordBuilder::build(2, true, false); + ret.modeToRegValueMap[PreemptionMode::MidBatch] = DwordBuilder::build(2, true) | DwordBuilder::build(1, true, false); + ret.modeToRegValueMap[PreemptionMode::MidThread] = DwordBuilder::build(2, true, false) | DwordBuilder::build(1, true, false); + ret.defaultRegValue = ret.modeToRegValueMap[PreemptionMode::MidBatch]; + ret.regAddress = 0x2580u; + return ret; +} diff --git a/shared/test/common/xe_hpc_core/test_traits_xe_hpc_core.h b/shared/test/common/xe_hpc_core/test_traits_xe_hpc_core.h new file mode 100644 index 0000000000..13d472e73b --- /dev/null +++ b/shared/test/common/xe_hpc_core/test_traits_xe_hpc_core.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "shared/test/common/helpers/test_traits.h" + +template <> +struct TestTraits { + static constexpr bool surfaceStateCompressionParamsSupported = true; + static constexpr bool clearColorAddressMatcher = false; + static constexpr bool auxBuiltinsSupported = true; + static constexpr bool localMemCompressionAubsSupported = false; + static constexpr bool systemMemCompressionAubsSupported = false; + static constexpr bool l3ControlSupported = false; + static constexpr bool forceNonCoherentSupported = true; + static constexpr bool threadPreemptionDisableBitMatcher = true; + static constexpr bool programOnlyChangedFieldsInComputeStateMode = true; + static constexpr bool iohInSbaSupported = false; + static constexpr bool auxTranslationSupported = true; + static constexpr bool deviceEnqueueSupport = false; + static constexpr bool fusedEuDispatchSupported = true; + static constexpr bool numberOfWalkersInCfeStateSupported = true; +}; diff --git a/shared/test/common/xe_hpc_core/unit_test_helper_xe_hpc_core.cpp b/shared/test/common/xe_hpc_core/unit_test_helper_xe_hpc_core.cpp new file mode 100644 index 0000000000..745a9222cc --- /dev/null +++ b/shared/test/common/xe_hpc_core/unit_test_helper_xe_hpc_core.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/xe_hpc_core/hw_info.h" +#include "shared/test/common/helpers/unit_test_helper.h" +#include "shared/test/common/helpers/unit_test_helper.inl" +using Family = NEO::XE_HPC_COREFamily; +#include "shared/test/common/helpers/unit_test_helper_xehp_and_later.inl" + +namespace NEO { + +template <> +const AuxTranslationMode UnitTestHelper::requiredAuxTranslationMode = AuxTranslationMode::Blit; + +template <> +uint64_t UnitTestHelper::getAtomicMemoryAddress(const Family::MI_ATOMIC &atomic) { + return atomic.getMemoryAddress(); +} + +template <> +const bool UnitTestHelper::tiledImagesSupported = false; + +template <> +const uint32_t UnitTestHelper::smallestTestableSimdSize = 16; + +template <> +uint32_t UnitTestHelper::getAppropriateThreadArbitrationPolicy(uint32_t policy) { + using STATE_COMPUTE_MODE = typename Family::STATE_COMPUTE_MODE; + switch (policy) { + case ThreadArbitrationPolicy::RoundRobin: + return STATE_COMPUTE_MODE::EU_THREAD_SCHEDULING_MODE_OVERRIDE::EU_THREAD_SCHEDULING_MODE_OVERRIDE_ROUND_ROBIN; + case ThreadArbitrationPolicy::AgeBased: + return STATE_COMPUTE_MODE::EU_THREAD_SCHEDULING_MODE_OVERRIDE::EU_THREAD_SCHEDULING_MODE_OVERRIDE_OLDEST_FIRST; + case ThreadArbitrationPolicy::RoundRobinAfterDependency: + return STATE_COMPUTE_MODE::EU_THREAD_SCHEDULING_MODE_OVERRIDE::EU_THREAD_SCHEDULING_MODE_OVERRIDE_STALL_BASED_ROUND_ROBIN; + default: + return STATE_COMPUTE_MODE::EU_THREAD_SCHEDULING_MODE_OVERRIDE::EU_THREAD_SCHEDULING_MODE_OVERRIDE_HW_DEFAULT; + } +} + +template <> +bool UnitTestHelper::requiresTimestampPacketsInSystemMemory(HardwareInfo &hwInfo) { + return false; +} + +template <> +bool UnitTestHelper::isAdditionalSynchronizationRequired() { + return true; +} + +template <> +bool UnitTestHelper::isAdditionalMiSemaphoreWaitRequired(const HardwareInfo &hwInfo) { + auto programGlobalFenceAsMiMemFenceCommandInCommandStream = !Family::isXlA0(hwInfo); + if (DebugManager.flags.ProgramGlobalFenceAsMiMemFenceCommandInCommandStream.get() != -1) { + programGlobalFenceAsMiMemFenceCommandInCommandStream = !!DebugManager.flags.ProgramGlobalFenceAsMiMemFenceCommandInCommandStream.get(); + } + return !programGlobalFenceAsMiMemFenceCommandInCommandStream; +} + +template <> +const bool UnitTestHelper::additionalMiFlushDwRequired = false; + +template <> +uint32_t UnitTestHelper::getDebugModeRegisterOffset() { + return 0x20d8; +} + +template <> +uint32_t UnitTestHelper::getDebugModeRegisterValue() { + return (1u << 5) | (1u << 21); +} + +template <> +uint32_t UnitTestHelper::getTdCtlRegisterOffset() { + return 0xe400; +} + +template <> +uint32_t UnitTestHelper::getTdCtlRegisterValue() { + return (1u << 7) | (1u << 4) | (1u << 2) | (1u << 0); +} + +template struct UnitTestHelper; + +} // namespace NEO diff --git a/shared/test/unit_test/encoders/CMakeLists.txt b/shared/test/unit_test/encoders/CMakeLists.txt index dc07d37979..604d64700d 100644 --- a/shared/test/unit_test/encoders/CMakeLists.txt +++ b/shared/test/unit_test/encoders/CMakeLists.txt @@ -61,4 +61,18 @@ if(TESTS_XE_HPG_CORE) ) endif() +if(TESTS_XE_HPC_CORE) + target_sources(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/test_implicit_scaling_xe_hpc.cpp + ) +endif() + +if(TESTS_PVC_AND_LATER) + target_sources(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/test_encode_dispatch_kernel_pvc_and_later.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_encode_3dstate_btd_pvc_and_later.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/walker_partition_tests_pvc_and_later.cpp + ) +endif() + add_subdirectories() diff --git a/shared/test/unit_test/encoders/test_encode_3dstate_btd_pvc_and_later.cpp b/shared/test/unit_test/encoders/test_encode_3dstate_btd_pvc_and_later.cpp new file mode 100644 index 0000000000..0a9c88061e --- /dev/null +++ b/shared/test/unit_test/encoders/test_encode_3dstate_btd_pvc_and_later.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/command_container/command_encoder.h" +#include "shared/source/command_stream/linear_stream.h" +#include "shared/source/helpers/ptr_math.h" +#include "shared/test/common/cmd_parse/hw_parse.h" +#include "shared/test/common/fixtures/command_container_fixture.h" +#include "shared/test/common/mocks/mock_graphics_allocation.h" + +using namespace NEO; + +using CommandEncodeEnableRayTracing = Test; + +HWTEST2_F(CommandEncodeEnableRayTracing, whenEnableRayTracingIsProgrammedThen3DStateBtdIsEncodedInStream, IsAtLeastXeHpcCore) { + using _3DSTATE_BTD = typename FamilyType::_3DSTATE_BTD; + + uint32_t pCmdBuffer[1024]; + uint32_t pMemoryBackedBuffer[1024]; + + MockGraphicsAllocation gfxAllocation(static_cast(pCmdBuffer), sizeof(pCmdBuffer)); + LinearStream stream(&gfxAllocation); + + MockGraphicsAllocation memoryBackedBuffer(static_cast(pMemoryBackedBuffer), sizeof(pMemoryBackedBuffer)); + + EncodeEnableRayTracing::programEnableRayTracing(stream, memoryBackedBuffer); + + GenCmdList commands; + CmdParse::parseCommandBuffer(commands, stream.getCpuBase(), stream.getUsed()); + + auto itor = commands.begin(); + itor = find<_3DSTATE_BTD *>(itor, commands.end()); + ASSERT_NE(itor, commands.end()); +} diff --git a/shared/test/unit_test/encoders/test_encode_dispatch_kernel_pvc_and_later.cpp b/shared/test/unit_test/encoders/test_encode_dispatch_kernel_pvc_and_later.cpp new file mode 100644 index 0000000000..04bb8e934c --- /dev/null +++ b/shared/test/unit_test/encoders/test_encode_dispatch_kernel_pvc_and_later.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/command_stream/stream_properties.h" +#include "shared/source/kernel/grf_config.h" +#include "shared/source/os_interface/hw_info_config.h" +#include "shared/test/common/cmd_parse/gen_cmd_parse.h" +#include "shared/test/common/fixtures/command_container_fixture.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/mocks/mock_dispatch_kernel_encoder_interface.h" +#include "shared/test/unit_test/encoders/test_encode_dispatch_kernel_dg2_and_later.h" + +#include "test.h" + +#include "hw_cmds.h" + +using namespace NEO; + +using CommandEncodeStatesTestPvcAndLater = Test; + +HWTEST2_F(CommandEncodeStatesTestPvcAndLater, givenOverrideSlmTotalSizeDebugVariableWhenDispatchingKernelThenSharedMemorySizeIsSetCorrectly, IsAtLeastXeHpcCore) { + using INTERFACE_DESCRIPTOR_DATA = typename FamilyType::INTERFACE_DESCRIPTOR_DATA; + using WALKER_TYPE = typename FamilyType::WALKER_TYPE; + DebugManagerStateRestore restorer; + uint32_t dims[] = {2, 1, 1}; + std::unique_ptr dispatchInterface(new MockDispatchKernelEncoder()); + uint32_t slmTotalSize = 0; + EXPECT_CALL(*dispatchInterface.get(), getSlmTotalSize()).WillRepeatedly(::testing::Return(slmTotalSize)); + + bool requiresUncachedMocs = false; + + int32_t maxValueToProgram = 0xC; + + for (int32_t valueToProgram = 0x0; valueToProgram < maxValueToProgram; valueToProgram++) { + DebugManager.flags.OverrideSlmAllocationSize.set(valueToProgram); + cmdContainer->reset(); + uint32_t partitionCount = 0; + EncodeDispatchKernel::encode(*cmdContainer.get(), dims, false, false, dispatchInterface.get(), 0, false, false, + pDevice, NEO::PreemptionMode::Disabled, requiresUncachedMocs, false, partitionCount, + false, false); + + GenCmdList commands; + CmdParse::parseCommandBuffer(commands, ptrOffset(cmdContainer->getCommandStream()->getCpuBase(), 0), cmdContainer->getCommandStream()->getUsed()); + auto itor = find(commands.begin(), commands.end()); + ASSERT_NE(itor, commands.end()); + auto cmd = genCmdCast(*itor); + auto &idd = cmd->getInterfaceDescriptor(); + + EXPECT_EQ(valueToProgram, idd.getSharedLocalMemorySize()); + } +} + +HWCMDTEST_F(IGFX_XE_HP_CORE, CommandEncodeStatesTestPvcAndLater, givenCommandContainerWhenNumGrfRequiredIsGreaterThanDefaultThenLargeGrfModeEnabled) { + using PIPELINE_SELECT = typename FamilyType::PIPELINE_SELECT; + using STATE_COMPUTE_MODE = typename FamilyType::STATE_COMPUTE_MODE; + cmdContainer->lastSentNumGrfRequired = GrfConfig::DefaultGrfNumber; + auto stateComputeMode = FamilyType::cmdInitStateComputeMode; + StreamProperties streamProperties{}; + streamProperties.stateComputeMode.setProperties(false, GrfConfig::LargeGrfNumber, 0u); + EncodeComputeMode::adjustComputeMode(*cmdContainer->getCommandStream(), &stateComputeMode, streamProperties.stateComputeMode, *defaultHwInfo); + GenCmdList commands; + CmdParse::parseCommandBuffer(commands, ptrOffset(cmdContainer->getCommandStream()->getCpuBase(), 0), cmdContainer->getCommandStream()->getUsed()); + + auto itorCmd = find(commands.begin(), commands.end()); + ASSERT_NE(itorCmd, commands.end()); + + auto cmd = genCmdCast(*itorCmd); + EXPECT_TRUE(cmd->getLargeGrfMode()); +} + +HWTEST2_F(CommandEncodeStatesTestPvcAndLater, GivenVariousSlmTotalSizesAndSettingRevIDToDifferentValuesWhenSetAdditionalInfoIsCalledThenCorrectValuesAreSet, IsXeHpcCore) { + using PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS = typename FamilyType::INTERFACE_DESCRIPTOR_DATA::PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS; + + const std::vector> valuesToTest = { + {0, PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS::PREFERRED_SLM_SIZE_IS_0K}, + {16 * KB, PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS::PREFERRED_SLM_SIZE_IS_16K}, + {32 * KB, PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS::PREFERRED_SLM_SIZE_IS_32K}, + {64 * KB, PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS::PREFERRED_SLM_SIZE_IS_64K}, + {96 * KB, PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS::PREFERRED_SLM_SIZE_IS_96K}, + {128 * KB, PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS::PREFERRED_SLM_SIZE_IS_128K}, + }; + + const std::vector> valuesToTestForPvcAStep = { + {0, PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS::PREFERRED_SLM_SIZE_IS_16K}, + {16 * KB, PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS::PREFERRED_SLM_SIZE_IS_16K}, + {32 * KB, PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS::PREFERRED_SLM_SIZE_IS_32K}, + {64 * KB, PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS::PREFERRED_SLM_SIZE_IS_64K}, + {96 * KB, PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS::PREFERRED_SLM_SIZE_IS_96K}, + {128 * KB, PREFERRED_SLM_ALLOCATION_SIZE_PER_DSS::PREFERRED_SLM_SIZE_IS_128K}, + }; + + const std::array revs{REVISION_A0, REVISION_B, REVISION_C, REVISION_D, REVISION_K}; + auto &hwInfo = *pDevice->getRootDeviceEnvironment().getMutableHardwareInfo(); + for (auto rev : revs) { + hwInfo.platform.usRevId = HwInfoConfig::get(productFamily)->getHwRevIdFromStepping(rev, hwInfo); + if ((hwInfo.platform.eProductFamily == IGFX_PVC) && (rev == REVISION_A0)) { + verifyPreferredSlmValues(valuesToTestForPvcAStep, hwInfo); + } else { + verifyPreferredSlmValues(valuesToTest, hwInfo); + } + } +} diff --git a/shared/test/unit_test/encoders/test_implicit_scaling_xe_hpc.cpp b/shared/test/unit_test/encoders/test_implicit_scaling_xe_hpc.cpp new file mode 100644 index 0000000000..62ad502af5 --- /dev/null +++ b/shared/test/unit_test/encoders/test_implicit_scaling_xe_hpc.cpp @@ -0,0 +1,12 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/test/common/fixtures/implicit_scaling_fixture.h" + +HWTEST2_F(ImplicitScalingTests, GivenXeHpcWhenCheckingPipeControlStallRequiredThenExpectTrue, IsXeHpcCore) { + EXPECT_TRUE(ImplicitScalingDispatch::getPipeControlStallRequired()); +} diff --git a/shared/test/unit_test/encoders/walker_partition_tests_pvc_and_later.cpp b/shared/test/unit_test/encoders/walker_partition_tests_pvc_and_later.cpp new file mode 100644 index 0000000000..1135fe3c20 --- /dev/null +++ b/shared/test/unit_test/encoders/walker_partition_tests_pvc_and_later.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/command_container/walker_partition_xehp_and_later.h" +#include "shared/test/common/cmd_parse/gen_cmd_parse.h" +#include "shared/test/common/cmd_parse/hw_parse.h" +#include "shared/test/common/helpers/unit_test_helper.h" + +#include "test.h" + +using namespace WalkerPartition; +using namespace NEO; + +struct WalkerPartitionPvcAndLaterTests : public ::testing::Test { + void TearDown() override { + auto initialCommandBufferPointer = cmdBuffer; + if (checkForProperCmdBufferAddressOffset) { + EXPECT_EQ(ptrDiff(cmdBufferAddress, initialCommandBufferPointer), totalBytesProgrammed); + } + } + char cmdBuffer[4096u]; + uint32_t totalBytesProgrammed = 0u; + void *cmdBufferAddress = cmdBuffer; + bool checkForProperCmdBufferAddressOffset = true; + bool synchronizeBeforeExecution = false; +}; + +HWTEST2_F(WalkerPartitionPvcAndLaterTests, givenMiAtomicWhenItIsProgrammedThenAllFieldsAreSetCorrectly, IsAtLeastXeHpcCore) { + auto expectedUsedSize = sizeof(WalkerPartition::MI_ATOMIC); + uint64_t gpuAddress = 0xFFFFFFDFEEDBAC10llu; + + void *miAtomicAddress = cmdBufferAddress; + programMiAtomic(cmdBufferAddress, + totalBytesProgrammed, gpuAddress, true, MI_ATOMIC::ATOMIC_OPCODES::ATOMIC_4B_INCREMENT); + + auto miAtomic = genCmdCast *>(miAtomicAddress); + ASSERT_NE(nullptr, miAtomic); + EXPECT_EQ(expectedUsedSize, totalBytesProgrammed); + EXPECT_EQ(MI_ATOMIC::ATOMIC_OPCODES::ATOMIC_4B_INCREMENT, miAtomic->getAtomicOpcode()); + EXPECT_EQ(0u, miAtomic->getDataSize()); + EXPECT_TRUE(miAtomic->getCsStall()); + EXPECT_EQ(MI_ATOMIC::MEMORY_TYPE::MEMORY_TYPE_PER_PROCESS_GRAPHICS_ADDRESS, miAtomic->getMemoryType()); + EXPECT_TRUE(miAtomic->getReturnDataControl()); + EXPECT_FALSE(miAtomic->getWorkloadPartitionIdOffsetEnable()); + auto memoryAddress = UnitTestHelper::getAtomicMemoryAddress(*miAtomic); + + EXPECT_EQ(gpuAddress, memoryAddress); +} + +HWTEST2_F(WalkerPartitionPvcAndLaterTests, givenProgramBatchBufferStartCommandWhenItIsCalledThenCommandIsProgrammedCorrectly, IsAtLeastXeHpcCore) { + auto expectedUsedSize = sizeof(WalkerPartition::BATCH_BUFFER_START); + uint64_t gpuAddress = 0xFFFFFFDFEEDBAC10llu; + + void *batchBufferStartAddress = cmdBufferAddress; + WalkerPartition::programMiBatchBufferStart(cmdBufferAddress, totalBytesProgrammed, gpuAddress, true, false); + auto batchBufferStart = genCmdCast *>(batchBufferStartAddress); + ASSERT_NE(nullptr, batchBufferStart); + EXPECT_EQ(expectedUsedSize, totalBytesProgrammed); + + if (productFamily == IGFX_PVC) { + //bits 57-63 are zeroed + EXPECT_EQ((gpuAddress & 0x1FFFFFFFFFFFFFF), batchBufferStart->getBatchBufferStartAddress()); + } else { + //bits 48-63 are zeroed + EXPECT_EQ((gpuAddress & 0xFFFFFFFFFFFF), batchBufferStart->getBatchBufferStartAddress()); + } + EXPECT_TRUE(batchBufferStart->getPredicationEnable()); + EXPECT_FALSE(batchBufferStart->getEnableCommandCache()); + EXPECT_EQ(BATCH_BUFFER_START::SECOND_LEVEL_BATCH_BUFFER::SECOND_LEVEL_BATCH_BUFFER_FIRST_LEVEL_BATCH, batchBufferStart->getSecondLevelBatchBuffer()); + EXPECT_EQ(BATCH_BUFFER_START::ADDRESS_SPACE_INDICATOR::ADDRESS_SPACE_INDICATOR_PPGTT, batchBufferStart->getAddressSpaceIndicator()); +}