Skip to content

Commit 570c084

Browse files
Handle TimestampPacketNode residency
Change-Id: I1769d67426ca704b600931b58d3f505bef0e893d Signed-off-by: Dunajski, Bartosz <bartosz.dunajski@intel.com>
1 parent 41914d3 commit 570c084

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed

runtime/command_queue/enqueue_common.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "runtime/program/printf_handler.h"
4343
#include "runtime/program/block_kernel_manager.h"
4444
#include "runtime/utilities/range.h"
45+
#include "runtime/utilities/tag_allocator.h"
4546
#include <memory>
4647
#include <new>
4748

@@ -518,6 +519,9 @@ CompletionStamp CommandQueueHw<GfxFamily>::enqueueNonBlocked(
518519
blocking = true;
519520
printfHandler->makeResident(commandStreamReceiver);
520521
}
522+
if (timestampPacketNode) {
523+
device->getCommandStreamReceiver().makeResident(*timestampPacketNode->getGraphicsAllocation());
524+
}
521525

522526
auto requiresCoherency = false;
523527
for (auto surface : CreateRange(surfaces, surfaceCount)) {
@@ -670,7 +674,7 @@ void CommandQueueHw<GfxFamily>::enqueueBlocked(
670674
}
671675
PreemptionMode preemptionMode = PreemptionHelper::taskPreemptionMode(*device, multiDispatchInfo);
672676
auto kernelOperation = std::unique_ptr<KernelOperation>(blockedCommandsData); // marking ownership
673-
auto cmd = std::unique_ptr<Command>(new CommandComputeKernel(
677+
auto cmd = std::make_unique<CommandComputeKernel>(
674678
*this,
675679
commandStreamReceiver,
676680
std::move(kernelOperation),
@@ -681,7 +685,11 @@ void CommandQueueHw<GfxFamily>::enqueueBlocked(
681685
std::move(printfHandler),
682686
preemptionMode,
683687
multiDispatchInfo.peekMainKernel(),
684-
(uint32_t)multiDispatchInfo.size()));
688+
(uint32_t)multiDispatchInfo.size());
689+
690+
if (timestampPacketNode) {
691+
cmd->setTimestampPacketNode(timestampPacketNode);
692+
}
685693
eventBuilder->getEvent()->setCommand(std::move(cmd));
686694
}
687695

runtime/helpers/task_information.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ CommandComputeKernel::CommandComputeKernel(CommandQueue &commandQueue, CommandSt
128128
}
129129

130130
CommandComputeKernel::~CommandComputeKernel() {
131+
if (timestampPacketNode) {
132+
auto allocator = commandStreamReceiver.getMemoryManager()->getTimestampPacketAllocator();
133+
allocator->returnTag(timestampPacketNode);
134+
}
131135
for (auto surface : surfaces) {
132136
delete surface;
133137
}
@@ -177,6 +181,9 @@ CompletionStamp &CommandComputeKernel::submit(uint32_t taskLevel, bool terminate
177181
if (printfHandler) {
178182
printfHandler.get()->makeResident(commandStreamReceiver);
179183
}
184+
if (timestampPacketNode) {
185+
commandStreamReceiver.makeResident(*timestampPacketNode->getGraphicsAllocation());
186+
}
180187

181188
if (executionModelKernel) {
182189
uint32_t taskCount = commandStreamReceiver.peekTaskCount() + 1;
@@ -242,6 +249,11 @@ CompletionStamp &CommandComputeKernel::submit(uint32_t taskLevel, bool terminate
242249
return completionStamp;
243250
}
244251

252+
void CommandComputeKernel::setTimestampPacketNode(TagNode<TimestampPacket> *node) {
253+
node->incRefCount();
254+
timestampPacketNode = node;
255+
}
256+
245257
CompletionStamp &CommandMarker::submit(uint32_t taskLevel, bool terminated) {
246258
if (terminated) {
247259
return completionStamp;

runtime/helpers/task_information.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class Surface;
4040
class PrintfHandler;
4141
struct HwTimeStamps;
4242
class MemoryManager;
43+
class TimestampPacket;
44+
template <typename TagType>
45+
struct TagNode;
4346

4447
enum MapOperationType {
4548
MAP,
@@ -108,9 +111,9 @@ class CommandComputeKernel : public Command {
108111

109112
CompletionStamp &submit(uint32_t taskLevel, bool terminated) override;
110113

111-
LinearStream *getCommandStream() override {
112-
return kernelOperation->commandStream.get();
113-
}
114+
LinearStream *getCommandStream() override { return kernelOperation->commandStream.get(); }
115+
116+
void setTimestampPacketNode(TagNode<TimestampPacket> *node);
114117

115118
private:
116119
CommandQueue &commandQueue;
@@ -124,6 +127,7 @@ class CommandComputeKernel : public Command {
124127
Kernel *kernel;
125128
uint32_t kernelCount;
126129
PreemptionMode preemptionMode;
130+
TagNode<TimestampPacket> *timestampPacketNode = nullptr;
127131
};
128132

129133
class CommandMarker : public Command {

unit_tests/command_queue/enqueue_kernel_tests.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "runtime/helpers/preamble.h"
2828
#include "runtime/memory_manager/graphics_allocation.h"
2929
#include "runtime/memory_manager/memory_constants.h"
30+
#include "runtime/utilities/tag_allocator.h"
3031
#include "unit_tests/command_queue/enqueue_fixture.h"
3132
#include "unit_tests/fixtures/hello_world_fixture.h"
3233
#include "unit_tests/fixtures/memory_management_fixture.h"
@@ -35,6 +36,7 @@
3536
#include "unit_tests/helpers/debug_manager_state_restore.h"
3637
#include "unit_tests/helpers/unit_test_helper.h"
3738
#include "unit_tests/mocks/mock_csr.h"
39+
#include "unit_tests/mocks/mock_command_queue.h"
3840
#include "unit_tests/mocks/mock_device_queue.h"
3941
#include "unit_tests/mocks/mock_buffer.h"
4042
#include "unit_tests/mocks/mock_submissions_aggregator.h"
@@ -1574,6 +1576,43 @@ HWTEST_F(EnqueueKernelTest, givenNonVMEKernelWhenEnqueueKernelThenDispatchFlagsD
15741576
EXPECT_FALSE(mockCsr->passedDispatchFlags.mediaSamplerRequired);
15751577
}
15761578

1579+
HWTEST_F(EnqueueKernelTest, givenTimestampPacketWhenEnqueueingNonBlockedThenMakeItResident) {
1580+
DebugManagerStateRestore restore;
1581+
DebugManager.flags.EnableTimestampPacket.set(true);
1582+
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
1583+
MockKernelWithInternals mockKernel(*pDevice, context);
1584+
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, pDevice, nullptr);
1585+
1586+
csr.storeMakeResidentAllocations = true;
1587+
size_t gws[] = {1, 0, 0};
1588+
1589+
mockCmdQ->enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
1590+
auto timestampPacketNode = mockCmdQ->timestampPacketNode;
1591+
1592+
EXPECT_TRUE(csr.isMadeResident(timestampPacketNode->getGraphicsAllocation()));
1593+
}
1594+
1595+
HWTEST_F(EnqueueKernelTest, givenTimestampPacketWhenEnqueueingBlockedThenMakeItResidentOnSubmit) {
1596+
DebugManagerStateRestore restore;
1597+
DebugManager.flags.EnableTimestampPacket.set(true);
1598+
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
1599+
MockKernelWithInternals mockKernel(*pDevice, context);
1600+
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, pDevice, nullptr);
1601+
1602+
csr.storeMakeResidentAllocations = true;
1603+
size_t gws[] = {1, 0, 0};
1604+
1605+
UserEvent userEvent;
1606+
cl_event clEvent = &userEvent;
1607+
1608+
mockCmdQ->enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 1, &clEvent, nullptr);
1609+
auto timestampPacketNode = mockCmdQ->timestampPacketNode;
1610+
1611+
EXPECT_FALSE(csr.isMadeResident(timestampPacketNode->getGraphicsAllocation()));
1612+
userEvent.setStatus(CL_COMPLETE);
1613+
EXPECT_TRUE(csr.isMadeResident(timestampPacketNode->getGraphicsAllocation()));
1614+
}
1615+
15771616
struct EnqueueAuxKernelTests : public EnqueueKernelTest {
15781617
template <typename FamilyType>
15791618
class MyCmdQ : public CommandQueueHw<FamilyType> {

0 commit comments

Comments
 (0)