Skip to content

Commit 0ca1cdc

Browse files
Add State Sip end WA
Related-To: NEO-5479 Signed-off-by: Mateusz Hoppe <[email protected]>
1 parent 7e27ebe commit 0ca1cdc

File tree

14 files changed

+101
-64
lines changed

14 files changed

+101
-64
lines changed

level_zero/core/source/cmdqueue/cmdqueue_hw.inl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,19 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
8787
constexpr size_t residencyContainerSpaceForFence = 1;
8888
constexpr size_t residencyContainerSpaceForTagWrite = 1;
8989

90-
const bool initialPreemptionMode = commandQueuePreemptionMode == NEO::PreemptionMode::Initial;
91-
9290
NEO::Device *neoDevice = device->getNEODevice();
9391
NEO::PreemptionMode statePreemption = commandQueuePreemptionMode;
9492
auto devicePreemption = device->getDevicePreemptionMode();
9593

94+
const bool initialPreemptionMode = commandQueuePreemptionMode == NEO::PreemptionMode::Initial;
95+
const bool stateSipRequired = (initialPreemptionMode && devicePreemption == NEO::PreemptionMode::MidThread) ||
96+
(neoDevice->getDebugger() && NEO::Debugger::isDebugEnabled(internalUsage));
97+
9698
if (initialPreemptionMode) {
9799
preemptionSize += NEO::PreemptionHelper::getRequiredPreambleSize<GfxFamily>(*neoDevice);
98100
}
99101

100-
if ((initialPreemptionMode && devicePreemption == NEO::PreemptionMode::MidThread) ||
101-
(neoDevice->getDebugger() && NEO::Debugger::isDebugEnabled(internalUsage))) {
102+
if (stateSipRequired) {
102103
preemptionSize += NEO::PreemptionHelper::getRequiredStateSipCmdSize<GfxFamily>(*neoDevice);
103104
}
104105

@@ -243,8 +244,7 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
243244
NEO::PreemptionHelper::programCsrBaseAddress<GfxFamily>(child, *neoDevice, csr->getPreemptionAllocation());
244245
}
245246

246-
if ((initialPreemptionMode && devicePreemption == NEO::PreemptionMode::MidThread) ||
247-
(neoDevice->getDebugger() && NEO::Debugger::isDebugEnabled(internalUsage))) {
247+
if (stateSipRequired) {
248248
NEO::PreemptionHelper::programStateSip<GfxFamily>(child, *neoDevice);
249249
}
250250

@@ -330,6 +330,10 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
330330
}
331331
}
332332

333+
if (stateSipRequired) {
334+
NEO::PreemptionHelper::programStateSipEndWa<GfxFamily>(child, *neoDevice);
335+
}
336+
333337
commandQueuePreemptionMode = statePreemption;
334338

