Skip to content

Commit e06b370

Browse files
Pass eventWaitList to blocked command for semaphore programming
Change-Id: I8b56be03a7b89283f5368cf42d6788d70ebecdc7 Signed-off-by: Dunajski, Bartosz <[email protected]>
1 parent 26006a8 commit e06b370

File tree

7 files changed

+91
-82
lines changed

7 files changed

+91
-82
lines changed

runtime/command_queue/command_queue_hw.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,11 @@ class CommandQueueHw : public CommandQueue {
322322
bool &blocking,
323323
const MultiDispatchInfo &multiDispatchInfo,
324324
KernelOperation *blockedCommandsData,
325-
cl_uint numEventsInWaitList,
326-
const cl_event *eventWaitList,
325+
EventsRequest &eventsRequest,
327326
bool slmUsed,
328327
EventBuilder &externalEventBuilder,
329328
std::unique_ptr<PrintfHandler> printfHandler);
329+
330330
protected:
331331
MOCKABLE_VIRTUAL void enqueueHandlerHook(const unsigned int commandType, const MultiDispatchInfo &dispatchInfo){};
332332
MOCKABLE_VIRTUAL bool createAllocationForHostSurface(HostPtrSurface &surface);

runtime/command_queue/enqueue_common.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ void CommandQueueHw<GfxFamily>::enqueueHandler(Surface **surfacesForResidency,
292292
slmUsed = multiDispatchInfo.usesSlm();
293293
}
294294

