Add State Sip end WA

Related-To: NEO-5479

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2021-01-28 17:30:56 +00:00
committed by Compute-Runtime-Automation
parent 7e27ebe70b
commit 0ca1cdc565
14 changed files with 101 additions and 64 deletions

View File

@ -87,18 +87,19 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
constexpr size_t residencyContainerSpaceForFence = 1;
constexpr size_t residencyContainerSpaceForTagWrite = 1;
const bool initialPreemptionMode = commandQueuePreemptionMode == NEO::PreemptionMode::Initial;
NEO::Device *neoDevice = device->getNEODevice();
NEO::PreemptionMode statePreemption = commandQueuePreemptionMode;
auto devicePreemption = device->getDevicePreemptionMode();
const bool initialPreemptionMode = commandQueuePreemptionMode == NEO::PreemptionMode::Initial;
const bool stateSipRequired = (initialPreemptionMode && devicePreemption == NEO::PreemptionMode::MidThread) ||
(neoDevice->getDebugger() && NEO::Debugger::isDebugEnabled(internalUsage));
if (initialPreemptionMode) {
preemptionSize += NEO::PreemptionHelper::getRequiredPreambleSize<GfxFamily>(*neoDevice);
}
if ((initialPreemptionMode && devicePreemption == NEO::PreemptionMode::MidThread) ||
(neoDevice->getDebugger() && NEO::Debugger::isDebugEnabled(internalUsage))) {
if (stateSipRequired) {
preemptionSize += NEO::PreemptionHelper::getRequiredStateSipCmdSize<GfxFamily>(*neoDevice);
}
@ -243,8 +244,7 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
NEO::PreemptionHelper::programCsrBaseAddress<GfxFamily>(child, *neoDevice, csr->getPreemptionAllocation());
}
if ((initialPreemptionMode && devicePreemption == NEO::PreemptionMode::MidThread) ||
(neoDevice->getDebugger() && NEO::Debugger::isDebugEnabled(internalUsage))) {
if (stateSipRequired) {
NEO::PreemptionHelper::programStateSip<GfxFamily>(child, *neoDevice);
}
@ -330,6 +330,10 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
}
}
if (stateSipRequired) {
NEO::PreemptionHelper::programStateSipEndWa<GfxFamily>(child, *neoDevice);
}
commandQueuePreemptionMode = statePreemption;
if (hFence) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -19,6 +19,7 @@
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
#include "level_zero/core/test/unit_tests/mocks/mock_device.h"
#include "level_zero/core/test/unit_tests/mocks/mock_driver.h"
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h"
namespace L0 {
@ -29,8 +30,11 @@ struct ActiveDebuggerFixture {
auto executionEnvironment = new NEO::ExecutionEnvironment();
auto mockBuiltIns = new MockBuiltins();
executionEnvironment->prepareRootDeviceEnvironments(1);
hwInfo = *defaultHwInfo.get();
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(&hwInfo);
debugger = new MockActiveSourceLevelDebugger(new MockOsLibrary);
executionEnvironment->rootDeviceEnvironments[0]->debugger.reset(debugger);
@ -62,6 +66,7 @@ struct ActiveDebuggerFixture {
NEO::MockDevice *device = nullptr;
L0::Device *deviceL0;
MockActiveSourceLevelDebugger *debugger = nullptr;
HardwareInfo hwInfo;
};
} // namespace ult
} // namespace L0

View File

