Metric Api: Wait events for zetCommandListAppendMetricQueryEnd

Change-Id: I6fdf470035c1fc1f44d66778ec35ec47d0521e4d
Signed-off-by: Robert Krzemien <robert.krzemien@intel.com>
This commit is contained in:
Robert Krzemien
2020-07-27 16:51:20 +02:00
parent ffcec77d0e
commit 7dc8bbc160
10 changed files with 514 additions and 31 deletions

View File

@@ -184,7 +184,17 @@ zetCommandListAppendMetricQueryEnd(
zet_command_list_handle_t hCommandList,
zet_metric_query_handle_t hMetricQuery,
ze_event_handle_t hCompletionEvent) {
return L0::CommandList::fromHandle(hCommandList)->appendMetricQueryEnd(hMetricQuery, hCompletionEvent);
return L0::CommandList::fromHandle(hCommandList)->appendMetricQueryEnd(hMetricQuery, hCompletionEvent, 0, nullptr);
}
__zedllexport ze_result_t __zecall
zetCommandListAppendMetricQueryEndExt(
zet_command_list_handle_t hCommandList,
zet_metric_query_handle_t hMetricQuery,
ze_event_handle_t hSignalEvent,
uint32_t numWaitEvents,
ze_event_handle_t *phWaitEvents) {
return L0::CommandList::fromHandle(hCommandList)->appendMetricQueryEnd(hMetricQuery, hSignalEvent, numWaitEvents, phWaitEvents);
}
__zedllexport ze_result_t __zecall

View File