295+
EventsRequest eventsRequest(numEventsInWaitList, eventWaitList, event);
295296
CompletionStamp completionStamp;
296297
if (!blockQueue) {
297298
if (parentKernel) {
@@ -340,8 +341,6 @@ void CommandQueueHw<GfxFamily>::enqueueHandler(Surface **surfacesForResidency,
340341
auto submissionRequired = isCommandWithoutKernel(commandType) ? false : true;
341342

342343
if (submissionRequired) {
343-
EventsRequest eventsRequest(numEventsInWaitList, eventWaitList, nullptr);
344-
345344
completionStamp = enqueueNonBlocked<commandType>(
346345
surfacesForResidency,
347346
numSurfaceForResidency,
@@ -426,8 +425,7 @@ void CommandQueueHw<GfxFamily>::enqueueHandler(Surface **surfacesForResidency,
426425
blocking,
427426
multiDispatchInfo,
428427
blockedCommandsData,
429-
numEventsInWaitList,
430-
eventWaitList,
428+
eventsRequest,
431429
slmUsed,
432430
eventBuilder,
433431
std::move(printfHandler));
@@ -616,8 +614,7 @@ void CommandQueueHw<GfxFamily>::enqueueBlocked(
616614
bool &blocking,
617615
const MultiDispatchInfo &multiDispatchInfo,
618616
KernelOperation *blockedCommandsData,
619-
cl_uint numEventsInWaitList,
620-
const cl_event *eventWaitList,
617+
EventsRequest &eventsRequest,
621618
bool slmUsed,
622619
EventBuilder &externalEventBuilder,
623620
std::unique_ptr<PrintfHandler> printfHandler) {
@@ -678,7 +675,6 @@ void CommandQueueHw<GfxFamily>::enqueueBlocked(
678675
auto kernelOperation = std::unique_ptr<KernelOperation>(blockedCommandsData); // marking ownership
679676
auto cmd = std::make_unique<CommandComputeKernel>(
680677
*this,
681-
commandStreamReceiver,
682678
std::move(kernelOperation),
683679
allSurfaces,
684680
shouldFlushDC(commandType, printfHandler.get()),
@@ -692,10 +688,11 @@ void CommandQueueHw<GfxFamily>::enqueueBlocked(
692688
if (timestampPacketNode) {
693689
cmd->setTimestampPacketNode(timestampPacketNode);
694690
}
691+
cmd->setEventsRequest(eventsRequest);
695692
eventBuilder->getEvent()->setCommand(std::move(cmd));
696693
}
697694

698-
eventBuilder->addParentEvents(ArrayRef<const cl_event>(eventWaitList, numEventsInWaitList));
695+
eventBuilder->addParentEvents(ArrayRef<const cl_event>(eventsRequest.eventWaitList, eventsRequest.numEventsInWaitList));
699696
eventBuilder->addParentEvent(this->virtualEvent);
700697
eventBuilder->finalize();
701698

runtime/helpers/task_information.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,30 +89,21 @@ CompletionStamp &CommandMapUnmap::submit(uint32_t taskLevel, bool terminated) {
8989
return completionStamp;
9090
}
9191

92-
CommandComputeKernel::CommandComputeKernel(CommandQueue &commandQueue, CommandStreamReceiver &commandStreamReceiver,
93-
std::unique_ptr<KernelOperation> kernelOperation, std::vector<Surface *> &surfaces,
92+
CommandComputeKernel::CommandComputeKernel(CommandQueue &commandQueue, std::unique_ptr<KernelOperation> kernelOperation, std::vector<Surface *> &surfaces,
9493
bool flushDC, bool usesSLM, bool ndRangeKernel, std::unique_ptr<PrintfHandler> printfHandler,
9594
PreemptionMode preemptionMode, Kernel *kernel, uint32_t kernelCount)
96-
: commandQueue(commandQueue),
97-
commandStreamReceiver(commandStreamReceiver),
98-
kernelOperation(std::move(kernelOperation)),
99-
flushDC(flushDC),
100-
slmUsed(usesSLM),
101-
NDRangeKernel(ndRangeKernel),
102-
printfHandler(std::move(printfHandler)),
103-
kernel(nullptr),
104-
kernelCount(0) {
95+
: commandQueue(commandQueue), kernelOperation(std::move(kernelOperation)), flushDC(flushDC), slmUsed(usesSLM),
96+
NDRangeKernel(ndRangeKernel), printfHandler(std::move(printfHandler)), kernel(kernel),
97+
kernelCount(kernelCount), preemptionMode(preemptionMode) {
10598
for (auto surface : surfaces) {
10699
this->surfaces.push_back(surface);
107100
}
108-
this->kernel = kernel;
109101
UNRECOVERABLE_IF(nullptr == this->kernel);
110102
kernel->incRefInternal();
111-
this->kernelCount = kernelCount;
112-
this->preemptionMode = preemptionMode;
113103
}
114104

115105
CommandComputeKernel::~CommandComputeKernel() {
106+
auto &commandStreamReceiver = commandQueue.getDevice().getCommandStreamReceiver();
116107
if (timestampPacketNode) {
117108
auto allocator = commandStreamReceiver.getMemoryManager()->getTimestampPacketAllocator();
118109
allocator->returnTag(timestampPacketNode);
@@ -131,6 +122,7 @@ CompletionStamp &CommandComputeKernel::submit(uint32_t taskLevel, bool terminate
131122
if (terminated) {
132123
return completionStamp;
133124
}
125+
auto &commandStreamReceiver = commandQueue.getDevice().getCommandStreamReceiver();
134126
bool executionModelKernel = kernel->isParentKernel;
135127
auto devQueue = commandQueue.getContext().getDefaultDeviceQueue();
136128

@@ -213,6 +205,9 @@ CompletionStamp &CommandComputeKernel::submit(uint32_t taskLevel, bool terminate
213205
dispatchFlags.throttle = commandQueue.getThrottle();
214206
dispatchFlags.preemptionMode = preemptionMode;
215207
dispatchFlags.mediaSamplerRequired = kernel->isVmeKernel();
208+
if (commandStreamReceiver.peekTimestampPacketWriteEnabled()) {
209+
dispatchFlags.outOfDeviceDependencies = &eventsRequest;
210+
}
216211

217212
DEBUG_BREAK_IF(taskLevel >= Event::eventNotReady);
218213

runtime/helpers/task_information.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ struct KernelOperation {
8787

8888
class CommandComputeKernel : public Command {
8989
public:
90-
CommandComputeKernel(CommandQueue &commandQueue, CommandStreamReceiver &commandStreamReceiver,
91-
std::unique_ptr<KernelOperation> kernelResources, std::vector<Surface *> &surfaces,
90+
CommandComputeKernel(CommandQueue &commandQueue, std::unique_ptr<KernelOperation> kernelResources, std::vector<Surface *> &surfaces,
9291
bool flushDC, bool usesSLM, bool ndRangeKernel, std::unique_ptr<PrintfHandler> printfHandler,
9392
PreemptionMode preemptionMode, Kernel *kernel = nullptr, uint32_t kernelCount = 0);
9493

@@ -99,10 +98,10 @@ class CommandComputeKernel : public Command {
9998
LinearStream *getCommandStream() override { return kernelOperation->commandStream.get(); }
10099

101100
void setTimestampPacketNode(TagNode<TimestampPacket> *node);
101+
void setEventsRequest(EventsRequest &eventsRequest) { this->eventsRequest = eventsRequest; }
102102

103103
private:
104104
CommandQueue &commandQueue;
105-
CommandStreamReceiver &commandStreamReceiver;
106105
std::unique_ptr<KernelOperation> kernelOperation;
107106
std::vector<Surface *> surfaces;
108107
bool flushDC;
@@ -113,6 +112,7 @@ class CommandComputeKernel : public Command {
113112
uint32_t kernelCount;
114113
PreemptionMode preemptionMode;
115114
TagNode<TimestampPacket> *timestampPacketNode = nullptr;
115+
EventsRequest eventsRequest = {0, nullptr, nullptr};
116116
};
117117

118118
class CommandMarker : public Command {

unit_tests/event/event_tests.cpp

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -427,17 +427,17 @@ class SurfaceMock : public Surface {
427427
};
428428

429429
TEST_F(InternalsEventTest, processBlockedCommandsKernelOperation) {
430-
MockEvent<Event> event(nullptr, CL_COMMAND_NDRANGE_KERNEL, 0, 0);
431-
CommandQueue *pCmdQ = new CommandQueue(mockContext, pDevice, 0);
430+
CommandQueue cmdQ(mockContext, pDevice, nullptr);
431+
MockEvent<Event> event(&cmdQ, CL_COMMAND_NDRANGE_KERNEL, 0, 0);
432432

433433
auto cmdStream = new LinearStream(alignedMalloc(4096, 4096), 4096);
434434
IndirectHeap *dsh = nullptr, *ioh = nullptr, *ssh = nullptr;
435-
pCmdQ->allocateHeapMemory(IndirectHeap::DYNAMIC_STATE, 4096u, dsh);
436-
pCmdQ->allocateHeapMemory(IndirectHeap::INDIRECT_OBJECT, 4096u, ioh);
437-
pCmdQ->allocateHeapMemory(IndirectHeap::SURFACE_STATE, 4096u, ssh);
435+
cmdQ.allocateHeapMemory(IndirectHeap::DYNAMIC_STATE, 4096u, dsh);
436+
cmdQ.allocateHeapMemory(IndirectHeap::INDIRECT_OBJECT, 4096u, ioh);
437+
cmdQ.allocateHeapMemory(IndirectHeap::SURFACE_STATE, 4096u, ssh);
438438
using UniqueIH = std::unique_ptr<IndirectHeap>;
439439
auto blockedCommandsData = new KernelOperation(std::unique_ptr<LinearStream>(cmdStream), UniqueIH(dsh),
440-
UniqueIH(ioh), UniqueIH(ssh), *pCmdQ->getDevice().getMemoryManager());
440+
UniqueIH(ioh), UniqueIH(ssh), *cmdQ.getDevice().getMemoryManager());
441441

442442
MockKernelWithInternals mockKernelWithInternals(*pDevice);
443443
auto pKernel = mockKernelWithInternals.mockKernel;
@@ -448,7 +448,7 @@ TEST_F(InternalsEventTest, processBlockedCommandsKernelOperation) {
448448
surface->graphicsAllocation = new GraphicsAllocation((void *)0x1234, 100u);
449449
PreemptionMode preemptionMode = pDevice->getPreemptionMode();
450450
v.push_back(surface);
451-
auto cmd = new CommandComputeKernel(*pCmdQ, csr, std::unique_ptr<KernelOperation>(blockedCommandsData), v, false, false, false, nullptr, preemptionMode, pKernel, 1);
451+
auto cmd = new CommandComputeKernel(cmdQ, std::unique_ptr<KernelOperation>(blockedCommandsData), v, false, false, false, nullptr, preemptionMode, pKernel, 1);
452452
event.setCommand(std::unique_ptr<Command>(cmd));
453453

454454
auto taskLevelBefore = csr.peekTaskLevel();
@@ -458,25 +458,24 @@ TEST_F(InternalsEventTest, processBlockedCommandsKernelOperation) {
458458
auto taskLevelAfter = csr.peekTaskLevel();
459459

460460
EXPECT_EQ(taskLevelBefore + 1, taskLevelAfter);
461-
delete pCmdQ;
462461

463462
EXPECT_EQ(surface->resident, 1u);
464463
EXPECT_FALSE(surface->graphicsAllocation->isResident(0u));
465464
delete surface->graphicsAllocation;
466465
}
467466

468467
TEST_F(InternalsEventTest, processBlockedCommandsAbortKernelOperation) {
469-
MockEvent<Event> event(nullptr, CL_COMMAND_NDRANGE_KERNEL, 0, 0);
470-
CommandQueue *pCmdQ = new CommandQueue(mockContext, pDevice, 0);
468+
CommandQueue cmdQ(mockContext, pDevice, nullptr);
469+
MockEvent<Event> event(&cmdQ, CL_COMMAND_NDRANGE_KERNEL, 0, 0);
471470

472471
auto cmdStream = new LinearStream(alignedMalloc(4096, 4096), 4096);
473472
IndirectHeap *dsh = nullptr, *ioh = nullptr, *ssh = nullptr;
474-
pCmdQ->allocateHeapMemory(IndirectHeap::DYNAMIC_STATE, 4096u, dsh);
475-
pCmdQ->allocateHeapMemory(IndirectHeap::INDIRECT_OBJECT, 4096u, ioh);
476-
pCmdQ->allocateHeapMemory(IndirectHeap::SURFACE_STATE, 4096u, ssh);
473+
cmdQ.allocateHeapMemory(IndirectHeap::DYNAMIC_STATE, 4096u, dsh);
474+
cmdQ.allocateHeapMemory(IndirectHeap::INDIRECT_OBJECT, 4096u, ioh);
475+
cmdQ.allocateHeapMemory(IndirectHeap::SURFACE_STATE, 4096u, ssh);
477476
using UniqueIH = std::unique_ptr<IndirectHeap>;
478477
auto blockedCommandsData = new KernelOperation(std::unique_ptr<LinearStream>(cmdStream), UniqueIH(dsh),
479-
UniqueIH(ioh), UniqueIH(ssh), *pCmdQ->getDevice().getMemoryManager());
478+
UniqueIH(ioh), UniqueIH(ssh), *cmdQ.getDevice().getMemoryManager());
480479

481480
MockKernelWithInternals mockKernelWithInternals(*pDevice);
482481
auto pKernel = mockKernelWithInternals.mockKernel;
@@ -486,7 +485,7 @@ TEST_F(InternalsEventTest, processBlockedCommandsAbortKernelOperation) {
486485
NullSurface *surface = new NullSurface;
487486
v.push_back(surface);
488487
PreemptionMode preemptionMode = pDevice->getPreemptionMode();
489-
auto cmd = new CommandComputeKernel(*pCmdQ, csr, std::unique_ptr<KernelOperation>(blockedCommandsData), v, false, false, false, nullptr, preemptionMode, pKernel, 1);
488+
auto cmd = new CommandComputeKernel(cmdQ, std::unique_ptr<KernelOperation>(blockedCommandsData), v, false, false, false, nullptr, preemptionMode, pKernel, 1);
490489
event.setCommand(std::unique_ptr<Command>(cmd));
491490

492491
auto taskLevelBefore = csr.peekTaskLevel();
@@ -496,22 +495,21 @@ TEST_F(InternalsEventTest, processBlockedCommandsAbortKernelOperation) {
496495
auto taskLevelAfter = csr.peekTaskLevel();
497496

498497
EXPECT_EQ(taskLevelBefore, taskLevelAfter);
499-
delete pCmdQ;
500498
}
501499

502500
TEST_F(InternalsEventTest, givenBlockedKernelWithPrintfWhenSubmittedThenPrintOutput) {
503501
testing::internal::CaptureStdout();
504-
MockEvent<Event> event(nullptr, CL_COMMAND_NDRANGE_KERNEL, 0, 0);
505-
CommandQueue *pCmdQ = new CommandQueue(mockContext, pDevice, 0);
502+
CommandQueue cmdQ(mockContext, pDevice, nullptr);
503+
MockEvent<Event> event(&cmdQ, CL_COMMAND_NDRANGE_KERNEL, 0, 0);
506504

507505
auto cmdStream = new LinearStream(alignedMalloc(4096, 4096), 4096);
508506
IndirectHeap *dsh = nullptr, *ioh = nullptr, *ssh = nullptr;
509-
pCmdQ->allocateHeapMemory(IndirectHeap::DYNAMIC_STATE, 4096u, dsh);
510-
pCmdQ->allocateHeapMemory(IndirectHeap::INDIRECT_OBJECT, 4096u, ioh);
511-
pCmdQ->allocateHeapMemory(IndirectHeap::SURFACE_STATE, 4096u, ssh);
507+
cmdQ.allocateHeapMemory(IndirectHeap::DYNAMIC_STATE, 4096u, dsh);
508+
cmdQ.allocateHeapMemory(IndirectHeap::INDIRECT_OBJECT, 4096u, ioh);
509+
cmdQ.allocateHeapMemory(IndirectHeap::SURFACE_STATE, 4096u, ssh);
512510
using UniqueIH = std::unique_ptr<IndirectHeap>;
513511
auto blockedCommandsData = new KernelOperation(std::unique_ptr<LinearStream>(cmdStream), UniqueIH(dsh),
514-
UniqueIH(ioh), UniqueIH(ssh), *pCmdQ->getDevice().getMemoryManager());
512+
UniqueIH(ioh), UniqueIH(ssh), *cmdQ.getDevice().getMemoryManager());
515513

516514
SPatchAllocateStatelessPrintfSurface *pPrintfSurface = new SPatchAllocateStatelessPrintfSurface();
517515
pPrintfSurface->DataParamOffset = 0;
@@ -542,10 +540,9 @@ TEST_F(InternalsEventTest, givenBlockedKernelWithPrintfWhenSubmittedThenPrintOut
542540
printfSurface[0] = 8;
543541
printfSurface[1] = 0;
544542

545-
auto &csr = pDevice->getCommandStreamReceiver();
546543
std::vector<Surface *> v;
547544
PreemptionMode preemptionMode = pDevice->getPreemptionMode();
548-
auto cmd = new CommandComputeKernel(*pCmdQ, csr, std::unique_ptr<KernelOperation>(blockedCommandsData), v, false, false, false, std::move(printfHandler), preemptionMode, pKernel, 1);
545+
auto cmd = new CommandComputeKernel(cmdQ, std::unique_ptr<KernelOperation>(blockedCommandsData), v, false, false, false, std::move(printfHandler), preemptionMode, pKernel, 1);
549546
event.setCommand(std::unique_ptr<Command>(cmd));
550547

551548
event.submitCommand(false);
@@ -555,7 +552,6 @@ TEST_F(InternalsEventTest, givenBlockedKernelWithPrintfWhenSubmittedThenPrintOut
555552
EXPECT_FALSE(surface->isResident(0u));
556553

557554
delete pPrintfSurface;
558-
delete pCmdQ;
559555
}
560556

561557
TEST_F(InternalsEventTest, processBlockedCommandsMapOperation) {
@@ -1431,7 +1427,7 @@ HWTEST_F(InternalsEventTest, givenAbortedCommandWhenSubmitCalledThenDontUpdateFl
14311427
UniqueIH(ioh), UniqueIH(ssh), *pCmdQ->getDevice().getMemoryManager());
14321428
PreemptionMode preemptionMode = pDevice->getPreemptionMode();
14331429
std::vector<Surface *> v;
1434-
auto cmd = new CommandComputeKernel(*pCmdQ, csr, std::unique_ptr<KernelOperation>(blockedCommandsData), v, false, false, false, nullptr, preemptionMode, pKernel, 1);
1430+
auto cmd = new CommandComputeKernel(*pCmdQ, std::unique_ptr<KernelOperation>(blockedCommandsData), v, false, false, false, nullptr, preemptionMode, pKernel, 1);
14351431
event->setCommand(std::unique_ptr<Command>(cmd));
14361432

14371433
FlushStamp expectedFlushStamp = 0;

0 commit comments

Comments
 (0)