Skip to content

Commit eb1802c

Browse files
Metric Api: Pass workload partition client option
Resolves: LOCI-2583 Signed-off-by: Robert Krzemien <[email protected]>
1 parent 4cb7c10 commit eb1802c

8 files changed

+120
-64
lines changed

level_zero/tools/source/metrics/metric.cpp

+13-16
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include "shared/source/os_interface/os_library.h"
1111

12-
#include "level_zero/core/source/device/device.h"
12+
#include "level_zero/core/source/device/device_imp.h"
1313
#include "level_zero/core/source/driver/driver.h"
1414
#include "level_zero/core/source/driver/driver_handle_imp.h"
1515
#include "level_zero/source/inc/ze_intel_gpu.h"
@@ -67,6 +67,7 @@ struct MetricContextImp : public MetricContext {
6767
bool isComputeUsed() override;
6868
uint32_t getSubDeviceIndex() override;
6969
void setSubDeviceIndex(const uint32_t index) override;
70+
bool isMultiDeviceCapable() override;
7071

7172
protected:
7273
ze_result_t initializationState = ZE_RESULT_ERROR_UNINITIALIZED;
@@ -77,6 +78,7 @@ struct MetricContextImp : public MetricContext {
7778
MetricStreamer *pMetricStreamer = nullptr;
7879
uint32_t subDeviceIndex = 0;
7980
bool useCompute = false;
81+
bool multiDeviceCapable = false;
8082
};
8183

8284
MetricContextImp::MetricContextImp(Device &deviceInput)
@@ -91,6 +93,8 @@ MetricContextImp::MetricContextImp(Device &deviceInput)
9193
subDeviceIndex = isSubDevice
9294
? static_cast<NEO::SubDevice *>(deviceNeo)->getSubDeviceIndex()
9395
: 0;
96+
97+
multiDeviceCapable = !isSubDevice && device.isMultiDeviceCapable();
9498
}
9599