335339
if (hFence) {

level_zero/core/test/unit_tests/sources/debugger/active_debugger_fixture.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 Intel Corporation
2+
* Copyright (C) 2020-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -19,6 +19,7 @@
1919
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
2020
#include "level_zero/core/test/unit_tests/mocks/mock_device.h"
2121
#include "level_zero/core/test/unit_tests/mocks/mock_driver.h"
22+
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
2223
#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h"
2324

2425
namespace L0 {
@@ -29,8 +30,11 @@ struct ActiveDebuggerFixture {
2930
auto executionEnvironment = new NEO::ExecutionEnvironment();
3031
auto mockBuiltIns = new MockBuiltins();
3132
executionEnvironment->prepareRootDeviceEnvironments(1);
33+
34+
hwInfo = *defaultHwInfo.get();
35+
3236
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
33-
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
37+
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(&hwInfo);
3438

3539
debugger = new MockActiveSourceLevelDebugger(new MockOsLibrary);
3640
executionEnvironment->rootDeviceEnvironments[0]->debugger.reset(debugger);
@@ -62,6 +66,7 @@ struct ActiveDebuggerFixture {
6266
NEO::MockDevice *device = nullptr;
6367
L0::Device *deviceL0;
6468
MockActiveSourceLevelDebugger *debugger = nullptr;
69+
HardwareInfo hwInfo;
6570
};
6671
} // namespace ult
6772
} // namespace L0

opencl/test/unit_test/source_level_debugger/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2018-2020 Intel Corporation
2+
# Copyright (C) 2018-2021 Intel Corporation
33
#
44
# SPDX-License-Identifier: MIT
55
#
@@ -8,6 +8,7 @@ set(IGDRCL_SRCS_tests_source_level_debugger
88
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
99
${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_device_tests.cpp
1010
${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_csr_tests.cpp
11+
${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_csr_tests.h
1112
${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_tests.cpp
1213
)
1314

opencl/test/unit_test/source_level_debugger/source_level_debugger_csr_tests.cpp

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/*
2-
* Copyright (C) 2018-2020 Intel Corporation
2+
* Copyright (C) 2018-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
66
*/
77

8+
#include "opencl/test/unit_test/source_level_debugger/source_level_debugger_csr_tests.h"
9+
810
#include "shared/source/source_level_debugger/source_level_debugger.h"
911
#include "shared/test/unit_test/cmd_parse/hw_parse.h"
1012
#include "shared/test/unit_test/helpers/dispatch_flags_helper.h"
@@ -13,47 +15,10 @@
1315
#include "shared/test/unit_test/mocks/mock_os_library.h"
1416

1517
#include "opencl/source/command_queue/command_queue_hw.h"
16-
#include "opencl/test/unit_test/helpers/execution_environment_helper.h"
17-
#include "opencl/test/unit_test/mocks/mock_builtins.h"
18-
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
19-
#include "opencl/test/unit_test/mocks/mock_csr.h"
20-
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
21-
#include "opencl/test/unit_test/mocks/mock_source_level_debugger.h"
2218
#include "test.h"
2319

2420
#include <memory>
2521

26-
class CommandStreamReceiverWithActiveDebuggerTest : public ::testing::Test {
27-
protected:
28-
template <typename FamilyType>
29-
auto createCSR() {
30-
hwInfo = nullptr;
31-
EnvironmentWithCsrWrapper environment;
32-
environment.setCsrType<MockCsrHw2<FamilyType>>();
33-
executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1);
34-
hwInfo->capabilityTable = defaultHwInfo->capabilityTable;
35-
hwInfo->capabilityTable.debuggerSupported = true;
36-
37-
auto mockMemoryManager = new MockMemoryManager(*executionEnvironment);
38-
executionEnvironment->memoryManager.reset(mockMemoryManager);
39-
40-
executionEnvironment->rootDeviceEnvironments[0]->debugger.reset(new MockActiveSourceLevelDebugger(new MockOsLibrary));
41-
42-
device = std::make_unique<MockClDevice>(Device::create<MockDevice>(executionEnvironment, 0));
43-
device->setSourceLevelDebuggerActive(true);
44-
45-
return static_cast<MockCsrHw2<FamilyType> *>(device->getDefaultEngine().commandStreamReceiver);
46-
}
47-
48-
void TearDown() override {
49-
device->setSourceLevelDebuggerActive(false);
50-
}
51-
52-
std::unique_ptr<MockClDevice> device;
53-
ExecutionEnvironment *executionEnvironment = nullptr;
54-
HardwareInfo *hwInfo = nullptr;
55-
};
56-
5722
HWTEST_F(CommandStreamReceiverWithActiveDebuggerTest, givenCsrWithActiveDebuggerAndDisabledPreemptionWhenFlushTaskIsCalledThenSipKernelIsMadeResident) {
5823

5924
auto mockCsr = createCSR<FamilyType>();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/test/unit_test/mocks/mock_os_library.h"
9+
10+
#include "opencl/test/unit_test/helpers/execution_environment_helper.h"
11+
#include "opencl/test/unit_test/mocks/mock_builtins.h"
12+
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
13+
#include "opencl/test/unit_test/mocks/mock_csr.h"
14+
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
15+
#include "opencl/test/unit_test/mocks/mock_source_level_debugger.h"
16+
#include "test.h"
17+
18+
#include <memory>
19+
20+
class CommandStreamReceiverWithActiveDebuggerTest : public ::testing::Test {
21+
protected:
22+
template <typename FamilyType>
23+
auto createCSR() {
24+
hwInfo = nullptr;
25+
EnvironmentWithCsrWrapper environment;
26+
environment.setCsrType<MockCsrHw2<FamilyType>>();
27+
executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1);
28+
hwInfo->capabilityTable = defaultHwInfo->capabilityTable;
29+
hwInfo->capabilityTable.debuggerSupported = true;
30+
31+
auto mockMemoryManager = new MockMemoryManager(*executionEnvironment);
32+
executionEnvironment->memoryManager.reset(mockMemoryManager);
33+
34+
executionEnvironment->rootDeviceEnvironments[0]->debugger.reset(new MockActiveSourceLevelDebugger(new MockOsLibrary));
35+
36+
device = std::make_unique<MockClDevice>(Device::create<MockDevice>(executionEnvironment, 0));
37+
device->setSourceLevelDebuggerActive(true);
38+
39+
return static_cast<MockCsrHw2<FamilyType> *>(device->getDefaultEngine().commandStreamReceiver);
40+
}
41+
42+
void TearDown() override {
43+
device->setSourceLevelDebuggerActive(false);
44+
}
45+
46+
std::unique_ptr<MockClDevice> device;
47+
ExecutionEnvironment *executionEnvironment = nullptr;
48+
HardwareInfo *hwInfo = nullptr;
49+
};

shared/source/command_stream/command_stream_receiver_hw.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2020 Intel Corporation
2+
* Copyright (C) 2018-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -51,7 +51,7 @@ class CommandStreamReceiverHw : public CommandStreamReceiver {
5151
size_t getCmdsSizeForHardwareContext() const override;
5252

5353
static void addBatchBufferEnd(LinearStream &commandStream, void **patchLocation);
54-
void programEndingCmd(LinearStream &commandStream, void **patchLocation, bool directSubmissionEnabled);
54+
void programEndingCmd(LinearStream &commandStream, Device &device, void **patchLocation, bool directSubmissionEnabled);
5555
void addBatchBufferStart(MI_BATCH_BUFFER_START *commandBufferMemory, uint64_t startAddress, bool secondary);
5656
static void alignToCacheLine(LinearStream &commandStream);
5757

@@ -118,7 +118,7 @@ class CommandStreamReceiverHw : public CommandStreamReceiver {
118118
void programPreamble(LinearStream &csr, Device &device, DispatchFlags &dispatchFlags, uint32_t &newL3Config);
119119
void programPipelineSelect(LinearStream &csr, PipelineSelectArgs &pipelineSelectArgs);
120120
void programAdditionalPipelineSelect(LinearStream &csr, PipelineSelectArgs &pipelineSelectArgs, bool is3DPipeline);
121-
void programEpilogue(LinearStream &csr, void **batchBufferEndLocation, DispatchFlags &dispatchFlags);
121+
void programEpilogue(LinearStream &csr, Device &device, void **batchBufferEndLocation, DispatchFlags &dispatchFlags);
122122
void programEpliogueCommands(LinearStream &csr, const DispatchFlags &dispatchFlags);
123123
void programMediaSampler(LinearStream &csr, DispatchFlags &dispatchFlags);
124124
void programPerDssBackedBuffer(LinearStream &scr, Device &device, DispatchFlags &dispatchFlags);

shared/source/command_stream/command_stream_receiver_hw_base.inl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,15 @@ inline void CommandStreamReceiverHw<GfxFamily>::addBatchBufferEnd(LinearStream &
8888
}
8989

9090
template <typename GfxFamily>
91-
inline void CommandStreamReceiverHw<GfxFamily>::programEndingCmd(LinearStream &commandStream, void **patchLocation, bool directSubmissionEnabled) {
91+
inline void CommandStreamReceiverHw<GfxFamily>::programEndingCmd(LinearStream &commandStream, Device &device, void **patchLocation, bool directSubmissionEnabled) {
9292
if (directSubmissionEnabled) {
9393
*patchLocation = commandStream.getSpace(sizeof(MI_BATCH_BUFFER_START));
9494
auto bbStart = reinterpret_cast<MI_BATCH_BUFFER_START *>(*patchLocation);
9595
MI_BATCH_BUFFER_START cmd = {};
9696
addBatchBufferStart(&cmd, 0ull, false);
9797
*bbStart = cmd;
9898
} else {
99+
PreemptionHelper::programStateSipEndWa<GfxFamily>(commandStream, device);
99100
this->addBatchBufferEnd(commandStream, patchLocation);
100101
}
101102
}
@@ -515,7 +516,7 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
515516
GraphicsAllocation *chainedBatchBuffer = nullptr;
516517
bool directSubmissionEnabled = isDirectSubmissionEnabled();
517518
if (submitTask) {
518-
programEndingCmd(commandStreamTask, &bbEndLocation, directSubmissionEnabled);
519+
programEndingCmd(commandStreamTask, device, &bbEndLocation, directSubmissionEnabled);
519520
this->emitNoop(commandStreamTask, bbEndPaddingSize);
520521
this->alignToCacheLine(commandStreamTask);
521522

@@ -543,10 +544,10 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
543544
} else if (dispatchFlags.epilogueRequired) {
544545
this->makeResident(*commandStreamCSR.getGraphicsAllocation());
545546
}
546-
this->programEpilogue(commandStreamCSR, &bbEndLocation, dispatchFlags);
547+
this->programEpilogue(commandStreamCSR, device, &bbEndLocation, dispatchFlags);
547548

548549
} else if (submitCSR) {
549-
programEndingCmd(commandStreamCSR, &bbEndLocation, directSubmissionEnabled);
550+
programEndingCmd(commandStreamCSR, device, &bbEndLocation, directSubmissionEnabled);
550551
this->emitNoop(commandStreamCSR, bbEndPaddingSize);
551552
this->alignToCacheLine(commandStreamCSR);
552553
DEBUG_BREAK_IF(commandStreamCSR.getUsed() > commandStreamCSR.getMaxAvailableSpace());
@@ -1094,14 +1095,14 @@ inline bool CommandStreamReceiverHw<GfxFamily>::isPipelineSelectAlreadyProgramme
10941095
}
10951096

10961097
template <typename GfxFamily>
1097-
inline void CommandStreamReceiverHw<GfxFamily>::programEpilogue(LinearStream &csr, void **batchBufferEndLocation, DispatchFlags &dispatchFlags) {
1098+
inline void CommandStreamReceiverHw<GfxFamily>::programEpilogue(LinearStream &csr, Device &device, void **batchBufferEndLocation, DispatchFlags &dispatchFlags) {
10981099
if (dispatchFlags.epilogueRequired) {
10991100
auto currentOffset = ptrDiff(csr.getSpace(0u), csr.getCpuBase());
11001101
auto gpuAddress = ptrOffset(csr.getGraphicsAllocation()->getGpuAddress(), currentOffset);
11011102

11021103
addBatchBufferStart(reinterpret_cast<typename GfxFamily::MI_BATCH_BUFFER_START *>(*batchBufferEndLocation), gpuAddress, false);
11031104
this->programEpliogueCommands(csr, dispatchFlags);
1104-
programEndingCmd(csr, batchBufferEndLocation, isDirectSubmissionEnabled());
1105+
programEndingCmd(csr, device, batchBufferEndLocation, isDirectSubmissionEnabled());
11051106
this->alignToCacheLine(csr);
11061107
}
11071108
}

shared/source/command_stream/preemption.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2020 Intel Corporation
2+
* Copyright (C) 2018-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -61,6 +61,9 @@ class PreemptionHelper {
6161
template <typename GfxFamily>
6262
static void programStateSip(LinearStream &preambleCmdStream, Device &device);
6363

64+
template <typename GfxFamily>
65+
static void programStateSipEndWa(LinearStream &cmdStream, Device &device);
66+
6467
template <typename GfxFamily>
6568
static size_t getRequiredCmdStreamSize(PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode);
6669

shared/source/command_stream/preemption.inl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -45,6 +45,9 @@ void PreemptionHelper::programStateSip(LinearStream &preambleCmdStream, Device &
4545
}
4646
}
4747

48+
template <typename GfxFamily>
49+
void PreemptionHelper::programStateSipEndWa(LinearStream &cmdStream, Device &device) {}
50+
4851
template <typename GfxFamily>
4952
void PreemptionHelper::programCmdStream(LinearStream &cmdStream, PreemptionMode newPreemptionMode,
5053
PreemptionMode oldPreemptionMode, GraphicsAllocation *preemptionCsr) {

shared/source/gen11/preemption_gen11.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2020 Intel Corporation
2+
* Copyright (C) 2018-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -23,4 +23,6 @@ template size_t PreemptionHelper::getPreemptionWaCsSize<GfxFamily>(const Device
2323
template void PreemptionHelper::applyPreemptionWaCmdsBegin<GfxFamily>(LinearStream *pCommandStream, const Device &device);
2424
template void PreemptionHelper::applyPreemptionWaCmdsEnd<GfxFamily>(LinearStream *pCommandStream, const Device &device);
2525
template void PreemptionHelper::programInterfaceDescriptorDataPreemption<GfxFamily>(INTERFACE_DESCRIPTOR_DATA<GfxFamily> *idd, PreemptionMode preemptionMode);
26+
template void PreemptionHelper::programStateSipEndWa<GfxFamily>(LinearStream &cmdStream, Device &device);
27+
2628
} // namespace NEO

0 commit comments

Comments
 (0)