2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2020-01-14 14:32:11 +01:00
|
|
|
* Copyright (C) 2018-2020 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
2018-09-18 09:11:08 +02:00
|
|
|
|
2020-02-24 13:10:44 +01:00
|
|
|
#include "shared/source/built_ins/built_ins.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/command_stream/preemption.h"
|
|
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2020-03-31 07:43:07 +02:00
|
|
|
#include "shared/test/unit_test/cmd_parse/hw_parse.h"
|
2020-02-24 01:01:38 +01:00
|
|
|
#include "shared/test/unit_test/fixtures/preemption_fixture.h"
|
2020-05-22 18:11:28 +02:00
|
|
|
#include "shared/test/unit_test/mocks/mock_command_stream_receiver.h"
|
2020-02-24 10:22:30 +01:00
|
|
|
|
2020-02-23 15:20:22 +01:00
|
|
|
#include "opencl/test/unit_test/command_queue/enqueue_fixture.h"
|
2020-06-10 12:52:05 +02:00
|
|
|
#include "opencl/test/unit_test/libult/ult_command_stream_receiver.h"
|
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_graphics_allocation.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-06-02 10:14:02 +02:00
|
|
|
#include "preemption_test_hw_details_gen9.h"
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
void HardwareParse::findCsrBaseAddress<SKLFamily>() {
|
|
|
|
|
typedef typename GEN9::GPGPU_CSR_BASE_ADDRESS GPGPU_CSR_BASE_ADDRESS;
|
|
|
|
|
itorGpgpuCsrBaseAddress = find<GPGPU_CSR_BASE_ADDRESS *>(cmdList.begin(), itorWalker);
|
|
|
|
|
if (itorGpgpuCsrBaseAddress != itorWalker) {
|
|
|
|
|
cmdGpgpuCsrBaseAddress = *itorGpgpuCsrBaseAddress;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
using namespace NEO;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-01-08 16:13:51 +01:00
|
|
|
using Gen9PreemptionTests = DevicePreemptionTests;
|
|
|
|
|
using Gen9PreemptionEnqueueKernelTest = PreemptionEnqueueKernelTest;
|
|
|
|
|
using Gen9MidThreadPreemptionEnqueueKernelTest = MidThreadPreemptionEnqueueKernelTest;
|
|
|
|
|
using Gen9ThreadGroupPreemptionEnqueueKernelTest = ThreadGroupPreemptionEnqueueKernelTest;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-01-08 15:58:02 +01:00
|
|
|
GEN9TEST_F(Gen9PreemptionTests, whenMidThreadPreemptionIsNotAvailableThenDoesNotProgramPreamble) {
|
|
|
|
|
device->setPreemptionMode(PreemptionMode::ThreadGroup);
|
|
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
size_t requiredSize = PreemptionHelper::getRequiredStateSipCmdSize<FamilyType>(device->getDevice());
|
2018-01-08 15:58:02 +01:00
|
|
|
EXPECT_EQ(0U, requiredSize);
|
|
|
|
|
|
|
|
|
|
LinearStream cmdStream{nullptr, 0};
|
2020-01-14 14:32:11 +01:00
|
|
|
PreemptionHelper::programStateSip<FamilyType>(cmdStream, device->getDevice());
|
2018-01-08 15:58:02 +01:00
|
|
|
EXPECT_EQ(0U, cmdStream.getUsed());
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-05 11:52:19 +01:00
|
|
|
GEN9TEST_F(Gen9PreemptionTests, whenMidThreadPreemptionIsAvailableThenStateSipIsProgrammed) {
|
2018-01-08 15:58:02 +01:00
|
|
|
using STATE_SIP = typename FamilyType::STATE_SIP;
|
|
|
|
|
|
|
|
|
|
device->setPreemptionMode(PreemptionMode::MidThread);
|
|
|
|
|
executionEnvironment->DisableMidThreadPreemption = 0;
|
|
|
|
|
|
2019-05-08 16:00:24 +02:00
|
|
|
size_t minCsrSize = device->getHardwareInfo().gtSystemInfo.CsrSizeInMb * MemoryConstants::megaByte;
|
2018-01-08 15:58:02 +01:00
|
|
|
uint64_t minCsrAlignment = 2 * 256 * MemoryConstants::kiloByte;
|
|
|
|
|
MockGraphicsAllocation csrSurface((void *)minCsrAlignment, minCsrSize);
|
|
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
size_t requiredCmdStreamSize = PreemptionHelper::getRequiredStateSipCmdSize<FamilyType>(device->getDevice());
|
2018-11-05 11:52:19 +01:00
|
|
|
size_t expectedPreambleSize = sizeof(STATE_SIP);
|
|
|
|
|
EXPECT_EQ(expectedPreambleSize, requiredCmdStreamSize);
|
2018-01-08 15:58:02 +01:00
|
|
|
|
2018-11-05 11:52:19 +01:00
|
|
|
StackVec<char, 8192> streamStorage(requiredCmdStreamSize);
|
|
|
|
|
ASSERT_LE(requiredCmdStreamSize, streamStorage.size());
|
2018-01-08 15:58:02 +01:00
|
|
|
|
2018-11-05 11:52:19 +01:00
|
|
|
LinearStream cmdStream{streamStorage.begin(), streamStorage.size()};
|
2020-01-14 14:32:11 +01:00
|
|
|
PreemptionHelper::programStateSip<FamilyType>(cmdStream, device->getDevice());
|
2018-01-08 15:58:02 +01:00
|
|
|
|
2018-11-05 11:52:19 +01:00
|
|
|
HardwareParse hwParsePreamble;
|
|
|
|
|
hwParsePreamble.parseCommands<FamilyType>(cmdStream);
|
2018-01-08 15:58:02 +01:00
|
|
|
|
|
|
|
|
auto stateSipCmd = hwParsePreamble.getCommand<STATE_SIP>();
|
|
|
|
|
ASSERT_NE(nullptr, stateSipCmd);
|
2020-02-27 15:32:57 +01:00
|
|
|
EXPECT_EQ(device->getBuiltIns()->getSipKernel(SipKernelType::Csr, device->getDevice()).getSipAllocation()->getGpuAddressToPatch(), stateSipCmd->getSystemInstructionPointer());
|
2018-01-08 15:58:02 +01:00
|
|
|
}
|
|
|
|
|
|
2018-01-02 12:10:34 +01:00
|
|
|
GEN9TEST_F(Gen9ThreadGroupPreemptionEnqueueKernelTest, givenSecondEnqueueWithTheSamePreemptionRequestThenDontReprogramThreadGroupNoWa) {
|
2017-12-21 00:45:38 +01:00
|
|
|
pDevice->setPreemptionMode(PreemptionMode::ThreadGroup);
|
2019-08-05 08:07:29 +02:00
|
|
|
|
2020-03-04 08:51:02 +01:00
|
|
|
pDevice->getRootDeviceEnvironment().getMutableHardwareInfo()->workaroundTable.waModifyVFEStateAfterGPGPUPreemption = false;
|
2017-12-21 00:45:38 +01:00
|
|
|
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
|
|
|
|
|
csr.getMemoryManager()->setForce32BitAllocations(false);
|
2018-12-13 11:06:28 +01:00
|
|
|
csr.setMediaVFEStateDirty(false);
|
2019-06-27 21:33:05 +02:00
|
|
|
auto csrSurface = csr.getPreemptionAllocation();
|
2017-12-21 00:45:38 +01:00
|
|
|
EXPECT_EQ(nullptr, csrSurface);
|
|
|
|
|
size_t off[3] = {0, 0, 0};
|
|
|
|
|
size_t gws[3] = {1, 1, 1};
|
|
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
MockKernelWithInternals mockKernel(*pClDevice);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-01-08 16:13:51 +01:00
|
|
|
HardwareParse hwParserCsr;
|
|
|
|
|
HardwareParse hwParserCmdQ;
|
2017-12-21 00:45:38 +01:00
|
|
|
pCmdQ->enqueueKernel(mockKernel.mockKernel, 1, off, gws, nullptr, 0, nullptr, nullptr);
|
2018-01-08 16:13:51 +01:00
|
|
|
hwParserCsr.parseCommands<FamilyType>(csr.commandStream);
|
2018-08-24 08:48:59 +02:00
|
|
|
hwParserCmdQ.parseCommands<FamilyType>(pCmdQ->getCS(1024));
|
2018-01-02 12:10:34 +01:00
|
|
|
auto offsetCsr = csr.commandStream.getUsed();
|
2018-08-24 08:48:59 +02:00
|
|
|
auto offsetCmdQ = pCmdQ->getCS(1024).getUsed();
|
2017-12-21 00:45:38 +01:00
|
|
|
pCmdQ->enqueueKernel(mockKernel.mockKernel, 1, off, gws, nullptr, 0, nullptr, nullptr);
|
2018-01-08 16:13:51 +01:00
|
|
|
pCmdQ->flush();
|
|
|
|
|
hwParserCsr.parseCommands<FamilyType>(csr.commandStream, offsetCsr);
|
2018-08-24 08:48:59 +02:00
|
|
|
hwParserCmdQ.parseCommands<FamilyType>(pCmdQ->getCS(1024), offsetCmdQ);
|
2018-01-08 16:13:51 +01:00
|
|
|
|
|
|
|
|
EXPECT_EQ(1U, countMmio<FamilyType>(hwParserCsr.cmdList.begin(), hwParserCsr.cmdList.end(), 0x2580u));
|
|
|
|
|
EXPECT_EQ(0U, countMmio<FamilyType>(hwParserCsr.cmdList.begin(), hwParserCsr.cmdList.end(), 0x2600u));
|
|
|
|
|
EXPECT_EQ(0U, countMmio<FamilyType>(hwParserCmdQ.cmdList.begin(), hwParserCmdQ.cmdList.end(), 0x2580u));
|
|
|
|
|
EXPECT_EQ(0U, countMmio<FamilyType>(hwParserCmdQ.cmdList.begin(), hwParserCmdQ.cmdList.end(), 0x2600u));
|
2018-01-02 12:10:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GEN9TEST_F(Gen9ThreadGroupPreemptionEnqueueKernelTest, givenSecondEnqueueWithTheSamePreemptionRequestThenDontReprogramThreadGroupWa) {
|
|
|
|
|
pDevice->setPreemptionMode(PreemptionMode::ThreadGroup);
|
2019-08-05 08:07:29 +02:00
|
|
|
|
2020-03-04 08:51:02 +01:00
|
|
|
pDevice->getRootDeviceEnvironment().getMutableHardwareInfo()->workaroundTable.waModifyVFEStateAfterGPGPUPreemption = true;
|
2018-01-02 12:10:34 +01:00
|
|
|
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
|
|
|
|
|
csr.getMemoryManager()->setForce32BitAllocations(false);
|
2018-12-13 11:06:28 +01:00
|
|
|
csr.setMediaVFEStateDirty(false);
|
2019-06-27 21:33:05 +02:00
|
|
|
auto csrSurface = csr.getPreemptionAllocation();
|
2018-01-02 12:10:34 +01:00
|
|
|
EXPECT_EQ(nullptr, csrSurface);
|
|
|
|
|
HardwareParse hwCsrParser;
|
|
|
|
|
HardwareParse hwCmdQParser;
|
|
|
|
|
size_t off[3] = {0, 0, 0};
|
|
|
|
|
size_t gws[3] = {1, 1, 1};
|
|
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
MockKernelWithInternals mockKernel(*pClDevice);
|
2018-01-02 12:10:34 +01:00
|
|
|
|
|
|
|
|
pCmdQ->enqueueKernel(mockKernel.mockKernel, 1, off, gws, nullptr, 0, nullptr, nullptr);
|
|
|
|
|
hwCsrParser.parseCommands<FamilyType>(csr.commandStream);
|
|
|
|
|
hwCsrParser.findHardwareCommands<FamilyType>();
|
2018-08-24 08:48:59 +02:00
|
|
|
hwCmdQParser.parseCommands<FamilyType>(pCmdQ->getCS(1024));
|
2018-01-02 12:10:34 +01:00
|
|
|
hwCmdQParser.findHardwareCommands<FamilyType>();
|
|
|
|
|
auto offsetCsr = csr.commandStream.getUsed();
|
2018-08-24 08:48:59 +02:00
|
|
|
auto offsetCmdQ = pCmdQ->getCS(1024).getUsed();
|
2018-01-02 12:10:34 +01:00
|
|
|
|
|
|
|
|
bool foundOne = false;
|
|
|
|
|
for (auto it : hwCsrParser.lriList) {
|
|
|
|
|
auto cmd = genCmdCast<typename FamilyType::MI_LOAD_REGISTER_IMM *>(it);
|
|
|
|
|
if (cmd->getRegisterOffset() == 0x2580u) {
|
|
|
|
|
EXPECT_FALSE(foundOne);
|
|
|
|
|
foundOne = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
EXPECT_TRUE(foundOne);
|
|
|
|
|
hwCsrParser.cmdList.clear();
|
|
|
|
|
hwCsrParser.lriList.clear();
|
|
|
|
|
|
|
|
|
|
int foundWaLri = 0;
|
|
|
|
|
int foundWaLriBegin = 0;
|
|
|
|
|
int foundWaLriEnd = 0;
|
|
|
|
|
for (auto it : hwCmdQParser.lriList) {
|
|
|
|
|
auto cmd = genCmdCast<typename FamilyType::MI_LOAD_REGISTER_IMM *>(it);
|
|
|
|
|
if (cmd->getRegisterOffset() == 0x2600u) {
|
|
|
|
|
foundWaLri++;
|
|
|
|
|
if (cmd->getDataDword() == 0xFFFFFFFF) {
|
|
|
|
|
foundWaLriBegin++;
|
|
|
|
|
}
|
|
|
|
|
if (cmd->getDataDword() == 0x0) {
|
|
|
|
|
foundWaLriEnd++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
EXPECT_EQ(2, foundWaLri);
|
|
|
|
|
EXPECT_EQ(1, foundWaLriBegin);
|
|
|
|
|
EXPECT_EQ(1, foundWaLriEnd);
|
|
|
|
|
hwCmdQParser.cmdList.clear();
|
|
|
|
|
hwCmdQParser.lriList.clear();
|
|
|
|
|
|
|
|
|
|
pCmdQ->enqueueKernel(mockKernel.mockKernel, 1, off, gws, nullptr, 0, nullptr, nullptr);
|
|
|
|
|
hwCsrParser.parseCommands<FamilyType>(csr.commandStream, offsetCsr);
|
|
|
|
|
hwCsrParser.findHardwareCommands<FamilyType>();
|
|
|
|
|
|
2018-08-24 08:48:59 +02:00
|
|
|
hwCmdQParser.parseCommands<FamilyType>(pCmdQ->getCS(1024), offsetCmdQ);
|
2018-01-02 12:10:34 +01:00
|
|
|
hwCmdQParser.findHardwareCommands<FamilyType>();
|
|
|
|
|
|
|
|
|
|
for (auto it : hwCsrParser.lriList) {
|
|
|
|
|
auto cmd = genCmdCast<typename FamilyType::MI_LOAD_REGISTER_IMM *>(it);
|
|
|
|
|
EXPECT_FALSE(cmd->getRegisterOffset() == 0x2580u);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foundWaLri = 0;
|
|
|
|
|
foundWaLriBegin = 0;
|
|
|
|
|
foundWaLriEnd = 0;
|
|
|
|
|
for (auto it : hwCmdQParser.lriList) {
|
|
|
|
|
auto cmd = genCmdCast<typename FamilyType::MI_LOAD_REGISTER_IMM *>(it);
|
|
|
|
|
if (cmd->getRegisterOffset() == 0x2600u) {
|
|
|
|
|
foundWaLri++;
|
|
|
|
|
if (cmd->getDataDword() == 0xFFFFFFFF) {
|
|
|
|
|
foundWaLriBegin++;
|
|
|
|
|
}
|
|
|
|
|
if (cmd->getDataDword() == 0x0) {
|
|
|
|
|
foundWaLriEnd++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
EXPECT_EQ(2, foundWaLri);
|
|
|
|
|
EXPECT_EQ(1, foundWaLriBegin);
|
|
|
|
|
EXPECT_EQ(1, foundWaLriEnd);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GEN9TEST_F(Gen9PreemptionEnqueueKernelTest, givenValidKernelForPreemptionWhenEnqueueKernelCalledThenPassDevicePreemptionModeThreadGroup) {
|
|
|
|
|
pDevice->setPreemptionMode(PreemptionMode::ThreadGroup);
|
2019-08-05 08:07:29 +02:00
|
|
|
|
2019-10-29 08:01:53 +01:00
|
|
|
auto mockCsr = new MockCsrHw2<FamilyType>(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex());
|
2017-12-21 00:45:38 +01:00
|
|
|
pDevice->resetCommandStreamReceiver(mockCsr);
|
|
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
MockKernelWithInternals mockKernel(*pClDevice);
|
2019-11-27 12:59:47 +01:00
|
|
|
MultiDispatchInfo multiDispatch(mockKernel.mockKernel);
|
|
|
|
|
EXPECT_EQ(PreemptionMode::ThreadGroup, PreemptionHelper::taskPreemptionMode(*pDevice, multiDispatch));
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
size_t gws[3] = {1, 0, 0};
|
|
|
|
|
pCmdQ->enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
|
|
|
|
|
pCmdQ->flush();
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(1, mockCsr->flushCalledCount);
|
|
|
|
|
EXPECT_EQ(PreemptionMode::ThreadGroup, mockCsr->passedDispatchFlags.preemptionMode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GEN9TEST_F(Gen9PreemptionEnqueueKernelTest, givenValidKernelForPreemptionWhenEnqueueKernelCalledAndBlockedThenPassDevicePreemptionModeThreadGroup) {
|
|
|
|
|
pDevice->setPreemptionMode(PreemptionMode::ThreadGroup);
|
2019-08-05 08:07:29 +02:00
|
|
|
|
2019-10-29 08:01:53 +01:00
|
|
|
auto mockCsr = new MockCsrHw2<FamilyType>(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex());
|
2017-12-21 00:45:38 +01:00
|
|
|
pDevice->resetCommandStreamReceiver(mockCsr);
|
|
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
MockKernelWithInternals mockKernel(*pClDevice);
|
2019-11-27 12:59:47 +01:00
|
|
|
MultiDispatchInfo multiDispatch(mockKernel.mockKernel);
|
|
|
|
|
EXPECT_EQ(PreemptionMode::ThreadGroup, PreemptionHelper::taskPreemptionMode(*pDevice, multiDispatch));
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
UserEvent userEventObj;
|
|
|
|
|
cl_event userEvent = &userEventObj;
|
|
|
|
|
size_t gws[3] = {1, 0, 0};
|
|
|
|
|
pCmdQ->enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 1, &userEvent, nullptr);
|
|
|
|
|
pCmdQ->flush();
|
|
|
|
|
EXPECT_EQ(0, mockCsr->flushCalledCount);
|
|
|
|
|
|
|
|
|
|
userEventObj.setStatus(CL_COMPLETE);
|
|
|
|
|
pCmdQ->flush();
|
|
|
|
|
EXPECT_EQ(1, mockCsr->flushCalledCount);
|
|
|
|
|
EXPECT_EQ(PreemptionMode::ThreadGroup, mockCsr->passedDispatchFlags.preemptionMode);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-02 12:10:34 +01:00
|
|
|
GEN9TEST_F(Gen9MidThreadPreemptionEnqueueKernelTest, givenSecondEnqueueWithTheSamePreemptionRequestThenDontReprogramMidThreadNoWa) {
|
|
|
|
|
typedef typename FamilyType::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM;
|
|
|
|
|
typedef typename FamilyType::GPGPU_CSR_BASE_ADDRESS GPGPU_CSR_BASE_ADDRESS;
|
|
|
|
|
|
2020-03-04 08:51:02 +01:00
|
|
|
pDevice->getRootDeviceEnvironment().getMutableHardwareInfo()->workaroundTable.waModifyVFEStateAfterGPGPUPreemption = false;
|
2018-01-02 12:10:34 +01:00
|
|
|
|
|
|
|
|
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
|
|
|
|
|
csr.getMemoryManager()->setForce32BitAllocations(false);
|
2018-12-13 11:06:28 +01:00
|
|
|
csr.setMediaVFEStateDirty(false);
|
2019-06-27 21:33:05 +02:00
|
|
|
auto csrSurface = csr.getPreemptionAllocation();
|
2018-01-02 12:10:34 +01:00
|
|
|
ASSERT_NE(nullptr, csrSurface);
|
|
|
|
|
HardwareParse hwCsrParser;
|
|
|
|
|
HardwareParse hwCmdQParser;
|
|
|
|
|
size_t off[3] = {0, 0, 0};
|
|
|
|
|
size_t gws[3] = {1, 1, 1};
|
|
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
MockKernelWithInternals mockKernel(*pClDevice);
|
2018-01-02 12:10:34 +01:00
|
|
|
|
|
|
|
|
pCmdQ->enqueueKernel(mockKernel.mockKernel, 1, off, gws, nullptr, 0, nullptr, nullptr);
|
|
|
|
|
hwCsrParser.parseCommands<FamilyType>(csr.commandStream);
|
|
|
|
|
hwCsrParser.findHardwareCommands<FamilyType>();
|
2018-08-24 08:48:59 +02:00
|
|
|
hwCmdQParser.parseCommands<FamilyType>(pCmdQ->getCS(1024));
|
2018-01-02 12:10:34 +01:00
|
|
|
hwCmdQParser.findHardwareCommands<FamilyType>();
|
|
|
|
|
auto offsetCsr = csr.commandStream.getUsed();
|
2018-08-24 08:48:59 +02:00
|
|
|
auto offsetCmdQ = pCmdQ->getCS(1024).getUsed();
|
2018-01-02 12:10:34 +01:00
|
|
|
|
|
|
|
|
bool foundOneLri = false;
|
|
|
|
|
for (auto it : hwCsrParser.lriList) {
|
|
|
|
|
auto cmdLri = genCmdCast<MI_LOAD_REGISTER_IMM *>(it);
|
|
|
|
|
if (cmdLri->getRegisterOffset() == 0x2580u) {
|
|
|
|
|
EXPECT_FALSE(foundOneLri);
|
|
|
|
|
foundOneLri = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
EXPECT_TRUE(foundOneLri);
|
|
|
|
|
|
|
|
|
|
bool foundWaLri = false;
|
|
|
|
|
for (auto it : hwCmdQParser.lriList) {
|
|
|
|
|
auto cmdLri = genCmdCast<MI_LOAD_REGISTER_IMM *>(it);
|
|
|
|
|
if (cmdLri->getRegisterOffset() == 0x2600u) {
|
|
|
|
|
foundWaLri = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
EXPECT_FALSE(foundWaLri);
|
|
|
|
|
|
|
|
|
|
hwCsrParser.findCsrBaseAddress<FamilyType>();
|
|
|
|
|
ASSERT_NE(nullptr, hwCsrParser.cmdGpgpuCsrBaseAddress);
|
|
|
|
|
auto cmdCsr = genCmdCast<GPGPU_CSR_BASE_ADDRESS *>(hwCsrParser.cmdGpgpuCsrBaseAddress);
|
|
|
|
|
ASSERT_NE(nullptr, cmdCsr);
|
|
|
|
|
EXPECT_EQ(csrSurface->getGpuAddressToPatch(), cmdCsr->getGpgpuCsrBaseAddress());
|
|
|
|
|
|
|
|
|
|
hwCsrParser.cmdList.clear();
|
|
|
|
|
hwCsrParser.lriList.clear();
|
|
|
|
|
hwCsrParser.cmdGpgpuCsrBaseAddress = nullptr;
|
|
|
|
|
hwCmdQParser.cmdList.clear();
|
|
|
|
|
hwCmdQParser.lriList.clear();
|
|
|
|
|
|
|
|
|
|
pCmdQ->enqueueKernel(mockKernel.mockKernel, 1, off, gws, nullptr, 0, nullptr, nullptr);
|
|
|
|
|
hwCsrParser.parseCommands<FamilyType>(csr.commandStream, offsetCsr);
|
|
|
|
|
hwCsrParser.findHardwareCommands<FamilyType>();
|
|
|
|
|
hwCmdQParser.parseCommands<FamilyType>(csr.commandStream, offsetCmdQ);
|
|
|
|
|
hwCmdQParser.findHardwareCommands<FamilyType>();
|
|
|
|
|
|
|
|
|
|
for (auto it : hwCsrParser.lriList) {
|
|
|
|
|
auto cmd = genCmdCast<MI_LOAD_REGISTER_IMM *>(it);
|
|
|
|
|
EXPECT_FALSE(cmd->getRegisterOffset() == 0x2580u);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hwCsrParser.findCsrBaseAddress<FamilyType>();
|
|
|
|
|
EXPECT_EQ(nullptr, hwCsrParser.cmdGpgpuCsrBaseAddress);
|
|
|
|
|
|
|
|
|
|
for (auto it : hwCmdQParser.lriList) {
|
|
|
|
|
auto cmd = genCmdCast<MI_LOAD_REGISTER_IMM *>(it);
|
|
|
|
|
EXPECT_FALSE(cmd->getRegisterOffset() == 0x2600u);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GEN9TEST_F(Gen9MidThreadPreemptionEnqueueKernelTest, givenSecondEnqueueWithTheSamePreemptionRequestThenDontReprogramMidThreadWa) {
|
2017-12-21 00:45:38 +01:00
|
|
|
typedef typename FamilyType::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM;
|
|
|
|
|
typedef typename FamilyType::GPGPU_CSR_BASE_ADDRESS GPGPU_CSR_BASE_ADDRESS;
|
|
|
|
|
|
2020-03-04 08:51:02 +01:00
|
|
|
pDevice->getRootDeviceEnvironment().getMutableHardwareInfo()->workaroundTable.waModifyVFEStateAfterGPGPUPreemption = true;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
|
|
|
|
|
csr.getMemoryManager()->setForce32BitAllocations(false);
|
2018-12-13 11:06:28 +01:00
|
|
|
csr.setMediaVFEStateDirty(false);
|
2019-06-27 21:33:05 +02:00
|
|
|
auto csrSurface = csr.getPreemptionAllocation();
|
2017-12-21 00:45:38 +01:00
|
|
|
ASSERT_NE(nullptr, csrSurface);
|
2018-01-02 12:10:34 +01:00
|
|
|
HardwareParse hwCsrParser;
|
|
|
|
|
HardwareParse hwCmdQParser;
|
2017-12-21 00:45:38 +01:00
|
|
|
size_t off[3] = {0, 0, 0};
|
|
|
|
|
size_t gws[3] = {1, 1, 1};
|
|
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
MockKernelWithInternals mockKernel(*pClDevice);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
pCmdQ->enqueueKernel(mockKernel.mockKernel, 1, off, gws, nullptr, 0, nullptr, nullptr);
|
2018-01-02 12:10:34 +01:00
|
|
|
hwCsrParser.parseCommands<FamilyType>(csr.commandStream);
|
|
|
|
|
hwCsrParser.findHardwareCommands<FamilyType>();
|
2018-08-24 08:48:59 +02:00
|
|
|
hwCmdQParser.parseCommands<FamilyType>(pCmdQ->getCS(1024));
|
2018-01-02 12:10:34 +01:00
|
|
|
hwCmdQParser.findHardwareCommands<FamilyType>();
|
|
|
|
|
auto offsetCsr = csr.commandStream.getUsed();
|
2018-08-24 08:48:59 +02:00
|
|
|
auto offsetCmdQ = pCmdQ->getCS(1024).getUsed();
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
bool foundOneLri = false;
|
2018-01-02 12:10:34 +01:00
|
|
|
for (auto it : hwCsrParser.lriList) {
|
2017-12-21 00:45:38 +01:00
|
|
|
auto cmdLri = genCmdCast<MI_LOAD_REGISTER_IMM *>(it);
|
|
|
|
|
if (cmdLri->getRegisterOffset() == 0x2580u) {
|
|
|
|
|
EXPECT_FALSE(foundOneLri);
|
|
|
|
|
foundOneLri = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
EXPECT_TRUE(foundOneLri);
|
2018-01-02 12:10:34 +01:00
|
|
|
|
|
|
|
|
int foundWaLri = 0;
|
|
|
|
|
int foundWaLriBegin = 0;
|
|
|
|
|
int foundWaLriEnd = 0;
|
|
|
|
|
for (auto it : hwCmdQParser.lriList) {
|
|
|
|
|
auto cmdLri = genCmdCast<MI_LOAD_REGISTER_IMM *>(it);
|
|
|
|
|
if (cmdLri->getRegisterOffset() == 0x2600u) {
|
|
|
|
|
foundWaLri++;
|
|
|
|
|
if (cmdLri->getDataDword() == 0xFFFFFFFF) {
|
|
|
|
|
foundWaLriBegin++;
|
|
|
|
|
}
|
|
|
|
|
if (cmdLri->getDataDword() == 0x0) {
|
|
|
|
|
foundWaLriEnd++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
EXPECT_EQ(2, foundWaLri);
|
|
|
|
|
EXPECT_EQ(1, foundWaLriBegin);
|
|
|
|
|
EXPECT_EQ(1, foundWaLriEnd);
|
|
|
|
|
|
|
|
|
|
hwCsrParser.findCsrBaseAddress<FamilyType>();
|
|
|
|
|
ASSERT_NE(nullptr, hwCsrParser.cmdGpgpuCsrBaseAddress);
|
|
|
|
|
auto cmdCsr = genCmdCast<GPGPU_CSR_BASE_ADDRESS *>(hwCsrParser.cmdGpgpuCsrBaseAddress);
|
2017-12-21 00:45:38 +01:00
|
|
|
ASSERT_NE(nullptr, cmdCsr);
|
|
|
|
|
EXPECT_EQ(csrSurface->getGpuAddressToPatch(), cmdCsr->getGpgpuCsrBaseAddress());
|
|
|
|
|
|
2018-01-02 12:10:34 +01:00
|
|
|
hwCsrParser.cmdList.clear();
|
|
|
|
|
hwCsrParser.lriList.clear();
|
|
|
|
|
hwCsrParser.cmdGpgpuCsrBaseAddress = nullptr;
|
|
|
|
|
hwCmdQParser.cmdList.clear();
|
|
|
|
|
hwCmdQParser.lriList.clear();
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
pCmdQ->enqueueKernel(mockKernel.mockKernel, 1, off, gws, nullptr, 0, nullptr, nullptr);
|
2018-01-02 12:10:34 +01:00
|
|
|
hwCsrParser.parseCommands<FamilyType>(csr.commandStream, offsetCsr);
|
|
|
|
|
hwCsrParser.findHardwareCommands<FamilyType>();
|
2018-08-24 08:48:59 +02:00
|
|
|
hwCmdQParser.parseCommands<FamilyType>(pCmdQ->getCS(1024), offsetCmdQ);
|
2018-01-02 12:10:34 +01:00
|
|
|
hwCmdQParser.findHardwareCommands<FamilyType>();
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-01-02 12:10:34 +01:00
|
|
|
for (auto it : hwCsrParser.lriList) {
|
2017-12-21 00:45:38 +01:00
|
|
|
auto cmd = genCmdCast<MI_LOAD_REGISTER_IMM *>(it);
|
|
|
|
|
EXPECT_FALSE(cmd->getRegisterOffset() == 0x2580u);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-02 12:10:34 +01:00
|
|
|
hwCsrParser.findCsrBaseAddress<FamilyType>();
|
|
|
|
|
EXPECT_EQ(nullptr, hwCsrParser.cmdGpgpuCsrBaseAddress);
|
|
|
|
|
|
|
|
|
|
foundWaLri = 0;
|
|
|
|
|
foundWaLriBegin = 0;
|
|
|
|
|
foundWaLriEnd = 0;
|
|
|
|
|
for (auto it : hwCmdQParser.lriList) {
|
|
|
|
|
auto cmd = genCmdCast<MI_LOAD_REGISTER_IMM *>(it);
|
|
|
|
|
if (cmd->getRegisterOffset() == 0x2600u) {
|
|
|
|
|
foundWaLri++;
|
|
|
|
|
if (cmd->getDataDword() == 0xFFFFFFFF) {
|
|
|
|
|
foundWaLriBegin++;
|
|
|
|
|
}
|
|
|
|
|
if (cmd->getDataDword() == 0x0) {
|
|
|
|
|
foundWaLriEnd++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
EXPECT_EQ(2, foundWaLri);
|
|
|
|
|
EXPECT_EQ(1, foundWaLriBegin);
|
|
|
|
|
EXPECT_EQ(1, foundWaLriEnd);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GEN9TEST_F(Gen9PreemptionEnqueueKernelTest, givenDisabledPreemptionWhenEnqueueKernelCalledThenPassDisabledPreemptionMode) {
|
|
|
|
|
pDevice->setPreemptionMode(PreemptionMode::Disabled);
|
2019-08-05 08:07:29 +02:00
|
|
|
|
2019-10-29 08:01:53 +01:00
|
|
|
auto mockCsr = new MockCsrHw2<FamilyType>(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex());
|
2017-12-21 00:45:38 +01:00
|
|
|
pDevice->resetCommandStreamReceiver(mockCsr);
|
|
|
|
|
|
2020-01-14 14:32:11 +01:00
|
|
|
MockKernelWithInternals mockKernel(*pClDevice);
|
2019-11-27 12:59:47 +01:00
|
|
|
MultiDispatchInfo multiDispatch(mockKernel.mockKernel);
|
|
|
|
|
EXPECT_EQ(PreemptionMode::Disabled, PreemptionHelper::taskPreemptionMode(*pDevice, multiDispatch));
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
size_t gws[3] = {1, 0, 0};
|
|
|
|
|
pCmdQ->enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
|
|
|
|
|
pCmdQ->flush();
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(1, mockCsr->flushCalledCount);
|
|
|
|
|
EXPECT_EQ(PreemptionMode::Disabled, mockCsr->passedDispatchFlags.preemptionMode);
|
|
|
|
|
}
|
2018-01-02 12:10:34 +01:00
|
|
|
|
|
|
|
|
GEN9TEST_F(Gen9PreemptionTests, getPreemptionWaCsSizeMidBatch) {
|
|
|
|
|
size_t expectedSize = 0;
|
|
|
|
|
device->setPreemptionMode(PreemptionMode::MidBatch);
|
2020-01-14 14:32:11 +01:00
|
|
|
size_t size = PreemptionHelper::getPreemptionWaCsSize<FamilyType>(device->getDevice());
|
2018-01-02 12:10:34 +01:00
|
|
|
EXPECT_EQ(expectedSize, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GEN9TEST_F(Gen9PreemptionTests, getPreemptionWaCsSizeThreadGroupNoWa) {
|
|
|
|
|
size_t expectedSize = 0;
|
|
|
|
|
device->setPreemptionMode(PreemptionMode::ThreadGroup);
|
2020-03-04 08:51:02 +01:00
|
|
|
device->getRootDeviceEnvironment().getMutableHardwareInfo()->workaroundTable.waModifyVFEStateAfterGPGPUPreemption = false;
|
2020-01-14 14:32:11 +01:00
|
|
|
size_t size = PreemptionHelper::getPreemptionWaCsSize<FamilyType>(device->getDevice());
|
2018-01-02 12:10:34 +01:00
|
|
|
EXPECT_EQ(expectedSize, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GEN9TEST_F(Gen9PreemptionTests, getPreemptionWaCsSizeThreadGroupWa) {
|
|
|
|
|
typedef typename FamilyType::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM;
|
|
|
|
|
size_t expectedSize = 2 * sizeof(MI_LOAD_REGISTER_IMM);
|
|
|
|
|
device->setPreemptionMode(PreemptionMode::ThreadGroup);
|
2020-03-04 08:51:02 +01:00
|
|
|
device->getRootDeviceEnvironment().getMutableHardwareInfo()->workaroundTable.waModifyVFEStateAfterGPGPUPreemption = true;
|
2020-01-14 14:32:11 +01:00
|
|
|
size_t size = PreemptionHelper::getPreemptionWaCsSize<FamilyType>(device->getDevice());
|
2018-01-02 12:10:34 +01:00
|
|
|
EXPECT_EQ(expectedSize, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GEN9TEST_F(Gen9PreemptionTests, getPreemptionWaCsSizeMidThreadNoWa) {
|
|
|
|
|
size_t expectedSize = 0;
|
|
|
|
|
device->setPreemptionMode(PreemptionMode::MidThread);
|
2020-03-04 08:51:02 +01:00
|
|
|
device->getRootDeviceEnvironment().getMutableHardwareInfo()->workaroundTable.waModifyVFEStateAfterGPGPUPreemption = false;
|
2020-01-14 14:32:11 +01:00
|
|
|
size_t size = PreemptionHelper::getPreemptionWaCsSize<FamilyType>(device->getDevice());
|
2018-01-02 12:10:34 +01:00
|
|
|
EXPECT_EQ(expectedSize, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GEN9TEST_F(Gen9PreemptionTests, getPreemptionWaCsSizeMidThreadWa) {
|
|
|
|
|
typedef typename FamilyType::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM;
|
|
|
|
|
size_t expectedSize = 2 * sizeof(MI_LOAD_REGISTER_IMM);
|
|
|
|
|
device->setPreemptionMode(PreemptionMode::MidThread);
|
2020-03-04 08:51:02 +01:00
|
|
|
device->getRootDeviceEnvironment().getMutableHardwareInfo()->workaroundTable.waModifyVFEStateAfterGPGPUPreemption = true;
|
2020-01-14 14:32:11 +01:00
|
|
|
size_t size = PreemptionHelper::getPreemptionWaCsSize<FamilyType>(device->getDevice());
|
2018-01-02 12:10:34 +01:00
|
|
|
EXPECT_EQ(expectedSize, size);
|
|
|
|
|
}
|
2018-03-01 22:43:04 +01:00
|
|
|
|
|
|
|
|
GEN9TEST_F(Gen9PreemptionTests, givenInterfaceDescriptorDataWhenAnyPreemptionModeThenNoChange) {
|
|
|
|
|
using INTERFACE_DESCRIPTOR_DATA = typename FamilyType::INTERFACE_DESCRIPTOR_DATA;
|
|
|
|
|
|
|
|
|
|
INTERFACE_DESCRIPTOR_DATA idd;
|
|
|
|
|
INTERFACE_DESCRIPTOR_DATA iddArg;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
idd = FamilyType::cmdInitInterfaceDescriptorData;
|
|
|
|
|
iddArg = FamilyType::cmdInitInterfaceDescriptorData;
|
|
|
|
|
|
|
|
|
|
PreemptionHelper::programInterfaceDescriptorDataPreemption<FamilyType>(&iddArg, PreemptionMode::Disabled);
|
|
|
|
|
ret = memcmp(&idd, &iddArg, sizeof(INTERFACE_DESCRIPTOR_DATA));
|
|
|
|
|
EXPECT_EQ(0, ret);
|
|
|
|
|
|
|
|
|
|
PreemptionHelper::programInterfaceDescriptorDataPreemption<FamilyType>(&iddArg, PreemptionMode::MidBatch);
|
|
|
|
|
ret = memcmp(&idd, &iddArg, sizeof(INTERFACE_DESCRIPTOR_DATA));
|
|
|
|
|
EXPECT_EQ(0, ret);
|
|
|
|
|
|
|
|
|
|
PreemptionHelper::programInterfaceDescriptorDataPreemption<FamilyType>(&iddArg, PreemptionMode::ThreadGroup);
|
|
|
|
|
ret = memcmp(&idd, &iddArg, sizeof(INTERFACE_DESCRIPTOR_DATA));
|
|
|
|
|
EXPECT_EQ(0, ret);
|
|
|
|
|
|
|
|
|
|
PreemptionHelper::programInterfaceDescriptorDataPreemption<FamilyType>(&iddArg, PreemptionMode::MidThread);
|
|
|
|
|
ret = memcmp(&idd, &iddArg, sizeof(INTERFACE_DESCRIPTOR_DATA));
|
|
|
|
|
EXPECT_EQ(0, ret);
|
|
|
|
|
}
|
2018-11-05 11:52:19 +01:00
|
|
|
|
|
|
|
|
GEN9TEST_F(Gen9PreemptionTests, givenMidThreadPreemptionModeWhenStateSipIsProgrammedThenSipEqualsSipAllocationGpuAddressToPatch) {
|
|
|
|
|
using STATE_SIP = typename FamilyType::STATE_SIP;
|
|
|
|
|
auto mockDevice = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
|
|
|
|
|
|
|
|
|
mockDevice->setPreemptionMode(PreemptionMode::MidThread);
|
|
|
|
|
auto cmdSizePreemptionMidThread = PreemptionHelper::getRequiredStateSipCmdSize<FamilyType>(*mockDevice);
|
|
|
|
|
|
|
|
|
|
StackVec<char, 4096> preemptionBuffer;
|
|
|
|
|
preemptionBuffer.resize(cmdSizePreemptionMidThread);
|
|
|
|
|
LinearStream preemptionStream(&*preemptionBuffer.begin(), preemptionBuffer.size());
|
|
|
|
|
|
|
|
|
|
PreemptionHelper::programStateSip<FamilyType>(preemptionStream, *mockDevice);
|
|
|
|
|
|
|
|
|
|
HardwareParse hwParserOnlyPreemption;
|
|
|
|
|
hwParserOnlyPreemption.parseCommands<FamilyType>(preemptionStream, 0);
|
|
|
|
|
auto cmd = hwParserOnlyPreemption.getCommand<STATE_SIP>();
|
|
|
|
|
EXPECT_NE(nullptr, cmd);
|
|
|
|
|
|
2020-02-10 15:57:49 +01:00
|
|
|
auto sipType = SipKernel::getSipKernelType(mockDevice->getHardwareInfo().platform.eRenderCoreFamily, mockDevice->isDebuggerActive());
|
2020-02-27 15:32:57 +01:00
|
|
|
EXPECT_EQ(mockDevice->getBuiltIns()->getSipKernel(sipType, *mockDevice).getSipAllocation()->getGpuAddressToPatch(), cmd->getSystemInstructionPointer());
|
2018-11-05 11:52:19 +01:00
|
|
|
}
|