diff --git a/level_zero/api/tools/zet_metric.cpp b/level_zero/api/tools/zet_metric.cpp index 1d5406805f..b5d7e815ff 100644 --- a/level_zero/api/tools/zet_metric.cpp +++ b/level_zero/api/tools/zet_metric.cpp @@ -161,6 +161,16 @@ zetMetricQueryPoolCreate( return L0::metricQueryPoolCreate(hDevice, hMetricGroup, desc, phMetricQueryPool); } +__zedllexport ze_result_t __zecall +zetMetricQueryPoolCreateExt( + zet_context_handle_t hContext, + zet_device_handle_t hDevice, + zet_metric_group_handle_t hMetricGroup, + const zet_metric_query_pool_desc_ext_t *desc, + zet_metric_query_pool_handle_t *phMetricQueryPool) { + return L0::metricQueryPoolCreateExt(hContext, hDevice, hMetricGroup, desc, phMetricQueryPool); +} + __zedllexport ze_result_t __zecall zetMetricQueryPoolDestroy( zet_metric_query_pool_handle_t hMetricQueryPool) { diff --git a/level_zero/tools/source/metrics/metric.h b/level_zero/tools/source/metrics/metric.h index 66eec6aa5e..08581944c5 100644 --- a/level_zero/tools/source/metrics/metric.h +++ b/level_zero/tools/source/metrics/metric.h @@ -134,7 +134,7 @@ struct MetricQueryPool : _zet_metric_query_pool_handle_t { virtual ze_result_t createMetricQuery(uint32_t index, zet_metric_query_handle_t *phMetricQuery) = 0; - static MetricQueryPool *create(zet_device_handle_t hDevice, zet_metric_group_handle_t hMetricGroup, const zet_metric_query_pool_desc_t &desc); + static MetricQueryPool *create(zet_device_handle_t hDevice, zet_metric_group_handle_t hMetricGroup, const zet_metric_query_pool_desc_ext_t &desc); static MetricQueryPool *fromHandle(zet_metric_query_pool_handle_t handle); zet_metric_query_pool_handle_t toHandle(); @@ -176,5 +176,7 @@ ze_result_t metricTracerOpen(zet_device_handle_t hDevice, zet_metric_group_handl // MetricQueryPool. ze_result_t metricQueryPoolCreate(zet_device_handle_t hDevice, zet_metric_group_handle_t hMetricGroup, const zet_metric_query_pool_desc_t *pDesc, zet_metric_query_pool_handle_t *phMetricQueryPool); +ze_result_t metricQueryPoolCreateExt(zet_context_handle_t hContext, zet_device_handle_t hDevice, zet_metric_group_handle_t hMetricGroup, + const zet_metric_query_pool_desc_ext_t *pDesc, zet_metric_query_pool_handle_t *phMetricQueryPool); } // namespace L0 diff --git a/level_zero/tools/source/metrics/metric_query_imp.cpp b/level_zero/tools/source/metrics/metric_query_imp.cpp index 726696ac7d..ae622b3c6f 100644 --- a/level_zero/tools/source/metrics/metric_query_imp.cpp +++ b/level_zero/tools/source/metrics/metric_query_imp.cpp @@ -379,6 +379,19 @@ void MetricsLibrary::deleteAllConfigurations() { ze_result_t metricQueryPoolCreate(zet_device_handle_t hDevice, zet_metric_group_handle_t hMetricGroup, const zet_metric_query_pool_desc_t *pDesc, zet_metric_query_pool_handle_t *phMetricQueryPool) { + zet_metric_query_pool_desc_ext_t descExt = {}; + descExt.stype = ZET_STRUCTURE_TYPE_METRIC_QUERY_POOL_DESC; + descExt.type = (pDesc->flags == ZET_METRIC_QUERY_POOL_FLAG_PERFORMANCE) + ? ZET_METRIC_QUERY_POOL_TYPE_PERFORMANCE + : ZET_METRIC_QUERY_POOL_TYPE_EXECUTION; + descExt.count = pDesc->count; + + return metricQueryPoolCreateExt(nullptr, hDevice, hMetricGroup, &descExt, phMetricQueryPool); +} + +ze_result_t metricQueryPoolCreateExt(zet_context_handle_t hContext, zet_device_handle_t hDevice, zet_metric_group_handle_t hMetricGroup, + const zet_metric_query_pool_desc_ext_t *pDesc, zet_metric_query_pool_handle_t *phMetricQueryPool) { + auto device = Device::fromHandle(hDevice); auto &metricContext = device->getMetricContext(); @@ -397,7 +410,7 @@ ze_result_t metricQueryPoolCreate(zet_device_handle_t hDevice, zet_metric_group_ MetricQueryPool *MetricQueryPool::create(zet_device_handle_t hDevice, zet_metric_group_handle_t hMetricGroup, - const zet_metric_query_pool_desc_t &desc) { + const zet_metric_query_pool_desc_ext_t &desc) { auto device = Device::fromHandle(hDevice); auto metricPoolImp = new MetricQueryPoolImp(device->getMetricContext(), hMetricGroup, desc); @@ -411,14 +424,14 @@ MetricQueryPool *MetricQueryPool::create(zet_device_handle_t hDevice, MetricQueryPoolImp::MetricQueryPoolImp(MetricContext &metricContextInput, zet_metric_group_handle_t hEventMetricGroupInput, - const zet_metric_query_pool_desc_t &poolDescription) + const zet_metric_query_pool_desc_ext_t &poolDescription) : metricContext(metricContextInput), metricsLibrary(metricContext.getMetricsLibrary()), description(poolDescription), hMetricGroup(hEventMetricGroupInput) {} bool MetricQueryPoolImp::create() { - switch (description.flags) { - case ZET_METRIC_QUERY_POOL_FLAG_PERFORMANCE: + switch (description.type) { + case ZET_METRIC_QUERY_POOL_TYPE_PERFORMANCE: return createMetricQueryPool(); default: @@ -428,8 +441,8 @@ bool MetricQueryPoolImp::create() { } ze_result_t MetricQueryPoolImp::destroy() { - switch (description.flags) { - case ZET_METRIC_QUERY_POOL_FLAG_PERFORMANCE: + switch (description.type) { + case ZET_METRIC_QUERY_POOL_TYPE_PERFORMANCE: DEBUG_BREAK_IF(!(pAllocation && query.IsValid())); metricContext.getDevice().getDriverHandle()->getMemoryManager()->freeGraphicsMemory(pAllocation); metricsLibrary.destroyMetricQuery(query); @@ -487,8 +500,8 @@ MetricQueryImp::MetricQueryImp(MetricContext &metricContextInput, MetricQueryPoo ze_result_t MetricQueryImp::appendBegin(CommandList &commandList) { - switch (pool.description.flags) { - case ZET_METRIC_QUERY_POOL_FLAG_PERFORMANCE: + switch (pool.description.type) { + case ZET_METRIC_QUERY_POOL_TYPE_PERFORMANCE: return writeMetricQuery(commandList, nullptr, 0, nullptr, true); default: @@ -499,8 +512,8 @@ ze_result_t MetricQueryImp::appendBegin(CommandList &commandList) { 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: + switch (pool.description.type) { + case ZET_METRIC_QUERY_POOL_TYPE_PERFORMANCE: return writeMetricQuery(commandList, hSignalEvent, numWaitEvents, phWaitEvents, false); default: diff --git a/level_zero/tools/source/metrics/metric_query_imp.h b/level_zero/tools/source/metrics/metric_query_imp.h index 06b18a7729..8e70e8ae81 100644 --- a/level_zero/tools/source/metrics/metric_query_imp.h +++ b/level_zero/tools/source/metrics/metric_query_imp.h @@ -123,7 +123,7 @@ struct MetricQueryImp : MetricQuery { struct MetricQueryPoolImp : MetricQueryPool { public: - MetricQueryPoolImp(MetricContext &metricContext, zet_metric_group_handle_t hEventMetricGroup, const zet_metric_query_pool_desc_t &poolDescription); + MetricQueryPoolImp(MetricContext &metricContext, zet_metric_group_handle_t hEventMetricGroup, const zet_metric_query_pool_desc_ext_t &poolDescription); bool create(); ze_result_t destroy() override; @@ -138,7 +138,7 @@ struct MetricQueryPoolImp : MetricQueryPool { MetricsLibrary &metricsLibrary; std::vector pool; NEO::GraphicsAllocation *pAllocation = nullptr; - zet_metric_query_pool_desc_t description = {}; + zet_metric_query_pool_desc_ext_t description = {}; zet_metric_group_handle_t hMetricGroup = nullptr; QueryHandle_1_0 query = {}; }; diff --git a/level_zero/tools/test/unit_tests/sources/metrics/CMakeLists.txt b/level_zero/tools/test/unit_tests/sources/metrics/CMakeLists.txt index a50cf78cd6..b1c999e24b 100644 --- a/level_zero/tools/test/unit_tests/sources/metrics/CMakeLists.txt +++ b/level_zero/tools/test/unit_tests/sources/metrics/CMakeLists.txt @@ -11,7 +11,8 @@ target_sources(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/mock_metric_enumeration.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_metric_enumeration.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_metric_enumeration.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test_metric_query_pool.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_metric_query_pool_1.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_metric_query_pool_2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_metric_streamer.cpp ) diff --git a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool.cpp b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_1.cpp similarity index 73% rename from level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool.cpp rename to level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_1.cpp index 843d2ee907..7ad6a53c24 100644 --- a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool.cpp +++ b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_1.cpp @@ -825,122 +825,6 @@ 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 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; - zet_metric_group_properties_ext_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, getPropertiesExt(_)) - .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(); @@ -1057,122 +941,6 @@ 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 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; - zet_metric_group_properties_ext_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, getPropertiesExt(_)) - .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(); @@ -1308,140 +1076,5 @@ 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 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; - zet_metric_group_properties_ext_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, getPropertiesExt(_)) - .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 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 diff --git a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_2.cpp b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_2.cpp new file mode 100644 index 0000000000..0369945703 --- /dev/null +++ b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_2.cpp @@ -0,0 +1,640 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/device_factory.h" + +#include "test.h" + +#include "level_zero/core/source/driver/driver_imp.h" +#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" +#include "level_zero/core/test/unit_tests/mocks/mock_device.h" +#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" +#include "level_zero/tools/test/unit_tests/sources/metrics/mock_metric.h" + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +using ::testing::_; +using ::testing::Return; + +namespace L0 { +namespace ult { + +class MetricQueryPoolTest : public MetricContextFixture, + public ::testing::Test { + public: + void SetUp() override { + MetricContextFixture::SetUp(); + auto executionEnvironment = new NEO::ExecutionEnvironment(); + driverHandle.reset(DriverHandle::create(NEO::DeviceFactory::createDevices(*executionEnvironment), L0EnvVariables{})); + } + + void TearDown() override { + MetricContextFixture::TearDown(); + driverHandle.reset(); + GlobalDriver = nullptr; + } + std::unique_ptr driverHandle; +}; + +TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenZetMetricQueryPoolCreateExtIsCalledThenQueryPoolIsObtained) { + + zet_device_handle_t metricDevice = device->toHandle(); + + Mock metricGroup; + zet_metric_group_properties_ext_t metricGroupProperties = {}; + metricGroupProperties.samplingType = ZET_METRIC_GROUP_SAMPLING_TYPE_EVENT_BASED; + + zet_metric_query_pool_handle_t poolHandle = {}; + zet_metric_query_pool_desc_ext_t poolDesc = {}; + poolDesc.stype = ZET_STRUCTURE_TYPE_METRIC_QUERY_POOL_DESC; + poolDesc.count = 1; + poolDesc.type = ZET_METRIC_QUERY_POOL_TYPE_PERFORMANCE; + + TypedValue_1_0 value = {}; + value.Type = ValueType::Uint32; + value.ValueUInt32 = 64; + + QueryHandle_1_0 queryHandle = {&value}; + ContextHandle_1_0 contextHandle = {&value}; + + 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, getPropertiesExt(_)) + .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>(queryHandle), 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>(contextHandle), Return(StatusCode::Success))); + + EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockContextDelete(_)) + .Times(1) + .WillOnce(Return(StatusCode::Success)); + + EXPECT_EQ(zetMetricQueryPoolCreateExt(context->toHandle(), metricDevice, metricGroup.toHandle(), &poolDesc, &poolHandle), ZE_RESULT_SUCCESS); + EXPECT_NE(poolHandle, nullptr); + EXPECT_EQ(zetMetricQueryPoolDestroy(poolHandle), ZE_RESULT_SUCCESS); +} + +TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenStreamerIsOpenThenQueryPoolExtIsNotAvailable) { + + zet_device_handle_t metricDevice = device->toHandle(); + + ze_event_handle_t eventHandle = {}; + + zet_metric_streamer_handle_t streamerHandle = {}; + zet_metric_streamer_desc_t streamerDesc = {}; + + streamerDesc.stype = ZET_STRUCTURE_TYPE_METRIC_STREAMER_DESC; + streamerDesc.notifyEveryNReports = 32768; + streamerDesc.samplingPeriod = 1000; + + Mock metricGroup; + zet_metric_group_handle_t metricGroupHandle = metricGroup.toHandle(); + zet_metric_group_properties_t metricGroupProperties = {}; + + metricsDeviceParams.ConcurrentGroupsCount = 1; + + Mock metricsConcurrentGroup; + TConcurrentGroupParams_1_0 metricsConcurrentGroupParams = {}; + metricsConcurrentGroupParams.MetricSetsCount = 1; + metricsConcurrentGroupParams.SymbolName = "OA"; + metricsConcurrentGroupParams.Description = "OA description"; + + Mock metricsSet; + MetricsDiscovery::TMetricSetParams_1_4 metricsSetParams = {}; + metricsSetParams.ApiMask = MetricsDiscovery::API_TYPE_IOSTREAM; + metricsSetParams.MetricsCount = 0; + metricsSetParams.SymbolName = "Metric set name"; + metricsSetParams.ShortName = "Metric set description"; + metricsSetParams.RawReportSize = 256; + + zet_metric_query_pool_handle_t poolHandle = {}; + zet_metric_query_pool_desc_ext_t poolDesc = {}; + poolDesc.stype = ZET_STRUCTURE_TYPE_METRIC_QUERY_POOL_DESC; + poolDesc.count = 1; + poolDesc.type = ZET_METRIC_QUERY_POOL_TYPE_PERFORMANCE; + + TypedValue_1_0 value = {}; + value.Type = ValueType::Uint32; + value.ValueUInt32 = 64; + + QueryHandle_1_0 queryHandle = {&value}; + ContextHandle_1_0 contextHandle = {&value}; + + EXPECT_CALL(*mockMetricsLibrary, load()) + .Times(0); + + EXPECT_CALL(*mockMetricEnumeration, loadMetricsDiscovery()) + .Times(0); + + EXPECT_CALL(*mockMetricEnumeration->g_mockApi, MockOpenMetricsDevice(_)) + .Times(1) + .WillOnce(DoAll(::testing::SetArgPointee<0>(&metricsDevice), Return(TCompletionCode::CC_OK))); + + EXPECT_CALL(*mockMetricEnumeration->g_mockApi, MockCloseMetricsDevice(_)) + .Times(1) + .WillOnce(Return(TCompletionCode::CC_OK)); + + EXPECT_CALL(metricsDevice, GetParams()) + .WillRepeatedly(Return(&metricsDeviceParams)); + + EXPECT_CALL(metricsDevice, GetConcurrentGroup(_)) + .Times(1) + .WillOnce(Return(&metricsConcurrentGroup)); + + EXPECT_CALL(metricsConcurrentGroup, GetParams()) + .Times(1) + .WillRepeatedly(Return(&metricsConcurrentGroupParams)); + + EXPECT_CALL(metricsConcurrentGroup, GetMetricSet(_)) + .WillRepeatedly(Return(&metricsSet)); + + EXPECT_CALL(metricsSet, GetParams()) + .WillRepeatedly(Return(&metricsSetParams)); + + EXPECT_CALL(metricsSet, SetApiFiltering(_)) + .WillRepeatedly(Return(TCompletionCode::CC_OK)); + + EXPECT_CALL(metricsConcurrentGroup, OpenIoStream(_, _, _, _)) + .Times(1) + .WillOnce(Return(TCompletionCode::CC_OK)); + + EXPECT_CALL(metricsConcurrentGroup, CloseIoStream()) + .Times(1) + .WillOnce(Return(TCompletionCode::CC_OK)); + + uint32_t metricGroupCount = 0; + EXPECT_EQ(zetMetricGroupGet(metricDevice, &metricGroupCount, nullptr), ZE_RESULT_SUCCESS); + EXPECT_EQ(metricGroupCount, 1u); + + EXPECT_EQ(zetMetricGroupGet(metricDevice, &metricGroupCount, &metricGroupHandle), ZE_RESULT_SUCCESS); + EXPECT_EQ(metricGroupCount, 1u); + EXPECT_NE(metricGroupHandle, nullptr); + + EXPECT_EQ(zetMetricGroupGetProperties(metricGroupHandle, &metricGroupProperties), ZE_RESULT_SUCCESS); + EXPECT_EQ(metricGroupProperties.domain, 0u); + EXPECT_EQ(metricGroupProperties.samplingType, ZET_METRIC_GROUP_SAMPLING_TYPE_TIME_BASED); + EXPECT_EQ(metricGroupProperties.metricCount, metricsSetParams.MetricsCount); + EXPECT_EQ(strcmp(metricGroupProperties.description, metricsSetParams.ShortName), 0); + EXPECT_EQ(strcmp(metricGroupProperties.name, metricsSetParams.SymbolName), 0); + + EXPECT_EQ(zetDeviceActivateMetricGroups(metricDevice, 1, &metricGroupHandle), ZE_RESULT_SUCCESS); + + EXPECT_EQ(zetMetricStreamerOpen(metricDevice, metricGroupHandle, &streamerDesc, eventHandle, &streamerHandle), ZE_RESULT_SUCCESS); + EXPECT_NE(streamerHandle, nullptr); + + EXPECT_EQ(zetMetricQueryPoolCreateExt(context->toHandle(), metricDevice, metricGroupHandle, &poolDesc, &poolHandle), ZE_RESULT_ERROR_NOT_AVAILABLE); + + EXPECT_EQ(zetMetricStreamerClose(streamerHandle), ZE_RESULT_SUCCESS); + EXPECT_NE(streamerHandle, nullptr); +} + +TEST_F(MetricQueryPoolTest, givenIncorrectMetricGroupTypeWhenZetMetricQueryPoolCreateExtIsCalledThenReturnsFail) { + + zet_device_handle_t metricDevice = device->toHandle(); + + Mock metricGroup; + zet_metric_group_properties_ext_t metricGroupProperties = {}; + metricGroupProperties.samplingType = ZET_METRIC_GROUP_SAMPLING_TYPE_TIME_BASED; + + zet_metric_query_pool_handle_t poolHandle = {}; + zet_metric_query_pool_desc_ext_t poolDesc = {}; + poolDesc.stype = ZET_STRUCTURE_TYPE_METRIC_QUERY_POOL_DESC; + poolDesc.count = 1; + poolDesc.type = ZET_METRIC_QUERY_POOL_TYPE_PERFORMANCE; + + TypedValue_1_0 value = {}; + value.Type = ValueType::Uint32; + value.ValueUInt32 = 64; + + QueryHandle_1_0 queryHandle = {&value}; + ContextHandle_1_0 contextHandle = {&value}; + + EXPECT_CALL(*mockMetricEnumeration, isInitialized()) + .Times(0); + + EXPECT_CALL(*mockMetricsLibrary, getContextData(_, _)) + .Times(0); + + EXPECT_CALL(*mockMetricsLibrary, load()) + .Times(0); + + EXPECT_CALL(metricGroup, getPropertiesExt(_)) + .Times(1) + .WillOnce(DoAll(::testing::SetArgPointee<0>(metricGroupProperties), Return(ZE_RESULT_SUCCESS))); + + EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockQueryCreate(_, _)) + .Times(0); + + EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockQueryDelete(_)) + .Times(0); + + EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockGetParameter(_, _, _)) + .Times(0); + + EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockContextCreate(_, _, _)) + .Times(0); + + EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockContextDelete(_)) + .Times(0); + + EXPECT_EQ(zetMetricQueryPoolCreateExt(context->toHandle(), metricDevice, metricGroup.toHandle(), &poolDesc, &poolHandle), ZE_RESULT_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(poolHandle, nullptr); +} + +TEST_F(MetricQueryPoolTest, givenCorrectArgumentsWhenZetCommandListAppendMetricQueryEndExtIsCalledThenReturnsSuccess) { + + zet_device_handle_t metricDevice = device->toHandle(); + zet_driver_handle_t driver = driverHandle->toHandle(); + + std::unique_ptr 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; + zet_metric_group_properties_ext_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, getPropertiesExt(_)) + .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, givenIncorrectArgumentsWhenZetMetricQueryGetDataIsCalledThenReturnsFailExt) { + + zet_device_handle_t metricDevice = device->toHandle(); + zet_driver_handle_t driver = driverHandle->toHandle(); + + std::unique_ptr 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; + zet_metric_group_properties_ext_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, getPropertiesExt(_)) + .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, givenCorrectArgumentsWhenZetMetricQueryGetDataIsCalledThenReturnsSuccessExt) { + + zet_device_handle_t metricDevice = device->toHandle(); + zet_driver_handle_t driver = driverHandle->toHandle(); + + std::unique_ptr 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; + zet_metric_group_properties_ext_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, getPropertiesExt(_)) + .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 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 diff --git a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_streamer.cpp b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_streamer.cpp index 7469c0ae7f..fd11bef66b 100644 --- a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_streamer.cpp +++ b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_streamer.cpp @@ -296,6 +296,202 @@ TEST_F(MetricStreamerTest, givenValidArgumentsWhenZetMetricTracerOpenIsCalledThe EXPECT_NE(tracerHandle, nullptr); } +TEST_F(MetricStreamerTest, givenValidArgumentsWhenZetMetricStreamerOpenIsCalledTwiceThenReturnsObjectInUse) { + + // One api: device handle. + zet_device_handle_t metricDeviceHandle = device->toHandle(); + + // One api: event handle. + ze_event_handle_t eventHandle = {}; + + // One api: streamer handle. + zet_metric_streamer_handle_t firstStreamerHandle = {}; + zet_metric_streamer_handle_t secondStreamerHandle = {}; + zet_metric_streamer_desc_t streamerDesc = {}; + + streamerDesc.stype = ZET_STRUCTURE_TYPE_METRIC_STREAMER_DESC; + streamerDesc.notifyEveryNReports = 32768; + streamerDesc.samplingPeriod = 1000; + + // One api: metric group handle. + Mock metricGroup; + zet_metric_group_handle_t metricGroupHandle = metricGroup.toHandle(); + zet_metric_group_properties_t metricGroupProperties = {}; + + // Metrics Discovery device. + metricsDeviceParams.ConcurrentGroupsCount = 1; + + // Metrics Discovery concurrent group. + Mock metricsConcurrentGroup; + TConcurrentGroupParams_1_0 metricsConcurrentGroupParams = {}; + metricsConcurrentGroupParams.MetricSetsCount = 1; + metricsConcurrentGroupParams.SymbolName = "OA"; + metricsConcurrentGroupParams.Description = "OA description"; + + // Metrics Discovery metric set. + Mock metricsSet; + MetricsDiscovery::TMetricSetParams_1_4 metricsSetParams = {}; + metricsSetParams.ApiMask = MetricsDiscovery::API_TYPE_IOSTREAM; + metricsSetParams.MetricsCount = 0; + metricsSetParams.SymbolName = "Metric set name"; + metricsSetParams.ShortName = "Metric set description"; + metricsSetParams.RawReportSize = 256; + + EXPECT_CALL(*mockMetricEnumeration, loadMetricsDiscovery()) + .Times(0); + + EXPECT_CALL(*mockMetricEnumeration->g_mockApi, MockOpenMetricsDevice(_)) + .Times(1) + .WillOnce(DoAll(::testing::SetArgPointee<0>(&metricsDevice), Return(TCompletionCode::CC_OK))); + + EXPECT_CALL(*mockMetricEnumeration->g_mockApi, MockCloseMetricsDevice(_)) + .Times(1) + .WillOnce(Return(TCompletionCode::CC_OK)); + + EXPECT_CALL(metricsDevice, GetParams()) + .WillRepeatedly(Return(&metricsDeviceParams)); + + EXPECT_CALL(metricsDevice, GetConcurrentGroup(_)) + .Times(1) + .WillOnce(Return(&metricsConcurrentGroup)); + + EXPECT_CALL(metricsConcurrentGroup, GetParams()) + .Times(1) + .WillRepeatedly(Return(&metricsConcurrentGroupParams)); + + EXPECT_CALL(metricsConcurrentGroup, GetMetricSet(_)) + .WillRepeatedly(Return(&metricsSet)); + + EXPECT_CALL(metricsSet, GetParams()) + .WillRepeatedly(Return(&metricsSetParams)); + + EXPECT_CALL(metricsSet, SetApiFiltering(_)) + .WillRepeatedly(Return(TCompletionCode::CC_OK)); + + EXPECT_CALL(metricsConcurrentGroup, OpenIoStream(_, _, _, _)) + .Times(1) + .WillOnce(Return(TCompletionCode::CC_OK)); + + EXPECT_CALL(metricsConcurrentGroup, CloseIoStream()) + .Times(1) + .WillOnce(Return(TCompletionCode::CC_OK)); + + // Metric group count. + uint32_t metricGroupCount = 0; + EXPECT_EQ(zetMetricGroupGet(metricDeviceHandle, &metricGroupCount, nullptr), ZE_RESULT_SUCCESS); + EXPECT_EQ(metricGroupCount, 1u); + + // Metric group handle. + EXPECT_EQ(zetMetricGroupGet(metricDeviceHandle, &metricGroupCount, &metricGroupHandle), ZE_RESULT_SUCCESS); + EXPECT_EQ(metricGroupCount, 1u); + EXPECT_NE(metricGroupHandle, nullptr); + + // Metric group properties. + EXPECT_EQ(zetMetricGroupGetProperties(metricGroupHandle, &metricGroupProperties), ZE_RESULT_SUCCESS); + EXPECT_EQ(metricGroupProperties.domain, 0u); + EXPECT_EQ(metricGroupProperties.samplingType, ZET_METRIC_GROUP_SAMPLING_TYPE_TIME_BASED); + EXPECT_EQ(metricGroupProperties.metricCount, metricsSetParams.MetricsCount); + EXPECT_EQ(strcmp(metricGroupProperties.description, metricsSetParams.ShortName), 0); + EXPECT_EQ(strcmp(metricGroupProperties.name, metricsSetParams.SymbolName), 0); + + // Metric group activation. + EXPECT_EQ(zetDeviceActivateMetricGroups(metricDeviceHandle, 1, &metricGroupHandle), ZE_RESULT_SUCCESS); + + // Metric streamer open. + EXPECT_EQ(zetMetricStreamerOpen(metricDeviceHandle, metricGroupHandle, &streamerDesc, eventHandle, &firstStreamerHandle), ZE_RESULT_SUCCESS); + EXPECT_NE(firstStreamerHandle, nullptr); + + EXPECT_EQ(zetMetricStreamerOpen(metricDeviceHandle, metricGroupHandle, &streamerDesc, eventHandle, &secondStreamerHandle), ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE); + EXPECT_EQ(secondStreamerHandle, nullptr); + + // Metric streamer close. + EXPECT_EQ(zetMetricStreamerClose(firstStreamerHandle), ZE_RESULT_SUCCESS); + EXPECT_NE(firstStreamerHandle, nullptr); +} + +TEST_F(MetricStreamerTest, givenCorrectArgumentsWhenZetMetricQueryPoolCreateExtIsCalledThenMetricStreamerIsNotAvailable) { + + // One api: device handle. + zet_device_handle_t metricDevice = device->toHandle(); + + // One api: event handle. + ze_event_handle_t eventHandle = {}; + + // One api: streamer handle. + zet_metric_streamer_handle_t streamerHandle = {}; + zet_metric_streamer_desc_t streamerDesc = {}; + + streamerDesc.stype = ZET_STRUCTURE_TYPE_METRIC_STREAMER_DESC; + streamerDesc.notifyEveryNReports = 32768; + streamerDesc.samplingPeriod = 1000; + + // One api: metric group handle. + Mock metricGroup; + zet_metric_group_handle_t metricGroupHandle = metricGroup.toHandle(); + zet_metric_group_properties_ext_t metricGroupProperties = {}; + metricGroupProperties.samplingType = ZET_METRIC_GROUP_SAMPLING_TYPE_EVENT_BASED; + + // One api: query pool handle. + zet_metric_query_pool_handle_t poolHandle = {}; + zet_metric_query_pool_desc_ext_t poolDesc = {}; + poolDesc.stype = ZET_STRUCTURE_TYPE_METRIC_QUERY_POOL_DESC; + poolDesc.count = 1; + poolDesc.type = ZET_METRIC_QUERY_POOL_TYPE_PERFORMANCE; + + TypedValue_1_0 value = {}; + value.Type = ValueType::Uint32; + value.ValueUInt32 = 64; + + QueryHandle_1_0 queryHandle = {&value}; + ContextHandle_1_0 contextHandle = {&value}; + + 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, getPropertiesExt(_)) + .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>(queryHandle), 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>(contextHandle), Return(StatusCode::Success))); + + EXPECT_CALL(*mockMetricsLibrary->g_mockApi, MockContextDelete(_)) + .Times(1) + .WillOnce(Return(StatusCode::Success)); + + // Metric query pool create. + EXPECT_EQ(zetMetricQueryPoolCreateExt(context->toHandle(), metricDevice, metricGroup.toHandle(), &poolDesc, &poolHandle), ZE_RESULT_SUCCESS); + EXPECT_NE(poolHandle, nullptr); + + // Metric streamer open. + EXPECT_EQ(zetMetricStreamerOpen(metricDevice, metricGroupHandle, &streamerDesc, eventHandle, &streamerHandle), ZE_RESULT_ERROR_NOT_AVAILABLE); + EXPECT_EQ(streamerHandle, nullptr); + + // Metric query pool destroy. + EXPECT_EQ(zetMetricQueryPoolDestroy(poolHandle), ZE_RESULT_SUCCESS); +} + TEST_F(MetricStreamerTest, givenInvalidArgumentsWhenZetMetricStreamerReadDataIsCalledThenReturnsFail) { // One api: device handle. diff --git a/third_party/level_zero/zet_api_ext.h b/third_party/level_zero/zet_api_ext.h index 7e7b7252df..683fdbe2a3 100644 --- a/third_party/level_zero/zet_api_ext.h +++ b/third_party/level_zero/zet_api_ext.h @@ -53,6 +53,10 @@ typedef enum _zet_structure_type_t { /// @brief Forward-declare zet_metric_streamer_desc_t typedef struct _zet_metric_streamer_desc_t zet_metric_streamer_desc_t; +/////////////////////////////////////////////////////////////////////////////// +/// @brief Forward-declare zet_metric_query_pool_desc_ext_t +typedef struct _zet_metric_query_pool_desc_ext_t zet_metric_query_pool_desc_ext_t; + /////////////////////////////////////////////////////////////////////////////// /// @brief Metric streamer descriptor typedef struct _zet_metric_streamer_desc_t { @@ -172,6 +176,54 @@ zetMetricStreamerReadData( ///< reports in raw format ); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Metric query pool types +typedef enum _zet_metric_query_pool_type_t { + ZET_METRIC_QUERY_POOL_TYPE_PERFORMANCE = 0, ///< Performance metric query pool. + ZET_METRIC_QUERY_POOL_TYPE_EXECUTION = 1, ///< Skips workload execution between begin/end calls. + ZET_METRIC_QUERY_POOL_TYPE_FORCE_UINT32 = 0x7fffffff + +} zet_metric_query_pool_type_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Metric query pool description +typedef struct _zet_metric_query_pool_desc_ext_t { + zet_structure_type_t stype; ///< [in] type of this structure + const void *pNext; ///< [in][optional] pointer to extension-specific structure + zet_metric_query_pool_type_t type; ///< [in] Query pool type. + uint32_t count; ///< [in] Internal slots count within query pool object. + +} zet_metric_query_pool_desc_ext_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Creates a pool of metric queries on the context. +/// +/// @details +/// - The application may call this function from simultaneous threads. +/// - The implementation of this function must be thread-safe. +/// +/// @returns +/// - ::ZE_RESULT_SUCCESS +/// - ::ZE_RESULT_ERROR_UNINITIALIZED +/// - ::ZE_RESULT_ERROR_DEVICE_LOST +/// - ::ZE_RESULT_ERROR_INVALID_NULL_HANDLE +/// + `nullptr == hContext` +/// + `nullptr == hDevice` +/// + `nullptr == hMetricGroup` +/// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER +/// + `nullptr == desc` +/// + `nullptr == phMetricQueryPool` +/// - ::ZE_RESULT_ERROR_INVALID_ENUMERATION +/// + `::ZET_METRIC_QUERY_POOL_TYPE_EXECUTION < desc->type` +ZE_APIEXPORT ze_result_t ZE_APICALL +zetMetricQueryPoolCreateExt( + zet_context_handle_t hContext, ///< [in] handle of the context object + zet_device_handle_t hDevice, ///< [in] handle of the device + zet_metric_group_handle_t hMetricGroup, ///< [in] metric group associated with the query object. + const zet_metric_query_pool_desc_ext_t *desc, ///< [in] metric query pool descriptor + zet_metric_query_pool_handle_t *phMetricQueryPool ///< [out] handle of metric query pool +); + /////////////////////////////////////////////////////////////////////////////// /// @brief Activates metric groups. ///