From 0bb8591e7915f2438151f074768b1aeaf4566f8a Mon Sep 17 00:00:00 2001 From: Matias Cabral Date: Fri, 8 Aug 2025 20:54:20 +0000 Subject: [PATCH] feature: support metrics calculable property Resolves: NEO-13994 Signed-off-by: Matias Cabral --- level_zero/include/level_zero/ze_stypes.h | 1 + .../include/level_zero/zet_intel_gpu_metric.h | 15 ++++++-- .../metrics/metric_ip_sampling_source.cpp | 12 +++++++ .../test_metric_ip_sampling_enumeration.cpp | 36 +++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/level_zero/include/level_zero/ze_stypes.h b/level_zero/include/level_zero/ze_stypes.h index 734298af8c..035deeacf9 100644 --- a/level_zero/include/level_zero/ze_stypes.h +++ b/level_zero/include/level_zero/ze_stypes.h @@ -47,6 +47,7 @@ using zes_structure_type_ext_t = uint32_t; #define ZET_INTEL_STRUCTURE_TYPE_METRIC_CALCULATION_DESC_EXP static_cast(0x00010009) #define ZET_INTEL_STRUCTURE_TYPE_METRIC_SOURCE_ID_EXP static_cast(0x0001000a) #define ZET_INTEL_STRUCTURE_TYPE_METRIC_DECODED_BUFFER_PROPERTIES_EXP static_cast(0x0001000b) +#define ZET_INTEL_STRUCTURE_TYPE_METRIC_CALCULABLE_PROPERTIES_EXP static_cast(0x0001000c) // Sysman structure types #define ZES_INTEL_PCI_LINK_SPEED_DOWNGRADE_EXP_STATE static_cast(0x00040001) diff --git a/level_zero/include/level_zero/zet_intel_gpu_metric.h b/level_zero/include/level_zero/zet_intel_gpu_metric.h index 8574b78d97..c2ea39787a 100644 --- a/level_zero/include/level_zero/zet_intel_gpu_metric.h +++ b/level_zero/include/level_zero/zet_intel_gpu_metric.h @@ -243,12 +243,13 @@ ze_result_t ZE_APICALL zetIntelMetricScopeGetPropertiesExp( /// @brief Metric Calculation extension Version(s) typedef enum _zet_intel_metric_calculation_exp_version_t { ZET_INTEL_METRIC_CALCULATION_EXP_VERSION_1_0 = ZE_MAKE_VERSION(1, 0), ///< version 1.0 - ZET_INTEL_METRIC_CALCULATION_EXP_VERSION_CURRENT = ZET_INTEL_METRIC_CALCULATION_EXP_VERSION_1_0, ///< latest known version + ZET_INTEL_METRIC_CALCULATION_EXP_VERSION_1_1 = ZE_MAKE_VERSION(1, 1), ///< version 1.1 + ZET_INTEL_METRIC_CALCULATION_EXP_VERSION_CURRENT = ZET_INTEL_METRIC_CALCULATION_EXP_VERSION_1_1, ///< latest known version ZET_INTEL_METRIC_CALCULATION_EXP_VERSION_FORCE_UINT32 = 0x7fffffff } zet_intel_metric_calculation_exp_version_t; /////////////////////////////////////////////////////////////////////////////// -/// @brief Query an metric group calculation properties +/// @brief Query metric group calculation properties /// This structure can be passed in the 'pNext' of zet_metric_group_properties_t typedef struct _zet_intel_metric_group_calculation_properties_exp_t { zet_structure_type_ext_t stype; ///< [in] type of this structure @@ -258,6 +259,16 @@ typedef struct _zet_intel_metric_group_calculation_properties_exp_t { ///< metrics calculation. } zet_intel_metric_group_calculation_properties_exp_t; +/////////////////////////////////////////////////////////////////////////////// +/// @brief Query a metric calculable property +/// This structure can be passed in the 'pNext' of zet_metric_properties_t +typedef struct _zet_intel_metric_calculable_properties_exp_t { + zet_structure_type_ext_t stype; ///< [in] type of this structure + void *pNext; ///< [in][optional] must be null or a pointer to an extension-specific + ///< structure (i.e. contains stype and pNext). + bool isCalculable; ///< [out] Flag to indicate if the metric supports calculation. +} zet_intel_metric_calculable_properties_exp_t; + /////////////////////////////////////////////////////////////////////////////// /// @brief Handle of metric calculation operation struct _zet_intel_metric_calculation_operation_exp_handle_t {}; diff --git a/level_zero/tools/source/metrics/metric_ip_sampling_source.cpp b/level_zero/tools/source/metrics/metric_ip_sampling_source.cpp index 35f2b535a5..4816b7b79b 100644 --- a/level_zero/tools/source/metrics/metric_ip_sampling_source.cpp +++ b/level_zero/tools/source/metrics/metric_ip_sampling_source.cpp @@ -669,7 +669,19 @@ IpSamplingMetricImp::IpSamplingMetricImp(MetricSource &metricSource, zet_metric_ } ze_result_t IpSamplingMetricImp::getProperties(zet_metric_properties_t *pProperties) { + auto pNext = pProperties->pNext; *pProperties = properties; + + while (pNext != nullptr) { + auto extendedProperties = reinterpret_cast(pNext); + if (static_cast(extendedProperties->stype) == ZET_INTEL_STRUCTURE_TYPE_METRIC_CALCULABLE_PROPERTIES_EXP) { + auto calculableProperties = reinterpret_cast(extendedProperties); + // All metrics are calculable in IP Sampling + calculableProperties->isCalculable = true; + } + pNext = extendedProperties->pNext; + } + return ZE_RESULT_SUCCESS; } diff --git a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_ip_sampling_enumeration.cpp b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_ip_sampling_enumeration.cpp index 28ad97662a..789baf00d0 100644 --- a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_ip_sampling_enumeration.cpp +++ b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_ip_sampling_enumeration.cpp @@ -245,6 +245,42 @@ HWTEST2_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenMetricG } } } + +HWTEST2_F(MetricIpSamplingEnumerationTest, GivenIpSamplingMetricsCalculablePropertyIsAlwaysTrue, EustallSupportedPlatforms) { + + EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi()); + for (auto device : testDevices) { + + uint32_t metricGroupCount = 0; + zetMetricGroupGet(device->toHandle(), &metricGroupCount, nullptr); + EXPECT_EQ(metricGroupCount, 1u); + std::vector metricGroups(metricGroupCount); + zetMetricGroupGet(device->toHandle(), &metricGroupCount, metricGroups.data()); + ASSERT_NE(metricGroups[0], nullptr); + + uint32_t metricCount = 0; + EXPECT_EQ(zetMetricGet(metricGroups[0], &metricCount, nullptr), ZE_RESULT_SUCCESS); + std::vector metricHandles(metricCount); + EXPECT_EQ(zetMetricGet(metricGroups[0], &metricCount, metricHandles.data()), ZE_RESULT_SUCCESS); + + zet_metric_properties_t ipSamplingMetricProperties = {}; + zet_intel_metric_calculable_properties_exp_t calculableProperties{}; + calculableProperties.stype = ZET_INTEL_STRUCTURE_TYPE_METRIC_CALCULABLE_PROPERTIES_EXP; + calculableProperties.pNext = nullptr; + ipSamplingMetricProperties.pNext = &calculableProperties; + + for (auto &metricHandle : metricHandles) { + EXPECT_EQ(zetMetricGetProperties(metricHandle, &ipSamplingMetricProperties), ZE_RESULT_SUCCESS); + EXPECT_TRUE(calculableProperties.isCalculable); + } + + // Check that invalid structure is handled gracefully + zet_metric_group_properties_t metricGroupProperties = {ZET_STRUCTURE_TYPE_METRIC_GROUP_PROPERTIES, nullptr}; + ipSamplingMetricProperties.pNext = &metricGroupProperties; + EXPECT_EQ(zetMetricGetProperties(metricHandles[0], &ipSamplingMetricProperties), ZE_RESULT_SUCCESS); + } +} + using IsNotGen9ThruPVC = IsNotWithinProducts; HWTEST2_F(MetricIpSamplingEnumerationTest, GivenEnableMetricAPIOnUnsupportedPlatformsThenFailureIsReturned, IsNotGen9ThruPVC) { EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi());