mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-23 03:33:13 +08:00
Metric Api: Wait events for zetCommandListAppendMetricQueryEnd
Change-Id: I6fdf470035c1fc1f44d66778ec35ec47d0521e4d Signed-off-by: Robert Krzemien <robert.krzemien@intel.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user