@@ -111,8 +111,8 @@ struct CommandList : _ze_command_list_handle_t {
virtual ze_result_t appendMetricTracerMarker(zet_metric_tracer_handle_t hMetricTracer,
uint32_t value) = 0;
virtual ze_result_t appendMetricQueryBegin(zet_metric_query_handle_t hMetricQuery) = 0;
virtual ze_result_t appendMetricQueryEnd(zet_metric_query_handle_t hMetricQuery,
ze_event_handle_t hCompletionEvent) = 0;
virtual ze_result_t appendMetricQueryEnd(zet_metric_query_handle_t hMetricQuery, ze_event_handle_t hSignalEvent,
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) = 0;
virtual ze_result_t appendMILoadRegImm(uint32_t reg, uint32_t value) = 0;
virtual ze_result_t appendMILoadRegReg(uint32_t reg1, uint32_t reg2) = 0;

View File

@@ -52,9 +52,9 @@ ze_result_t CommandListImp::appendMetricQueryBegin(zet_metric_query_handle_t hMe
return MetricQuery::fromHandle(hMetricQuery)->appendBegin(*this);
}
ze_result_t CommandListImp::appendMetricQueryEnd(zet_metric_query_handle_t hMetricQuery,
ze_event_handle_t hCompletionEvent) {
return MetricQuery::fromHandle(hMetricQuery)->appendEnd(*this, hCompletionEvent);
ze_result_t CommandListImp::appendMetricQueryEnd(zet_metric_query_handle_t hMetricQuery, ze_event_handle_t hSignalEvent,
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) {
return MetricQuery::fromHandle(hMetricQuery)->appendEnd(*this, hSignalEvent, numWaitEvents, phWaitEvents);
}
CommandList *CommandList::create(uint32_t productFamily, Device *device, bool isCopyOnly) {

View File

@@ -23,8 +23,8 @@ struct CommandListImp : CommandList {
ze_result_t appendMetricTracerMarker(zet_metric_tracer_handle_t hMetricTracer,
uint32_t value) override;
ze_result_t appendMetricQueryBegin(zet_metric_query_handle_t hMetricQuery) override;
ze_result_t appendMetricQueryEnd(zet_metric_query_handle_t hMetricQuery,
ze_event_handle_t hCompletionEvent) override;
ze_result_t appendMetricQueryEnd(zet_metric_query_handle_t hMetricQuery, ze_event_handle_t hSignalEvent,
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) override;
protected:
~CommandListImp() override = default;

View File

@@ -252,7 +252,9 @@ struct MockCommandList : public CommandList {
ADDMETHOD_NOBASE(appendMetricQueryEnd, ze_result_t, ZE_RESULT_SUCCESS,
(zet_metric_query_handle_t hMetricQuery,
ze_event_handle_t hCompletionEvent));
ze_event_handle_t hSignalEvent,
uint32_t numWaitEvents,
ze_event_handle_t *phWaitEvents));
ADDMETHOD_NOBASE(appendMILoadRegImm, ze_result_t, ZE_RESULT_SUCCESS,
(uint32_t reg,

View File

@@ -142,7 +142,8 @@ struct MetricQuery : _zet_metric_query_handle_t {
virtual ~MetricQuery() = default;
virtual ze_result_t appendBegin(CommandList &commandList) = 0;
virtual ze_result_t appendEnd(CommandList &commandList, ze_event_handle_t hCompletionEvent) = 0;
virtual ze_result_t appendEnd(CommandList &commandList, ze_event_handle_t hSignalEvent,
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) = 0;
static ze_result_t appendMemoryBarrier(CommandList &commandList);
static ze_result_t appendStreamerMarker(CommandList &commandList,

View File

@@ -489,7 +489,7 @@ ze_result_t MetricQueryImp::appendBegin(CommandList &commandList) {
switch (pool.description.flags) {
case ZET_METRIC_QUERY_POOL_FLAG_PERFORMANCE:
return writeMetricQuery(commandList, nullptr, true);
return writeMetricQuery(commandList, nullptr, 0, nullptr, true);
default:
DEBUG_BREAK_IF(true);
@@ -497,11 +497,11 @@ ze_result_t MetricQueryImp::appendBegin(CommandList &commandList) {
}
}
ze_result_t MetricQueryImp::appendEnd(CommandList &commandList,
ze_event_handle_t hCompletionEvent) {
ze_result_t MetricQueryImp::appendEnd(CommandList &commandList, ze_event_handle_t hSignalEvent,
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) {
switch (pool.description.flags) {
case ZET_METRIC_QUERY_POOL_FLAG_PERFORMANCE:
return writeMetricQuery(commandList, hCompletionEvent, false);
return writeMetricQuery(commandList, hSignalEvent, numWaitEvents, phWaitEvents, false);
default:
DEBUG_BREAK_IF(true);
@@ -529,8 +529,13 @@ ze_result_t MetricQueryImp::destroy() {
return ZE_RESULT_SUCCESS;
}
ze_result_t MetricQueryImp::writeMetricQuery(CommandList &commandList,
ze_event_handle_t hCompletionEvent, const bool begin) {
ze_result_t MetricQueryImp::writeMetricQuery(CommandList &commandList, ze_event_handle_t hSignalEvent,
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents,
const bool begin) {
bool writeCompletionEvent = hSignalEvent && !begin;
bool result = false;
// Make gpu allocation visible.
commandList.commandContainer.addToResidencyContainer(pool.pAllocation);
@@ -546,12 +551,18 @@ ze_result_t MetricQueryImp::writeMetricQuery(CommandList &commandList,
? GpuCommandBufferType::Compute
: GpuCommandBufferType::Render;
bool writeCompletionEvent = hCompletionEvent && !begin;
bool result = metricsLibrary.getGpuCommands(commandList, commandBuffer);
// Wait for events before executing query.
result = zeCommandListAppendWaitOnEvents(commandList.toHandle(), numWaitEvents, phWaitEvents) ==
ZE_RESULT_SUCCESS;
// Get query commands.
if (result) {
result = metricsLibrary.getGpuCommands(commandList, commandBuffer);
}
// Write completion event.
if (result && writeCompletionEvent) {
result = zeCommandListAppendSignalEvent(commandList.toHandle(), hCompletionEvent) ==
result = zeCommandListAppendSignalEvent(commandList.toHandle(), hSignalEvent) ==
ZE_RESULT_SUCCESS;
}

View File

@@ -101,7 +101,8 @@ struct MetricQueryImp : MetricQuery {
const uint32_t slot);
ze_result_t appendBegin(CommandList &commandList) override;
ze_result_t appendEnd(CommandList &commandList, ze_event_handle_t hCompletionEvent) override;
ze_result_t appendEnd(CommandList &commandList, ze_event_handle_t hSignalEvent,
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) override;
ze_result_t getData(size_t *pRawDataSize, uint8_t *pRawData) override;
@@ -109,7 +110,8 @@ struct MetricQueryImp : MetricQuery {
ze_result_t destroy() override;
protected:
ze_result_t writeMetricQuery(CommandList &commandList, ze_event_handle_t hCompletionEvent,
ze_result_t writeMetricQuery(CommandList &commandList, ze_event_handle_t hSignalEvent,
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents,
const bool begin);
protected:

View File

@@ -444,8 +444,8 @@ TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenZetCommandListAppendMetricQ
zet_device_handle_t metricDevice = device->toHandle();
MockCommandList commandList;
zet_command_list_handle_t commandListHandle = commandList.toHandle();
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, false));
zet_command_list_handle_t commandListHandle = commandList->toHandle();
Mock<MetricGroup> metricGroup;
zet_metric_group_properties_t metricGroupProperties = {};
@@ -465,6 +465,9 @@ TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenZetCommandListAppendMetricQ
QueryHandle_1_0 metricsLibraryQueryHandle = {&value};
ContextHandle_1_0 metricsLibraryContextHandle = {&value};
CommandBufferSize_1_0 commandBufferSize = {};
commandBufferSize.GpuMemorySize = 100;
EXPECT_CALL(*mockMetricEnumeration, isInitialized())
.Times(1)
.WillOnce(Return(true));
@@ -496,6 +499,14 @@ TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenZetCommandListAppendMetricQ
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<2>(metricsLibraryContextHandle), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockCommandBufferGetSize(_, _))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<1>(::testing::ByRef(commandBufferSize)), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockCommandBufferGet(_))
.Times(1)
.WillOnce(Return(StatusCode::Success));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockContextDelete(_))
.Times(1)
.WillOnce(Return(StatusCode::Success));
@@ -592,8 +603,8 @@ TEST_F(MetricQueryPoolTest, givenIncorrectArgumentsWhenZetCommandListAppendMetri
zet_device_handle_t metricDevice = device->toHandle();
zet_driver_handle_t driver = driverHandle->toHandle();
MockCommandList commandList;
zet_command_list_handle_t commandListHandle = commandList.toHandle();
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, false));
zet_command_list_handle_t commandListHandle = commandList->toHandle();
ze_event_pool_handle_t eventPoolHandle = {};
ze_event_pool_desc_t eventPoolDesc = {};
@@ -626,6 +637,9 @@ TEST_F(MetricQueryPoolTest, givenIncorrectArgumentsWhenZetCommandListAppendMetri
QueryHandle_1_0 metricsLibraryQueryHandle = {&value};
ContextHandle_1_0 metricsLibraryContextHandle = {&value};
CommandBufferSize_1_0 commandBufferSize = {};
commandBufferSize.GpuMemorySize = 100;
EXPECT_CALL(*mockMetricEnumeration, isInitialized())
.Times(1)
.WillOnce(Return(true));
@@ -657,6 +671,14 @@ TEST_F(MetricQueryPoolTest, givenIncorrectArgumentsWhenZetCommandListAppendMetri
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<2>(metricsLibraryContextHandle), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockCommandBufferGetSize(_, _))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<1>(::testing::ByRef(commandBufferSize)), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockCommandBufferGet(_))
.Times(1)
.WillOnce(Return(StatusCode::Success));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockContextDelete(_))
.Times(1)
.WillOnce(Return(StatusCode::Success));
@@ -692,8 +714,8 @@ TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenZetCommandListAppendMetricQ
zet_device_handle_t metricDevice = device->toHandle();
zet_driver_handle_t driver = driverHandle->toHandle();
MockCommandList commandList;
zet_command_list_handle_t commandListHandle = commandList.toHandle();
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, false));
zet_command_list_handle_t commandListHandle = commandList->toHandle();
ze_event_pool_handle_t eventPoolHandle = {};
ze_event_pool_desc_t eventPoolDesc = {};
@@ -726,6 +748,9 @@ TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenZetCommandListAppendMetricQ
QueryHandle_1_0 metricsLibraryQueryHandle = {&value};
ContextHandle_1_0 metricsLibraryContextHandle = {&value};
CommandBufferSize_1_0 commandBufferSize = {};
commandBufferSize.GpuMemorySize = 100;
EXPECT_CALL(*mockMetricEnumeration, isInitialized())
.Times(1)
.WillOnce(Return(true));
@@ -757,6 +782,14 @@ TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenZetCommandListAppendMetricQ
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<2>(metricsLibraryContextHandle), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockCommandBufferGetSize(_, _))
.Times(2)
.WillRepeatedly(DoAll(::testing::SetArgPointee<1>(::testing::ByRef(commandBufferSize)), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockCommandBufferGet(_))
.Times(2)
.WillRepeatedly(Return(StatusCode::Success));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockContextDelete(_))
.Times(1)
.WillOnce(Return(StatusCode::Success));
@@ -792,13 +825,129 @@ TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenZetCommandListAppendMetricQ
EXPECT_EQ(zetMetricQueryPoolDestroy(poolHandle), ZE_RESULT_SUCCESS);
}
TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenZetCommandListAppendMetricQueryEndExtIsCalledThenReturnsSuccess) {
zet_device_handle_t metricDevice = device->toHandle();
zet_driver_handle_t driver = driverHandle->toHandle();
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, false));
zet_command_list_handle_t commandListHandle = commandList->toHandle();
ze_event_pool_handle_t eventPoolHandle = {};
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 1;
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_DEFAULT;
eventPoolDesc.version = ZE_EVENT_POOL_DESC_VERSION_CURRENT;
ze_event_handle_t eventHandle = {};
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.version = ZE_EVENT_DESC_VERSION_CURRENT;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
eventDesc.signal = ZE_EVENT_SCOPE_FLAG_DEVICE;
Mock<MetricGroup> metricGroup;
zet_metric_group_properties_t metricGroupProperties = {};
metricGroupProperties.samplingType = ZET_METRIC_GROUP_SAMPLING_TYPE_EVENT_BASED;
zet_metric_query_handle_t queryHandle = {};
zet_metric_query_pool_handle_t poolHandle = {};
zet_metric_query_pool_desc_t poolDesc = {};
poolDesc.version = ZET_METRIC_QUERY_POOL_DESC_VERSION_CURRENT;
poolDesc.count = 1;
poolDesc.flags = ZET_METRIC_QUERY_POOL_FLAG_PERFORMANCE;
TypedValue_1_0 value = {};
value.Type = ValueType::Uint32;
value.ValueUInt32 = 64;
QueryHandle_1_0 metricsLibraryQueryHandle = {&value};
ContextHandle_1_0 metricsLibraryContextHandle = {&value};
CommandBufferSize_1_0 commandBufferSize = {};
commandBufferSize.GpuMemorySize = 100;
EXPECT_CALL(*mockMetricEnumeration, isInitialized())
.Times(1)
.WillOnce(Return(true));
EXPECT_CALL(*mockMetricsLibrary, getContextData(_, _))
.Times(1)
.WillOnce(Return(true));
EXPECT_CALL(*mockMetricsLibrary, load())
.Times(0);
EXPECT_CALL(metricGroup, getProperties(_))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<0>(metricGroupProperties), Return(ZE_RESULT_SUCCESS)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockQueryCreate(_, _))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<1>(metricsLibraryQueryHandle), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockQueryDelete(_))
.Times(1)
.WillOnce(Return(StatusCode::Success));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockGetParameter(_, _, _))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<2>(value), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockContextCreate(_, _, _))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<2>(metricsLibraryContextHandle), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockCommandBufferGetSize(_, _))
.Times(2)
.WillRepeatedly(DoAll(::testing::SetArgPointee<1>(::testing::ByRef(commandBufferSize)), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockCommandBufferGet(_))
.Times(2)
.WillRepeatedly(Return(StatusCode::Success));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockContextDelete(_))
.Times(1)
.WillOnce(Return(StatusCode::Success));
// Create metric query pool.
EXPECT_EQ(zetMetricQueryPoolCreate(metricDevice, metricGroup.toHandle(), &poolDesc, &poolHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(poolHandle, nullptr);
// Create metric query.
EXPECT_EQ(zetMetricQueryCreate(poolHandle, 0, &queryHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(queryHandle, nullptr);
// Create event pool.
EXPECT_EQ(zeEventPoolCreate(driver, &eventPoolDesc, 1, &metricDevice, &eventPoolHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(eventPoolHandle, nullptr);
// Create event.
EXPECT_EQ(zeEventCreate(eventPoolHandle, &eventDesc, &eventHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(eventHandle, nullptr);
// Write BEGIN metric query to command list.
EXPECT_EQ(zetCommandListAppendMetricQueryBegin(commandListHandle, queryHandle), ZE_RESULT_SUCCESS);
// Write END metric query to command list, use an event to determine if the data is available.
EXPECT_EQ(zetCommandListAppendMetricQueryEndExt(commandListHandle, queryHandle, eventHandle, 0, nullptr), ZE_RESULT_SUCCESS);
// Destroy event and its pool.
EXPECT_EQ(zeEventDestroy(eventHandle), ZE_RESULT_SUCCESS);
EXPECT_EQ(zeEventPoolDestroy(eventPoolHandle), ZE_RESULT_SUCCESS);
// Destroy query and its pool.
EXPECT_EQ(zetMetricQueryDestroy(queryHandle), ZE_RESULT_SUCCESS);
EXPECT_EQ(zetMetricQueryPoolDestroy(poolHandle), ZE_RESULT_SUCCESS);
}
TEST_F(MetricQueryPoolTest, givenIncorrectArgumentsWhenZetMetricQueryGetDataIsCalledThenReturnsFail) {
zet_device_handle_t metricDevice = device->toHandle();
zet_driver_handle_t driver = driverHandle->toHandle();
MockCommandList commandList;
zet_command_list_handle_t commandListHandle = commandList.toHandle();
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, false));
zet_command_list_handle_t commandListHandle = commandList->toHandle();
ze_event_pool_handle_t eventPoolHandle = {};
ze_event_pool_desc_t eventPoolDesc = {};
@@ -831,6 +980,9 @@ TEST_F(MetricQueryPoolTest, givenIncorrectArgumentsWhenZetMetricQueryGetDataIsCa
QueryHandle_1_0 metricsLibraryQueryHandle = {&value};
ContextHandle_1_0 metricsLibraryContextHandle = {&value};
CommandBufferSize_1_0 commandBufferSize = {};
commandBufferSize.GpuMemorySize = 100;
EXPECT_CALL(*mockMetricEnumeration, isInitialized())
.Times(1)
.WillOnce(Return(true));
@@ -862,6 +1014,14 @@ TEST_F(MetricQueryPoolTest, givenIncorrectArgumentsWhenZetMetricQueryGetDataIsCa
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<2>(metricsLibraryContextHandle), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockCommandBufferGetSize(_, _))
.Times(2)
.WillRepeatedly(DoAll(::testing::SetArgPointee<1>(::testing::ByRef(commandBufferSize)), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockCommandBufferGet(_))
.Times(2)
.WillRepeatedly(Return(StatusCode::Success));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockContextDelete(_))
.Times(1)
.WillOnce(Return(StatusCode::Success));
@@ -897,13 +1057,129 @@ TEST_F(MetricQueryPoolTest, givenIncorrectArgumentsWhenZetMetricQueryGetDataIsCa
EXPECT_EQ(zetMetricQueryPoolDestroy(poolHandle), ZE_RESULT_SUCCESS);
}
TEST_F(MetricQueryPoolTest, givenIncorrectArgumentsWhenZetMetricQueryGetDataIsCalledThenReturnsFailExt) {
zet_device_handle_t metricDevice = device->toHandle();
zet_driver_handle_t driver = driverHandle->toHandle();
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, false));
zet_command_list_handle_t commandListHandle = commandList->toHandle();
ze_event_pool_handle_t eventPoolHandle = {};
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 1;
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_DEFAULT;
eventPoolDesc.version = ZE_EVENT_POOL_DESC_VERSION_CURRENT;
ze_event_handle_t eventHandle = {};
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.version = ZE_EVENT_DESC_VERSION_CURRENT;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
eventDesc.signal = ZE_EVENT_SCOPE_FLAG_DEVICE;
Mock<MetricGroup> metricGroup;
zet_metric_group_properties_t metricGroupProperties = {};
metricGroupProperties.samplingType = ZET_METRIC_GROUP_SAMPLING_TYPE_EVENT_BASED;
zet_metric_query_handle_t queryHandle = {};
zet_metric_query_pool_handle_t poolHandle = {};
zet_metric_query_pool_desc_t poolDesc = {};
poolDesc.version = ZET_METRIC_QUERY_POOL_DESC_VERSION_CURRENT;
poolDesc.count = 1;
poolDesc.flags = ZET_METRIC_QUERY_POOL_FLAG_PERFORMANCE;
TypedValue_1_0 value = {};
value.Type = ValueType::Uint32;
value.ValueUInt32 = 64;
QueryHandle_1_0 metricsLibraryQueryHandle = {&value};
ContextHandle_1_0 metricsLibraryContextHandle = {&value};
CommandBufferSize_1_0 commandBufferSize = {};
commandBufferSize.GpuMemorySize = 100;
EXPECT_CALL(*mockMetricEnumeration, isInitialized())
.Times(1)
.WillOnce(Return(true));
EXPECT_CALL(*mockMetricsLibrary, getContextData(_, _))
.Times(1)
.WillOnce(Return(true));
EXPECT_CALL(*mockMetricsLibrary, load())
.Times(0);
EXPECT_CALL(metricGroup, getProperties(_))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<0>(metricGroupProperties), Return(ZE_RESULT_SUCCESS)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockQueryCreate(_, _))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<1>(metricsLibraryQueryHandle), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockQueryDelete(_))
.Times(1)
.WillOnce(Return(StatusCode::Success));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockGetParameter(_, _, _))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<2>(value), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockContextCreate(_, _, _))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<2>(metricsLibraryContextHandle), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockCommandBufferGetSize(_, _))
.Times(2)
.WillRepeatedly(DoAll(::testing::SetArgPointee<1>(::testing::ByRef(commandBufferSize)), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockCommandBufferGet(_))
.Times(2)
.WillRepeatedly(Return(StatusCode::Success));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockContextDelete(_))
.Times(1)
.WillOnce(Return(StatusCode::Success));
// Create metric query pool.
EXPECT_EQ(zetMetricQueryPoolCreate(metricDevice, metricGroup.toHandle(), &poolDesc, &poolHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(poolHandle, nullptr);
// Create metric query.
EXPECT_EQ(zetMetricQueryCreate(poolHandle, 0, &queryHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(queryHandle, nullptr);
// Create event pool.
EXPECT_EQ(zeEventPoolCreate(driver, &eventPoolDesc, 1, &metricDevice, &eventPoolHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(eventPoolHandle, nullptr);
// Create event.
EXPECT_EQ(zeEventCreate(eventPoolHandle, &eventDesc, &eventHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(eventHandle, nullptr);
// Write BEGIN metric query to command list.
EXPECT_EQ(zetCommandListAppendMetricQueryBegin(commandListHandle, queryHandle), ZE_RESULT_SUCCESS);
// Write END metric query to command list, use an event to determine if the data is available.
EXPECT_EQ(zetCommandListAppendMetricQueryEndExt(commandListHandle, queryHandle, eventHandle, 0, nullptr), ZE_RESULT_SUCCESS);
// Destroy event and its pool.
EXPECT_EQ(zeEventDestroy(eventHandle), ZE_RESULT_SUCCESS);
EXPECT_EQ(zeEventPoolDestroy(eventPoolHandle), ZE_RESULT_SUCCESS);
// Destroy query and its pool.
EXPECT_EQ(zetMetricQueryDestroy(queryHandle), ZE_RESULT_SUCCESS);
EXPECT_EQ(zetMetricQueryPoolDestroy(poolHandle), ZE_RESULT_SUCCESS);
}
TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenZetMetricQueryGetDataIsCalledThenReturnsSuccess) {
zet_device_handle_t metricDevice = device->toHandle();
zet_driver_handle_t driver = driverHandle->toHandle();
MockCommandList commandList;
zet_command_list_handle_t commandListHandle = commandList.toHandle();
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, false));
zet_command_list_handle_t commandListHandle = commandList->toHandle();
ze_event_pool_handle_t eventPoolHandle = {};
ze_event_pool_desc_t eventPoolDesc = {};
@@ -938,6 +1214,9 @@ TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenZetMetricQueryGetDataIsCall
QueryHandle_1_0 metricsLibraryQueryHandle = {&value};
ContextHandle_1_0 metricsLibraryContextHandle = {&value};
CommandBufferSize_1_0 commandBufferSize = {};
commandBufferSize.GpuMemorySize = 100;
EXPECT_CALL(*mockMetricEnumeration, isInitialized())
.Times(1)
.WillOnce(Return(true));
@@ -969,6 +1248,14 @@ TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenZetMetricQueryGetDataIsCall
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<2>(metricsLibraryContextHandle), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockCommandBufferGetSize(_, _))
.Times(2)
.WillRepeatedly(DoAll(::testing::SetArgPointee<1>(::testing::ByRef(commandBufferSize)), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockCommandBufferGet(_))
.Times(2)
.WillRepeatedly(Return(StatusCode::Success));
EXPECT_CALL(*mockMetricsLibrary, getMetricQueryReportSize(_))
.Times(1)
.WillOnce(DoAll(::testing::SetArgReferee<0>(reportSize), Return(true)));
@@ -1021,5 +1308,140 @@ TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenZetMetricQueryGetDataIsCall
EXPECT_EQ(zetMetricQueryPoolDestroy(poolHandle), ZE_RESULT_SUCCESS);
}
TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenZetMetricQueryGetDataIsCalledThenReturnsSuccessExt) {
zet_device_handle_t metricDevice = device->toHandle();
zet_driver_handle_t driver = driverHandle->toHandle();
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, false));
zet_command_list_handle_t commandListHandle = commandList->toHandle();
ze_event_pool_handle_t eventPoolHandle = {};
ze_event_pool_desc_t eventPoolDesc = {};
eventPoolDesc.count = 1;
eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_DEFAULT;
eventPoolDesc.version = ZE_EVENT_POOL_DESC_VERSION_CURRENT;
ze_event_handle_t eventHandle = {};
ze_event_desc_t eventDesc = {};
eventDesc.index = 0;
eventDesc.version = ZE_EVENT_DESC_VERSION_CURRENT;
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
eventDesc.signal = ZE_EVENT_SCOPE_FLAG_DEVICE;
Mock<MetricGroup> metricGroup;
zet_metric_group_properties_t metricGroupProperties = {};
metricGroupProperties.samplingType = ZET_METRIC_GROUP_SAMPLING_TYPE_EVENT_BASED;
zet_metric_query_handle_t queryHandle = {};
zet_metric_query_pool_handle_t poolHandle = {};
zet_metric_query_pool_desc_t poolDesc = {};
poolDesc.version = ZET_METRIC_QUERY_POOL_DESC_VERSION_CURRENT;
poolDesc.count = 1;
poolDesc.flags = ZET_METRIC_QUERY_POOL_FLAG_PERFORMANCE;
TypedValue_1_0 value = {};
value.Type = ValueType::Uint32;
value.ValueUInt32 = 64;
size_t reportSize = 256;
QueryHandle_1_0 metricsLibraryQueryHandle = {&value};
ContextHandle_1_0 metricsLibraryContextHandle = {&value};
CommandBufferSize_1_0 commandBufferSize = {};
commandBufferSize.GpuMemorySize = 100;
EXPECT_CALL(*mockMetricEnumeration, isInitialized())
.Times(1)
.WillOnce(Return(true));
EXPECT_CALL(*mockMetricsLibrary, getContextData(_, _))
.Times(1)
.WillOnce(Return(true));
EXPECT_CALL(*mockMetricsLibrary, load())
.Times(0);
EXPECT_CALL(metricGroup, getProperties(_))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<0>(metricGroupProperties), Return(ZE_RESULT_SUCCESS)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockQueryCreate(_, _))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<1>(metricsLibraryQueryHandle), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockQueryDelete(_))
.Times(1)
.WillOnce(Return(StatusCode::Success));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockGetParameter(_, _, _))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<2>(value), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockContextCreate(_, _, _))
.Times(1)
.WillOnce(DoAll(::testing::SetArgPointee<2>(metricsLibraryContextHandle), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockCommandBufferGetSize(_, _))
.Times(2)
.WillRepeatedly(DoAll(::testing::SetArgPointee<1>(::testing::ByRef(commandBufferSize)), Return(StatusCode::Success)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockCommandBufferGet(_))
.Times(2)
.WillRepeatedly(Return(StatusCode::Success));
EXPECT_CALL(*mockMetricsLibrary, getMetricQueryReportSize(_))
.Times(1)
.WillOnce(DoAll(::testing::SetArgReferee<0>(reportSize), Return(true)));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockGetData(_))
.Times(1)
.WillOnce(Return(StatusCode::Success));
EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockContextDelete(_))
.Times(1)
.WillOnce(Return(StatusCode::Success));
// Create metric query pool.
EXPECT_EQ(zetMetricQueryPoolCreate(metricDevice, metricGroup.toHandle(), &poolDesc, &poolHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(poolHandle, nullptr);
// Create metric query.
EXPECT_EQ(zetMetricQueryCreate(poolHandle, 0, &queryHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(queryHandle, nullptr);
// Create event pool.
EXPECT_EQ(zeEventPoolCreate(driver, &eventPoolDesc, 1, &metricDevice, &eventPoolHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(eventPoolHandle, nullptr);
// Create event.
EXPECT_EQ(zeEventCreate(eventPoolHandle, &eventDesc, &eventHandle), ZE_RESULT_SUCCESS);
EXPECT_NE(eventHandle, nullptr);
// Write BEGIN metric query to command list.
EXPECT_EQ(zetCommandListAppendMetricQueryBegin(commandListHandle, queryHandle), ZE_RESULT_SUCCESS);
// Write END metric query to command list, use an event to determine if the data is available.
EXPECT_EQ(zetCommandListAppendMetricQueryEndExt(commandListHandle, queryHandle, eventHandle, 0, nullptr), ZE_RESULT_SUCCESS);
// Get desired raw data size.
size_t rawSize = 0;
EXPECT_EQ(zetMetricQueryGetData(queryHandle, &rawSize, nullptr), ZE_RESULT_SUCCESS);
// Get data.
std::vector<uint8_t> rawData;
rawData.resize(rawSize);
EXPECT_EQ(zetMetricQueryGetData(queryHandle, &rawSize, rawData.data()), ZE_RESULT_SUCCESS);
// Destroy event and its pool.
EXPECT_EQ(zeEventDestroy(eventHandle), ZE_RESULT_SUCCESS);
EXPECT_EQ(zeEventPoolDestroy(eventPoolHandle), ZE_RESULT_SUCCESS);
// Destroy query and its pool.
EXPECT_EQ(zetMetricQueryDestroy(queryHandle), ZE_RESULT_SUCCESS);
EXPECT_EQ(zetMetricQueryPoolDestroy(poolHandle), ZE_RESULT_SUCCESS);
}
} // namespace ult
} // namespace L0

View File

@@ -210,6 +210,41 @@ zetContextActivateMetricGroups(
///< metric query and metric stream must use activated metric groups.
);
///////////////////////////////////////////////////////////////////////////////
/// @brief Appends metric query end into a command list.
///
/// @details
/// - The application must ensure the metric query and events are accessible
/// by the device on which the command list was created.
/// - The application must ensure the command list, events and metric query
/// were created on the same context.
/// - The application must ensure the signal event was **not** created from
/// an event pool that was created using
/// ::ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP flag.
/// - The application must **not** call this function from simultaneous
/// threads with the same command list handle.
///
/// @returns
/// - ::ZE_RESULT_SUCCESS
/// - ::ZE_RESULT_ERROR_UNINITIALIZED
/// - ::ZE_RESULT_ERROR_DEVICE_LOST
/// - ::ZE_RESULT_ERROR_INVALID_NULL_HANDLE
/// + `nullptr == hCommandList`
/// + `nullptr == hMetricQuery`
/// - ::ZE_RESULT_ERROR_INVALID_SYNCHRONIZATION_OBJECT
/// - ::ZE_RESULT_ERROR_INVALID_SIZE
/// + `(nullptr == phWaitEvents) && (0 < numWaitEvents)`
ZE_APIEXPORT ze_result_t ZE_APICALL
zetCommandListAppendMetricQueryEndExt(
zet_command_list_handle_t hCommandList, ///< [in] handle of the command list
zet_metric_query_handle_t hMetricQuery, ///< [in] handle of the metric query
ze_event_handle_t hSignalEvent, ///< [in][optional] handle of the event to signal on completion
uint32_t numWaitEvents, ///< [in][optional] number of events to wait on before launching; must be 0
///< if `nullptr == phWaitEvents`
ze_event_handle_t *phWaitEvents ///< [in][optional][range(0, numWaitEvents)] handle of the events to wait
///< on before launching
);
#if defined(__cplusplus)
} // extern "C"
#endif