feature: Metrics properties show metric scopes in Tracelib

Related-To: NEO-15832

Signed-off-by: Shreyas Kunder <shreyas.kunder@intel.com>
This commit is contained in:
Shreyas Kunder
2025-09-09 22:29:20 +00:00
committed by Compute-Runtime-Automation
parent c08aa1d400
commit 5c6ae48d17
6 changed files with 97 additions and 1 deletions

View File

@@ -127,6 +127,10 @@ ze_result_t ZE_APICALL zetIntelMetricScopeGetPropertiesExp(zet_intel_metric_scop
return L0::metricScopeGetProperties(hMetricScope, pMetricScopeProperties); return L0::metricScopeGetProperties(hMetricScope, pMetricScopeProperties);
} }
ze_result_t ZE_APICALL zetIntelMetricSupportedScopesGetExp(zet_metric_handle_t *phMetric, uint32_t *pCount, zet_intel_metric_scope_exp_handle_t *phScopes) {
return L0::getMetricSupportedScopes(phMetric, pCount, phScopes);
}
} // namespace L0 } // namespace L0
extern "C" { extern "C" {
@@ -269,4 +273,8 @@ ze_result_t ZE_APICALL zetIntelMetricScopeGetPropertiesExp(zet_intel_metric_scop
return L0::zetIntelMetricScopeGetPropertiesExp(hMetricScope, pMetricScopeProperties); return L0::zetIntelMetricScopeGetPropertiesExp(hMetricScope, pMetricScopeProperties);
} }
ze_result_t ZE_APICALL zetIntelMetricSupportedScopesGetExp(zet_metric_handle_t *phMetric, uint32_t *pCount, zet_intel_metric_scope_exp_handle_t *phScopes) {
return L0::getMetricSupportedScopes(phMetric, pCount, phScopes);
}
} // extern "C" } // extern "C"

View File

