Add xe_hpg ocl unit tests

Signed-off-by: Bartosz Dunajski <bartosz.dunajski@intel.com>
This commit is contained in:
Bartosz Dunajski
2021-11-22 13:52:32 +00:00
committed by Compute-Runtime-Automation
parent f56773d166
commit 2d5eaf3cc1
37 changed files with 3396 additions and 0 deletions

View File

@@ -52,5 +52,18 @@ if(TESTS_XEHP_AND_LATER)
)
endif()
if(TESTS_DG2)
list(APPEND IGDRCL_SRCS_tests_command_stream
${CMAKE_CURRENT_SOURCE_DIR}/compute_mode_tests_dg2.cpp
)
endif()
if(TESTS_DG2_AND_LATER)
list(APPEND IGDRCL_SRCS_tests_command_stream
${CMAKE_CURRENT_SOURCE_DIR}/cache_flush_tests_dg2_and_later.cpp
${CMAKE_CURRENT_SOURCE_DIR}/command_stream_receiver_hw_tests_dg2_and_later.cpp
)
endif()
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_command_stream})
add_subdirectories()

View File

@@ -0,0 +1,57 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/l3_range.h"
#include "shared/source/helpers/ray_tracing_helper.h"
#include "shared/test/common/cmd_parse/hw_parse.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/mocks/mock_csr.h"
#include "opencl/source/command_queue/command_queue_hw.h"
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
#include "opencl/test/unit_test/helpers/cmd_buffer_validator.h"
#include "opencl/test/unit_test/helpers/hardware_commands_helper_tests.h"
#include "test.h"
using namespace NEO;
using CacheFlushTestsDg2AndLater = HardwareCommandsTest;
HWTEST2_F(CacheFlushTestsDg2AndLater, WhenProgrammingCacheFlushAfterWalkerThenExpectProperCacheFlushCommand, IsAtLeastXeHpgCore) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
DebugManagerStateRestore dbgRestore;
DebugManager.flags.EnableCacheFlushAfterWalker.set(1);
CommandQueueHw<FamilyType> cmdQ(nullptr, pClDevice, 0, false);
auto &commandStream = cmdQ.getCS(1024);
void *allocPtr = reinterpret_cast<void *>(static_cast<uintptr_t>(6 * MemoryConstants::pageSize));
MockGraphicsAllocation globalAllocation{allocPtr, MemoryConstants::pageSize * 2};
this->mockKernelWithInternal->mockProgram->setGlobalSurface(&globalAllocation);
constexpr uint64_t postSyncAddress = 1024;
HardwareCommandsHelper<FamilyType>::programCacheFlushAfterWalkerCommand(&commandStream, cmdQ, this->mockKernelWithInternal->mockKernel, postSyncAddress);
std::string err;
std::vector<MatchCmd *> expectedCommands;
expectedCommands.push_back(new MatchHwCmd<FamilyType, PIPE_CONTROL>(
1, Expects{EXPECT_MEMBER(PIPE_CONTROL, getUnTypedDataPortCacheFlush, true)}));
if constexpr (FamilyType::isUsingL3Control) {
using L3_CONTROL = typename FamilyType::L3_CONTROL;
expectedCommands.push_back(new MatchHwCmd<FamilyType, L3_CONTROL>(
1, Expects{EXPECT_MEMBER(L3_CONTROL, getUnTypedDataPortCacheFlush, false)}));
}
bool cmdBuffOk = expectCmdBuff<FamilyType>(cmdQ.getCS(0), 0, std::move(expectedCommands), &err);
EXPECT_TRUE(cmdBuffOk) << err;
this->mockKernelWithInternal->mockProgram->setGlobalSurface(nullptr);
}

View File

