Skip to content

Commit 7dc8bbc

Browse files
Metric Api: Wait events for zetCommandListAppendMetricQueryEnd
Change-Id: I6fdf470035c1fc1f44d66778ec35ec47d0521e4d Signed-off-by: Robert Krzemien <[email protected]>
1 parent ffcec77 commit 7dc8bbc

File tree

10 files changed

+514
-31
lines changed

10 files changed

+514
-31
lines changed

level_zero/api/tools/zet_metric.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,17 @@ zetCommandListAppendMetricQueryEnd(
184184
zet_command_list_handle_t hCommandList,
185185
zet_metric_query_handle_t hMetricQuery,
186186
ze_event_handle_t hCompletionEvent) {
187-
return L0::CommandList::fromHandle(hCommandList)->appendMetricQueryEnd(hMetricQuery, hCompletionEvent);
187+
return L0::CommandList::fromHandle(hCommandList)->appendMetricQueryEnd(hMetricQuery, hCompletionEvent, 0, nullptr);
188+
}
189+
190+
__zedllexport ze_result_t __zecall
191+
zetCommandListAppendMetricQueryEndExt(
192+
zet_command_list_handle_t hCommandList,
193+
zet_metric_query_handle_t hMetricQuery,
194+
ze_event_handle_t hSignalEvent,
195+
uint32_t numWaitEvents,
196+
ze_event_handle_t *phWaitEvents) {
197+
return L0::CommandList::fromHandle(hCommandList)->appendMetricQueryEnd(hMetricQuery, hSignalEvent, numWaitEvents, phWaitEvents);
188198
}
189199

190200
__zedllexport ze_result_t __zecall