96100
MetricContextImp::~MetricContextImp() {
@@ -163,6 +167,10 @@ void MetricContextImp::setSubDeviceIndex(const uint32_t index) {
163167
subDeviceIndex = index;
164168
}
165169

170+
bool MetricContextImp::isMultiDeviceCapable() {
171+
return multiDeviceCapable;
172+
}
173+
166174
ze_result_t
167175
MetricContextImp::activateMetricGroupsDeferred(const uint32_t count,
168176
zet_metric_group_handle_t *phMetricGroups) {
@@ -200,23 +208,12 @@ ze_result_t MetricContext::enableMetricApi() {
200208
for (auto rootDeviceHandle : rootDevices) {
201209

202210
// Initialize root device.
203-
auto rootDevice = L0::Device::fromHandle(rootDeviceHandle);
204-
failed |= !rootDevice->getMetricContext().loadDependencies();
205-
206-
// Sub devices count.
207-
uint32_t subDeviceCount = 0;
208-
rootDevice->getSubDevices(&subDeviceCount, nullptr);
209-
210-
// Sub device instances.
211-
subDevices.clear();
212-
subDevices.resize(subDeviceCount);
213-
rootDevice->getSubDevices(&subDeviceCount, subDevices.data());
211+
auto rootDevice = static_cast<DeviceImp *>(L0::Device::fromHandle(rootDeviceHandle));
212+
failed |= !rootDevice->metricContext->loadDependencies();
214213

215214
// Initialize sub devices.
216-
for (uint32_t i = 0; i < subDevices.size(); ++i) {
217-
218-
auto subDevice = L0::Device::fromHandle(subDevices[i]);
219-
failed |= !subDevice->getMetricContext().loadDependencies();
215+
for (uint32_t i = 0; i < rootDevice->numSubDevices; ++i) {
216+
failed |= !rootDevice->subDevices[i]->getMetricContext().loadDependencies();
220217
}
221218
}
222219

level_zero/tools/source/metrics/metric.h

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct MetricContext {
5656
virtual bool isComputeUsed() = 0;
5757
virtual uint32_t getSubDeviceIndex() = 0;
5858
virtual void setSubDeviceIndex(const uint32_t index) = 0;
59+
virtual bool isMultiDeviceCapable() = 0;
5960
};
6061

6162
struct Metric : _zet_metric_handle_t {

level_zero/tools/source/metrics/metric_enumeration_imp.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ ze_result_t MetricEnumeration::openMetricsDiscovery() {
128128

129129
auto &device = metricContext.getDevice();
130130
const auto &deviceImp = *static_cast<DeviceImp *>(&device);
131-
if (!deviceImp.isSubdevice && deviceImp.isMultiDeviceCapable()) {
131+
if (metricContext.isMultiDeviceCapable()) {
132132

133133
// Open metrics device for each sub device.
134134
for (size_t i = 0; i < deviceImp.numSubDevices; i++) {
@@ -167,7 +167,7 @@ ze_result_t MetricEnumeration::cleanupMetricsDiscovery() {
167167

168168
auto &device = metricContext.getDevice();
169169
const auto &deviceImp = *static_cast<DeviceImp *>(&device);
170-
if (!deviceImp.isSubdevice && deviceImp.isMultiDeviceCapable()) {
170+
if (metricContext.isMultiDeviceCapable()) {
171171

172172
for (size_t i = 0; i < deviceImp.numSubDevices; i++) {
173173
deviceImp.subDevices[i]->getMetricContext().getMetricEnumeration().cleanupMetricsDiscovery();
@@ -201,7 +201,7 @@ ze_result_t MetricEnumeration::cacheMetricInformation() {
201201

202202
auto &device = metricContext.getDevice();
203203
const auto &deviceImp = *static_cast<DeviceImp *>(&device);
204-
if (!deviceImp.isSubdevice && deviceImp.isMultiDeviceCapable()) {
204+
if (metricContext.isMultiDeviceCapable()) {
205205

206206
ze_result_t result = ZE_RESULT_SUCCESS;
207207

level_zero/tools/source/metrics/metric_query_imp.cpp

+31-14
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ void MetricsLibrary::release() {
169169
api = {};
170170
callbacks = {};
171171
context = {};
172+
isWorkloadPartitionEnabled = false;
172173
initializationState = ZE_RESULT_ERROR_UNINITIALIZED;
173174
}
174175

@@ -193,13 +194,19 @@ bool MetricsLibrary::load() {
193194
return true;
194195
}
195196

197+
void MetricsLibrary::enableWorkloadPartition() {
198+
isWorkloadPartitionEnabled = true;
199+
}
200+
196201
void MetricsLibrary::getSubDeviceClientOptions(
197-
NEO::Device &neoDevice,
198202
ClientOptionsData_1_0 &subDevice,
199203
ClientOptionsData_1_0 &subDeviceIndex,
200-
ClientOptionsData_1_0 &subDeviceCount) {
204+
ClientOptionsData_1_0 &subDeviceCount,
205+
ClientOptionsData_1_0 &workloadPartition) {
206+
207+
const auto &deviceImp = *static_cast<DeviceImp *>(&metricContext.getDevice());
201208

202-
if (!neoDevice.isSubDevice()) {
209+
if (!deviceImp.isSubdevice) {
203210

204211
// Root device.
205212
subDevice.Type = ClientOptionsType::SubDevice;
@@ -209,7 +216,10 @@ void MetricsLibrary::getSubDeviceClientOptions(
209216
subDeviceIndex.SubDeviceIndex.Index = 0;
210217

211218
subDeviceCount.Type = ClientOptionsType::SubDeviceCount;
212-
subDeviceCount.SubDeviceCount.Count = std::max(neoDevice.getNumSubDevices(), 1u);
219+
subDeviceCount.SubDeviceCount.Count = std::max(deviceImp.neoDevice->getRootDevice()->getNumSubDevices(), 1u);
220+
221+
workloadPartition.Type = ClientOptionsType::WorkloadPartition;
222+
workloadPartition.WorkloadPartition.Enabled = false;
213223

214224
} else {
215225

@@ -218,10 +228,13 @@ void MetricsLibrary::getSubDeviceClientOptions(
218228
subDevice.SubDevice.Enabled = true;
219229

220230
subDeviceIndex.Type = ClientOptionsType::SubDeviceIndex;
221-
subDeviceIndex.SubDeviceIndex.Index = static_cast<NEO::SubDevice *>(&neoDevice)->getSubDeviceIndex();
231+
subDeviceIndex.SubDeviceIndex.Index = static_cast<NEO::SubDevice *>(deviceImp.neoDevice)->getSubDeviceIndex();
222232

223233
subDeviceCount.Type = ClientOptionsType::SubDeviceCount;
224-
subDeviceCount.SubDeviceCount.Count = std::max(neoDevice.getRootDevice()->getNumSubDevices(), 1u);
234+
subDeviceCount.SubDeviceCount.Count = std::max(deviceImp.neoDevice->getRootDevice()->getNumSubDevices(), 1u);
235+
236+
workloadPartition.Type = ClientOptionsType::WorkloadPartition;
237+
workloadPartition.WorkloadPartition.Enabled = isWorkloadPartitionEnabled;
225238
}
226239
}
227240

@@ -230,7 +243,7 @@ bool MetricsLibrary::createContext() {
230243
const auto &hwHelper = device.getHwHelper();
231244
const auto &asyncComputeEngines = hwHelper.getGpgpuEngineInstances(device.getHwInfo());
232245
ContextCreateData_1_0 createData = {};
233-
ClientOptionsData_1_0 clientOptions[5] = {};
246+
ClientOptionsData_1_0 clientOptions[6] = {};
234247
ClientData_1_0 clientData = {};
235248
ClientType_1_0 clientType = {};
236249
ClientDataLinuxAdapter_1_0 adapter = {};
@@ -259,7 +272,7 @@ bool MetricsLibrary::createContext() {
259272
clientOptions[1].Tbs.Enabled = metricContext.getMetricStreamer() != nullptr;
260273

261274
// Sub device client options #2
262-
getSubDeviceClientOptions(*device.getNEODevice(), clientOptions[2], clientOptions[3], clientOptions[4]);
275+
getSubDeviceClientOptions(clientOptions[2], clientOptions[3], clientOptions[4], clientOptions[5]);
263276

264277
clientData.Linux.Adapter = &adapter;
265278
clientData.ClientOptions = clientOptions;
@@ -422,7 +435,7 @@ ze_result_t metricQueryPoolCreate(zet_context_handle_t hContext, zet_device_hand
422435
const auto &deviceImp = *static_cast<DeviceImp *>(device);
423436
auto metricPoolImp = new MetricQueryPoolImp(device->getMetricContext(), hMetricGroup, *pDesc);
424437

425-
if (!deviceImp.isSubdevice && deviceImp.isMultiDeviceCapable()) {
438+
if (metricContext.isMultiDeviceCapable()) {
426439

427440
auto emptyMetricGroups = std::vector<zet_metric_group_handle_t>();
428441
auto &metricGroups = hMetricGroup
@@ -436,12 +449,15 @@ ze_result_t metricQueryPoolCreate(zet_context_handle_t hContext, zet_device_hand
436449
for (size_t i = 0; i < deviceImp.numSubDevices; ++i) {
437450

438451
auto &subDevice = deviceImp.subDevices[i];
452+
auto &subDeviceMetricContext = subDevice->getMetricContext();
453+
454+
subDeviceMetricContext.getMetricsLibrary().enableWorkloadPartition();
439455

440456
zet_metric_group_handle_t metricGroupHandle = useMetricGroupSubDevice
441-
? metricGroups[subDevice->getMetricContext().getSubDeviceIndex()]
457+
? metricGroups[subDeviceMetricContext.getSubDeviceIndex()]
442458
: hMetricGroup;
443459

444-
auto metricPoolSubdeviceImp = new MetricQueryPoolImp(subDevice->getMetricContext(), metricGroupHandle, *pDesc);
460+
auto metricPoolSubdeviceImp = new MetricQueryPoolImp(subDeviceMetricContext, metricGroupHandle, *pDesc);
445461

446462
// Create metric query pool.
447463
if (!metricPoolSubdeviceImp->create()) {
@@ -534,7 +550,7 @@ bool MetricQueryPoolImp::allocateGpuMemory() {
534550
if (description.type == ZET_METRIC_QUERY_POOL_TYPE_PERFORMANCE) {
535551
// Get allocation size.
536552
const auto &deviceImp = *static_cast<DeviceImp *>(&metricContext.getDevice());
537-
allocationSize = (!deviceImp.isSubdevice && deviceImp.isMultiDeviceCapable())
553+
allocationSize = (metricContext.isMultiDeviceCapable())
538554
? deviceImp.subDevices[0]->getMetricContext().getMetricsLibrary().getQueryReportGpuSize() * description.count * deviceImp.numSubDevices
539555
: metricsLibrary.getQueryReportGpuSize() * description.count;
540556

@@ -867,7 +883,7 @@ ze_result_t MetricQuery::appendMemoryBarrier(CommandList &commandList) {
867883

868884
DeviceImp *pDeviceImp = static_cast<DeviceImp *>(commandList.device);
869885

870-
if (!pDeviceImp->isSubdevice && pDeviceImp->isMultiDeviceCapable()) {
886+
if (pDeviceImp->metricContext->isMultiDeviceCapable()) {
871887
// Use one of the sub-device contexts to append to command list.
872888
pDeviceImp = static_cast<DeviceImp *>(pDeviceImp->subDevices[0]);
873889
}
@@ -893,9 +909,10 @@ ze_result_t MetricQuery::appendStreamerMarker(CommandList &commandList,
893909

894910
DeviceImp *pDeviceImp = static_cast<DeviceImp *>(commandList.device);
895911

896-
if (!pDeviceImp->isSubdevice && pDeviceImp->isMultiDeviceCapable()) {
912+
if (pDeviceImp->metricContext->isMultiDeviceCapable()) {
897913
// Use one of the sub-device contexts to append to command list.
898914
pDeviceImp = static_cast<DeviceImp *>(pDeviceImp->subDevices[0]);
915+
pDeviceImp->metricContext->getMetricsLibrary().enableWorkloadPartition();
899916
}
900917
auto &metricContext = pDeviceImp->getMetricContext();
901918
auto &metricsLibrary = metricContext.getMetricsLibrary();

level_zero/tools/source/metrics/metric_query_imp.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ struct MetricsLibrary {
4545
virtual bool load();
4646
bool isInitialized();
4747
ze_result_t getInitializationState();
48-
void getSubDeviceClientOptions(NEO::Device &neoDevice,
49-
ClientOptionsData_1_0 &subDevice,
48+
void enableWorkloadPartition();
49+
void getSubDeviceClientOptions(ClientOptionsData_1_0 &subDevice,
5050
ClientOptionsData_1_0 &subDeviceIndex,
51-
ClientOptionsData_1_0 &subDeviceCount);
51+
ClientOptionsData_1_0 &subDeviceCount,
52+
ClientOptionsData_1_0 &workloadPartition);
5253
static const char *getFilename();
5354

5455
// Deinitialization.
@@ -91,6 +92,7 @@ struct MetricsLibrary {
9192
NEO::OsLibrary *handle = nullptr;
9293
MetricContext &metricContext;
9394
ze_result_t initializationState = ZE_RESULT_ERROR_UNINITIALIZED;
95+
bool isWorkloadPartitionEnabled = false;
9496
std::mutex mutex;
9597

9698
// Metrics library types.

level_zero/tools/source/metrics/metric_streamer_imp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ ze_result_t MetricStreamer::open(zet_context_handle_t hContext, zet_device_handl
295295
auto pDevice = Device::fromHandle(hDevice);
296296
const auto pDeviceImp = static_cast<const DeviceImp *>(pDevice);
297297

298-
if (!pDeviceImp->isSubdevice && pDeviceImp->isMultiDeviceCapable()) {
298+
if (pDeviceImp->metricContext->isMultiDeviceCapable()) {
299299
const uint32_t subDeviceCount = pDeviceImp->numSubDevices;
300300
auto pMetricStreamer = new MetricStreamerImp();
301301
UNRECOVERABLE_IF(pMetricStreamer == nullptr);

level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_2.cpp

+4-27
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,9 @@ TEST_F(MetricQueryPoolTest, givenRootDeviceWhenGetSubDeviceClientOptionsIsCalled
401401
auto subDevice = ClientOptionsData_1_0{};
402402
auto subDeviceIndex = ClientOptionsData_1_0{};
403403
auto subDeviceCount = ClientOptionsData_1_0{};
404+
auto workloadPartition = ClientOptionsData_1_0{};
404405

405-
metricsLibrary.getSubDeviceClientOptions(*device->getNEODevice(), subDevice, subDeviceIndex, subDeviceCount);
406+
metricsLibrary.getSubDeviceClientOptions(subDevice, subDeviceIndex, subDeviceCount, workloadPartition);
406407

407408
// Root device
408409
EXPECT_EQ(subDevice.Type, MetricsLibraryApi::ClientOptionsType::SubDevice);
@@ -413,33 +414,9 @@ TEST_F(MetricQueryPoolTest, givenRootDeviceWhenGetSubDeviceClientOptionsIsCalled
413414

414415
EXPECT_EQ(subDeviceCount.Type, MetricsLibraryApi::ClientOptionsType::SubDeviceCount);
415416
EXPECT_EQ(subDeviceCount.SubDeviceCount.Count, std::max(device->getNEODevice()->getNumSubDevices(), 1u));
416-
}
417-
418-
TEST_F(MetricQueryPoolTest, givenSubDeviceWhenGetSubDeviceClientOptionsIsCalledThenReturnSubDeviceProperties) {
419-
420-
auto deviceFactory = std::make_unique<UltDeviceFactory>(1, 4);
421-
auto rootDevice = deviceFactory->rootDevices[0];
422-
423-
auto &metricContext = device->getMetricContext();
424-
auto &metricsLibrary = metricContext.getMetricsLibrary();
425-
auto subDevice = ClientOptionsData_1_0{};
426-
auto subDeviceIndex = ClientOptionsData_1_0{};
427-
auto subDeviceCount = ClientOptionsData_1_0{};
428-
429-
// Sub devices
430-
for (uint32_t i = 0, count = std::max(rootDevice->getNumSubDevices(), 1u); i < count; ++i) {
431-
432-
metricsLibrary.getSubDeviceClientOptions(*rootDevice->subdevices[i], subDevice, subDeviceIndex, subDeviceCount);
433417

434-
EXPECT_EQ(subDevice.Type, MetricsLibraryApi::ClientOptionsType::SubDevice);
435-
EXPECT_EQ(subDevice.SubDevice.Enabled, true);
436-
437-
EXPECT_EQ(subDeviceIndex.Type, MetricsLibraryApi::ClientOptionsType::SubDeviceIndex);
438-
EXPECT_EQ(subDeviceIndex.SubDeviceIndex.Index, i);
439-
440-
EXPECT_EQ(subDeviceCount.Type, MetricsLibraryApi::ClientOptionsType::SubDeviceCount);
441-
EXPECT_EQ(subDeviceCount.SubDeviceCount.Count, std::max(rootDevice->getNumSubDevices(), 1u));
442-
}
418+
EXPECT_EQ(workloadPartition.Type, MetricsLibraryApi::ClientOptionsType::WorkloadPartition);
419+
EXPECT_EQ(workloadPartition.WorkloadPartition.Enabled, false);
443420
}
444421

445422
TEST_F(MetricQueryPoolTest, givenUninitializedMetricEnumerationWhenGetQueryReportGpuSizeIsCalledThenReturnInvalidSize) {

level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_3.cpp

+62
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,68 @@ class MultiDeviceMetricQueryPoolTest : public MetricMultiDeviceFixture,
4343
std::unique_ptr<L0::DriverHandle> driverHandle;
4444
};
4545

46+
TEST_F(MultiDeviceMetricQueryPoolTest, givenSubDeviceWhenGetSubDeviceClientOptionsIsCalledThenReturnSubDeviceProperties) {
47+
48+
auto &deviceImp = *static_cast<DeviceImp *>(devices[0]);
49+
auto subDevice = ClientOptionsData_1_0{};
50+
auto subDeviceIndex = ClientOptionsData_1_0{};
51+
auto subDeviceCount = ClientOptionsData_1_0{};
52+
auto workloadPartition = ClientOptionsData_1_0{};
53+
54+
// Sub devices
55+
for (uint32_t i = 0, count = deviceImp.numSubDevices; i < count; ++i) {
56+
57+
auto &metricContext = deviceImp.subDevices[i]->getMetricContext();
58+
auto &metricsLibrary = metricContext.getMetricsLibrary();
59+
60+
metricsLibrary.getSubDeviceClientOptions(subDevice, subDeviceIndex, subDeviceCount, workloadPartition);
61+
62+
EXPECT_EQ(subDevice.Type, MetricsLibraryApi::ClientOptionsType::SubDevice);
63+
EXPECT_EQ(subDevice.SubDevice.Enabled, true);
64+
65+
EXPECT_EQ(subDeviceIndex.Type, MetricsLibraryApi::ClientOptionsType::SubDeviceIndex);
66+
EXPECT_EQ(subDeviceIndex.SubDeviceIndex.Index, i);
67+
68+
EXPECT_EQ(subDeviceCount.Type, MetricsLibraryApi::ClientOptionsType::SubDeviceCount);
69+
EXPECT_EQ(subDeviceCount.SubDeviceCount.Count, std::max(deviceImp.numSubDevices, 1u));
70+
71+
EXPECT_EQ(workloadPartition.Type, MetricsLibraryApi::ClientOptionsType::WorkloadPartition);
72+
EXPECT_EQ(workloadPartition.WorkloadPartition.Enabled, false);
73+
}
74+
}
75+
76+
TEST_F(MultiDeviceMetricQueryPoolTest, givenSubDeviceWithWorkloadPartitionWhenGetSubDeviceClientOptionsIsCalledThenReturnSubDeviceProperties) {
77+
78+
auto &deviceImp = *static_cast<DeviceImp *>(devices[0]);
79+
auto subDevice = ClientOptionsData_1_0{};
80+
auto subDeviceIndex = ClientOptionsData_1_0{};
81+
auto subDeviceCount = ClientOptionsData_1_0{};
82+
auto workloadPartition = ClientOptionsData_1_0{};
83+
84+
// Sub devices
85+
for (uint32_t i = 0, count = deviceImp.numSubDevices; i < count; ++i) {
86+
87+
auto &metricContext = deviceImp.subDevices[i]->getMetricContext();
88+
auto &metricsLibrary = metricContext.getMetricsLibrary();
89+
90+
metricsLibrary.enableWorkloadPartition();
91+
92+
metricsLibrary.getSubDeviceClientOptions(subDevice, subDeviceIndex, subDeviceCount, workloadPartition);
93+
94+
EXPECT_EQ(subDevice.Type, MetricsLibraryApi::ClientOptionsType::SubDevice);
95+
EXPECT_EQ(subDevice.SubDevice.Enabled, true);
96+
97+
EXPECT_EQ(subDeviceIndex.Type, MetricsLibraryApi::ClientOptionsType::SubDeviceIndex);
98+
EXPECT_EQ(subDeviceIndex.SubDeviceIndex.Index, i);
99+
100+
EXPECT_EQ(subDeviceCount.Type, MetricsLibraryApi::ClientOptionsType::SubDeviceCount);
101+
EXPECT_EQ(subDeviceCount.SubDeviceCount.Count, std::max(deviceImp.numSubDevices, 1u));
102+
103+
EXPECT_EQ(workloadPartition.Type, MetricsLibraryApi::ClientOptionsType::WorkloadPartition);
104+
EXPECT_EQ(workloadPartition.WorkloadPartition.Enabled, true);
105+
}
106+
}
107+
46108
TEST_F(MultiDeviceMetricQueryPoolTest, givenCorrectArgumentsWhenZetMetricQueryPoolCreateIsCalledThenReturnsSuccess) {
47109

48110
zet_device_handle_t metricDevice = devices[0]->toHandle();

0 commit comments

Comments
 (0)