Skip to content

Commit f1c50a8

Browse files
Metric Refactor Metric Context
Rename Metric Context and move OA specific functions and members from Metric Context to OA specific class(MetricSource). This refactoring is done so that additional Metric Source like Stall Sampling could be Seamlessly implemented. Related-To: LOCI-2753 Signed-off-by: Joshua Santosh Ranjan <[email protected]>
1 parent 27c90ac commit f1c50a8

31 files changed

+682
-512
lines changed

level_zero/core/source/cmdlist/cmdlist_imp.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -36,7 +36,8 @@ ze_result_t CommandListImp::destroy() {
3636
}
3737

3838
ze_result_t CommandListImp::appendMetricMemoryBarrier() {
39-
return MetricQuery::appendMemoryBarrier(*this);
39+
40+
return device->getMetricDeviceContext().appendMetricMemoryBarrier(*this);
4041
}
4142

4243
ze_result_t CommandListImp::appendMetricStreamerMarker(zet_metric_streamer_handle_t hMetricStreamer,

level_zero/core/source/device/device.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace L0 {
3636
struct DriverHandle;
3737
struct BuiltinFunctionsLib;
3838
struct ExecutionEnvironment;
39-
struct MetricContext;
39+
class MetricDeviceContext;
4040
struct SysmanDevice;
4141
struct DebugSession;
4242

@@ -103,7 +103,7 @@ struct Device : _ze_device_handle_t {
103103
virtual const NEO::HardwareInfo &getHwInfo() const = 0;
104104
virtual NEO::OSInterface &getOsInterface() = 0;
105105
virtual uint32_t getPlatformInfo() const = 0;
106-
virtual MetricContext &getMetricContext() = 0;
106+
virtual MetricDeviceContext &getMetricDeviceContext() = 0;
107107
virtual DebugSession *getDebugSession(const zet_debug_config_t &config) = 0;
108108
virtual DebugSession *createDebugSession(const zet_debug_config_t &config, ze_result_t &result) = 0;
109109
virtual void removeDebugSession() = 0;

level_zero/core/source/device/device_imp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ ze_result_t DeviceImp::activateMetricGroupsDeferred(uint32_t count,
734734
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN;
735735
if (!this->isSubdevice && this->isImplicitScalingCapable()) {
736736
for (auto subDevice : this->subDevices) {
737-
result = subDevice->getMetricContext().activateMetricGroupsDeferred(count, phMetricGroups);
737+
result = subDevice->getMetricDeviceContext().activateMetricGroupsDeferred(count, phMetricGroups);
738738
if (result != ZE_RESULT_SUCCESS)
739739
break;
740740
}
@@ -764,13 +764,13 @@ uint32_t DeviceImp::getPlatformInfo() const {
764764
return hardwareInfo.platform.eRenderCoreFamily;
765765
}
766766

767-
MetricContext &DeviceImp::getMetricContext() { return *metricContext; }
767+
MetricDeviceContext &DeviceImp::getMetricDeviceContext() { return *metricContext; }
768768

769769
void DeviceImp::activateMetricGroups() {
770770
if (metricContext != nullptr) {
771771
if (metricContext->isImplicitScalingCapable()) {
772772
for (uint32_t i = 0; i < numSubDevices; i++) {
773-
subDevices[i]->getMetricContext().activateMetricGroups();
773+
subDevices[i]->getMetricDeviceContext().activateMetricGroups();
774774
}
775775
} else {
776776
metricContext->activateMetricGroups();
@@ -815,7 +815,7 @@ Device *Device::create(DriverHandle *driverHandle, NEO::Device *neoDevice, bool
815815
device->allocationsForReuse = std::make_unique<NEO::AllocationsList>();
816816
bool platformImplicitScaling = hwHelper.platformSupportsImplicitScaling(hwInfo);
817817
device->implicitScalingCapable = NEO::ImplicitScalingHelper::isImplicitScalingEnabled(neoDevice->getDeviceBitfield(), platformImplicitScaling);
818-
device->metricContext = MetricContext::create(*device);
818+
device->metricContext = MetricDeviceContext::create(*device);
819819
device->builtins = BuiltinFunctionsLib::create(
820820
device, neoDevice->getBuiltIns());
821821
device->cacheReservation = CacheReservation::create(*device);

level_zero/core/source/device/device_imp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct DeviceImp : public Device {
6969
const NEO::HardwareInfo &getHwInfo() const override;
7070
NEO::OSInterface &getOsInterface() override;
7171
uint32_t getPlatformInfo() const override;
72-
MetricContext &getMetricContext() override;
72+
MetricDeviceContext &getMetricDeviceContext() override;
7373
DebugSession *getDebugSession(const zet_debug_config_t &config) override;
7474
DebugSession *createDebugSession(const zet_debug_config_t &config, ze_result_t &result) override;
7575
void removeDebugSession() override { debugSession.release(); }
@@ -104,7 +104,7 @@ struct DeviceImp : public Device {
104104
bool isSubdevice = false;
105105
void *execEnvironment = nullptr;
106106
std::unique_ptr<BuiltinFunctionsLib> builtins = nullptr;
107-
std::unique_ptr<MetricContext> metricContext = nullptr;
107+
std::unique_ptr<MetricDeviceContext> metricContext = nullptr;
108108
std::unique_ptr<CacheReservation> cacheReservation = nullptr;
109109
uint32_t maxNumHwThreads = 0;
110110
uint32_t numSubDevices = 0;

level_zero/core/source/driver/driver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -60,7 +60,7 @@ void DriverImp::initialize(ze_result_t *result) {
6060
*result = ZE_RESULT_SUCCESS;
6161

6262
if (envVariables.metrics) {
63-
*result = MetricContext::enableMetricApi();
63+
*result = MetricDeviceContext::enableMetricApi();
6464
if (*result != ZE_RESULT_SUCCESS) {
6565
delete GlobalDriver;
6666
GlobalDriverHandle = nullptr;

level_zero/core/test/unit_tests/mocks/mock_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct Mock<Device> : public Device {
6262
ADDMETHOD_NOBASE(activateMetricGroupsDeferred, ze_result_t, ZE_RESULT_SUCCESS, (uint32_t count, zet_metric_group_handle_t *phMetricGroups));
6363
ADDMETHOD_NOBASE_REFRETURN(getOsInterface, NEO::OSInterface &, ());
6464
ADDMETHOD_CONST_NOBASE(getPlatformInfo, uint32_t, 0u, ());
65-
ADDMETHOD_NOBASE_REFRETURN(getMetricContext, MetricContext &, ());
65+
ADDMETHOD_NOBASE_REFRETURN(getMetricDeviceContext, MetricDeviceContext &, ());
6666
ADDMETHOD_CONST_NOBASE_REFRETURN(getHwInfo, const NEO::HardwareInfo &, ());
6767
ADDMETHOD_NOBASE(getDriverHandle, L0::DriverHandle *, nullptr, ());
6868
ADDMETHOD_NOBASE_VOIDRETURN(setDriverHandle, (L0::DriverHandle *));

level_zero/tools/source/metrics/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2020-2021 Intel Corporation
2+
# Copyright (C) 2020-2022 Intel Corporation
33
#
44
# SPDX-License-Identifier: MIT
55
#
@@ -12,6 +12,7 @@ list(APPEND L0_SRCS_TOOLS_METRICS
1212
${CMAKE_CURRENT_SOURCE_DIR}/metric_enumeration_imp.cpp
1313
${CMAKE_CURRENT_SOURCE_DIR}/metric_streamer_imp.cpp
1414
${CMAKE_CURRENT_SOURCE_DIR}/metric_query_imp.cpp
15+
${CMAKE_CURRENT_SOURCE_DIR}/metric_source_oa.h
1516
)
1617

1718
if(UNIX)

level_zero/tools/source/metrics/linux/os_metric_enumeration_imp_linux.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -10,6 +10,7 @@
1010
#include "shared/source/os_interface/os_interface.h"
1111

1212
#include "level_zero/tools/source/metrics/metric_enumeration_imp.h"
13+
#include "level_zero/tools/source/metrics/metric_source_oa.h"
1314

1415
#include <sys/stat.h>
1516
#include <sys/sysmacros.h>
@@ -20,7 +21,7 @@ const char *MetricEnumeration::getMetricsDiscoveryFilename() { return "libmd.so.
2021

2122
bool MetricEnumeration::getAdapterId(uint32_t &adapterMajor, uint32_t &adapterMinor) {
2223

23-
auto &device = metricContext.getDevice();
24+
auto &device = metricSource.getMetricDeviceContext().getDevice();
2425
auto &osInterface = device.getOsInterface();
2526
auto drm = osInterface.getDriverModel()->as<NEO::Drm>();
2627
auto drmFile = drm->getFileDescriptor();

level_zero/tools/source/metrics/linux/os_metric_query_imp_linux.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -10,6 +10,7 @@
1010

1111
#include "level_zero/core/source/device/device.h"
1212
#include "level_zero/tools/source/metrics/metric_query_imp.h"
13+
#include "level_zero/tools/source/metrics/metric_source_oa.h"
1314

1415
using namespace MetricsLibraryApi;
1516

0 commit comments

Comments
 (0)