Skip to content

Commit 59a1adc

Browse files
Poll csr completion at CmdQueue
Related-To: NEO-6090 Signed-off-by: Dominik Dabek <[email protected]>
1 parent b193dd2 commit 59a1adc

File tree

9 files changed

+92
-2
lines changed

9 files changed

+92
-2
lines changed

level_zero/core/source/cmdqueue/cmdqueue_hw.inl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
474474

475475
this->heapContainer.clear();
476476

477+
csr->pollForCompletion();
478+
477479
return ZE_RESULT_SUCCESS;
478480
}
479481

level_zero/core/test/unit_tests/fixtures/device_fixture.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
#include "shared/test/common/mocks/mock_memory_manager.h"
1616
#include "shared/test/unit_test/page_fault_manager/cpu_page_fault_manager_tests_fixture.h"
1717

18+
#include "opencl/test/unit_test/libult/ult_aub_command_stream_receiver.h"
19+
1820
#include "level_zero/core/source/context/context_imp.h"
1921
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
2022

2123
namespace NEO {
2224
struct UltDeviceFactory;
23-
}
25+
extern CommandStreamReceiverCreateFunc commandStreamReceiverFactory[2 * IGFX_MAX_CORE];
26+
} // namespace NEO
2427

2528
namespace L0 {
2629
struct Context;
@@ -74,6 +77,24 @@ struct ContextFixture : DeviceFixture {
7477
void TearDown() override;
7578
};
7679

80+
struct AubCsrFixture : ContextFixture {
81+
template <typename T>
82+
void SetUpT() {
83+
auto csrCreateFcn = &commandStreamReceiverFactory[IGFX_MAX_CORE + NEO::defaultHwInfo->platform.eRenderCoreFamily];
84+
variableBackup = std::make_unique<VariableBackup<CommandStreamReceiverCreateFunc>>(csrCreateFcn);
85+
*csrCreateFcn = UltAubCommandStreamReceiver<T>::create;
86+
ContextFixture::SetUp();
87+
}
88+
template <typename T>
89+
void TearDownT() {
90+
ContextFixture::TearDown();
91+
}
92+
93+
void SetUp() override{};
94+
void TearDown() override{};
95+
std::unique_ptr<VariableBackup<CommandStreamReceiverCreateFunc>> variableBackup;
96+
};
97+
7798
struct MultipleDevicesWithCustomHwInfo {
7899
void SetUp();
79100
void TearDown() {}

level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "shared/test/common/mocks/mock_memory_manager.h"
2121
#include "shared/test/common/mocks/ult_device_factory.h"
2222

23+
#include "opencl/test/unit_test/libult/ult_aub_command_stream_receiver.h"
2324
#include "opencl/test/unit_test/libult/ult_command_stream_receiver.h"
2425
#include "test.h"
2526

@@ -1518,6 +1519,31 @@ HWTEST2_F(ExecuteCommandListTests, givenTwoCommandQueuesHavingTwoB2BCommandLists
15181519
commandQueue1->destroy();
15191520
}
15201521

1522+
using AubCsrTest = Test<AubCsrFixture>;
1523+
1524+
HWTEST_TEMPLATED_F(AubCsrTest, givenAubCsrWhenCallingExecuteCommandListsThenPollForCompletionIsCalled) {
1525+
auto csr = neoDevice->getDefaultEngine().commandStreamReceiver;
1526+
ze_result_t returnValue;
1527+
ze_command_queue_desc_t desc = {};
1528+
ze_command_queue_handle_t commandQueue = {};
1529+
ze_result_t res = context->createCommandQueue(device, &desc, &commandQueue);
1530+
ASSERT_EQ(ZE_RESULT_SUCCESS, res);
1531+
ASSERT_NE(nullptr, commandQueue);
1532+
1533+
auto aub_csr = static_cast<NEO::UltAubCommandStreamReceiver<FamilyType> *>(csr);
1534+
CommandQueue *queue = static_cast<CommandQueue *>(L0::CommandQueue::fromHandle(commandQueue));
1535+
queue->setCommandQueuePreemptionMode(PreemptionMode::Disabled);
1536+
EXPECT_EQ(aub_csr->pollForCompletionCalled, 0u);
1537+
1538+
std::unique_ptr<L0::CommandList> commandList(L0::CommandList::create(productFamily, device, NEO::EngineGroupType::Compute, 0u, returnValue));
1539+
ASSERT_NE(nullptr, commandList);
1540+
1541+
auto commandListHandle = commandList->toHandle();
1542+
queue->executeCommandLists(1, &commandListHandle, nullptr, false);
1543+
EXPECT_EQ(aub_csr->pollForCompletionCalled, 1u);
1544+
1545+
L0::CommandQueue::fromHandle(commandQueue)->destroy();
1546+
}
15211547
using CommandQueueSynchronizeTest = Test<ContextFixture>;
15221548

15231549
template <typename GfxFamily>

opencl/test/unit_test/command_stream/command_stream_receiver_with_aub_dump_tests.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,31 @@ HWTEST_F(CommandStreamReceiverWithAubDumpSimpleTest, givenCsrWithAubDumpWhenWait
236236
csrWithAubDump.waitForTaskCountWithKmdNotifyFallback(1, 0, false, false);
237237
}
238238

239+
HWTEST_F(CommandStreamReceiverWithAubDumpSimpleTest, givenCsrWithAubDumpWhenPollForCompletionCalledThenAubCsrPollForCompletionCalled) {
240+
auto executionEnvironment = pDevice->getExecutionEnvironment();
241+
executionEnvironment->initializeMemoryManager();
242+
243+
auto gmmHelper = executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper();
244+
MockAubCenter *mockAubCenter = new MockAubCenter(defaultHwInfo.get(), *gmmHelper, false, "file_name.aub", CommandStreamReceiverType::CSR_HW_WITH_AUB);
245+
mockAubCenter->aubManager = std::unique_ptr<MockAubManager>(new MockAubManager());
246+
247+
executionEnvironment->rootDeviceEnvironments[0]->aubCenter = std::unique_ptr<MockAubCenter>(mockAubCenter);
248+
DeviceBitfield deviceBitfield(1);
249+
CommandStreamReceiverWithAUBDump<UltCommandStreamReceiver<FamilyType>> csrWithAubDump("file_name.aub", *executionEnvironment, 0, deviceBitfield);
250+
csrWithAubDump.initializeTagAllocation();
251+
252+
csrWithAubDump.aubCSR.reset(nullptr);
253+
csrWithAubDump.pollForCompletion();
254+
255+
auto mockAubCsr = new MockAubCsr<FamilyType>("file_name.aub", false, *executionEnvironment, 0, deviceBitfield);
256+
mockAubCsr->initializeTagAllocation();
257+
csrWithAubDump.aubCSR.reset(mockAubCsr);
258+
259+
EXPECT_FALSE(mockAubCsr->pollForCompletionCalled);
260+
csrWithAubDump.pollForCompletion();
261+
EXPECT_TRUE(mockAubCsr->pollForCompletionCalled);
262+
}
263+
239264
HWTEST_F(CommandStreamReceiverWithAubDumpSimpleTest, givenCsrWithAubDumpWhenCreatingAubCsrThenInitializeTagAllocation) {
240265
auto executionEnvironment = pDevice->getExecutionEnvironment();
241266
executionEnvironment->initializeMemoryManager();

opencl/test/unit_test/libult/ult_aub_command_stream_receiver.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class UltAubCommandStreamReceiver : public AUBCommandStreamReceiverHw<GfxFamily>
5454
return BaseClass::blitBuffer(blitPropertiesContainer, blocking, profilingEnabled, device);
5555
}
5656

57+
void pollForCompletion() override {
58+
pollForCompletionCalled++;
59+
BaseClass::pollForCompletion();
60+
}
61+
5762
uint32_t blitBufferCalled = 0;
63+
uint32_t pollForCompletionCalled = 0;
5864
};
5965
} // namespace NEO

