Skip to content

Commit ba156c7

Browse files
Add writeStreamInline at the end of flushTask
Signed-off-by: Bartosz Dunajski <[email protected]>
1 parent c0121eb commit ba156c7

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

opencl/test/unit_test/command_queue/enqueue_command_without_kernel_tests.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
#include "shared/source/helpers/timestamp_packet.h"
99
#include "shared/source/memory_manager/surface.h"
1010
#include "shared/source/os_interface/os_context.h"
11+
#include "shared/test/common/cmd_parse/hw_parse.h"
1112
#include "shared/test/common/mocks/mock_csr.h"
1213
#include "shared/test/common/mocks/mock_execution_environment.h"
1314
#include "shared/test/common/mocks/mock_graphics_allocation.h"
15+
#include "shared/test/common/mocks/mock_logical_state_helper.h"
1416
#include "shared/test/common/mocks/mock_timestamp_container.h"
1517
#include "shared/test/common/test_macros/test.h"
1618
#include "shared/test/common/test_macros/test_checks_shared.h"
@@ -60,6 +62,66 @@ HWTEST_F(EnqueueHandlerTest, GivenCommandStreamWithoutKernelWhenCommandEnqueuedT
6062
EXPECT_EQ(allocation->getTaskCount(mockCmdQ->getGpgpuCommandStreamReceiver().getOsContext().getContextId()), 1u);
6163
}
6264

65+
HWTEST_F(EnqueueHandlerTest, givenLogicalStateHelperWhenDispatchingCommandsThenAddLastCommand) {
66+
using MI_NOOP = typename FamilyType::MI_NOOP;
67+
68+
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, pClDevice, nullptr);
69+
auto logicalStateHelper = new LogicalStateHelperMock<FamilyType>();
70+
71+
auto &ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> &>(mockCmdQ->getGpgpuCommandStreamReceiver());
72+
ultCsr.logicalStateHelper.reset(logicalStateHelper);
73+
74+
auto surface = std::make_unique<NullSurface>();
75+
EventsRequest eventsRequest(0, nullptr, nullptr);
76+
EventBuilder eventBuilder;
77+
Surface *surfaces[] = {surface.get()};
78+
bool blocking = true;
79+
80+
TimestampPacketDependencies timestampPacketDependencies;
81+
82+
CsrDependencies csrDeps;
83+
EnqueueProperties enqueueProperties(false, false, false, true, false, nullptr);
84+
85+
EXPECT_EQ(0u, logicalStateHelper->writeStreamInlineCalledCounter);
86+
87+
mockCmdQ->enqueueCommandWithoutKernel(surfaces, 1, &mockCmdQ->getCS(0), 0, blocking, enqueueProperties, timestampPacketDependencies,
88+
eventsRequest, eventBuilder, 0, csrDeps, nullptr);
89+
90+
EXPECT_EQ(1u, logicalStateHelper->writeStreamInlineCalledCounter);
91+
92+
HardwareParse cmdParser;
93+
cmdParser.parseCommands<FamilyType>(ultCsr.commandStream);
94+
95+
auto miNoop = find<MI_NOOP *>(cmdParser.cmdList.begin(), cmdParser.cmdList.end());
96+
bool miNoopFound = false;
97+
uint32_t cmdsAfterNoop = 0;
98+
99+
while (miNoop != cmdParser.cmdList.end()) {
100+
auto miNoopCmd = genCmdCast<MI_NOOP *>(*miNoop);
101+
if (miNoopCmd->getIdentificationNumber() == 0x123) {
102+
miNoopFound = true;
103+
break;
104+
}
105+
106+
miNoop = find<MI_NOOP *>(++miNoop, cmdParser.cmdList.end());
107+
}
108+
109+
miNoop++;
110+
111+
while (miNoop != cmdParser.cmdList.end()) {
112+
auto miNoopCmd = genCmdCast<MI_NOOP *>(*miNoop);
113+
114+
if (miNoopCmd == nullptr) {
115+
cmdsAfterNoop++;
116+
}
117+
118+
miNoop++;
119+
}
120+
121+
EXPECT_TRUE(miNoopFound);
122+
EXPECT_EQ(1u, cmdsAfterNoop);
123+
}
124+
63125
template <bool enabled>
64126
struct EnqueueHandlerTimestampTest : public EnqueueHandlerTest {
65127
void SetUp() override {

shared/source/command_stream/command_stream_receiver_hw_base.inl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
533533
makeResident(*workPartitionAllocation);
534534
}
535535

536+
if (logicalStateHelper) {
537+
logicalStateHelper->writeStreamInline(commandStreamCSR);
538+
}
539+
536540
// If the CSR has work in its CS, flush it before the task
537541
bool submitTask = commandStreamStartTask != commandStreamTask.getUsed();
538542
bool submitCSR = (commandStreamStartCSR != commandStreamCSR.getUsed()) || this->isMultiOsContextCapable();

shared/test/common/mocks/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ set(NEO_CORE_tests_mocks
6666
${CMAKE_CURRENT_SOURCE_DIR}/mock_io_functions.h
6767
${CMAKE_CURRENT_SOURCE_DIR}/mock_kernel_info.cpp
6868
${CMAKE_CURRENT_SOURCE_DIR}/mock_kernel_info.h
69+
${CMAKE_CURRENT_SOURCE_DIR}/mock_logical_state_helper.h
6970
${CMAKE_CURRENT_SOURCE_DIR}/mock_lrca_helper.h
7071
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_manager.h
7172
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_operations_handler.h
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2022 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
10+
#include "shared/source/command_stream/linear_stream.h"
11+
#include "shared/source/helpers/logical_state_helper.h"
12+
13+
#include "hw_cmds.h"
14+
15+
namespace NEO {
16+
17+
template <typename GfxFamily>
18+
class LogicalStateHelperMock : public LogicalStateHelper {
19+
public:
20+
LogicalStateHelperMock() = default;
21+
22+
void writeStreamInline(LinearStream &linearStream) override {
23+
writeStreamInlineCalledCounter++;
24+
25+
auto cmd = linearStream.getSpaceForCmd<typename GfxFamily::MI_NOOP>();
26+
*cmd = GfxFamily::cmdInitNoop;
27+
cmd->setIdentificationNumber(0x123);
28+
}
29+
30+
uint32_t writeStreamInlineCalledCounter = 0;
31+
};
32+
} // namespace NEO

0 commit comments

Comments
 (0)