feature: expose source ids for metric groups

Related-To: NEO-13480

Signed-off-by: Joshua Santosh Ranjan <joshua.santosh.ranjan@intel.com>
This commit is contained in:
Joshua Santosh Ranjan
2025-01-31 10:16:04 +00:00
committed by Compute-Runtime-Automation
parent b11322332c
commit c8eb085cdb
11 changed files with 198 additions and 16 deletions

View File

@@ -47,5 +47,6 @@ const std::vector<std::pair<std::string, uint32_t>> DriverHandleImp::extensionsS
{ZE_INTEL_KERNEL_GET_PROGRAM_BINARY_EXP_NAME, ZE_INTEL_KERNEL_GET_PROGRAM_BINARY_EXP_VERSION_CURRENT},
// Metrics Driver experimental extensions
{ZET_INTEL_METRIC_APPEND_MARKER_EXP_NAME, ZET_INTEL_METRIC_APPEND_MARKER_EXP_VERSION_CURRENT}};
{ZET_INTEL_METRIC_APPEND_MARKER_EXP_NAME, ZET_INTEL_METRIC_APPEND_MARKER_EXP_VERSION_CURRENT},
{ZET_INTEL_METRIC_SOURCE_ID_EXP_NAME, ZET_INTEL_METRIC_SOURCE_ID_EXP_VERSION_CURRENT}};
} // namespace L0

View File

@@ -9,6 +9,7 @@
#define _ZE_STYPES_H
#include <level_zero/ze_api.h>
#include <level_zero/zet_api.h>
#define ZE_STRUCTURE_TYPE_PITCHED_ALLOC_DEVICE_EXP_PROPERTIES (ze_structure_type_t)0x0002001D
#define ZE_STRUCTURE_TYPE_BINDLESS_IMAGE_EXP_DESC (ze_structure_type_t)0x0002001E
@@ -34,4 +35,6 @@
#define ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS_EXP (ze_structure_type_t)0x00030024
#define ZE_INTEL_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_WAIT_PARAMS_EXP (ze_structure_type_t)0x00030025
// Metric structure types
#define ZET_INTEL_STRUCTURE_TYPE_METRIC_SOURCE_ID_EXP (zet_structure_type_t)0x0001000a // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange), NEO-12901
#endif

View File

