feature: support device open with scopes

Related-To: NEO-15830

Signed-off-by: Joshua Santosh Ranjan <joshua.santosh.ranjan@intel.com>
This commit is contained in:
Joshua Santosh Ranjan
2025-08-26 18:38:43 +00:00
committed by Compute-Runtime-Automation
parent 812fc5b3f0
commit d68b5856b9
4 changed files with 76 additions and 49 deletions

View File

@@ -34,17 +34,6 @@ void MetricSource::getMetricGroupSourceIdProperty(zet_base_properties_t *propert
void MetricSource::initComputeMetricScopes(MetricDeviceContext &metricDeviceContext) {
auto createScope = [&metricDeviceContext](const std::string &name, const std::string &desc, uint32_t id, bool aggregated) {
zet_intel_metric_scope_properties_exp_t scopeProperties = {ZET_STRUCTURE_TYPE_INTEL_METRIC_SCOPE_PROPERTIES_EXP, nullptr};
scopeProperties.iD = id;
snprintf(scopeProperties.name, ZET_INTEL_MAX_METRIC_SCOPE_NAME_EXP, "%s", name.c_str());
snprintf(scopeProperties.description, ZET_INTEL_MAX_METRIC_SCOPE_NAME_EXP, "%s", desc.c_str());
auto metricScopeImp = MetricScopeImp::create(scopeProperties, aggregated);
DEBUG_BREAK_IF(metricScopeImp == nullptr);
metricDeviceContext.addMetricScope(std::move(metricScopeImp));
};
if (metricDeviceContext.isMultiDeviceCapable()) {
auto deviceImp = static_cast<DeviceImp *>(&metricDeviceContext.getDevice());
@@ -52,23 +41,18 @@ void MetricSource::initComputeMetricScopes(MetricDeviceContext &metricDeviceCont
for (uint32_t i = 0; i < subDeviceCount; i++) {
std::string scopeName = std::string(computeScopeNamePrefix) + std::to_string(i);
std::string scopeDesc = std::string(computeScopeDescriptionPrefix) + std::to_string(i);
createScope(scopeName, scopeDesc, i, false);
metricDeviceContext.addMetricScope(scopeName, scopeDesc);
}
auto &l0GfxCoreHelper = metricDeviceContext.getDevice().getNEODevice()->getRootDeviceEnvironment().getHelper<L0GfxCoreHelper>();
if (l0GfxCoreHelper.supportMetricsAggregation()) {
std::string scopeName(aggregatedScopeName);
std::string scopeDesc(aggregatedScopeDescription);
createScope(scopeName, scopeDesc, subDeviceCount, true);
metricDeviceContext.addMetricScope(aggregatedScopeName, aggregatedScopeDescription);
}
} else {
auto subDeviceIndex = metricDeviceContext.getSubDeviceIndex();
std::string scopeName = std::string(computeScopeNamePrefix) + std::to_string(subDeviceIndex);
std::string scopeDesc = std::string(computeScopeDescriptionPrefix) + std::to_string(subDeviceIndex);
createScope(scopeName, scopeDesc, subDeviceIndex, false);
metricDeviceContext.addMetricScope(scopeName, scopeDesc);
}
metricDeviceContext.setComputeMetricScopeInitialized();
@@ -718,6 +702,27 @@ ze_result_t MetricDeviceContext::metricScopesGet(zet_context_handle_t hContext,
return ZE_RESULT_SUCCESS;
}
uint32_t MetricDeviceContext::addMetricScope(std::string_view scopeName, std::string_view scopeDescription) {
// If scope exists, return id
for (const auto &scopePtr : metricScopes) {
if (scopePtr->isName(scopeName)) {
return scopePtr->getId();
}
}
// Create new scope
zet_intel_metric_scope_properties_exp_t properties = {};
snprintf(properties.name, sizeof(properties.name), "%s", scopeName.data());
snprintf(properties.description, sizeof(properties.description), "%s", scopeDescription.data());
properties.iD = static_cast<uint32_t>(metricScopes.size());
bool aggregated = (scopeName == aggregatedScopeName);
auto newScope = MetricScopeImp::create(properties, aggregated);
metricScopes.push_back(std::move(newScope));
return properties.iD;
}
ze_result_t MetricScopeImp::getProperties(zet_intel_metric_scope_properties_exp_t *pProperties) {
*pProperties = properties;
return ZE_RESULT_SUCCESS;

View File

@@ -190,9 +190,8 @@ class MetricDeviceContext {
bool isMultiDeviceCapable() const {
return multiDeviceCapable;
}
void addMetricScope(std::unique_ptr<MetricScopeImp> metricScope) {
metricScopes.push_back(std::move(metricScope));
}
uint32_t addMetricScope(std::string_view scopeName, std::string_view scopeDescription);
void setComputeMetricScopeInitialized() {
computeMetricScopesInitialized = true;
@@ -525,6 +524,14 @@ struct MetricScopeImp : public MetricScope {
static std::unique_ptr<MetricScopeImp> create(zet_intel_metric_scope_properties_exp_t &scopeProperties, bool aggregated);
bool isAggregated() const { return aggregated; }
uint32_t getId() const {
return properties.iD;
}
bool isName(std::string_view name) const {
return strcmp(properties.name, name.data()) == 0;
}
private:
zet_intel_metric_scope_properties_exp_t properties;
bool aggregated = false;