@ -1,5 +1,5 @@
#
# Copyright (C) 2018-2020 Intel Corporation
# Copyright (C) 2018-2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
@ -8,6 +8,7 @@ set(IGDRCL_SRCS_tests_source_level_debugger
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_device_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_csr_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_csr_tests.h
${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_tests.cpp
)

View File

@ -1,10 +1,12 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "opencl/test/unit_test/source_level_debugger/source_level_debugger_csr_tests.h"
#include "shared/source/source_level_debugger/source_level_debugger.h"
#include "shared/test/unit_test/cmd_parse/hw_parse.h"
#include "shared/test/unit_test/helpers/dispatch_flags_helper.h"
@ -13,47 +15,10 @@
#include "shared/test/unit_test/mocks/mock_os_library.h"
#include "opencl/source/command_queue/command_queue_hw.h"
#include "opencl/test/unit_test/helpers/execution_environment_helper.h"
#include "opencl/test/unit_test/mocks/mock_builtins.h"
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
#include "opencl/test/unit_test/mocks/mock_csr.h"
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
#include "opencl/test/unit_test/mocks/mock_source_level_debugger.h"
#include "test.h"
#include <memory>
class CommandStreamReceiverWithActiveDebuggerTest : public ::testing::Test {
protected:
template <typename FamilyType>
auto createCSR() {
hwInfo = nullptr;
EnvironmentWithCsrWrapper environment;
environment.setCsrType<MockCsrHw2<FamilyType>>();
executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1);
hwInfo->capabilityTable = defaultHwInfo->capabilityTable;
hwInfo->capabilityTable.debuggerSupported = true;
auto mockMemoryManager = new MockMemoryManager(*executionEnvironment);
executionEnvironment->memoryManager.reset(mockMemoryManager);
executionEnvironment->rootDeviceEnvironments[0]->debugger.reset(new MockActiveSourceLevelDebugger(new MockOsLibrary));
device = std::make_unique<MockClDevice>(Device::create<MockDevice>(executionEnvironment, 0));
device->setSourceLevelDebuggerActive(true);
return static_cast<MockCsrHw2<FamilyType> *>(device->getDefaultEngine().commandStreamReceiver);
}
void TearDown() override {
device->setSourceLevelDebuggerActive(false);
}
std::unique_ptr<MockClDevice> device;
ExecutionEnvironment *executionEnvironment = nullptr;
HardwareInfo *hwInfo = nullptr;
};
HWTEST_F(CommandStreamReceiverWithActiveDebuggerTest, givenCsrWithActiveDebuggerAndDisabledPreemptionWhenFlushTaskIsCalledThenSipKernelIsMadeResident) {
auto mockCsr = createCSR<FamilyType>();

View File

@ -0,0 +1,49 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/test/unit_test/mocks/mock_os_library.h"
#include "opencl/test/unit_test/helpers/execution_environment_helper.h"
#include "opencl/test/unit_test/mocks/mock_builtins.h"
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
#include "opencl/test/unit_test/mocks/mock_csr.h"
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
#include "opencl/test/unit_test/mocks/mock_source_level_debugger.h"
#include "test.h"
#include <memory>
class CommandStreamReceiverWithActiveDebuggerTest : public ::testing::Test {
protected:
template <typename FamilyType>
auto createCSR() {
hwInfo = nullptr;
EnvironmentWithCsrWrapper environment;
environment.setCsrType<MockCsrHw2<FamilyType>>();
executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1);
hwInfo->capabilityTable = defaultHwInfo->capabilityTable;
hwInfo->capabilityTable.debuggerSupported = true;
auto mockMemoryManager = new MockMemoryManager(*executionEnvironment);
executionEnvironment->memoryManager.reset(mockMemoryManager);
executionEnvironment->rootDeviceEnvironments[0]->debugger.reset(new MockActiveSourceLevelDebugger(new MockOsLibrary));
device = std::make_unique<MockClDevice>(Device::create<MockDevice>(executionEnvironment, 0));
device->setSourceLevelDebuggerActive(true);
return static_cast<MockCsrHw2<FamilyType> *>(device->getDefaultEngine().commandStreamReceiver);
}
void TearDown() override {
device->setSourceLevelDebuggerActive(false);
}
std::unique_ptr<MockClDevice> device;
ExecutionEnvironment *executionEnvironment = nullptr;
HardwareInfo *hwInfo = nullptr;
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -51,7 +51,7 @@ class CommandStreamReceiverHw : public CommandStreamReceiver {
size_t getCmdsSizeForHardwareContext() const override;
static void addBatchBufferEnd(LinearStream &commandStream, void **patchLocation);
void programEndingCmd(LinearStream &commandStream, void **patchLocation, bool directSubmissionEnabled);
void programEndingCmd(LinearStream &commandStream, Device &device, void **patchLocation, bool directSubmissionEnabled);
void addBatchBufferStart(MI_BATCH_BUFFER_START *commandBufferMemory, uint64_t startAddress, bool secondary);
static void alignToCacheLine(LinearStream &commandStream);
@ -118,7 +118,7 @@ class CommandStreamReceiverHw : public CommandStreamReceiver {
void programPreamble(LinearStream &csr, Device &device, DispatchFlags &dispatchFlags, uint32_t &newL3Config);
void programPipelineSelect(LinearStream &csr, PipelineSelectArgs &pipelineSelectArgs);
void programAdditionalPipelineSelect(LinearStream &csr, PipelineSelectArgs &pipelineSelectArgs, bool is3DPipeline);
void programEpilogue(LinearStream &csr, void **batchBufferEndLocation, DispatchFlags &dispatchFlags);
void programEpilogue(LinearStream &csr, Device &device, void **batchBufferEndLocation, DispatchFlags &dispatchFlags);
void programEpliogueCommands(LinearStream &csr, const DispatchFlags &dispatchFlags);
void programMediaSampler(LinearStream &csr, DispatchFlags &dispatchFlags);
void programPerDssBackedBuffer(LinearStream &scr, Device &device, DispatchFlags &dispatchFlags);

View File

@ -88,7 +88,7 @@ inline void CommandStreamReceiverHw<GfxFamily>::addBatchBufferEnd(LinearStream &
}
template <typename GfxFamily>
inline void CommandStreamReceiverHw<GfxFamily>::programEndingCmd(LinearStream &commandStream, void **patchLocation, bool directSubmissionEnabled) {
inline void CommandStreamReceiverHw<GfxFamily>::programEndingCmd(LinearStream &commandStream, Device &device, void **patchLocation, bool directSubmissionEnabled) {
if (directSubmissionEnabled) {
*patchLocation = commandStream.getSpace(sizeof(MI_BATCH_BUFFER_START));
auto bbStart = reinterpret_cast<MI_BATCH_BUFFER_START *>(*patchLocation);
@ -96,6 +96,7 @@ inline void CommandStreamReceiverHw<GfxFamily>::programEndingCmd(LinearStream &c
addBatchBufferStart(&cmd, 0ull, false);
*bbStart = cmd;
} else {
PreemptionHelper::programStateSipEndWa<GfxFamily>(commandStream, device);
this->addBatchBufferEnd(commandStream, patchLocation);
}
}
@ -515,7 +516,7 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
GraphicsAllocation *chainedBatchBuffer = nullptr;
bool directSubmissionEnabled = isDirectSubmissionEnabled();
if (submitTask) {
programEndingCmd(commandStreamTask, &bbEndLocation, directSubmissionEnabled);
programEndingCmd(commandStreamTask, device, &bbEndLocation, directSubmissionEnabled);
this->emitNoop(commandStreamTask, bbEndPaddingSize);
this->alignToCacheLine(commandStreamTask);
@ -543,10 +544,10 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
} else if (dispatchFlags.epilogueRequired) {
this->makeResident(*commandStreamCSR.getGraphicsAllocation());
}
this->programEpilogue(commandStreamCSR, &bbEndLocation, dispatchFlags);
this->programEpilogue(commandStreamCSR, device, &bbEndLocation, dispatchFlags);
} else if (submitCSR) {
programEndingCmd(commandStreamCSR, &bbEndLocation, directSubmissionEnabled);
programEndingCmd(commandStreamCSR, device, &bbEndLocation, directSubmissionEnabled);
this->emitNoop(commandStreamCSR, bbEndPaddingSize);
this->alignToCacheLine(commandStreamCSR);
DEBUG_BREAK_IF(commandStreamCSR.getUsed() > commandStreamCSR.getMaxAvailableSpace());
@ -1094,14 +1095,14 @@ inline bool CommandStreamReceiverHw<GfxFamily>::isPipelineSelectAlreadyProgramme
}
template <typename GfxFamily>
inline void CommandStreamReceiverHw<GfxFamily>::programEpilogue(LinearStream &csr, void **batchBufferEndLocation, DispatchFlags &dispatchFlags) {
inline void CommandStreamReceiverHw<GfxFamily>::programEpilogue(LinearStream &csr, Device &device, void **batchBufferEndLocation, DispatchFlags &dispatchFlags) {
if (dispatchFlags.epilogueRequired) {
auto currentOffset = ptrDiff(csr.getSpace(0u), csr.getCpuBase());
auto gpuAddress = ptrOffset(csr.getGraphicsAllocation()->getGpuAddress(), currentOffset);
addBatchBufferStart(reinterpret_cast<typename GfxFamily::MI_BATCH_BUFFER_START *>(*batchBufferEndLocation), gpuAddress, false);
this->programEpliogueCommands(csr, dispatchFlags);
programEndingCmd(csr, batchBufferEndLocation, isDirectSubmissionEnabled());
programEndingCmd(csr, device, batchBufferEndLocation, isDirectSubmissionEnabled());
this->alignToCacheLine(csr);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -61,6 +61,9 @@ class PreemptionHelper {
template <typename GfxFamily>
static void programStateSip(LinearStream &preambleCmdStream, Device &device);
template <typename GfxFamily>
static void programStateSipEndWa(LinearStream &cmdStream, Device &device);
template <typename GfxFamily>
static size_t getRequiredCmdStreamSize(PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2020 Intel Corporation
* Copyright (C) 2017-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -45,6 +45,9 @@ void PreemptionHelper::programStateSip(LinearStream &preambleCmdStream, Device &
}
}
template <typename GfxFamily>
void PreemptionHelper::programStateSipEndWa(LinearStream &cmdStream, Device &device) {}
template <typename GfxFamily>
void PreemptionHelper::programCmdStream(LinearStream &cmdStream, PreemptionMode newPreemptionMode,
PreemptionMode oldPreemptionMode, GraphicsAllocation *preemptionCsr) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -23,4 +23,6 @@ template size_t PreemptionHelper::getPreemptionWaCsSize<GfxFamily>(const Device
template void PreemptionHelper::applyPreemptionWaCmdsBegin<GfxFamily>(LinearStream *pCommandStream, const Device &device);
template void PreemptionHelper::applyPreemptionWaCmdsEnd<GfxFamily>(LinearStream *pCommandStream, const Device &device);
template void PreemptionHelper::programInterfaceDescriptorDataPreemption<GfxFamily>(INTERFACE_DESCRIPTOR_DATA<GfxFamily> *idd, PreemptionMode preemptionMode);
template void PreemptionHelper::programStateSipEndWa<GfxFamily>(LinearStream &cmdStream, Device &device);
} // namespace NEO

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2020 Intel Corporation
* Copyright (C) 2019-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -23,4 +23,5 @@ template size_t PreemptionHelper::getPreemptionWaCsSize<GfxFamily>(const Device
template void PreemptionHelper::applyPreemptionWaCmdsBegin<GfxFamily>(LinearStream *pCommandStream, const Device &device);
template void PreemptionHelper::applyPreemptionWaCmdsEnd<GfxFamily>(LinearStream *pCommandStream, const Device &device);
template void PreemptionHelper::programInterfaceDescriptorDataPreemption<GfxFamily>(INTERFACE_DESCRIPTOR_DATA<GfxFamily> *idd, PreemptionMode preemptionMode);
template void PreemptionHelper::programStateSipEndWa<GfxFamily>(LinearStream &cmdStream, Device &device);
} // namespace NEO

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -108,4 +108,5 @@ void PreemptionHelper::programInterfaceDescriptorDataPreemption<GfxFamily>(INTER
}
template size_t PreemptionHelper::getRequiredCmdStreamSize<GfxFamily>(PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode);
template void PreemptionHelper::programStateSipEndWa<GfxFamily>(LinearStream &cmdStream, Device &device);
} // namespace NEO

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -72,5 +72,6 @@ template void PreemptionHelper::programCsrBaseAddress<GfxFamily>(LinearStream &p
template void PreemptionHelper::programStateSip<GfxFamily>(LinearStream &preambleCmdStream, Device &device);
template size_t PreemptionHelper::getRequiredStateSipCmdSize<GfxFamily>(const Device &device);
template size_t PreemptionHelper::getRequiredCmdStreamSize<GfxFamily>(PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode);
template void PreemptionHelper::programStateSipEndWa<GfxFamily>(LinearStream &cmdStream, Device &device);
} // namespace NEO

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -865,7 +865,8 @@ HWTEST_F(DirectSubmissionTest, givenDirectSubmissionAvailableWhenProgrammingEndi
void *location = nullptr;
uint8_t buffer[128];
mockCsr->commandStream.replaceBuffer(&buffer[0], 128u);
mockCsr->programEndingCmd(mockCsr->commandStream, &location, ret);
auto &device = *pDevice;
mockCsr->programEndingCmd(mockCsr->commandStream, device, &location, ret);
EXPECT_EQ(sizeof(MI_BATCH_BUFFER_START), mockCsr->commandStream.getUsed());
DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags();