Skip to content

Commit f83b51e

Browse files
Refactor Drm::queryTopology() to take struct
Related-To: NEO-5640 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
1 parent 4958418 commit f83b51e

File tree

6 files changed

+109
-29
lines changed

6 files changed

+109
-29
lines changed

opencl/test/unit_test/os_interface/linux/hw_info_config_linux_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ TEST_F(HwInfoConfigTestLinuxDummy, givenInvalidTopologyDataWhenConfiguringThenRe
301301
drm->StoredSSVal = storedSSVal;
302302
drm->StoredEUVal = 0;
303303

304-
int sliceCount, subSliceCount, euCount;
305-
EXPECT_FALSE(drm->queryTopology(outHwInfo, sliceCount, subSliceCount, euCount));
304+
Drm::QueryTopologyData topologyData = {};
305+
EXPECT_FALSE(drm->queryTopology(outHwInfo, topologyData));
306306
}
307307

308308
{
@@ -311,8 +311,8 @@ TEST_F(HwInfoConfigTestLinuxDummy, givenInvalidTopologyDataWhenConfiguringThenRe
311311
drm->StoredSSVal = 0;
312312
drm->StoredEUVal = storedEUVal;
313313

314-
int sliceCount, subSliceCount, euCount;
315-
EXPECT_FALSE(drm->queryTopology(outHwInfo, sliceCount, subSliceCount, euCount));
314+
Drm::QueryTopologyData topologyData = {};
315+
EXPECT_FALSE(drm->queryTopology(outHwInfo, topologyData));
316316
}
317317

318318
{
@@ -321,8 +321,8 @@ TEST_F(HwInfoConfigTestLinuxDummy, givenInvalidTopologyDataWhenConfiguringThenRe
321321
drm->StoredSSVal = storedSSVal;
322322
drm->StoredEUVal = storedEUVal;
323323

324-
int sliceCount, subSliceCount, euCount;
325-
EXPECT_FALSE(drm->queryTopology(outHwInfo, sliceCount, subSliceCount, euCount));
324+
Drm::QueryTopologyData topologyData = {};
325+
EXPECT_FALSE(drm->queryTopology(outHwInfo, topologyData));
326326
}
327327
}
328328

shared/source/os_interface/linux/drm_neo.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,33 +307,40 @@ int Drm::getErrno() {
307307
int Drm::setupHardwareInfo(DeviceDescriptor *device, bool setupFeatureTableAndWorkaroundTable) {
308308
HardwareInfo *hwInfo = const_cast<HardwareInfo *>(device->pHwInfo);
309309
int ret;
310-
int sliceTotal;
311-
int subSliceTotal;
312-
int euTotal;
313310

314-
bool status = queryTopology(*hwInfo, sliceTotal, subSliceTotal, euTotal);
311+
Drm::QueryTopologyData topologyData = {};
312+
313+
bool status = queryTopology(*hwInfo, topologyData);
315314

316315
if (!status) {
317316
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "WARNING: Topology query failed!\n");
318317

319-
sliceTotal = hwInfo->gtSystemInfo.SliceCount;
318+
topologyData.sliceCount = hwInfo->gtSystemInfo.SliceCount;
320319

321-
ret = getEuTotal(euTotal);
320+
ret = getEuTotal(topologyData.euCount);
322321
if (ret != 0) {
323322
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "FATAL: Cannot query EU total parameter!\n");
324323
return ret;
325324
}
326325

327-
ret = getSubsliceTotal(subSliceTotal);
326+
ret = getSubsliceTotal(topologyData.subSliceCount);
328327
if (ret != 0) {
329328
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "FATAL: Cannot query subslice total parameter!\n");
330329
return ret;
331330
}
331+
332+
topologyData.maxEuCount = topologyData.euCount;
333+
topologyData.maxSliceCount = topologyData.sliceCount;
334+
topologyData.maxSubSliceCount = topologyData.subSliceCount;
332335
}
333336

334-
hwInfo->gtSystemInfo.SliceCount = static_cast<uint32_t>(sliceTotal);
335-
hwInfo->gtSystemInfo.SubSliceCount = static_cast<uint32_t>(subSliceTotal);
336-
hwInfo->gtSystemInfo.EUCount = static_cast<uint32_t>(euTotal);
337+
hwInfo->gtSystemInfo.SliceCount = static_cast<uint32_t>(topologyData.sliceCount);
338+
hwInfo->gtSystemInfo.SubSliceCount = static_cast<uint32_t>(topologyData.subSliceCount);
339+
hwInfo->gtSystemInfo.EUCount = static_cast<uint32_t>(topologyData.euCount);
340+
341+
hwInfo->gtSystemInfo.MaxSubSlicesSupported = topologyData.maxSubSliceCount;
342+
hwInfo->gtSystemInfo.MaxDualSubSlicesSupported = topologyData.maxSubSliceCount;
343+
hwInfo->gtSystemInfo.MaxSlicesSupported = topologyData.maxSliceCount;
337344

