mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-07 12:42:54 +08:00
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:
committed by
Compute-Runtime-Automation
parent
812fc5b3f0
commit
d68b5856b9
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -17,6 +17,11 @@ class MockMetricSource : public L0::MetricSource {
|
||||
public:
|
||||
uint32_t enableCallCount = 0;
|
||||
bool isAvailableReturn = false;
|
||||
std::vector<std::pair<std::string, std::string>> testMetricScopeNames = {
|
||||
{std::string(aggregatedScopeName), std::string(aggregatedScopeDescription)},
|
||||
{std::string(computeScopeNamePrefix) + std::to_string(1), std::string(computeScopeDescriptionPrefix) + std::to_string(1)},
|
||||
{std::string(computeScopeNamePrefix) + std::to_string(0), std::string(computeScopeDescriptionPrefix) + std::to_string(0)},
|
||||
{std::string(computeScopeNamePrefix) + std::to_string(1), std::string(computeScopeDescriptionPrefix) + std::to_string(1)}};
|
||||
void enable() override { enableCallCount++; }
|
||||
bool isAvailable() override { return isAvailableReturn; }
|
||||
ze_result_t appendMetricMemoryBarrier(L0::CommandList &commandList) override { return ZE_RESULT_ERROR_UNKNOWN; }
|
||||
@@ -57,10 +62,11 @@ class MockMetricSource : public L0::MetricSource {
|
||||
}
|
||||
bool canDisable() override { return false; }
|
||||
void initMetricScopes(MetricDeviceContext &metricDeviceContext) override {
|
||||
if (!metricDeviceContext.isComputeMetricScopesInitialized()) {
|
||||
initComputeMetricScopes(metricDeviceContext);
|
||||
for (auto index = 0u; index < static_cast<uint32_t>(testMetricScopeNames.size()); index++) {
|
||||
metricDeviceContext.addMetricScope(testMetricScopeNames[index].first, testMetricScopeNames[index].second);
|
||||
}
|
||||
};
|
||||
initComputeMetricScopes(metricDeviceContext);
|
||||
}
|
||||
|
||||
~MockMetricSource() override = default;
|
||||
};
|
||||
|
||||
@@ -347,14 +347,13 @@ TEST_F(MetricScopesFixture, WhenGettingMetricScopeForSingleDeviceTheyAreCorrectl
|
||||
&metricScopesCount,
|
||||
nullptr));
|
||||
|
||||
EXPECT_EQ(metricScopesCount, 1u);
|
||||
EXPECT_EQ(metricScopesCount, 3u);
|
||||
std::vector<zet_intel_metric_scope_exp_handle_t> metricScopes(metricScopesCount);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zetIntelMetricScopesGetExp(context->toHandle(),
|
||||
device->toHandle(),
|
||||
&metricScopesCount,
|
||||
metricScopes.data()));
|
||||
EXPECT_EQ(metricScopesCount, 1u);
|
||||
EXPECT_EQ(metricScopes.size(), 1u);
|
||||
EXPECT_EQ(metricScopesCount, 3u);
|
||||
}
|
||||
|
||||
TEST_F(MetricScopesFixture, WhenMultipleSourcesAreAvailableComputeMetricScopesAreEnumeratedOnlyOnce) {
|
||||
@@ -377,7 +376,7 @@ TEST_F(MetricScopesFixture, WhenMultipleSourcesAreAvailableComputeMetricScopesAr
|
||||
device->toHandle(),
|
||||
&metricScopesCount,
|
||||
nullptr));
|
||||
EXPECT_EQ(metricScopesCount, 1u);
|
||||
EXPECT_EQ(metricScopesCount, 3u);
|
||||
}
|
||||
|
||||
TEST_F(MetricScopesFixture, GettingMetricsScopesPropertiesReturnsExpectedValues) {
|
||||
@@ -390,23 +389,28 @@ TEST_F(MetricScopesFixture, GettingMetricsScopesPropertiesReturnsExpectedValues)
|
||||
auto deviceImp = static_cast<DeviceImp *>(device);
|
||||
deviceImp->metricContext.reset(mockDeviceContext);
|
||||
|
||||
uint32_t metricScopesCount = 1;
|
||||
zet_intel_metric_scope_exp_handle_t metricScope;
|
||||
uint32_t metricScopesCount = 0;
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zetIntelMetricScopesGetExp(context->toHandle(),
|
||||
device->toHandle(),
|
||||
&metricScopesCount,
|
||||
&metricScope));
|
||||
EXPECT_EQ(metricScopesCount, 1u);
|
||||
nullptr));
|
||||
std::vector<zet_intel_metric_scope_exp_handle_t> metricScopes(metricScopesCount);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zetIntelMetricScopesGetExp(context->toHandle(),
|
||||
device->toHandle(),
|
||||
&metricScopesCount,
|
||||
metricScopes.data()));
|
||||
EXPECT_EQ(metricScopesCount, 3u);
|
||||
zet_intel_metric_scope_properties_exp_t scopeProperties{};
|
||||
scopeProperties.stype = ZET_STRUCTURE_TYPE_INTEL_METRIC_SCOPE_PROPERTIES_EXP;
|
||||
scopeProperties.pNext = nullptr;
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zetIntelMetricScopeGetPropertiesExp(metricScope,
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zetIntelMetricScopeGetPropertiesExp(metricScopes[0],
|
||||
&scopeProperties));
|
||||
|
||||
EXPECT_EQ(scopeProperties.iD, 0u);
|
||||
EXPECT_STREQ(scopeProperties.name, "COMPUTE_TILE_0");
|
||||
EXPECT_STREQ(scopeProperties.description, "Metrics results for tile 0");
|
||||
EXPECT_STREQ(scopeProperties.name, "DEVICE_AGGREGATED");
|
||||
EXPECT_STREQ(scopeProperties.description, "Metrics results aggregated at device level");
|
||||
}
|
||||
|
||||
TEST_F(MetricScopesFixture, MetricScopeObjectToAndFromHandleBaseClassWorkAsExpected) {
|
||||
@@ -482,12 +486,17 @@ HWTEST_F(MetricScopesFixture, GivenMetricsAggregationIsSupportedWhenCreatingCalc
|
||||
deviceImp->metricContext.reset(mockDeviceContext);
|
||||
mockDeviceContext->setMultiDeviceCapable(true);
|
||||
|
||||
uint32_t metricScopesCount = 1;
|
||||
zet_intel_metric_scope_exp_handle_t metricScope;
|
||||
uint32_t metricScopesCount = 0;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zetIntelMetricScopesGetExp(context->toHandle(),
|
||||
device->toHandle(),
|
||||
&metricScopesCount,
|
||||
&metricScope));
|
||||
nullptr));
|
||||
EXPECT_NE(metricScopesCount, 0u);
|
||||
std::vector<zet_intel_metric_scope_exp_handle_t> metricScopes(metricScopesCount);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zetIntelMetricScopesGetExp(context->toHandle(),
|
||||
device->toHandle(),
|
||||
&metricScopesCount,
|
||||
metricScopes.data()));
|
||||
|
||||
MockMetricGroup mockMetricGroup(*metricSource);
|
||||
mockMetricGroup.isMultiDevice = true;
|
||||
@@ -496,16 +505,16 @@ HWTEST_F(MetricScopesFixture, GivenMetricsAggregationIsSupportedWhenCreatingCalc
|
||||
// Aggregation window is zero
|
||||
zet_intel_metric_calculation_exp_desc_t calculationDesc{
|
||||
ZET_INTEL_STRUCTURE_TYPE_METRIC_CALCULATION_DESC_EXP,
|
||||
nullptr, // pNext
|
||||
1, // metricGroupCount
|
||||
&hMetricGroup, // phMetricGroups
|
||||
0, // metricCount
|
||||
nullptr, // phMetrics
|
||||
0, // timeWindowsCount
|
||||
nullptr, // pCalculationTimeWindows
|
||||
100, // timeAggregationWindow
|
||||
1, // metricScopesCount
|
||||
&metricScope, // phMetricScopes
|
||||
nullptr, // pNext
|
||||
1, // metricGroupCount
|
||||
&hMetricGroup, // phMetricGroups
|
||||
0, // metricCount
|
||||
nullptr, // phMetrics
|
||||
0, // timeWindowsCount
|
||||
nullptr, // pCalculationTimeWindows
|
||||
100, // timeAggregationWindow
|
||||
metricScopesCount, // metricScopesCount
|
||||
metricScopes.data(), // phMetricScopes
|
||||
};
|
||||
|
||||
zet_intel_metric_calculation_operation_exp_handle_t hCalculationOperation;
|
||||
|
||||
Reference in New Issue
Block a user