Skip to content

Commit 04bb54d

Browse files
Jaime ArteagaCompute-Runtime-Automation
authored andcommitted
Flush print buffer when destroying the command queue
This ensures all pending prints are flushed, in the case for instance zeCommandQueueSynchronize() is not called. Change-Id: I4b50c535e4681eff4708242febc948c21c715055 Signed-off: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
1 parent 87dccc2 commit 04bb54d

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

level_zero/core/source/cmdqueue/cmdqueue_hw.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::createFence(const ze_fence_desc_t *de
4242

4343
template <GFXCORE_FAMILY gfxCoreFamily>
4444
ze_result_t CommandQueueHw<gfxCoreFamily>::destroy() {
45+
this->printFunctionsPrintfOutput();
4546
delete commandStream;
4647
buffers.destroy(this->getDevice()->getNEODevice()->getMemoryManager());
4748
delete this;

level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ template <GFXCORE_FAMILY gfxCoreFamily>
5858
struct MockCommandQueueHw : public L0::CommandQueueHw<gfxCoreFamily> {
5959
using BaseClass = ::L0::CommandQueueHw<gfxCoreFamily>;
6060
using BaseClass::commandStream;
61+
using BaseClass::printfFunctionContainer;
6162

6263
MockCommandQueueHw(L0::Device *device, NEO::CommandStreamReceiver *csr, const ze_command_queue_desc_t *desc) : L0::CommandQueueHw<gfxCoreFamily>(device, csr, desc) {
6364
}

level_zero/core/test/unit_tests/mocks/mock_kernel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,13 @@ struct Mock<::L0::Kernel> : public ::L0::KernelImp {
8686
return nullptr;
8787
}
8888

89+
void printPrintfOutput() override {
90+
printPrintfOutputCalledTimes++;
91+
}
92+
8993
WhiteBox<::L0::KernelImmutableData> immutableData;
9094
NEO::KernelDescriptor descriptor;
95+
uint32_t printPrintfOutputCalledTimes = 0;
9196
};
9297

9398
} // namespace ult

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "level_zero/core/source/driver/driver_handle_imp.h"
1616
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
1717
#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
18+
#include "level_zero/core/test/unit_tests/mocks/mock_kernel.h"
1819
#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h"
1920

2021
namespace L0 {
@@ -156,5 +157,23 @@ TEST_F(CommandQueueCreate, givenCmdQueueWithBlitCopyWhenExecutingCopyBlitCommand
156157
commandQueue->destroy();
157158
}
158159

160+
using CommandQueueDestroySupport = IsAtLeastProduct<IGFX_SKYLAKE>;
161+
using CommandQueueDestroy = Test<DeviceFixture>;
162+
163+
HWTEST2_F(CommandQueueDestroy, whenCommandQueueDestroyIsCalledPrintPrintfOutputIsCalled, CommandQueueDestroySupport) {
164+
ze_command_queue_desc_t desc = {};
165+
desc.version = ZE_COMMAND_QUEUE_DESC_VERSION_CURRENT;
166+
auto csr = std::unique_ptr<NEO::CommandStreamReceiver>(neoDevice->createCommandStreamReceiver());
167+
auto commandQueue = new MockCommandQueueHw<gfxCoreFamily>(device, csr.get(), &desc);
168+
commandQueue->initialize(false);
169+
170+
Mock<Kernel> kernel;
171+
commandQueue->printfFunctionContainer.push_back(&kernel);
172+
173+
EXPECT_EQ(0u, kernel.printPrintfOutputCalledTimes);
174+
commandQueue->destroy();
175+
EXPECT_EQ(1u, kernel.printPrintfOutputCalledTimes);
176+
}
177+
159178
} // namespace ult
160179
} // namespace L0

0 commit comments

Comments
 (0)