2019-01-10 22:36:57 +08:00
|
|
|
/*
|
2020-01-14 21:32:11 +08:00
|
|
|
* Copyright (C) 2018-2020 Intel Corporation
|
2019-01-10 22:36:57 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2020-02-24 08:01:38 +08:00
|
|
|
#include "shared/test/unit_test/fixtures/preemption_fixture.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/built_ins/built_ins.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/helpers/hw_parse.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_buffer.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_command_queue.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_csr.h"
|
2019-01-10 22:36:57 +08:00
|
|
|
|
|
|
|
using namespace NEO;
|
|
|
|
|
|
|
|
using Gen11PreemptionTests = DevicePreemptionTests;
|
|
|
|
|
|
|
|
template <>
|
|
|
|
PreemptionTestHwDetails GetPreemptionTestHwDetails<ICLFamily>() {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
GEN11TEST_F(Gen11PreemptionTests, whenMidThreadPreemptionIsNotAvailableThenDoesNotProgramStateSip) {
|
|
|
|
device->setPreemptionMode(PreemptionMode::ThreadGroup);
|
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
size_t requiredSize = PreemptionHelper::getRequiredPreambleSize<FamilyType>(device->getDevice());
|
2019-01-10 22:36:57 +08:00
|
|
|
EXPECT_EQ(0U, requiredSize);
|
|
|
|
|
|
|
|
LinearStream cmdStream{nullptr, 0};
|
2020-01-14 21:32:11 +08:00
|
|
|
PreemptionHelper::getRequiredStateSipCmdSize<FamilyType>(device->getDevice());
|
2019-01-10 22:36:57 +08:00
|
|
|
EXPECT_EQ(0U, cmdStream.getUsed());
|
|
|
|
}
|
|
|
|
|
|
|
|
GEN11TEST_F(Gen11PreemptionTests, whenMidThreadPreemptionIsAvailableThenStateSipIsProgrammed) {
|
|
|
|
using STATE_SIP = typename FamilyType::STATE_SIP;
|
|
|
|
|
|
|
|
device->setPreemptionMode(PreemptionMode::MidThread);
|
|
|
|
executionEnvironment->DisableMidThreadPreemption = 0;
|
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
size_t requiredCmdStreamSize = PreemptionHelper::getRequiredStateSipCmdSize<FamilyType>(device->getDevice());
|
2019-01-10 22:36:57 +08:00
|
|
|
size_t expectedPreambleSize = sizeof(STATE_SIP);
|
|
|
|
EXPECT_EQ(expectedPreambleSize, requiredCmdStreamSize);
|
|
|
|
|
|
|
|
StackVec<char, 8192> streamStorage(requiredCmdStreamSize);
|
|
|
|
ASSERT_LE(requiredCmdStreamSize, streamStorage.size());
|
|
|
|
|
|
|
|
LinearStream cmdStream{streamStorage.begin(), streamStorage.size()};
|
2020-01-14 21:32:11 +08:00
|
|
|
PreemptionHelper::programStateSip<FamilyType>(cmdStream, device->getDevice());
|
2019-01-10 22:36:57 +08:00
|
|
|
|
|
|
|
HardwareParse hwParsePreamble;
|
|
|
|
hwParsePreamble.parseCommands<FamilyType>(cmdStream);
|
|
|
|
|
|
|
|
auto stateSipCmd = hwParsePreamble.getCommand<STATE_SIP>();
|
|
|
|
ASSERT_NE(nullptr, stateSipCmd);
|
2020-01-14 21:32:11 +08:00
|
|
|
EXPECT_EQ(device->getExecutionEnvironment()->getBuiltIns()->getSipKernel(SipKernelType::Csr, device->getDevice()).getSipAllocation()->getGpuAddressToPatch(), stateSipCmd->getSystemInstructionPointer());
|
2019-01-10 22:36:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GEN11TEST_F(Gen11PreemptionTests, getRequiredCmdQSize) {
|
|
|
|
size_t expectedSize = 0;
|
2020-01-14 21:32:11 +08:00
|
|
|
EXPECT_EQ(expectedSize, PreemptionHelper::getPreemptionWaCsSize<FamilyType>(device->getDevice()));
|
2019-01-10 22:36:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GEN11TEST_F(Gen11PreemptionTests, applyPreemptionWaCmds) {
|
|
|
|
size_t usedSize = 0;
|
|
|
|
auto &cmdStream = cmdQ->getCS(0);
|
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
PreemptionHelper::applyPreemptionWaCmdsBegin<FamilyType>(&cmdStream, device->getDevice());
|
2019-01-10 22:36:57 +08:00
|
|
|
EXPECT_EQ(usedSize, cmdStream.getUsed());
|
2020-01-14 21:32:11 +08:00
|
|
|
PreemptionHelper::applyPreemptionWaCmdsEnd<FamilyType>(&cmdStream, device->getDevice());
|
2019-01-10 22:36:57 +08:00
|
|
|
EXPECT_EQ(usedSize, cmdStream.getUsed());
|
|
|
|
}
|
|
|
|
|
|
|
|
GEN11TEST_F(Gen11PreemptionTests, givenInterfaceDescriptorDataWhenMidThreadPreemptionModeThenSetDisableThreadPreemptionBitToDisable) {
|
|
|
|
using INTERFACE_DESCRIPTOR_DATA = typename FamilyType::INTERFACE_DESCRIPTOR_DATA;
|
|
|
|
|
|
|
|
INTERFACE_DESCRIPTOR_DATA iddArg;
|
|
|
|
iddArg = FamilyType::cmdInitInterfaceDescriptorData;
|
|
|
|
|
|
|
|
iddArg.setThreadPreemptionDisable(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_ENABLE);
|
|
|
|
|
|
|
|
PreemptionHelper::programInterfaceDescriptorDataPreemption<FamilyType>(&iddArg, PreemptionMode::MidThread);
|
|
|
|
EXPECT_EQ(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_DISABLE, iddArg.getThreadPreemptionDisable());
|
|
|
|
}
|
|
|
|
|
|
|
|
GEN11TEST_F(Gen11PreemptionTests, givenInterfaceDescriptorDataWhenNoMidThreadPreemptionModeThenSetDisableThreadPreemptionBitToEnable) {
|
|
|
|
using INTERFACE_DESCRIPTOR_DATA = typename FamilyType::INTERFACE_DESCRIPTOR_DATA;
|
|
|
|
|
|
|
|
INTERFACE_DESCRIPTOR_DATA iddArg;
|
|
|
|
iddArg = FamilyType::cmdInitInterfaceDescriptorData;
|
|
|
|
|
|
|
|
iddArg.setThreadPreemptionDisable(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_DISABLE);
|
|
|
|
|
|
|
|
PreemptionHelper::programInterfaceDescriptorDataPreemption<FamilyType>(&iddArg, PreemptionMode::Disabled);
|
|
|
|
EXPECT_EQ(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_ENABLE, iddArg.getThreadPreemptionDisable());
|
|
|
|
|
|
|
|
iddArg.setThreadPreemptionDisable(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_DISABLE);
|
|
|
|
|
|
|
|
PreemptionHelper::programInterfaceDescriptorDataPreemption<FamilyType>(&iddArg, PreemptionMode::MidBatch);
|
|
|
|
EXPECT_EQ(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_ENABLE, iddArg.getThreadPreemptionDisable());
|
|
|
|
|
|
|
|
iddArg.setThreadPreemptionDisable(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_DISABLE);
|
|
|
|
|
|
|
|
PreemptionHelper::programInterfaceDescriptorDataPreemption<FamilyType>(&iddArg, PreemptionMode::ThreadGroup);
|
|
|
|
EXPECT_EQ(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_ENABLE, iddArg.getThreadPreemptionDisable());
|
|
|
|
}
|