From 02e00b2969714dd44fba77a1e848ed3b6d1d12d4 Mon Sep 17 00:00:00 2001 From: Bartosz Dunajski Date: Tue, 23 Nov 2021 09:54:06 +0000 Subject: [PATCH] Add xe_hp_and_later L0 cmdlist unit tests Signed-off-by: Bartosz Dunajski --- .../unit_tests/sources/cmdlist/CMakeLists.txt | 7 + .../cmdlist/test_cmdlist_xehp_and_later.cpp | 171 ++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_xehp_and_later.cpp diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/CMakeLists.txt b/level_zero/core/test/unit_tests/sources/cmdlist/CMakeLists.txt index f720bd2fed..2b9df9090c 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/CMakeLists.txt +++ b/level_zero/core/test/unit_tests/sources/cmdlist/CMakeLists.txt @@ -23,4 +23,11 @@ target_sources(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_fill.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_append_multipartition_prologue.cpp ) + +if(TESTS_XEHP_AND_LATER) + target_sources(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_xehp_and_later.cpp + ) +endif() + add_subdirectories() diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_xehp_and_later.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_xehp_and_later.cpp new file mode 100644 index 0000000000..d549687395 --- /dev/null +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_xehp_and_later.cpp @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/gmm_helper/gmm_helper.h" +#include "shared/source/helpers/preamble.h" +#include "shared/test/common/cmd_parse/gen_cmd_parse.h" +#include "shared/test/common/test_macros/test.h" + +#include "level_zero/core/source/cmdlist/cmdlist_hw.h" +#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" +#include "level_zero/core/test/unit_tests/fixtures/module_fixture.h" +#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" +#include "level_zero/core/test/unit_tests/mocks/mock_module.h" + +namespace L0 { +namespace ult { + +using CommandListTests = Test; +HWCMDTEST_F(IGFX_XE_HP_CORE, CommandListTests, whenCommandListIsCreatedThenPCAndStateBaseAddressCmdsAreAddedAndCorrectlyProgrammed) { + using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS; + using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; + + ze_result_t returnValue; + std::unique_ptr commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Compute, 0u, returnValue)); + auto &commandContainer = commandList->commandContainer; + auto gmmHelper = commandContainer.getDevice()->getGmmHelper(); + + ASSERT_NE(nullptr, commandContainer.getCommandStream()); + auto usedSpaceBefore = commandContainer.getCommandStream()->getUsed(); + + auto result = commandList->close(); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + + auto usedSpaceAfter = commandContainer.getCommandStream()->getUsed(); + ASSERT_GT(usedSpaceAfter, usedSpaceBefore); + + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(commandContainer.getCommandStream()->getCpuBase(), 0), usedSpaceAfter)); + + auto itorPc = find(cmdList.begin(), cmdList.end()); + ASSERT_NE(cmdList.end(), itorPc); + auto cmdPc = genCmdCast(*itorPc); + EXPECT_EQ(MemorySynchronizationCommands::isDcFlushAllowed(), cmdPc->getDcFlushEnable()); + EXPECT_TRUE(cmdPc->getCommandStreamerStallEnable()); + EXPECT_TRUE(cmdPc->getTextureCacheInvalidationEnable()); + + auto itor = find(itorPc, cmdList.end()); + ASSERT_NE(cmdList.end(), itor); + + auto cmdSba = genCmdCast(*itor); + + auto dsh = commandContainer.getIndirectHeap(NEO::HeapType::DYNAMIC_STATE); + auto ssh = commandContainer.getIndirectHeap(NEO::HeapType::SURFACE_STATE); + + EXPECT_TRUE(cmdSba->getDynamicStateBaseAddressModifyEnable()); + EXPECT_TRUE(cmdSba->getDynamicStateBufferSizeModifyEnable()); + EXPECT_EQ(dsh->getHeapGpuBase(), cmdSba->getDynamicStateBaseAddress()); + EXPECT_EQ(dsh->getHeapSizeInPages(), cmdSba->getDynamicStateBufferSize()); + + EXPECT_TRUE(cmdSba->getSurfaceStateBaseAddressModifyEnable()); + EXPECT_EQ(ssh->getHeapGpuBase(), cmdSba->getSurfaceStateBaseAddress()); + + EXPECT_EQ(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CONST), cmdSba->getStatelessDataPortAccessMemoryObjectControlState()); +} + +using CommandListTestsReserveSize = Test; +HWTEST2_F(CommandListTestsReserveSize, givenCommandListWhenGetReserveSshSizeThen4PagesReturned, IsAtLeastXeHpCore) { + L0::CommandListCoreFamily commandList(1u); + + EXPECT_EQ(commandList.getReserveSshSize(), 4 * MemoryConstants::pageSize); +} + +using CommandListAppendLaunchKernel = Test; +HWTEST2_F(CommandListAppendLaunchKernel, givenVariousKernelsWhenUpdateStreamPropertiesIsCalledThenRequiredStateFinalStateAndCommandsToPatchAreCorrectlySet, IsAtLeastXeHpCore) { + DebugManagerStateRestore restorer; + DebugManager.flags.AllowMixingRegularAndCooperativeKernels.set(1); + DebugManager.flags.AllowPatchingVfeStateInCommandLists.set(1); + + Mock<::L0::Kernel> defaultKernel; + auto pMockModule1 = std::unique_ptr(new Mock(device, nullptr)); + defaultKernel.module = pMockModule1.get(); + + Mock<::L0::Kernel> cooperativeKernel; + auto pMockModule2 = std::unique_ptr(new Mock(device, nullptr)); + cooperativeKernel.module = pMockModule2.get(); + cooperativeKernel.immutableData.kernelDescriptor->kernelAttributes.flags.usesSyncBuffer = true; + + auto pCommandList = std::make_unique>>(); + auto result = pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + + EXPECT_EQ(-1, pCommandList->requiredStreamState.frontEndState.computeDispatchAllWalkerEnable.value); + EXPECT_EQ(-1, pCommandList->finalStreamState.frontEndState.computeDispatchAllWalkerEnable.value); + EXPECT_EQ(0u, pCommandList->commandsToPatch.size()); + + pCommandList->updateStreamProperties(defaultKernel, false, false); + EXPECT_EQ(0, pCommandList->requiredStreamState.frontEndState.computeDispatchAllWalkerEnable.value); + EXPECT_EQ(0, pCommandList->finalStreamState.frontEndState.computeDispatchAllWalkerEnable.value); + EXPECT_EQ(0u, pCommandList->commandsToPatch.size()); + pCommandList->reset(); + + pCommandList->updateStreamProperties(cooperativeKernel, false, true); + pCommandList->updateStreamProperties(cooperativeKernel, false, true); + EXPECT_EQ(1, pCommandList->requiredStreamState.frontEndState.computeDispatchAllWalkerEnable.value); + EXPECT_EQ(1, pCommandList->finalStreamState.frontEndState.computeDispatchAllWalkerEnable.value); + EXPECT_EQ(0u, pCommandList->commandsToPatch.size()); + pCommandList->reset(); + + pCommandList->updateStreamProperties(defaultKernel, false, false); + pCommandList->updateStreamProperties(cooperativeKernel, false, true); + EXPECT_EQ(0, pCommandList->requiredStreamState.frontEndState.computeDispatchAllWalkerEnable.value); + EXPECT_EQ(1, pCommandList->finalStreamState.frontEndState.computeDispatchAllWalkerEnable.value); + EXPECT_EQ(1u, pCommandList->commandsToPatch.size()); + pCommandList->reset(); + + pCommandList->updateStreamProperties(cooperativeKernel, false, true); + pCommandList->updateStreamProperties(defaultKernel, false, false); + pCommandList->updateStreamProperties(cooperativeKernel, false, true); + EXPECT_EQ(1, pCommandList->requiredStreamState.frontEndState.computeDispatchAllWalkerEnable.value); + EXPECT_EQ(1, pCommandList->finalStreamState.frontEndState.computeDispatchAllWalkerEnable.value); + EXPECT_EQ(2u, pCommandList->commandsToPatch.size()); + pCommandList->reset(); + + pCommandList->updateStreamProperties(defaultKernel, false, false); + pCommandList->updateStreamProperties(defaultKernel, false, false); + pCommandList->updateStreamProperties(cooperativeKernel, false, true); + EXPECT_EQ(0, pCommandList->requiredStreamState.frontEndState.computeDispatchAllWalkerEnable.value); + EXPECT_EQ(1, pCommandList->finalStreamState.frontEndState.computeDispatchAllWalkerEnable.value); + EXPECT_EQ(1u, pCommandList->commandsToPatch.size()); + pCommandList->reset(); + + EXPECT_EQ(-1, pCommandList->requiredStreamState.frontEndState.computeDispatchAllWalkerEnable.value); + EXPECT_EQ(-1, pCommandList->finalStreamState.frontEndState.computeDispatchAllWalkerEnable.value); + EXPECT_EQ(0u, pCommandList->commandsToPatch.size()); +} + +HWTEST2_F(CommandListAppendLaunchKernel, givenVariousKernelsAndPatchingDisallowedWhenUpdateStreamPropertiesIsCalledThenCommandsToPatchAreEmpty, IsAtLeastXeHpCore) { + DebugManagerStateRestore restorer; + DebugManager.flags.AllowMixingRegularAndCooperativeKernels.set(1); + Mock<::L0::Kernel> defaultKernel; + auto pMockModule1 = std::unique_ptr(new Mock(device, nullptr)); + defaultKernel.module = pMockModule1.get(); + + Mock<::L0::Kernel> cooperativeKernel; + auto pMockModule2 = std::unique_ptr(new Mock(device, nullptr)); + cooperativeKernel.module = pMockModule2.get(); + cooperativeKernel.immutableData.kernelDescriptor->kernelAttributes.flags.usesSyncBuffer = true; + + auto pCommandList = std::make_unique>>(); + auto result = pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + + pCommandList->updateStreamProperties(defaultKernel, false, false); + pCommandList->updateStreamProperties(cooperativeKernel, false, true); + EXPECT_EQ(0u, pCommandList->commandsToPatch.size()); + pCommandList->reset(); + + DebugManager.flags.AllowPatchingVfeStateInCommandLists.set(1); + pCommandList->updateStreamProperties(defaultKernel, false, false); + pCommandList->updateStreamProperties(cooperativeKernel, false, true); + EXPECT_EQ(1u, pCommandList->commandsToPatch.size()); + pCommandList->reset(); +} + +} // namespace ult +} // namespace L0