@@ -8,6 +8,7 @@
#ifndef _ZET_INTEL_GPU_METRIC_H
#define _ZET_INTEL_GPU_METRIC_H
#include "level_zero/include/level_zero/ze_stypes.h"
#include <level_zero/zet_api.h>
#if defined(__cplusplus)
@@ -22,6 +23,29 @@ extern "C" {
#define ZET_INTEL_MAX_METRIC_GROUP_NAME_PREFIX_EXP 64u
#define ZET_INTEL_METRIC_PROGRAMMABLE_PARAM_TYPE_GENERIC_EXP (0x7ffffffe)
#ifndef ZET_INTEL_METRIC_SOURCE_ID_EXP_NAME
/// @brief Extension name for query to read the Intel Level Zero Driver Version String
#define ZET_INTEL_METRIC_SOURCE_ID_EXP_NAME "ZET_intel_metric_source_id"
#endif // ZET_INTEL_METRIC_SOURCE_ID_EXP_NAME
///////////////////////////////////////////////////////////////////////////////
/// @brief Metric Source Id extension Version(s)
typedef enum _zet_intel_metric_source_id_exp_version_t {
ZET_INTEL_METRIC_SOURCE_ID_EXP_VERSION_1_0 = ZE_MAKE_VERSION(1, 0), ///< version 1.0
ZET_INTEL_METRIC_SOURCE_ID_EXP_VERSION_CURRENT = ZE_MAKE_VERSION(1, 0), ///< latest known version
ZET_INTEL_METRIC_SOURCE_ID_EXP_VERSION_FORCE_UINT32 = 0x7fffffff
} zet_intel_metric_source_id_exp_version_t;
///////////////////////////////////////////////////////////////////////////////
/// @brief Query an unique identifier representing the source of a metric group
/// This structure can be passed in the 'pNext' of zet_metric_group_properties_t
typedef struct _zet_intel_metric_source_id_exp_t {
zet_structure_type_t stype; ///< [in] type of this structure
const void *pNext; ///< [in][optional] must be null or a pointer to an extension-specific
///< structure (i.e. contains stype and pNext).
uint32_t sourceId; ///< [out] Returns an unique source Id of the metric group
} zet_intel_metric_source_id_exp_t;
#ifndef ZET_INTEL_METRIC_APPEND_MARKER_EXP_NAME
/// @brief Extension name for query to read the Intel Level Zero Driver Version String
#define ZET_INTEL_METRIC_APPEND_MARKER_EXP_NAME "ZET_intel_metric_append_marker"

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2024 Intel Corporation
* Copyright (C) 2020-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -22,6 +22,12 @@
namespace L0 {
void MetricSource::getMetricGroupSourceIdProperty(zet_base_properties_t *property) {
zet_intel_metric_source_id_exp_t *groupProperty = reinterpret_cast<zet_intel_metric_source_id_exp_t *>(property);
groupProperty->sourceId = type;
}
MetricDeviceContext::MetricDeviceContext(Device &inputDevice) : device(inputDevice) {
auto deviceNeo = device.getNEODevice();
std::tuple<uint32_t, uint32_t, uint32_t> subDeviceMap;

View File

@@ -93,6 +93,7 @@ class MetricSource {
protected:
uint32_t type = MetricSource::metricSourceTypeUndefined;
void getMetricGroupSourceIdProperty(zet_base_properties_t *property);
};
class MultiDomainDeferredActivationTracker {

View File

@@ -212,7 +212,11 @@ ze_result_t IpSamplingMetricSourceImp::handleMetricGroupExtendedProperties(zet_m
while (pNext) {
auto extendedProperties = reinterpret_cast<zet_base_properties_t *>(pNext);
if (extendedProperties->stype == ZET_STRUCTURE_TYPE_METRIC_GLOBAL_TIMESTAMPS_RESOLUTION_EXP) {
if (extendedProperties->stype == ZET_INTEL_STRUCTURE_TYPE_METRIC_SOURCE_ID_EXP) {
getMetricGroupSourceIdProperty(extendedProperties);
retVal = ZE_RESULT_SUCCESS;
} else if (extendedProperties->stype == ZET_STRUCTURE_TYPE_METRIC_GLOBAL_TIMESTAMPS_RESOLUTION_EXP) {
zet_metric_global_timestamps_resolution_exp_t *metricsTimestampProperties =
reinterpret_cast<zet_metric_global_timestamps_resolution_exp_t *>(extendedProperties);
@@ -220,14 +224,11 @@ ze_result_t IpSamplingMetricSourceImp::handleMetricGroupExtendedProperties(zet_m
getTimerResolution(metricsTimestampProperties->timerResolution);
getTimestampValidBits(metricsTimestampProperties->timestampValidBits);
retVal = ZE_RESULT_SUCCESS;
}
if (extendedProperties->stype == ZET_STRUCTURE_TYPE_METRIC_GROUP_TYPE_EXP) {
} else if (extendedProperties->stype == ZET_STRUCTURE_TYPE_METRIC_GROUP_TYPE_EXP) {
zet_metric_group_type_exp_t *groupType = reinterpret_cast<zet_metric_group_type_exp_t *>(extendedProperties);
groupType->type = ZET_METRIC_GROUP_TYPE_EXP_FLAG_OTHER;
retVal = ZE_RESULT_SUCCESS;
}
pNext = extendedProperties->pNext;
}

View File

@@ -613,7 +613,7 @@ void MetricEnumeration::updateMetricProgrammablesFromPrototypes(
properties.tierNumber = getMetricTierNumber(metricPrototypeParams->UsageFlagsMask);
properties.samplingType = getSamplingTypeFromApiMask(metricPrototypeParams->ApiMask);
properties.parameterCount = metricPrototypeParams->OptionDescriptorCount;
properties.sourceId = oaSourceId;
properties.sourceId = MetricSource::metricSourceTypeOa;
auto pMetricProgrammable = OaMetricProgrammableImp::create(properties, concurrentGroup, *metricPrototype, metricSource);
metricProgrammables.push_back(pMetricProgrammable);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2024 Intel Corporation
* Copyright (C) 2020-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -20,7 +20,6 @@ static constexpr std::string_view globalSymbolOaMaxBufferSize = "OABufferMaxSize
static constexpr std::string_view globalSymbolOaMaxTimestamp = "MaxTimestamp";
struct MetricEnumeration {
static const uint32_t oaSourceId = 0x0A;
MetricEnumeration(OaMetricSourceImp &metricSource);
virtual ~MetricEnumeration();

View File

@@ -208,7 +208,11 @@ ze_result_t OaMetricSourceImp::handleMetricGroupExtendedProperties(zet_metric_gr
while (pNext) {
auto extendedProperties = reinterpret_cast<zet_base_properties_t *>(pNext);
if (extendedProperties->stype == ZET_STRUCTURE_TYPE_METRIC_GLOBAL_TIMESTAMPS_RESOLUTION_EXP) {
if (extendedProperties->stype == ZET_INTEL_STRUCTURE_TYPE_METRIC_SOURCE_ID_EXP) {
getMetricGroupSourceIdProperty(extendedProperties);
retVal = ZE_RESULT_SUCCESS;
} else if (extendedProperties->stype == ZET_STRUCTURE_TYPE_METRIC_GLOBAL_TIMESTAMPS_RESOLUTION_EXP) {
zet_metric_global_timestamps_resolution_exp_t *metricsTimestampProperties =
reinterpret_cast<zet_metric_global_timestamps_resolution_exp_t *>(extendedProperties);
@@ -226,9 +230,7 @@ ze_result_t OaMetricSourceImp::handleMetricGroupExtendedProperties(zet_metric_gr
metricsTimestampProperties->timestampValidBits = 0;
return retVal;
}
}
if (extendedProperties->stype == ZET_STRUCTURE_TYPE_METRIC_GROUP_TYPE_EXP) {
} else if (extendedProperties->stype == ZET_STRUCTURE_TYPE_METRIC_GROUP_TYPE_EXP) {
zet_metric_group_type_exp_t *groupType = reinterpret_cast<zet_metric_group_type_exp_t *>(extendedProperties);
groupType->type = ZET_METRIC_GROUP_TYPE_EXP_FLAG_OTHER;
retVal = ZE_RESULT_SUCCESS;

View File

@@ -132,6 +132,50 @@ HWTEST2_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenMetricG
}
}
HWTEST2_F(MetricIpSamplingEnumerationTest, GivenDependenciesAvailableWhenMetricGroupSourceIdIsRequestedThenCorrectSourceIdIsReturned, 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<zet_metric_group_handle_t> metricGroups;
metricGroups.resize(metricGroupCount);
ASSERT_EQ(zetMetricGroupGet(device->toHandle(), &metricGroupCount, metricGroups.data()), ZE_RESULT_SUCCESS);
ASSERT_NE(metricGroups[0], nullptr);
zet_intel_metric_source_id_exp_t metricGroupSourceId{};
metricGroupSourceId.sourceId = 0xFFFFFFFF;
metricGroupSourceId.pNext = nullptr;
metricGroupSourceId.stype = ZET_INTEL_STRUCTURE_TYPE_METRIC_SOURCE_ID_EXP;
zet_metric_group_properties_t metricGroupProperties = {ZET_STRUCTURE_TYPE_METRIC_GROUP_PROPERTIES, &metricGroupSourceId};
EXPECT_EQ(zetMetricGroupGetProperties(metricGroups[0], &metricGroupProperties), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupSourceId.sourceId, MetricSource::metricSourceTypeIpSampling);
}
}
using DriverVersionTest = Test<DeviceFixture>;
TEST_F(DriverVersionTest, givenSupportedExtensionsWhenCheckIfAppendMarkerIsSupportedThenCorrectResultsAreReturned) {
uint32_t count = 0;
ze_result_t res = driverHandle->getExtensionProperties(&count, nullptr);
EXPECT_NE(0u, count);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
std::vector<ze_driver_extension_properties_t> extensionProperties;
extensionProperties.resize(count);
res = driverHandle->getExtensionProperties(&count, extensionProperties.data());
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
auto it = std::find_if(extensionProperties.begin(), extensionProperties.end(), [](const auto &extension) { return (strcmp(extension.name, ZET_INTEL_METRIC_SOURCE_ID_EXP_NAME) == 0); });
EXPECT_NE(it, extensionProperties.end());
EXPECT_EQ((*it).version, ZET_INTEL_METRIC_SOURCE_ID_EXP_VERSION_CURRENT);
}
struct TestMetricProperties {
const char *name;
const char *description;
@@ -329,6 +373,35 @@ HWTEST2_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulWhenQuery
}
}
HWTEST2_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulWhenQueryingUnsupportedPropertyThenErrorIsReturned, EustallSupportedPlatforms) {
EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi());
for (auto device : testDevices) {
ze_device_properties_t deviceProps = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES_1_2, nullptr};
device->getProperties(&deviceProps);
uint32_t metricGroupCount = 0;
zetMetricGroupGet(device->toHandle(), &metricGroupCount, nullptr);
EXPECT_EQ(metricGroupCount, 1u);
std::vector<zet_metric_group_handle_t> metricGroups;
metricGroups.resize(metricGroupCount);
ASSERT_EQ(zetMetricGroupGet(device->toHandle(), &metricGroupCount, metricGroups.data()), ZE_RESULT_SUCCESS);
ASSERT_NE(metricGroups[0], nullptr);
zet_metric_group_type_exp_t metricGroupType{};
metricGroupType.stype = static_cast<zet_structure_type_t>(ZET_INTEL_STRUCTURE_TYPE_METRIC_SOURCE_ID_EXP + 1);
metricGroupType.pNext = nullptr;
metricGroupType.type = ZET_METRIC_GROUP_TYPE_EXP_FLAG_FORCE_UINT32;
zet_metric_group_properties_t metricGroupProperties = {ZET_STRUCTURE_TYPE_METRIC_GROUP_PROPERTIES, &metricGroupType};
EXPECT_EQ(zetMetricGroupGetProperties(metricGroups[0], &metricGroupProperties), ZE_RESULT_ERROR_INVALID_ARGUMENT);
}
}
HWTEST2_F(MetricIpSamplingEnumerationTest, GivenEnumerationIsSuccessfulOnMulitDeviceWhenReadingMetricsTimestampThenResultIsSuccess, EustallSupportedPlatforms) {
EXPECT_EQ(ZE_RESULT_SUCCESS, testDevices[0]->getMetricDeviceContext().enableMetricApi());

View File

@@ -270,6 +270,78 @@ TEST_F(MetricEnumerationTest, givenValidArgumentsWhenZetGetMetricGroupProperties
EXPECT_EQ(strcmp(metricGroupProperties.name, metricsSetParams.SymbolName), 0);
}
TEST_F(MetricEnumerationTest, givenOaMetricSourceWhenQueryingSourceIdThenCorrectSourceIdIsReturned) {
// Metrics Discovery device.
metricsDeviceParams.ConcurrentGroupsCount = 1;
// Metrics Discovery concurrent group.
Mock<IConcurrentGroup_1_13> metricsConcurrentGroup;
TConcurrentGroupParams_1_13 metricsConcurrentGroupParams = {};
metricsConcurrentGroupParams.MetricSetsCount = 1;
metricsConcurrentGroupParams.SymbolName = "OA";
metricsConcurrentGroupParams.Description = "OA description";
metricsConcurrentGroupParams.IoMeasurementInformationCount = 1;
Mock<MetricsDiscovery::IEquation_1_0> ioReadEquation;
MetricsDiscovery::TEquationElement_1_0 ioEquationElement = {};
ioEquationElement.Type = MetricsDiscovery::EQUATION_ELEM_IMM_UINT64;
ioEquationElement.ImmediateUInt64 = 0;
ioReadEquation.getEquationElement.push_back(&ioEquationElement);
Mock<MetricsDiscovery::IInformation_1_0> ioMeasurement;
MetricsDiscovery::TInformationParams_1_0 oaInformation = {};
oaInformation.SymbolName = "BufferOverflow";
oaInformation.IoReadEquation = &ioReadEquation;
metricsConcurrentGroup.GetIoMeasurementInformationResult = &ioMeasurement;
ioMeasurement.GetParamsResult = &oaInformation;
// Metrics Discovery:: metric set.
Mock<MetricsDiscovery::IMetricSet_1_13> metricsSet;
MetricsDiscovery::TMetricSetParams_1_11 metricsSetParams = {};
metricsSetParams.ApiMask = MetricsDiscovery::API_TYPE_OCL;
metricsSetParams.MetricsCount = 0;
metricsSetParams.SymbolName = "Metric set name";
metricsSetParams.ShortName = "Metric set description";
// One api: metric group handle.
zet_metric_group_handle_t metricGroupHandle = {};
zet_metric_group_properties_t metricGroupProperties = {ZET_STRUCTURE_TYPE_METRIC_GROUP_PROPERTIES, nullptr};
openMetricsAdapter();
setupDefaultMocksForMetricDevice(metricsDevice);
metricsDevice.getConcurrentGroupResults.push_back(&metricsConcurrentGroup);
metricsConcurrentGroup.GetParamsResult = &metricsConcurrentGroupParams;
metricsConcurrentGroup.getMetricSetResult = &metricsSet;
metricsSet.GetParamsResult = &metricsSetParams;
// Metric group count.
uint32_t metricGroupCount = 0;
EXPECT_EQ(zetMetricGroupGet(device->toHandle(), &metricGroupCount, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupCount, 1u);
// Metric group handle.
EXPECT_EQ(zetMetricGroupGet(device->toHandle(), &metricGroupCount, &metricGroupHandle), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupCount, 1u);
EXPECT_NE(metricGroupHandle, nullptr);
zet_intel_metric_source_id_exp_t metricGroupSourceId{};
metricGroupSourceId.sourceId = 0xFFFFFFFF;
metricGroupSourceId.pNext = nullptr;
metricGroupSourceId.stype = ZET_INTEL_STRUCTURE_TYPE_METRIC_SOURCE_ID_EXP;
metricGroupProperties.pNext = &metricGroupSourceId;
// Metric group properties.
EXPECT_EQ(zetMetricGroupGetProperties(metricGroupHandle, &metricGroupProperties), ZE_RESULT_SUCCESS);
EXPECT_EQ(metricGroupSourceId.sourceId, MetricSource::metricSourceTypeOa);
}
TEST_F(MetricEnumerationTest, givenInvalidArgumentsWhenZetMetricGetIsCalledThenReturnsFail) {
// Metrics Discovery device.
@@ -3408,9 +3480,9 @@ TEST_F(MetricEnumerationTest, givenValidArgumentsWhenAppendMarkerIsCalledThenRet
EXPECT_EQ(zetIntelCommandListAppendMarkerExp(nullptr, metricGroupHandle, 0), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
}
using DriverVersionTest = Test<DeviceFixture>;
using AppendMarkerDriverVersionTest = Test<DeviceFixture>;
TEST_F(DriverVersionTest, givenSupportedExtensionsWhenCheckIfAppendMarkerIsSupportedThenCorrectResultsAreReturned) {
TEST_F(AppendMarkerDriverVersionTest, givenSupportedExtensionsWhenCheckIfAppendMarkerIsSupportedThenCorrectResultsAreReturned) {
uint32_t count = 0;
ze_result_t res = driverHandle->getExtensionProperties(&count, nullptr);
EXPECT_NE(0u, count);