shared/source/command_stream/command_stream_receiver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class CommandStreamReceiver {
8585

8686
virtual bool flushBatchedSubmissions() = 0;
8787
MOCKABLE_VIRTUAL bool submitBatchBuffer(BatchBuffer &batchBuffer, ResidencyContainer &allocationsForResidency);
88+
virtual void pollForCompletion() {}
8889
virtual void programHardwareContext(LinearStream &cmdStream) = 0;
8990
virtual size_t getCmdsSizeForHardwareContext() const = 0;
9091

shared/source/command_stream/command_stream_receiver_simulated_common_hw.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class CommandStreamReceiverSimulatedCommonHw : public CommandStreamReceiverHw<Gf
5252
virtual bool expectMemoryEqual(void *gfxAddress, const void *srcAddress, size_t length);
5353
virtual bool expectMemoryNotEqual(void *gfxAddress, const void *srcAddress, size_t length);
5454
virtual bool expectMemoryCompressed(void *gfxAddress, const void *srcAddress, size_t length);
55-
virtual void pollForCompletion() = 0;
5655
virtual void pollForCompletionImpl(){};
5756
virtual bool writeMemory(GraphicsAllocation &gfxAllocation) = 0;
5857
virtual void writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits) = 0;

shared/source/command_stream/command_stream_receiver_with_aub_dump.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class CommandStreamReceiverWithAUBDump : public BaseCSR {
4646

4747
void addAubComment(const char *comment) override;
4848

49+
void pollForCompletion() override;
50+
4951
std::unique_ptr<CommandStreamReceiver> aubCSR;
5052
};
5153

shared/source/command_stream/command_stream_receiver_with_aub_dump.inl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,12 @@ void CommandStreamReceiverWithAUBDump<BaseCSR>::addAubComment(const char *commen
8585
}
8686
BaseCSR::addAubComment(comment);
8787
}
88+
89+
template <typename BaseCSR>
90+
void CommandStreamReceiverWithAUBDump<BaseCSR>::pollForCompletion() {
91+
if (aubCSR) {
92+
aubCSR->pollForCompletion();
93+
}
94+
BaseCSR::pollForCompletion();
95+
}
8896
} // namespace NEO

0 commit comments

Comments
 (0)