@@ -0,0 +1,172 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/ray_tracing_helper.h"
#include "shared/test/common/cmd_parse/hw_parse.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/mocks/mock_csr.h"
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
#include "opencl/test/unit_test/fixtures/ult_command_stream_receiver_fixture.h"
#include "test.h"
using namespace NEO;
using MatcherIsRTCapable = IsAtLeastXeHpgCore;
struct CommandStreamReceiverHwTestDg2AndLater : public ClDeviceFixture,
public HardwareParse,
public ::testing::Test {
void SetUp() override {
ClDeviceFixture::SetUp();
HardwareParse::SetUp();
}
void TearDown() override {
HardwareParse::TearDown();
ClDeviceFixture::TearDown();
}
};
HWTEST2_F(CommandStreamReceiverHwTestDg2AndLater, givenGen12AndLaterWhenRayTracingEnabledThenCommandIsAddedToBatchBuffer, MatcherIsRTCapable) {
using _3DSTATE_BTD = typename FamilyType::_3DSTATE_BTD;
MockCsrHw<FamilyType> commandStreamReceiver(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
commandStreamReceiver.setupContext(*osContext);
auto cmdSize = commandStreamReceiver.getCmdSizeForPerDssBackedBuffer(pDevice->getHardwareInfo());
EXPECT_EQ(sizeof(_3DSTATE_BTD), cmdSize);
auto memoryManager = pDevice->getExecutionEnvironment()->memoryManager.get();
AllocationProperties properties(pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SCRATCH_SURFACE, pDevice->getDeviceBitfield());
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
commandStreamReceiver.perDssBackedBuffer = allocation;
std::unique_ptr<char> buffer(new char[cmdSize]);
LinearStream cs(buffer.get(), cmdSize);
DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags();
dispatchFlags.usePerDssBackedBuffer = true;
EXPECT_FALSE(commandStreamReceiver.isPerDssBackedBufferSent);
commandStreamReceiver.programPerDssBackedBuffer(cs, *pDevice, dispatchFlags);
EXPECT_EQ(sizeof(_3DSTATE_BTD), cs.getUsed());
_3DSTATE_BTD *cmd = genCmdCast<_3DSTATE_BTD *>(cs.getCpuBase());
ASSERT_NE(nullptr, cmd);
EXPECT_EQ(RayTracingHelper::getMemoryBackedFifoSizeToPatch(), cmd->getBtdStateBody().getPerDssMemoryBackedBufferSize());
EXPECT_EQ(allocation->getGpuAddressToPatch(), cmd->getBtdStateBody().getMemoryBackedBufferBasePointer());
EXPECT_TRUE(commandStreamReceiver.isPerDssBackedBufferSent);
}
typedef UltCommandStreamReceiverTest CommandStreamReceiverFlushTasDg2AndLaterTests;
HWTEST2_F(CommandStreamReceiverFlushTasDg2AndLaterTests, givenProgramPipeControlPriorToNonPipelinedStateCommandWhenPerDssBackedBufferThenThereIsPipeControlPriorToIt, MatcherIsRTCapable) {
DebugManagerStateRestore restore;
DebugManager.flags.ProgramPipeControlPriorToNonPipelinedStateCommand.set(true);
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
using _3DSTATE_BTD = typename FamilyType::_3DSTATE_BTD;
auto expectedCmdSize = sizeof(_3DSTATE_BTD) + sizeof(PIPE_CONTROL);
auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver<FamilyType>();
auto cmdSize = commandStreamReceiver.getCmdSizeForPerDssBackedBuffer(pDevice->getHardwareInfo());
EXPECT_EQ(expectedCmdSize, cmdSize);
auto memoryManager = pDevice->getExecutionEnvironment()->memoryManager.get();
AllocationProperties properties(pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SCRATCH_SURFACE, pDevice->getDeviceBitfield());
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
commandStreamReceiver.perDssBackedBuffer = allocation;
StackVec<char, 4096> buffer(4096);
NEO::LinearStream cmdStream(buffer.begin(), buffer.size());
EXPECT_FALSE(commandStreamReceiver.isPerDssBackedBufferSent);
configureCSRtoNonDirtyState<FamilyType>(false);
ioh.replaceBuffer(ptrOffset(ioh.getCpuBase(), +1u), ioh.getMaxAvailableSpace() + MemoryConstants::pageSize * 3);
DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags();
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(pDevice->getHardwareInfo());
dispatchFlags.usePerDssBackedBuffer = true;
auto cmdSizeForAllCommands = commandStreamReceiver.getRequiredCmdStreamSize(dispatchFlags, *pDevice);
commandStreamReceiver.flushTask(commandStream,
0,
dsh,
ioh,
ssh,
taskLevel,
dispatchFlags,
*pDevice);
parseCommands<FamilyType>(commandStreamReceiver.getCS(0));
auto _3dStateBtdIterator = find<_3DSTATE_BTD *>(cmdList.begin(), cmdList.end());
auto _3dStateBtdCmd = genCmdCast<_3DSTATE_BTD *>(*_3dStateBtdIterator);
ASSERT_NE(nullptr, _3dStateBtdCmd);
EXPECT_EQ(RayTracingHelper::getMemoryBackedFifoSizeToPatch(), _3dStateBtdCmd->getBtdStateBody().getPerDssMemoryBackedBufferSize());
EXPECT_EQ(allocation->getGpuAddressToPatch(), _3dStateBtdCmd->getBtdStateBody().getMemoryBackedBufferBasePointer());
EXPECT_TRUE(commandStreamReceiver.isPerDssBackedBufferSent);
--_3dStateBtdIterator;
auto pipeControlCmd = genCmdCast<PIPE_CONTROL *>(*_3dStateBtdIterator);
EXPECT_TRUE(pipeControlCmd->getHdcPipelineFlush());
EXPECT_TRUE(pipeControlCmd->getAmfsFlushEnable());
EXPECT_TRUE(pipeControlCmd->getCommandStreamerStallEnable());
EXPECT_TRUE(pipeControlCmd->getInstructionCacheInvalidateEnable());
EXPECT_TRUE(pipeControlCmd->getTextureCacheInvalidationEnable());
EXPECT_TRUE(pipeControlCmd->getConstantCacheInvalidationEnable());
EXPECT_TRUE(pipeControlCmd->getStateCacheInvalidationEnable());
EXPECT_TRUE(pipeControlCmd->getUnTypedDataPortCacheFlush());
commandStreamReceiver.flushTask(commandStream,
0,
dsh,
ioh,
ssh,
taskLevel,
dispatchFlags,
*pDevice);
auto cmdSizeForAllCommandsWithoutPCand3dState = commandStreamReceiver.getRequiredCmdStreamSize(dispatchFlags, *pDevice);
EXPECT_EQ(cmdSizeForAllCommandsWithoutPCand3dState + expectedCmdSize, cmdSizeForAllCommands);
}
HWTEST2_F(CommandStreamReceiverHwTestDg2AndLater, givenGen12AndLaterWhenRayTracingEnabledButAlreadySentThenCommandIsNotAddedToBatchBuffer, MatcherIsRTCapable) {
using _3DSTATE_BTD = typename FamilyType::_3DSTATE_BTD;
MockCsrHw<FamilyType> commandStreamReceiver(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
commandStreamReceiver.setupContext(*osContext);
auto cmdSize = commandStreamReceiver.getCmdSizeForPerDssBackedBuffer(pDevice->getHardwareInfo());
EXPECT_EQ(sizeof(_3DSTATE_BTD), cmdSize);
auto memoryManager = pDevice->getExecutionEnvironment()->memoryManager.get();
AllocationProperties properties(pDevice->getRootDeviceIndex(), MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SCRATCH_SURFACE, pDevice->getDeviceBitfield());
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
commandStreamReceiver.perDssBackedBuffer = allocation;
std::unique_ptr<char> buffer(new char[cmdSize]);
LinearStream cs(buffer.get(), cmdSize);
DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags();
dispatchFlags.usePerDssBackedBuffer = true;
commandStreamReceiver.isPerDssBackedBufferSent = true;
commandStreamReceiver.programPerDssBackedBuffer(cs, *pDevice, dispatchFlags);
EXPECT_EQ(0u, cs.getUsed());
}
HWTEST2_F(CommandStreamReceiverHwTestDg2AndLater, givenNotXE_HP_COREWhenCheckingNewResourceImplicitFlushThenReturnFalse, IsAtLeastXeHpgCore) {
MockCsrHw<FamilyType> commandStreamReceiver(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
commandStreamReceiver.setupContext(*osContext);
EXPECT_FALSE(commandStreamReceiver.checkPlatformSupportsNewResourceImplicitFlush());
}
HWTEST2_F(CommandStreamReceiverHwTestDg2AndLater, givenNotXE_HP_COREWhenCheckingNewResourceGpuIdleThenReturnFalse, IsAtLeastXeHpgCore) {
MockCsrHw<FamilyType> commandStreamReceiver(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
commandStreamReceiver.setupContext(*osContext);
EXPECT_FALSE(commandStreamReceiver.checkPlatformSupportsGpuIdleImplicitFlush());
}

View File

@@ -0,0 +1,142 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/ptr_math.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/engine_descriptor_helper.h"
#include "shared/test/common/helpers/unit_test_helper.h"
#include "shared/test/common/mocks/mock_allocation_properties.h"
#include "shared/test/common/mocks/mock_device.h"
#include "opencl/test/unit_test/command_stream/compute_mode_tests.h"
#include "opencl/test/unit_test/mocks/mock_os_context.h"
#include "test.h"
#include "test_traits_common.h"
using namespace NEO;
using IsDG2 = IsProduct<IGFX_DG2>;
HWTEST2_F(ComputeModeRequirements, GivenProgramPipeControlPriorToNonPipelinedStateCommandThenCorrectCommandsAreAdded, IsDG2) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.ProgramPipeControlPriorToNonPipelinedStateCommand.set(true);
SetUpImpl<FamilyType>();
using STATE_COMPUTE_MODE = typename FamilyType::STATE_COMPUTE_MODE;
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
auto cmdsSize = sizeof(STATE_COMPUTE_MODE) + sizeof(PIPE_CONTROL);
char buff[1024] = {0};
LinearStream stream(buff, 1024);
auto expectedScmCmd = FamilyType::cmdInitStateComputeMode;
expectedScmCmd.setForceNonCoherent(STATE_COMPUTE_MODE::FORCE_NON_COHERENT_FORCE_GPU_NON_COHERENT);
auto expectedBitsMask = FamilyType::stateComputeModeForceNonCoherentMask | FamilyType::stateComputeModeLargeGrfModeMask;
overrideComputeModeRequest<FamilyType>(true, false, false, false);
getCsrHw<FamilyType>()->programComputeMode(stream, flags, *defaultHwInfo);
EXPECT_EQ(cmdsSize, stream.getUsed());
auto startOffset = getCsrHw<FamilyType>()->commandStream.getUsed();
HardwareParse hwParser;
hwParser.parseCommands<FamilyType>(stream, startOffset);
auto pipeControlIterator = find<PIPE_CONTROL *>(hwParser.cmdList.begin(), hwParser.cmdList.end());
auto pipeControlCmd = genCmdCast<PIPE_CONTROL *>(*pipeControlIterator);
EXPECT_TRUE(pipeControlCmd->getHdcPipelineFlush());
EXPECT_TRUE(pipeControlCmd->getAmfsFlushEnable());
EXPECT_TRUE(pipeControlCmd->getCommandStreamerStallEnable());
EXPECT_TRUE(pipeControlCmd->getInstructionCacheInvalidateEnable());
EXPECT_TRUE(pipeControlCmd->getTextureCacheInvalidationEnable());
EXPECT_TRUE(pipeControlCmd->getUnTypedDataPortCacheFlush());
EXPECT_TRUE(pipeControlCmd->getConstantCacheInvalidationEnable());
EXPECT_TRUE(pipeControlCmd->getStateCacheInvalidationEnable());
auto stateComputeModelCmd = reinterpret_cast<STATE_COMPUTE_MODE *>(ptrOffset(stream.getCpuBase(), sizeof(PIPE_CONTROL)));
EXPECT_TRUE(isValueSet(stateComputeModelCmd->getMaskBits(), expectedBitsMask));
expectedScmCmd.setMaskBits(stateComputeModelCmd->getMaskBits());
EXPECT_TRUE(memcmp(&expectedScmCmd, stateComputeModelCmd, sizeof(STATE_COMPUTE_MODE)) == 0);
}
HWTEST2_F(ComputeModeRequirements, GivenMultipleCCSEnabledSetupThenCorrectCommandsAreAdded, IsDG2) {
HardwareInfo hwInfo = *defaultHwInfo;
hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled = 2;
SetUpImpl<FamilyType>(&hwInfo);
MockOsContext ccsOsContext(0, EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_CCS, EngineUsage::Regular}));
getCsrHw<FamilyType>()->setupContext(ccsOsContext);
using STATE_COMPUTE_MODE = typename FamilyType::STATE_COMPUTE_MODE;
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
auto cmdsSize = sizeof(STATE_COMPUTE_MODE) + sizeof(PIPE_CONTROL);
char buff[1024] = {0};
LinearStream stream(buff, 1024);
auto expectedScmCmd = FamilyType::cmdInitStateComputeMode;
expectedScmCmd.setForceNonCoherent(STATE_COMPUTE_MODE::FORCE_NON_COHERENT_FORCE_GPU_NON_COHERENT);
auto expectedBitsMask = FamilyType::stateComputeModeForceNonCoherentMask | FamilyType::stateComputeModeLargeGrfModeMask;
overrideComputeModeRequest<FamilyType>(true, false, false, false);
getCsrHw<FamilyType>()->programComputeMode(stream, flags, hwInfo);
EXPECT_EQ(cmdsSize, stream.getUsed());
auto startOffset = getCsrHw<FamilyType>()->commandStream.getUsed();
HardwareParse hwParser;
hwParser.parseCommands<FamilyType>(stream, startOffset);
auto pipeControlIterator = find<PIPE_CONTROL *>(hwParser.cmdList.begin(), hwParser.cmdList.end());
auto pipeControlCmd = genCmdCast<PIPE_CONTROL *>(*pipeControlIterator);
EXPECT_TRUE(pipeControlCmd->getHdcPipelineFlush());
EXPECT_TRUE(pipeControlCmd->getAmfsFlushEnable());
EXPECT_TRUE(pipeControlCmd->getCommandStreamerStallEnable());
EXPECT_TRUE(pipeControlCmd->getInstructionCacheInvalidateEnable());
EXPECT_TRUE(pipeControlCmd->getTextureCacheInvalidationEnable());
EXPECT_TRUE(pipeControlCmd->getUnTypedDataPortCacheFlush());
EXPECT_TRUE(pipeControlCmd->getConstantCacheInvalidationEnable());
EXPECT_TRUE(pipeControlCmd->getStateCacheInvalidationEnable());
auto stateComputeModelCmd = reinterpret_cast<STATE_COMPUTE_MODE *>(ptrOffset(stream.getCpuBase(), sizeof(PIPE_CONTROL)));
EXPECT_TRUE(isValueSet(stateComputeModelCmd->getMaskBits(), expectedBitsMask));
expectedScmCmd.setMaskBits(stateComputeModelCmd->getMaskBits());
EXPECT_TRUE(memcmp(&expectedScmCmd, stateComputeModelCmd, sizeof(STATE_COMPUTE_MODE)) == 0);
}
HWTEST2_F(ComputeModeRequirements, GivenProgramPipeControlPriorToNonPipelinedStateCommandThenCommandSizeIsCalculatedAndCorrectCommandSizeIsReturned, IsDG2) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.ProgramPipeControlPriorToNonPipelinedStateCommand.set(true);
using STATE_COMPUTE_MODE = typename FamilyType::STATE_COMPUTE_MODE;
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
SetUpImpl<FamilyType>();
getCsrHw<FamilyType>()->requiredThreadArbitrationPolicy = getCsrHw<FamilyType>()->lastSentThreadArbitrationPolicy;
auto cmdsSize = sizeof(STATE_COMPUTE_MODE) + sizeof(PIPE_CONTROL);
overrideComputeModeRequest<FamilyType>(false, false, false);
auto retSize = getCsrHw<FamilyType>()->getCmdSizeForComputeMode();
EXPECT_EQ(0u, retSize);
overrideComputeModeRequest<FamilyType>(false, true, false);
retSize = getCsrHw<FamilyType>()->getCmdSizeForComputeMode();
EXPECT_EQ(0u, retSize);
overrideComputeModeRequest<FamilyType>(true, true, false);
retSize = getCsrHw<FamilyType>()->getCmdSizeForComputeMode();
EXPECT_EQ(cmdsSize, retSize);
overrideComputeModeRequest<FamilyType>(true, false, false);
retSize = getCsrHw<FamilyType>()->getCmdSizeForComputeMode();
EXPECT_EQ(cmdsSize, retSize);
}