338345
status = querySystemInfo();
339346
if (!status) {

shared/source/os_interface/linux/drm_neo.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ class Drm {
6565
MaxSize
6666
};
6767

68+
struct QueryTopologyData {
69+
int sliceCount;
70+
int subSliceCount;
71+
int euCount;
72+
73+
int maxSliceCount;
74+
int maxSubSliceCount;
75+
int maxEuCount;
76+
};
77+
6878
virtual ~Drm();
6979

7080
virtual int ioctl(unsigned long request, void *arg);
@@ -104,7 +114,7 @@ class Drm {
104114
MOCKABLE_VIRTUAL bool querySystemInfo();
105115
MOCKABLE_VIRTUAL bool queryEngineInfo();
106116
MOCKABLE_VIRTUAL bool queryMemoryInfo();
107-
bool queryTopology(const HardwareInfo &hwInfo, int &sliceCount, int &subSliceCount, int &euCount);
117+
bool queryTopology(const HardwareInfo &hwInfo, QueryTopologyData &data);
108118
bool createVirtualMemoryAddressSpace(uint32_t vmCount);
109119
void destroyVirtualMemoryAddressSpace();
110120
uint32_t getVirtualMemoryAddressSpace(uint32_t vmId);

shared/source/os_interface/linux/drm_query_extended.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace NEO {
1313

14-
bool Drm::queryTopology(const HardwareInfo &hwInfo, int &sliceCount, int &subSliceCount, int &euCount) {
14+
bool Drm::queryTopology(const HardwareInfo &hwInfo, QueryTopologyData &topologyData) {
1515
int32_t length;
1616
auto dataQuery = this->query(DRM_I915_QUERY_TOPOLOGY_INFO, DrmQueryItemFlags::topology, length);
1717
auto data = reinterpret_cast<drm_i915_query_topology_info *>(dataQuery.get());
@@ -20,7 +20,11 @@ bool Drm::queryTopology(const HardwareInfo &hwInfo, int &sliceCount, int &subSli
2020
return false;
2121
}
2222

23-
return translateTopologyInfo(data, sliceCount, subSliceCount, euCount);
23+
topologyData.maxSliceCount = data->max_slices;
24+
topologyData.maxSubSliceCount = data->max_subslices;
25+
topologyData.maxEuCount = data->max_eus_per_subslice;
26+
27+
return translateTopologyInfo(data, topologyData.sliceCount, topologyData.subSliceCount, topologyData.euCount);
2428
}
2529

2630
bool Drm::isDebugAttachAvailable() {

shared/source/os_interface/linux/hw_info_config.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,37 +90,43 @@ int HwInfoConfig::configureHwInfo(const HardwareInfo *inHwInfo, HardwareInfo *ou
9090
}
9191
platform->usRevId = static_cast<unsigned short>(val);
9292

93-
int sliceCount;
94-
int subSliceCount;
95-
int euCount;
93+
Drm::QueryTopologyData topologyData = {};
9694

97-
bool status = drm->queryTopology(*outHwInfo, sliceCount, subSliceCount, euCount);
95+
bool status = drm->queryTopology(*outHwInfo, topologyData);
9896

9997
if (!status) {
10098
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "WARNING: Topology query failed!\n");
10199

102-
sliceCount = gtSystemInfo->SliceCount;
100+
topologyData.sliceCount = gtSystemInfo->SliceCount;
103101

104-
ret = drm->getEuTotal(euCount);
102+
ret = drm->getEuTotal(topologyData.euCount);
105103
if (ret != 0) {
106104
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "FATAL: Cannot query EU total parameter!\n");
107105
*outHwInfo = {};
108106
return ret;
109107
}
110108

111-
ret = drm->getSubsliceTotal(subSliceCount);
109+
ret = drm->getSubsliceTotal(topologyData.subSliceCount);
112110
if (ret != 0) {
113111
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "FATAL: Cannot query subslice total parameter!\n");
114112
*outHwInfo = {};
115113
return ret;
116114
}
115+
116+
topologyData.maxEuCount = topologyData.euCount / topologyData.subSliceCount;
117+
topologyData.maxSliceCount = topologyData.sliceCount;
118+
topologyData.maxSubSliceCount = topologyData.subSliceCount;
117119
}
118120

119-
gtSystemInfo->SliceCount = static_cast<uint32_t>(sliceCount);
120-
gtSystemInfo->SubSliceCount = static_cast<uint32_t>(subSliceCount);
121-
gtSystemInfo->EUCount = static_cast<uint32_t>(euCount);
121+
gtSystemInfo->SliceCount = static_cast<uint32_t>(topologyData.sliceCount);
122+
gtSystemInfo->SubSliceCount = static_cast<uint32_t>(topologyData.subSliceCount);
123+
gtSystemInfo->EUCount = static_cast<uint32_t>(topologyData.euCount);
122124
gtSystemInfo->ThreadCount = this->threadsPerEu * gtSystemInfo->EUCount;
123125

126+
gtSystemInfo->MaxEuPerSubSlice = topologyData.maxEuCount;
127+
gtSystemInfo->MaxSubSlicesSupported = topologyData.maxSubSliceCount;
128+
gtSystemInfo->MaxSlicesSupported = topologyData.maxSliceCount;
129+
124130
uint64_t gttSizeQuery = 0;
125131
featureTable->ftrSVM = true;
126132

shared/test/unit_test/os_interface/linux/drm_query_tests.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77

88
#include "shared/source/helpers/file_io.h"
99
#include "shared/source/helpers/hw_info.h"
10+
#include "shared/source/os_interface/hw_info_config.h"
11+
#include "shared/source/os_interface/linux/os_interface.h"
1012
#include "shared/test/common/helpers/default_hw_info.h"
1113

1214
#include "opencl/test/unit_test/os_interface/linux/drm_mock.h"
15+
#include "test.h"
1316

1417
#include "gtest/gtest.h"
1518

@@ -43,3 +46,53 @@ TEST(DrmQueryTest, WhenCallingIsDebugAttachAvailableThenReturnValueIsFalse) {
4346

4447
EXPECT_FALSE(drm.isDebugAttachAvailable());
4548
}
49+
50+
TEST(DrmQueryTest, GivenDrmWhenQueryingTopologyInfoCorrectMaxValuesAreSet) {
51+
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
52+
executionEnvironment->prepareRootDeviceEnvironments(1);
53+
54+
*executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo() = *NEO::defaultHwInfo.get();
55+
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
56+
57+
Drm::QueryTopologyData topologyData = {};
58+
59+
EXPECT_TRUE(drm.queryTopology(*executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo(), topologyData));
60+
61+
EXPECT_EQ(drm.StoredSVal, topologyData.sliceCount);
62+
EXPECT_EQ(drm.StoredSSVal, topologyData.subSliceCount);
63+
EXPECT_EQ(drm.StoredEUVal, topologyData.euCount);
64+
65+
EXPECT_EQ(drm.StoredSVal, topologyData.maxSliceCount);
66+
EXPECT_EQ(drm.StoredSSVal / drm.StoredSVal, topologyData.maxSubSliceCount);
67+
EXPECT_EQ(drm.StoredEUVal / drm.StoredSSVal, topologyData.maxEuCount);
68+
}
69+
70+
using HwConfigTopologyQuery = ::testing::Test;
71+
72+
HWTEST2_F(HwConfigTopologyQuery, WhenGettingTopologyFailsThenSetMaxValuesBasedOnEuAndSubsliceIoctlQueries, MatchAny) {
73+
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
74+
executionEnvironment->prepareRootDeviceEnvironments(1);
75+
76+
*executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo() = *NEO::defaultHwInfo.get();
77+
auto drm = new DrmMock(*executionEnvironment->rootDeviceEnvironments[0]);
78+
79+
drm->setGtType(GTTYPE_GT1);
80+
81+
auto osInterface = std::make_unique<OSInterface>();
82+
osInterface->get()->setDrm(static_cast<Drm *>(drm));
83+
84+
drm->failRetTopology = true;
85+
86+
auto hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo();
87+
HardwareInfo outHwInfo;
88+
auto hwConfig = HwInfoConfigHw<productFamily>::get();
89+
int ret = hwConfig->configureHwInfo(&hwInfo, &outHwInfo, osInterface.get());
90+
EXPECT_NE(-1, ret);
91+
92+
EXPECT_EQ(outHwInfo.gtSystemInfo.EUCount / outHwInfo.gtSystemInfo.SubSliceCount, outHwInfo.gtSystemInfo.MaxEuPerSubSlice);
93+
EXPECT_EQ(outHwInfo.gtSystemInfo.SubSliceCount, outHwInfo.gtSystemInfo.MaxSubSlicesSupported);
94+
EXPECT_EQ(hwInfo.gtSystemInfo.SliceCount, outHwInfo.gtSystemInfo.MaxSlicesSupported);
95+
96+
EXPECT_EQ(static_cast<uint32_t>(drm->StoredEUVal), outHwInfo.gtSystemInfo.EUCount);
97+
EXPECT_EQ(static_cast<uint32_t>(drm->StoredSSVal), outHwInfo.gtSystemInfo.SubSliceCount);
98+
}

0 commit comments

Comments
 (0)