2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2023-02-02 00:23:01 +08:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
2018-09-18 15:11:08 +08:00
|
|
|
|
2020-02-24 20:10:44 +08:00
|
|
|
#include "shared/source/built_ins/built_ins.h"
|
2022-05-25 22:39:35 +08:00
|
|
|
#include "shared/source/built_ins/sip.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/preemption.h"
|
2023-02-15 21:02:48 +08:00
|
|
|
#include "shared/source/gen9/hw_cmds_base.h"
|
2023-02-02 00:23:01 +08:00
|
|
|
#include "shared/source/helpers/gfx_core_helper.h"
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/cmd_parse/hw_parse.h"
|
|
|
|
#include "shared/test/common/mocks/mock_command_stream_receiver.h"
|
|
|
|
#include "shared/test/common/mocks/mock_device.h"
|
|
|
|
#include "shared/test/common/mocks/mock_graphics_allocation.h"
|
2023-02-15 21:02:48 +08:00
|
|
|
#include "shared/test/common/test_macros/header/per_product_test_definitions.h"
|
2022-08-09 22:26:49 +08:00
|
|
|
#include "shared/test/unit_test/fixtures/preemption_fixture.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2021-04-08 17:05:45 +08:00
|
|
|
#include "patch_shared.h"
|
|
|
|
|
2020-06-10 18:47:58 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
template <>
|
2022-07-25 23:30:11 +08:00
|
|
|
PreemptionTestHwDetails getPreemptionTestHwDetails<Gen9Family>() {
|
2020-06-10 18:47:58 +08:00
|
|
|
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;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-01-08 23:13:51 +08:00
|
|
|
using Gen9PreemptionTests = DevicePreemptionTests;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-01-08 22:58:02 +08:00
|
|
|
GEN9TEST_F(Gen9PreemptionTests, whenMidThreadPreemptionIsNotAvailableThenDoesNotProgramPreamble) {
|
|
|
|
device->setPreemptionMode(PreemptionMode::ThreadGroup);
|
|
|
|
|
2021-10-17 20:21:29 +08:00
|
|
|
size_t requiredSize = PreemptionHelper::getRequiredStateSipCmdSize<FamilyType>(*device, false);
|
2018-01-08 22:58:02 +08:00
|
|
|
EXPECT_EQ(0U, requiredSize);
|
|
|
|
|
|
|
|
LinearStream cmdStream{nullptr, 0};
|
2023-09-13 01:51:43 +08:00
|
|
|
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr);
|
2018-01-08 22:58:02 +08:00
|
|
|
EXPECT_EQ(0U, cmdStream.getUsed());
|
|
|
|
}
|
|
|
|
|
2018-11-05 18:52:19 +08:00
|
|
|
GEN9TEST_F(Gen9PreemptionTests, whenMidThreadPreemptionIsAvailableThenStateSipIsProgrammed) {
|
2018-01-08 22:58:02 +08:00
|
|
|
using STATE_SIP = typename FamilyType::STATE_SIP;
|
|
|
|
|
|
|
|
device->setPreemptionMode(PreemptionMode::MidThread);
|
|
|
|
executionEnvironment->DisableMidThreadPreemption = 0;
|
|
|
|
|
2019-05-08 22:00:24 +08:00
|
|
|
size_t minCsrSize = device->getHardwareInfo().gtSystemInfo.CsrSizeInMb * MemoryConstants::megaByte;
|
2018-01-08 22:58:02 +08:00
|
|
|
uint64_t minCsrAlignment = 2 * 256 * MemoryConstants::kiloByte;
|
|
|
|
MockGraphicsAllocation csrSurface((void *)minCsrAlignment, minCsrSize);
|
|
|
|
|
2021-10-17 20:21:29 +08:00
|
|
|
size_t requiredCmdStreamSize = PreemptionHelper::getRequiredStateSipCmdSize<FamilyType>(*device, false);
|
2018-11-05 18:52:19 +08:00
|
|
|
size_t expectedPreambleSize = sizeof(STATE_SIP);
|
|
|
|
EXPECT_EQ(expectedPreambleSize, requiredCmdStreamSize);
|
2018-01-08 22:58:02 +08:00
|
|
|
|
2018-11-05 18:52:19 +08:00
|
|
|
StackVec<char, 8192> streamStorage(requiredCmdStreamSize);
|
|
|
|
ASSERT_LE(requiredCmdStreamSize, streamStorage.size());
|
2018-01-08 22:58:02 +08:00
|
|
|
|
2018-11-05 18:52:19 +08:00
|
|
|
LinearStream cmdStream{streamStorage.begin(), streamStorage.size()};
|
2023-09-13 01:51:43 +08:00
|
|
|
PreemptionHelper::programStateSip<FamilyType>(cmdStream, *device, nullptr);
|
2018-01-08 22:58:02 +08:00
|
|
|
|
2018-11-05 18:52:19 +08:00
|
|
|
HardwareParse hwParsePreamble;
|
|
|
|
hwParsePreamble.parseCommands<FamilyType>(cmdStream);
|
2018-01-08 22:58:02 +08:00
|
|
|
|
|
|
|
auto stateSipCmd = hwParsePreamble.getCommand<STATE_SIP>();
|
|
|
|
ASSERT_NE(nullptr, stateSipCmd);
|
2023-07-28 21:22:38 +08:00
|
|
|
EXPECT_EQ(SipKernel::getSipKernel(*device, nullptr).getSipAllocation()->getGpuAddressToPatch(), stateSipCmd->getSystemInstructionPointer());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2018-01-02 19:10:34 +08:00
|
|
|
|
2020-10-22 16:21:05 +08:00
|
|
|
GEN9TEST_F(Gen9PreemptionTests, givenMidBatchPreemptionWhenProgrammingWaCmdsBeginThenExpectNoCmds) {
|
2018-01-02 19:10:34 +08:00
|
|
|
size_t expectedSize = 0;
|
|
|
|
device->setPreemptionMode(PreemptionMode::MidBatch);
|
2020-06-10 18:47:58 +08:00
|
|
|
size_t size = PreemptionHelper::getPreemptionWaCsSize<FamilyType>(*device);
|
2018-01-02 19:10:34 +08:00
|
|
|
EXPECT_EQ(expectedSize, size);
|
|
|
|
}
|
|
|
|
|
2020-10-22 16:21:05 +08:00
|
|
|
GEN9TEST_F(Gen9PreemptionTests, givenThreadGroupPreemptionNoWaSetWhenProgrammingWaCmdsBeginThenExpectNoCmd) {
|
2018-01-02 19:10:34 +08:00
|
|
|
size_t expectedSize = 0;
|
|
|
|
device->setPreemptionMode(PreemptionMode::ThreadGroup);
|
2021-11-25 17:31:14 +08:00
|
|
|
device->getRootDeviceEnvironment().getMutableHardwareInfo()->workaroundTable.flags.waModifyVFEStateAfterGPGPUPreemption = false;
|
2020-06-10 18:47:58 +08:00
|
|
|
size_t size = PreemptionHelper::getPreemptionWaCsSize<FamilyType>(*device);
|
2018-01-02 19:10:34 +08:00
|
|
|
EXPECT_EQ(expectedSize, size);
|
|
|
|
}
|
|
|
|
|
2020-10-22 16:21:05 +08:00
|
|
|
GEN9TEST_F(Gen9PreemptionTests, givenThreadGroupPreemptionWaSetWhenProgrammingWaCmdsBeginThenExpectCmd) {
|
2018-01-02 19:10:34 +08:00
|
|
|
typedef typename FamilyType::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM;
|
|
|
|
size_t expectedSize = 2 * sizeof(MI_LOAD_REGISTER_IMM);
|
|
|
|
device->setPreemptionMode(PreemptionMode::ThreadGroup);
|
2021-11-25 17:31:14 +08:00
|
|
|
device->getRootDeviceEnvironment().getMutableHardwareInfo()->workaroundTable.flags.waModifyVFEStateAfterGPGPUPreemption = true;
|
2020-06-10 18:47:58 +08:00
|
|
|
size_t size = PreemptionHelper::getPreemptionWaCsSize<FamilyType>(*device);
|
2018-01-02 19:10:34 +08:00
|
|
|
EXPECT_EQ(expectedSize, size);
|
|
|
|
}
|
|
|
|
|
2020-10-22 16:21:05 +08:00
|
|
|
GEN9TEST_F(Gen9PreemptionTests, givenMidThreadPreemptionNoWaSetWhenProgrammingWaCmdsBeginThenExpectNoCmd) {
|
2018-01-02 19:10:34 +08:00
|
|
|
size_t expectedSize = 0;
|
|
|
|
device->setPreemptionMode(PreemptionMode::MidThread);
|
2021-11-25 17:31:14 +08:00
|
|
|
device->getRootDeviceEnvironment().getMutableHardwareInfo()->workaroundTable.flags.waModifyVFEStateAfterGPGPUPreemption = false;
|
2020-06-10 18:47:58 +08:00
|
|
|
size_t size = PreemptionHelper::getPreemptionWaCsSize<FamilyType>(*device);
|
2018-01-02 19:10:34 +08:00
|
|
|
EXPECT_EQ(expectedSize, size);
|
|
|
|
}
|
|
|
|
|
2020-10-22 16:21:05 +08:00
|
|
|
GEN9TEST_F(Gen9PreemptionTests, givenMidThreadPreemptionWaSetWhenProgrammingWaCmdsBeginThenExpectCmd) {
|
2018-01-02 19:10:34 +08:00
|
|
|
typedef typename FamilyType::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM;
|
|
|
|
size_t expectedSize = 2 * sizeof(MI_LOAD_REGISTER_IMM);
|
|
|
|
device->setPreemptionMode(PreemptionMode::MidThread);
|
2021-11-25 17:31:14 +08:00
|
|
|
device->getRootDeviceEnvironment().getMutableHardwareInfo()->workaroundTable.flags.waModifyVFEStateAfterGPGPUPreemption = true;
|
2020-06-10 18:47:58 +08:00
|
|
|
size_t size = PreemptionHelper::getPreemptionWaCsSize<FamilyType>(*device);
|
2018-01-02 19:10:34 +08:00
|
|
|
EXPECT_EQ(expectedSize, size);
|
|
|
|
}
|
2018-03-02 05:43:04 +08: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 18:52:19 +08: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);
|
2021-10-17 20:21:29 +08:00
|
|
|
auto cmdSizePreemptionMidThread = PreemptionHelper::getRequiredStateSipCmdSize<FamilyType>(*mockDevice, false);
|
2018-11-05 18:52:19 +08:00
|
|
|
|
|
|
|
StackVec<char, 4096> preemptionBuffer;
|
|
|
|
preemptionBuffer.resize(cmdSizePreemptionMidThread);
|
|
|
|
LinearStream preemptionStream(&*preemptionBuffer.begin(), preemptionBuffer.size());
|
|
|
|
|
2023-09-13 01:51:43 +08:00
|
|
|
PreemptionHelper::programStateSip<FamilyType>(preemptionStream, *mockDevice, nullptr);
|
2018-11-05 18:52:19 +08:00
|
|
|
|
|
|
|
HardwareParse hwParserOnlyPreemption;
|
|
|
|
hwParserOnlyPreemption.parseCommands<FamilyType>(preemptionStream, 0);
|
|
|
|
auto cmd = hwParserOnlyPreemption.getCommand<STATE_SIP>();
|
|
|
|
EXPECT_NE(nullptr, cmd);
|
|
|
|
|
2023-07-28 21:22:38 +08:00
|
|
|
EXPECT_EQ(SipKernel::getSipKernel(*mockDevice, nullptr).getSipAllocation()->getGpuAddressToPatch(), cmd->getSystemInstructionPointer());
|
2018-11-05 18:52:19 +08:00
|
|
|
}
|