level_zero/core/source/cmdlist/cmdlist.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ struct CommandList : _ze_command_list_handle_t {
111111
virtual ze_result_t appendMetricTracerMarker(zet_metric_tracer_handle_t hMetricTracer,
112112
uint32_t value) = 0;
113113
virtual ze_result_t appendMetricQueryBegin(zet_metric_query_handle_t hMetricQuery) = 0;
114-
virtual ze_result_t appendMetricQueryEnd(zet_metric_query_handle_t hMetricQuery,
115-
ze_event_handle_t hCompletionEvent) = 0;
114+
virtual ze_result_t appendMetricQueryEnd(zet_metric_query_handle_t hMetricQuery, ze_event_handle_t hSignalEvent,
115+
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) = 0;
116116

117117
virtual ze_result_t appendMILoadRegImm(uint32_t reg, uint32_t value) = 0;
118118
virtual ze_result_t appendMILoadRegReg(uint32_t reg1, uint32_t reg2) = 0;

level_zero/core/source/cmdlist/cmdlist_imp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ ze_result_t CommandListImp::appendMetricQueryBegin(zet_metric_query_handle_t hMe
5252
return MetricQuery::fromHandle(hMetricQuery)->appendBegin(*this);
5353
}
5454

55-
ze_result_t CommandListImp::appendMetricQueryEnd(zet_metric_query_handle_t hMetricQuery,
56-
ze_event_handle_t hCompletionEvent) {
57-
return MetricQuery::fromHandle(hMetricQuery)->appendEnd(*this, hCompletionEvent);
55+
ze_result_t CommandListImp::appendMetricQueryEnd(zet_metric_query_handle_t hMetricQuery, ze_event_handle_t hSignalEvent,
56+
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) {
57+
return MetricQuery::fromHandle(hMetricQuery)->appendEnd(*this, hSignalEvent, numWaitEvents, phWaitEvents);
5858
}
5959

6060
CommandList *CommandList::create(uint32_t productFamily, Device *device, bool isCopyOnly) {

level_zero/core/source/cmdlist/cmdlist_imp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ struct CommandListImp : CommandList {
2323
ze_result_t appendMetricTracerMarker(zet_metric_tracer_handle_t hMetricTracer,
2424
uint32_t value) override;
2525
ze_result_t appendMetricQueryBegin(zet_metric_query_handle_t hMetricQuery) override;
26-
ze_result_t appendMetricQueryEnd(zet_metric_query_handle_t hMetricQuery,
27-
ze_event_handle_t hCompletionEvent) override;
26+
ze_result_t appendMetricQueryEnd(zet_metric_query_handle_t hMetricQuery, ze_event_handle_t hSignalEvent,
27+
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) override;
2828

2929
protected:
3030
~CommandListImp() override = default;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ struct MockCommandList : public CommandList {
252252

253253
ADDMETHOD_NOBASE(appendMetricQueryEnd, ze_result_t, ZE_RESULT_SUCCESS,
254254
(zet_metric_query_handle_t hMetricQuery,
255-
ze_event_handle_t hCompletionEvent));
255+
ze_event_handle_t hSignalEvent,
256+
uint32_t numWaitEvents,
257+
ze_event_handle_t *phWaitEvents));
256258

257259
ADDMETHOD_NOBASE(appendMILoadRegImm, ze_result_t, ZE_RESULT_SUCCESS,
258260
(uint32_t reg,

level_zero/tools/source/metrics/metric.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ struct MetricQuery : _zet_metric_query_handle_t {
142142
virtual ~MetricQuery() = default;
143143

144144
virtual ze_result_t appendBegin(CommandList &commandList) = 0;
145-
virtual ze_result_t appendEnd(CommandList &commandList, ze_event_handle_t hCompletionEvent) = 0;
145+
virtual ze_result_t appendEnd(CommandList &commandList, ze_event_handle_t hSignalEvent,
146+
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) = 0;
146147

147148
static ze_result_t appendMemoryBarrier(CommandList &commandList);
148149
static ze_result_t appendStreamerMarker(CommandList &commandList,

level_zero/tools/source/metrics/metric_query_imp.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -489,19 +489,19 @@ ze_result_t MetricQueryImp::appendBegin(CommandList &commandList) {
489489

490490
switch (pool.description.flags) {
491491
case ZET_METRIC_QUERY_POOL_FLAG_PERFORMANCE:
492-
return writeMetricQuery(commandList, nullptr, true);
492+
return writeMetricQuery(commandList, nullptr, 0, nullptr, true);
493493

494494
default:
495495
DEBUG_BREAK_IF(true);
496496
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
497497
}
498498
}
499499

500-
ze_result_t MetricQueryImp::appendEnd(CommandList &commandList,
501-
ze_event_handle_t hCompletionEvent) {
500+
ze_result_t MetricQueryImp::appendEnd(CommandList &commandList, ze_event_handle_t hSignalEvent,
501+
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) {
502502
switch (pool.description.flags) {
503503
case ZET_METRIC_QUERY_POOL_FLAG_PERFORMANCE:
504-
return writeMetricQuery(commandList, hCompletionEvent, false);
504+
return writeMetricQuery(commandList, hSignalEvent, numWaitEvents, phWaitEvents, false);
505505

506506
default:
507507
DEBUG_BREAK_IF(true);
@@ -529,8 +529,13 @@ ze_result_t MetricQueryImp::destroy() {
529529
return ZE_RESULT_SUCCESS;
530530
}
531531

532-
ze_result_t MetricQueryImp::writeMetricQuery(CommandList &commandList,
533-
ze_event_handle_t hCompletionEvent, const bool begin) {
532+
ze_result_t MetricQueryImp::writeMetricQuery(CommandList &commandList, ze_event_handle_t hSignalEvent,
533+
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents,
534+
const bool begin) {
535+
536+
bool writeCompletionEvent = hSignalEvent && !begin;
537+
bool result = false;
538+
534539
// Make gpu allocation visible.
535540
commandList.commandContainer.addToResidencyContainer(pool.pAllocation);
536541

@@ -546,12 +551,18 @@ ze_result_t MetricQueryImp::writeMetricQuery(CommandList &commandList,
546551
? GpuCommandBufferType::Compute
547552
: GpuCommandBufferType::Render;
548553

549-
bool writeCompletionEvent = hCompletionEvent && !begin;
550-
bool result = metricsLibrary.getGpuCommands(commandList, commandBuffer);
554+
// Wait for events before executing query.
555+
result = zeCommandListAppendWaitOnEvents(commandList.toHandle(), numWaitEvents, phWaitEvents) ==
556+
ZE_RESULT_SUCCESS;
557+
558+
// Get query commands.
559+
if (result) {
560+
result = metricsLibrary.getGpuCommands(commandList, commandBuffer);
561+
}
551562

552563
// Write completion event.
553564
if (result && writeCompletionEvent) {
554-
result = zeCommandListAppendSignalEvent(commandList.toHandle(), hCompletionEvent) ==
565+
result = zeCommandListAppendSignalEvent(commandList.toHandle(), hSignalEvent) ==
555566
ZE_RESULT_SUCCESS;
556567
}
557568

level_zero/tools/source/metrics/metric_query_imp.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,17 @@ struct MetricQueryImp : MetricQuery {
101101
const uint32_t slot);
102102

103103
ze_result_t appendBegin(CommandList &commandList) override;
104-
ze_result_t appendEnd(CommandList &commandList, ze_event_handle_t hCompletionEvent) override;
104+
ze_result_t appendEnd(CommandList &commandList, ze_event_handle_t hSignalEvent,
105+
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) override;
105106

106107
ze_result_t getData(size_t *pRawDataSize, uint8_t *pRawData) override;
107108

108109
ze_result_t reset() override;
109110
ze_result_t destroy() override;
110111

111112
protected:
112-
ze_result_t writeMetricQuery(CommandList &commandList, ze_event_handle_t hCompletionEvent,
113+
ze_result_t writeMetricQuery(CommandList &commandList, ze_event_handle_t hSignalEvent,
114+
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents,
113115
const bool begin);
114116

115117
protected:

0 commit comments

Comments
 (0)