@@ -127,6 +127,7 @@ void *ExtensionFunctionAddressHelper::getExtensionFunctionAddress(const std::str
RETURN_FUNC_PTR_IF_EXIST(zetIntelMetricCalculationOperationGetReportFormatExp); RETURN_FUNC_PTR_IF_EXIST(zetIntelMetricCalculationOperationGetReportFormatExp);
RETURN_FUNC_PTR_IF_EXIST(zetIntelMetricDecodeCalculateMultipleValuesExp); RETURN_FUNC_PTR_IF_EXIST(zetIntelMetricDecodeCalculateMultipleValuesExp);
RETURN_FUNC_PTR_IF_EXIST(zetIntelMetricCalculateValuesExp); RETURN_FUNC_PTR_IF_EXIST(zetIntelMetricCalculateValuesExp);
RETURN_FUNC_PTR_IF_EXIST(zetIntelMetricSupportedScopesGetExp);
// Graphs // Graphs
RETURN_FUNC_PTR_IF_EXIST(zeGraphCreateExp); RETURN_FUNC_PTR_IF_EXIST(zeGraphCreateExp);

View File

@@ -196,7 +196,8 @@ ze_result_t ZE_APICALL zetIntelMetricTracerDecodeExp(
#endif // ZET_INTEL_METRIC_SCOPES_EXP_NAME #endif // ZET_INTEL_METRIC_SCOPES_EXP_NAME
typedef enum _zet_intel_metric_scopes_exp_version_t { typedef enum _zet_intel_metric_scopes_exp_version_t {
ZET_INTEL_METRIC_SCOPES_EXP_VERSION_1_0 = ZE_MAKE_VERSION(1, 0), ///< version 1.0 ZET_INTEL_METRIC_SCOPES_EXP_VERSION_1_0 = ZE_MAKE_VERSION(1, 0), ///< version 1.0
ZET_INTEL_METRIC_SCOPES_EXP_VERSION_CURRENT = ZET_INTEL_METRIC_SCOPES_EXP_VERSION_1_0, ///< latest known version ZET_INTEL_METRIC_SCOPES_EXP_VERSION_1_1 = ZE_MAKE_VERSION(1, 1), ///< version 1.1
ZET_INTEL_METRIC_SCOPES_EXP_VERSION_CURRENT = ZET_INTEL_METRIC_SCOPES_EXP_VERSION_1_1, ///< latest known version
ZET_INTEL_METRIC_SCOPES_EXP_VERSION_FORCE_UINT32 = 0x7fffffff ZET_INTEL_METRIC_SCOPES_EXP_VERSION_FORCE_UINT32 = 0x7fffffff
} zet_intel_metric_scopes_exp_version_t; } zet_intel_metric_scopes_exp_version_t;
@@ -236,6 +237,16 @@ ze_result_t ZE_APICALL zetIntelMetricScopeGetPropertiesExp(
zet_intel_metric_scope_exp_handle_t hMetricScope, ///< [in] handle of the metric scope zet_intel_metric_scope_exp_handle_t hMetricScope, ///< [in] handle of the metric scope
zet_intel_metric_scope_properties_exp_t *pMetricScopeProperties); ///< [out] pointer to the metric scope properties structure zet_intel_metric_scope_properties_exp_t *pMetricScopeProperties); ///< [out] pointer to the metric scope properties structure
ze_result_t ZE_APICALL zetIntelMetricSupportedScopesGetExp(
zet_metric_handle_t *phMetric, ///< [in] handle of the metric
uint32_t *pCount, ///< [in,out] pointer to the number of metric scopes available for the metric.
///< If set to zero, then the driver shall update the value with the total
///< number of metric scopes available for the metric.
zet_intel_metric_scope_exp_handle_t *phScopes); ///< [out][optional] [range(0, *pCount)] array of metric scopes handles
///< available for the metric. If pCount is greater than zero but
///< less than the total number of metric scopes available for the metric,
///< then driver shall only return that number of metric scopes.
#ifndef ZET_INTEL_METRIC_CALCULATION_EXP_NAME #ifndef ZET_INTEL_METRIC_CALCULATION_EXP_NAME
/// @brief Extension name to query Intel Metric Calculation operations /// @brief Extension name to query Intel Metric Calculation operations
#define ZET_INTEL_METRIC_CALCULATION_EXP_NAME "ZET_intel_metric_calculation" #define ZET_INTEL_METRIC_CALCULATION_EXP_NAME "ZET_intel_metric_calculation"

View File

@@ -743,6 +743,19 @@ MetricImp *MultiDeviceMetricImp::getMetricAtSubDeviceIndex(uint32_t index) {
return nullptr; return nullptr;
} }
ze_result_t MetricImp::getScopes(uint32_t *pCount, zet_intel_metric_scope_exp_handle_t *phScopes) {
if (*pCount == 0) {
*pCount = static_cast<uint32_t>(scopes.size());
return ZE_RESULT_SUCCESS;
}
*pCount = std::min(*pCount, static_cast<uint32_t>(scopes.size()));
for (uint32_t i = 0; i < *pCount; i++) {
phScopes[i] = scopes[i];
}
return ZE_RESULT_SUCCESS;
}
ze_result_t metricGroupGet(zet_device_handle_t hDevice, uint32_t *pCount, zet_metric_group_handle_t *phMetricGroups) { ze_result_t metricGroupGet(zet_device_handle_t hDevice, uint32_t *pCount, zet_metric_group_handle_t *phMetricGroups) {
auto device = Device::fromHandle(hDevice); auto device = Device::fromHandle(hDevice);
return device->getMetricDeviceContext().metricGroupGet(pCount, phMetricGroups); return device->getMetricDeviceContext().metricGroupGet(pCount, phMetricGroups);
@@ -1155,4 +1168,13 @@ ze_result_t metricAppendMarker(zet_command_list_handle_t hCommandList, zet_metri
return metricGroupImp->getMetricSource().appendMarker(hCommandList, hMetricGroup, value); return metricGroupImp->getMetricSource().appendMarker(hCommandList, hMetricGroup, value);
} }
ze_result_t getMetricSupportedScopes(
zet_metric_handle_t *phMetric,
uint32_t *pScopesCount,
zet_intel_metric_scope_exp_handle_t *phMetricScopes) {
auto metricImp = static_cast<MetricImp *>(Metric::fromHandle(*phMetric));
return metricImp->getScopes(pScopesCount, phMetricScopes);
}
} // namespace L0 } // namespace L0

View File

@@ -201,6 +201,10 @@ class MetricDeviceContext {
return computeMetricScopesInitialized; return computeMetricScopesInitialized;
} }
const std::vector<std::unique_ptr<MetricScopeImp>> &getMetricScopes() const {
return metricScopes;
}
protected: protected:
bool areMetricGroupsFromSameSource(uint32_t count, zet_metric_group_handle_t *phMetricGroups, uint32_t *sourceType); bool areMetricGroupsFromSameSource(uint32_t count, zet_metric_group_handle_t *phMetricGroups, uint32_t *sourceType);
bool areMetricsFromSameSource(uint32_t count, zet_metric_handle_t *phMetrics, uint32_t *sourceType); bool areMetricsFromSameSource(uint32_t count, zet_metric_handle_t *phMetrics, uint32_t *sourceType);
@@ -256,6 +260,10 @@ struct MetricImp : public Metric {
bool isPredefined = true; bool isPredefined = true;
bool isMultiDevice = false; bool isMultiDevice = false;
MultiDeviceMetricImp *rootDeviceMetricImp = nullptr; MultiDeviceMetricImp *rootDeviceMetricImp = nullptr;
std::vector<zet_intel_metric_scope_exp_handle_t> scopes = {};
public:
ze_result_t getScopes(uint32_t *pCount, zet_intel_metric_scope_exp_handle_t *phScopes);
}; };
struct MultiDeviceMetricImp : public MetricImp { struct MultiDeviceMetricImp : public MetricImp {
@@ -626,5 +634,6 @@ ze_result_t metricScopesGet(zet_context_handle_t hContext, zet_device_handle_t h
zet_intel_metric_scope_exp_handle_t *phMetricScopes); zet_intel_metric_scope_exp_handle_t *phMetricScopes);
ze_result_t metricScopeGetProperties(zet_intel_metric_scope_exp_handle_t hMetricScope, zet_intel_metric_scope_properties_exp_t *pMetricScopeProperties); ze_result_t metricScopeGetProperties(zet_intel_metric_scope_exp_handle_t hMetricScope, zet_intel_metric_scope_properties_exp_t *pMetricScopeProperties);
ze_result_t metricAppendMarker(zet_command_list_handle_t hCommandList, zet_metric_group_handle_t hMetricGroup, uint32_t value); ze_result_t metricAppendMarker(zet_command_list_handle_t hCommandList, zet_metric_group_handle_t hMetricGroup, uint32_t value);
ze_result_t getMetricSupportedScopes(zet_metric_handle_t *phMetric, uint32_t *pScopesCount, zet_intel_metric_scope_exp_handle_t *phMetricScopes);
} // namespace L0 } // namespace L0

