Refactor SipKernel

- add debug bindless SipKernelType

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2021-10-18 15:59:47 +00:00
committed by Compute-Runtime-Automation
parent d79317da35
commit 2fb8edb69f
14 changed files with 69 additions and 40 deletions

View File

@ -12,7 +12,7 @@
namespace L0 {
namespace ult {
const NEO::SipKernel &MockBuiltins::getSipKernel(NEO::SipKernelType type, bool bindlessSip, NEO::Device &device) {
const NEO::SipKernel &MockBuiltins::getSipKernel(NEO::SipKernelType type, NEO::Device &device) {
if (!(sipKernel && sipKernel->getType() == type)) {
sipKernel.reset(new NEO::SipKernel(type, allocation.get(), stateSaveAreaHeader));
}

View File

@ -17,7 +17,7 @@ class MockBuiltins : public NEO::BuiltIns {
MockBuiltins() : BuiltIns() {
allocation.reset(new NEO::MockGraphicsAllocation());
}
const NEO::SipKernel &getSipKernel(NEO::SipKernelType type, bool bindlessSip, NEO::Device &device) override;
const NEO::SipKernel &getSipKernel(NEO::SipKernelType type, NEO::Device &device) override;
std::unique_ptr<NEO::SipKernel> sipKernel;
std::unique_ptr<NEO::MockGraphicsAllocation> allocation;
std::vector<char> stateSaveAreaHeader{'s', 's', 'a', 'h'};

View File

@ -74,7 +74,8 @@ TEST(DebugBindlessSip, givenBindlessDebugSipIsRequestedThenCorrectSipKernelIsRet
auto &sipKernel = NEO::SipKernel::getBindlessDebugSipKernel(*mockDevice);
EXPECT_NE(nullptr, &sipKernel);
EXPECT_LE(SipKernelType::DbgCsr, sipKernel.getType());
EXPECT_EQ(SipKernelType::DbgBindless, sipKernel.getType());
EXPECT_FALSE(sipKernel.getStateSaveAreaHeader().empty());
}
} // namespace SipKernelTests

View File

@ -31,10 +31,6 @@ BuiltIns::BuiltIns() {
BuiltIns::~BuiltIns() = default;
const SipKernel &BuiltIns::getSipKernel(SipKernelType type, Device &device) {
return getSipKernel(type, false, device);
}
const SipKernel &BuiltIns::getSipKernel(SipKernelType type, bool bindlessSip, Device &device) {
uint32_t kernelId = static_cast<uint32_t>(type);
UNRECOVERABLE_IF(kernelId >= static_cast<uint32_t>(SipKernelType::COUNT));
auto &sipBuiltIn = this->sipKernels[kernelId];
@ -45,7 +41,7 @@ const SipKernel &BuiltIns::getSipKernel(SipKernelType type, bool bindlessSip, De
auto compilerInteface = device.getCompilerInterface();
UNRECOVERABLE_IF(compilerInteface == nullptr);
auto ret = compilerInteface->getSipKernelBinary(device, type, bindlessSip, sipBinary, stateSaveAreaHeader);
auto ret = compilerInteface->getSipKernelBinary(device, type, sipBinary, stateSaveAreaHeader);
UNRECOVERABLE_IF(ret != TranslationOutput::ErrorCode::Success);
UNRECOVERABLE_IF(sipBinary.size() == 0);

View File

@ -154,7 +154,6 @@ class BuiltIns {
virtual ~BuiltIns();
MOCKABLE_VIRTUAL const SipKernel &getSipKernel(SipKernelType type, Device &device);
MOCKABLE_VIRTUAL const SipKernel &getSipKernel(SipKernelType type, bool bindlessSip, Device &device);
MOCKABLE_VIRTUAL void freeSipKernels(MemoryManager *memoryManager);
BuiltinsLib &getBuiltinsLib() {

View File

@ -254,8 +254,15 @@ const SipKernel &SipKernel::getSipKernelImpl(Device &device) {
}
const SipKernel &SipKernel::getBindlessDebugSipKernel(Device &device) {
auto debugSipType = SipKernel::getSipKernelType(device, true);
return device.getBuiltIns()->getSipKernel(debugSipType, true, device);
auto debugSipType = SipKernelType::DbgBindless;
SipKernel::initSipKernelImpl(debugSipType, device);
switch (SipKernel::classType) {
case SipClassType::RawBinaryFromFile:
return *device.getRootDeviceEnvironment().sipKernels[static_cast<uint32_t>(debugSipType)].get();
default:
return device.getBuiltIns()->getSipKernel(debugSipType, device);
}
}
} // namespace NEO

View File

@ -15,6 +15,7 @@ enum class SipKernelType : std::uint32_t {
Csr = 0,
DbgCsr,
DbgCsrLocal,
DbgBindless,
COUNT
};

View File

@ -301,33 +301,33 @@ TranslationOutput::ErrorCode CompilerInterface::createLibrary(
return TranslationOutput::ErrorCode::Success;
}
TranslationOutput::ErrorCode CompilerInterface::getSipKernelBinary(NEO::Device &device, SipKernelType type, bool bindlessSip, std::vector<char> &retBinary,
TranslationOutput::ErrorCode CompilerInterface::getSipKernelBinary(NEO::Device &device, SipKernelType type, std::vector<char> &retBinary,
std::vector<char> &stateSaveAreaHeader) {
if (false == isIgcAvailable()) {
return TranslationOutput::ErrorCode::CompilerNotAvailable;
}
bool bindlessSip = false;
IGC::SystemRoutineType::SystemRoutineType_t typeOfSystemRoutine = IGC::SystemRoutineType::undefined;
bool debugSip = false;
switch (type) {
case SipKernelType::Csr:
typeOfSystemRoutine = IGC::SystemRoutineType::contextSaveRestore;
break;
case SipKernelType::DbgCsr:
typeOfSystemRoutine = IGC::SystemRoutineType::debug;
debugSip = true;
break;
case SipKernelType::DbgCsrLocal:
typeOfSystemRoutine = IGC::SystemRoutineType::debugSlm;
debugSip = true;
break;
case SipKernelType::DbgBindless:
typeOfSystemRoutine = IGC::SystemRoutineType::debug;
bindlessSip = true;
break;
default:
break;
}
auto deviceCtx = getIgcDeviceCtx(device);
bindlessSip |= debugSip ? DebugManager.flags.UseBindlessDebugSip.get() : false;
auto systemRoutineBuffer = igcMain.get()->CreateBuiltin<CIF::Builtins::BufferLatest>();
auto stateSaveAreaBuffer = igcMain.get()->CreateBuiltin<CIF::Builtins::BufferLatest>();

View File

@ -133,7 +133,7 @@ class CompilerInterface {
const TranslationInput &input,
TranslationOutput &output);
MOCKABLE_VIRTUAL TranslationOutput::ErrorCode getSipKernelBinary(NEO::Device &device, SipKernelType type, bool bindlessSip, std::vector<char> &retBinary,
MOCKABLE_VIRTUAL TranslationOutput::ErrorCode getSipKernelBinary(NEO::Device &device, SipKernelType type, std::vector<char> &retBinary,
std::vector<char> &stateSaveAreaHeader);
protected:

View File

@ -21,7 +21,7 @@ SipKernelType HwHelperHw<Family>::getSipKernelType(bool debuggingActive) const {
if (!debuggingActive) {
return SipKernelType::Csr;
}
return SipKernelType::DbgCsrLocal;
return DebugManager.flags.UseBindlessDebugSip.get() ? SipKernelType::DbgBindless : SipKernelType::DbgCsrLocal;
}
template <>

View File

@ -64,7 +64,7 @@ SipKernelType HwHelperHw<Family>::getSipKernelType(bool debuggingActive) const {
if (!debuggingActive) {
return SipKernelType::Csr;
}
return SipKernelType::DbgCsr;
return DebugManager.flags.UseBindlessDebugSip.get() ? SipKernelType::DbgBindless : SipKernelType::DbgCsr;
}
template <typename Family>

View File

@ -114,14 +114,14 @@ class MockCompilerInterface : public CompilerInterface {
return this->fclBaseTranslationCtx.get();
}
TranslationOutput::ErrorCode getSipKernelBinary(NEO::Device &device, SipKernelType type, bool bindlessSip, std::vector<char> &retBinary,
TranslationOutput::ErrorCode getSipKernelBinary(NEO::Device &device, SipKernelType type, std::vector<char> &retBinary,
std::vector<char> &stateAreaHeader) override {
if (this->sipKernelBinaryOverride.size() > 0) {
retBinary = this->sipKernelBinaryOverride;
this->requestedSipKernel = type;
return TranslationOutput::ErrorCode::Success;
} else {
return CompilerInterface::getSipKernelBinary(device, type, bindlessSip, retBinary, stateAreaHeader);
return CompilerInterface::getSipKernelBinary(device, type, retBinary, stateAreaHeader);
}
}

View File

@ -269,6 +269,21 @@ TEST_F(RawBinarySipTest, givenRawBinaryFileWhenInitSipKernelTwiceThenSipIsLoaded
EXPECT_EQ(storedAllocation, secondStoredAllocation);
}
TEST_F(RawBinarySipTest, givenRawBinaryFileWhenGettingBindlessDebugSipThenSipIsLoadedFromFile) {
auto sipAllocation = SipKernel::getBindlessDebugSipKernel(*pDevice).getSipAllocation();
uint32_t sipIndex = static_cast<uint32_t>(SipKernelType::DbgBindless);
auto sipKernel = pDevice->getRootDeviceEnvironment().sipKernels[sipIndex].get();
ASSERT_NE(nullptr, sipKernel);
auto storedAllocation = sipKernel->getSipAllocation();
EXPECT_NE(nullptr, storedAllocation);
EXPECT_EQ(storedAllocation, sipAllocation);
auto header = SipKernel::getSipKernel(*pDevice).getStateSaveAreaHeader();
EXPECT_NE(0u, header.size());
}
struct HexadecimalHeaderSipKernel : public SipKernel {
using SipKernel::getSipKernelImpl;
using SipKernel::initHexadecimalArraySipKernel;
@ -336,3 +351,15 @@ TEST_F(StateSaveAreaSipTest, givenCorrectStateSaveAreaHeaderWhenGetStateSaveArea
MockSipData::mockSipKernel->mockStateSaveAreaHeader = MockSipData::createStateSaveAreaHeader();
EXPECT_EQ(0x3F1000u, SipKernel::getSipKernel(*pDevice).getStateSaveAreaSize());
}
TEST(DebugBindlessSip, givenActiveDebuggerAndUseBindlessDebugSipWhenGettingSipTypeThenDebugBindlessTypeIsReturned) {
DebugManagerStateRestore restorer;
NEO::DebugManager.flags.UseBindlessDebugSip.set(1);
auto mockDevice = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
EXPECT_NE(nullptr, mockDevice);
mockDevice->setDebuggerActive(true);
auto sipType = NEO::SipKernel::getSipKernelType(*mockDevice);
EXPECT_EQ(SipKernelType::DbgBindless, sipType);
}

View File

@ -1006,7 +1006,7 @@ TEST_F(CompilerInterfaceTest, whenCompilerIsNotAvailableThenGetSipKernelBinaryFa
pCompilerInterface->igcMain.reset();
std::vector<char> sipBinary;
std::vector<char> stateAreaHeader;
auto err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::Csr, false, sipBinary, stateAreaHeader);
auto err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::Csr, sipBinary, stateAreaHeader);
EXPECT_EQ(TranslationOutput::ErrorCode::CompilerNotAvailable, err);
EXPECT_EQ(0U, sipBinary.size());
}
@ -1018,7 +1018,7 @@ TEST_F(CompilerInterfaceTest, whenIgcReturnsErrorThenGetSipKernelBinaryFailsGrac
std::vector<char> sipBinary;
std::vector<char> stateAreaHeader;
auto err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::Csr, false, sipBinary, stateAreaHeader);
auto err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::Csr, sipBinary, stateAreaHeader);
EXPECT_EQ(TranslationOutput::ErrorCode::UnknownError, err);
EXPECT_EQ(0U, sipBinary.size());
@ -1031,7 +1031,7 @@ TEST_F(CompilerInterfaceTest, whenEverythingIsOkThenGetSipKernelReturnsIgcsOutpu
gEnvironment->igcPushDebugVars(igcDebugVars);
std::vector<char> sipBinary;
std::vector<char> stateAreaHeader;
auto err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::Csr, false, sipBinary, stateAreaHeader);
auto err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::Csr, sipBinary, stateAreaHeader);
EXPECT_EQ(TranslationOutput::ErrorCode::Success, err);
EXPECT_NE(0U, sipBinary.size());
@ -1043,17 +1043,17 @@ TEST_F(CompilerInterfaceTest, whenRequestingSipKernelBinaryThenProperSystemRouti
gEnvironment->igcPushDebugVars(igcDebugVars);
std::vector<char> sipBinary;
std::vector<char> stateAreaHeader;
auto err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::Csr, false, sipBinary, stateAreaHeader);
auto err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::Csr, sipBinary, stateAreaHeader);
EXPECT_EQ(TranslationOutput::ErrorCode::Success, err);
EXPECT_NE(0U, sipBinary.size());
EXPECT_EQ(IGC::SystemRoutineType::contextSaveRestore, getIgcDebugVars().typeOfSystemRoutine);
err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::DbgCsr, false, sipBinary, stateAreaHeader);
err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::DbgCsr, sipBinary, stateAreaHeader);
EXPECT_EQ(TranslationOutput::ErrorCode::Success, err);
EXPECT_NE(0U, sipBinary.size());
EXPECT_EQ(IGC::SystemRoutineType::debug, getIgcDebugVars().typeOfSystemRoutine);
err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::DbgCsrLocal, false, sipBinary, stateAreaHeader);
err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::DbgCsrLocal, sipBinary, stateAreaHeader);
EXPECT_EQ(TranslationOutput::ErrorCode::Success, err);
EXPECT_NE(0U, sipBinary.size());
EXPECT_EQ(IGC::SystemRoutineType::debugSlm, getIgcDebugVars().typeOfSystemRoutine);
@ -1061,29 +1061,27 @@ TEST_F(CompilerInterfaceTest, whenRequestingSipKernelBinaryThenProperSystemRouti
gEnvironment->igcPopDebugVars();
}
TEST_F(CompilerInterfaceTest, givenUseBindlessDebugSipWhenRequestingSipKernelBinaryThenProperSystemRoutineIsSelectedFromCompiler) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.UseBindlessDebugSip.set(true);
TEST_F(CompilerInterfaceTest, WhenRequestingBindlessDebugSipThenProperSystemRoutineIsSelectedFromCompiler) {
MockCompilerDebugVars igcDebugVars;
gEnvironment->igcPushDebugVars(igcDebugVars);
std::vector<char> sipBinary;
std::vector<char> stateAreaHeader;
auto err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::Csr, false, sipBinary, stateAreaHeader);
auto err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::Csr, sipBinary, stateAreaHeader);
EXPECT_EQ(TranslationOutput::ErrorCode::Success, err);
EXPECT_NE(0U, sipBinary.size());
EXPECT_EQ(IGC::SystemRoutineType::contextSaveRestore, getIgcDebugVars().typeOfSystemRoutine);
EXPECT_EQ(MockCompilerDebugVars::SipAddressingType::bindful, getIgcDebugVars().receivedSipAddressingType);
err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::DbgCsr, false, sipBinary, stateAreaHeader);
EXPECT_EQ(TranslationOutput::ErrorCode::Success, err);
EXPECT_NE(0U, sipBinary.size());
EXPECT_EQ(IGC::SystemRoutineType::debug, getIgcDebugVars().typeOfSystemRoutine);
EXPECT_EQ(MockCompilerDebugVars::SipAddressingType::bindless, getIgcDebugVars().receivedSipAddressingType);
err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::DbgCsrLocal, false, sipBinary, stateAreaHeader);
err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::DbgCsrLocal, sipBinary, stateAreaHeader);
EXPECT_EQ(TranslationOutput::ErrorCode::Success, err);
EXPECT_NE(0U, sipBinary.size());
EXPECT_EQ(IGC::SystemRoutineType::debugSlm, getIgcDebugVars().typeOfSystemRoutine);
EXPECT_EQ(MockCompilerDebugVars::SipAddressingType::bindful, getIgcDebugVars().receivedSipAddressingType);
err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::DbgBindless, sipBinary, stateAreaHeader);
EXPECT_EQ(TranslationOutput::ErrorCode::Success, err);
EXPECT_NE(0U, sipBinary.size());
EXPECT_EQ(IGC::SystemRoutineType::debug, getIgcDebugVars().typeOfSystemRoutine);
EXPECT_EQ(MockCompilerDebugVars::SipAddressingType::bindless, getIgcDebugVars().receivedSipAddressingType);
gEnvironment->igcPopDebugVars();
@ -1094,7 +1092,7 @@ TEST_F(CompilerInterfaceTest, whenRequestingInvalidSipKernelBinaryThenErrorIsRet
gEnvironment->igcPushDebugVars(igcDebugVars);
std::vector<char> sipBinary;
std::vector<char> stateAreaHeader;
auto err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::COUNT, false, sipBinary, stateAreaHeader);
auto err = pCompilerInterface->getSipKernelBinary(*this->pDevice, SipKernelType::COUNT, sipBinary, stateAreaHeader);
EXPECT_EQ(TranslationOutput::ErrorCode::UnknownError, err);
EXPECT_EQ(0U, sipBinary.size());
EXPECT_EQ(IGC::SystemRoutineType::undefined, getIgcDebugVars().typeOfSystemRoutine);