View File

@@ -581,6 +581,51 @@ TEST_F(MetricIpSamplingStreamerTest, whenGetConcurrentMetricGroupsIsCalledThenCo
} }
} }
using MetricIpSamplingMetricSupportedScopeTest = MetricIpSamplingStreamerTest;
class MockMetricImp : public MetricImp {
public:
using MetricImp::MetricImp;
void setScopes(const std::vector<zet_intel_metric_scope_exp_handle_t> &newScopes) {
scopes = newScopes;
}
};
TEST_F(MetricIpSamplingMetricSupportedScopeTest, givenMetricWhenGettingSupportedMetricScopesThenExpectedCountAndHandlesAreReturned) {
EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi());
EXPECT_EQ(testDevices[0]->getMetricDeviceContext().getMetricScopes().size(), 0u);
zet_metric_group_handle_t metricGroupHandle = MetricIpSamplingStreamerTest::getMetricGroup(testDevices[0]);
uint32_t metricCount = 0;
EXPECT_EQ(zetMetricGet(metricGroupHandle, &metricCount, nullptr), ZE_RESULT_SUCCESS);
metricCount = 1;
zet_metric_handle_t phMetric{};
EXPECT_EQ(zetMetricGet(metricGroupHandle, &metricCount, &phMetric), ZE_RESULT_SUCCESS);
zet_intel_metric_scope_properties_exp_t scopeProperties{};
scopeProperties.stype = ZET_STRUCTURE_TYPE_INTEL_METRIC_SCOPE_PROPERTIES_EXP;
scopeProperties.pNext = nullptr;
std::vector<zet_intel_metric_scope_exp_handle_t> metricScopesHandles;
MockMetricScope *mockMetricScope = new MockMetricScope(scopeProperties, false);
metricScopesHandles.push_back(mockMetricScope->toHandle());
auto metricImp = static_cast<MockMetricImp *>(Metric::fromHandle(phMetric));
metricImp->setScopes(metricScopesHandles);
uint32_t metricScopesCount = 0;
EXPECT_EQ(zetIntelMetricSupportedScopesGetExp(&phMetric, &metricScopesCount, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricScopesCount, 1u);
std::vector<zet_intel_metric_scope_exp_handle_t> metricScopesHandle(metricScopesCount);
EXPECT_EQ(zetIntelMetricSupportedScopesGetExp(&phMetric, &metricScopesCount, metricScopesHandle.data()), ZE_RESULT_SUCCESS);
EXPECT_NE(metricScopesHandle[0], nullptr);
delete mockMetricScope;
}
using MetricIpSamplingCalcOpMultiDevTest = MetricIpSamplingCalculateMultiDevFixture; using MetricIpSamplingCalcOpMultiDevTest = MetricIpSamplingCalculateMultiDevFixture;
HWTEST2_F(MetricIpSamplingCalcOpMultiDevTest, givenIpSamplingMetricGroupThenCreateAndDestroyCalcOpIsSuccessful, EustallSupportedPlatforms) { HWTEST2_F(MetricIpSamplingCalcOpMultiDevTest, givenIpSamplingMetricGroupThenCreateAndDestroyCalcOpIsSuccessful, EustallSupportedPlatforms) {