Skip to content

Commit d3432c6

Browse files
fix: respect max subslice count when parsing subslice info in xe path
don't parse more data than max subslice count setup slice count based on slice indices size unify get topology map and get topology data methods to reduce loop iterations Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent 3a082c9 commit d3432c6

File tree

3 files changed

+85
-89
lines changed

3 files changed

+85
-89
lines changed

shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp

Lines changed: 62 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -442,75 +442,6 @@ bool IoctlHelperXe::setGpuCpuTimes(TimeStampData *pGpuCpuTime, OSTime *osTime) {
442442
return ret == 0;
443443
}
444444

445-
void IoctlHelperXe::getTopologyData(size_t nTiles, std::vector<std::bitset<8>> *geomDss, std::vector<std::bitset<8>> *computeDss,
446-
std::vector<std::bitset<8>> *euDss, std::vector<std::bitset<8>> *l3BanksMask, DrmQueryTopologyData &topologyData, bool &isComputeDssEmpty) {
447-
int subSliceCount = 0;
448-
int euPerDss = 0;
449-
int l3Banks = 0;
450-
451-
for (auto tileId = 0u; tileId < nTiles; tileId++) {
452-
453-
int subSliceCountPerTile = 0;
454-
455-
for (auto byte = 0u; byte < computeDss[tileId].size(); byte++) {
456-
subSliceCountPerTile += computeDss[tileId][byte].count();
457-
}
458-
459-
if (subSliceCountPerTile == 0) {
460-
isComputeDssEmpty = true;
461-
for (auto byte = 0u; byte < geomDss[tileId].size(); byte++) {
462-
subSliceCountPerTile += geomDss[tileId][byte].count();
463-
}
464-
}
465-
466-
int euPerDssPerTile = 0;
467-
for (auto byte = 0u; byte < euDss[tileId].size(); byte++) {
468-
euPerDssPerTile += euDss[tileId][byte].count();
469-
}
470-
471-
int l3BanksPerTile = 0;
472-
for (auto byte = 0u; byte < l3BanksMask[tileId].size(); byte++) {
473-
l3BanksPerTile += l3BanksMask[tileId][byte].count();
474-
}
475-
476-
// pick smallest config
477-
subSliceCount = (subSliceCount == 0) ? subSliceCountPerTile : std::min(subSliceCount, subSliceCountPerTile);
478-
euPerDss = (euPerDss == 0) ? euPerDssPerTile : std::min(euPerDss, euPerDssPerTile);
479-
l3Banks = (l3Banks == 0) ? l3BanksPerTile : std::min(l3Banks, l3BanksPerTile);
480-
481-
// pick max config
482-
topologyData.maxSubSlicesPerSlice = std::max(topologyData.maxSubSlicesPerSlice, subSliceCountPerTile);
483-
topologyData.maxEusPerSubSlice = std::max(topologyData.maxEusPerSubSlice, euPerDssPerTile);
484-
}
485-
486-
topologyData.sliceCount = 1;
487-
topologyData.subSliceCount = subSliceCount;
488-
topologyData.euCount = subSliceCount * euPerDss;
489-
topologyData.maxSlices = 1;
490-
topologyData.numL3Banks = l3Banks;
491-
}
492-
493-
void IoctlHelperXe::getTopologyMap(size_t nTiles, std::vector<std::bitset<8>> *dssInfo, TopologyMap &topologyMap) {
494-
for (auto tileId = 0u; tileId < nTiles; tileId++) {
495-
std::vector<int> sliceIndices;
496-
std::vector<int> subSliceIndices;
497-
498-
sliceIndices.push_back(0);
499-
500-
for (auto byte = 0u; byte < dssInfo[tileId].size(); byte++) {
501-
for (auto bit = 0u; bit < 8u; bit++) {
502-
if (dssInfo[tileId][byte].test(bit)) {
503-
auto subSliceIndex = byte * 8 + bit;
504-
subSliceIndices.push_back(subSliceIndex);
505-
}
506-
}
507-
}
508-
509-
topologyMap[tileId].sliceIndices = std::move(sliceIndices);
510-
topologyMap[tileId].subsliceIndices = std::move(subSliceIndices);
511-
}
512-
}
513-
514445
bool IoctlHelperXe::getTopologyDataAndMap(const HardwareInfo &hwInfo, DrmQueryTopologyData &topologyData, TopologyMap &topologyMap) {
515446

516447
auto queryGtTopology = queryData<uint8_t>(DRM_XE_DEVICE_QUERY_GT_TOPOLOGY);
@@ -569,12 +500,70 @@ bool IoctlHelperXe::getTopologyDataAndMap(const HardwareInfo &hwInfo, DrmQueryTo
569500
dataPtr = ptrOffset(dataPtr, itemSize);
570501
}
571502

572-
bool isComputeDssEmpty = false;
573-
getTopologyData(numTiles, geomDss.begin(), computeDss.begin(), euDss.begin(), l3Banks.begin(), topologyData, isComputeDssEmpty);
503+
int sliceCount = 0;
504+
int subSliceCount = 0;
505+
int euPerDss = 0;
506+
int l3BankCount = 0;
507+
uint32_t hwMaxSubSliceCount = hwInfo.gtSystemInfo.MaxSubSlicesSupported;
574508

575-
auto &dssInfo = isComputeDssEmpty ? geomDss : computeDss;
576-
getTopologyMap(numTiles, dssInfo.begin(), topologyMap);
509+
for (auto tileId = 0u; tileId < numTiles; tileId++) {
510+
511+
int subSliceCountPerTile = 0;
512+
513+
std::vector<int> sliceIndices;
514+
std::vector<int> subSliceIndices;
577515

516+
sliceIndices.push_back(0);
517+
518+
for (auto subSliceId = 0u; subSliceId < std::min(hwMaxSubSliceCount, static_cast<uint32_t>(computeDss[tileId].size() * 8)); subSliceId++) {
519+
auto byte = subSliceId / 8;
520+
auto bit = subSliceId & 0b111;
521+
if (computeDss[tileId][byte].test(bit)) {
522+
subSliceIndices.push_back(subSliceId);
523+
subSliceCountPerTile++;
524+
}
525+
}
526+
527+
if (subSliceCountPerTile == 0) {
528+
for (auto subSliceId = 0u; subSliceId < std::min(hwMaxSubSliceCount, static_cast<uint32_t>(geomDss[tileId].size() * 8)); subSliceId++) {
529+
auto byte = subSliceId / 8;
530+
auto bit = subSliceId & 0b111;
531+
if (geomDss[tileId][byte].test(bit)) {
532+
subSliceIndices.push_back(subSliceId);
533+
subSliceCountPerTile++;
534+
}
535+
}
536+
}
537+
topologyMap[tileId].sliceIndices = std::move(sliceIndices);
538+
topologyMap[tileId].subsliceIndices = std::move(subSliceIndices);
539+
int sliceCountPerTile = static_cast<int>(topologyMap[tileId].sliceIndices.size());
540+
541+
int euPerDssPerTile = 0;
542+
for (auto byte = 0u; byte < euDss[tileId].size(); byte++) {
543+
euPerDssPerTile += euDss[tileId][byte].count();
544+
}
545+
546+
int l3BankCountPerTile = 0;
547+
for (auto byte = 0u; byte < l3Banks[tileId].size(); byte++) {
548+
l3BankCountPerTile += l3Banks[tileId][byte].count();
549+
}
550+
551+
// pick smallest config
552+
sliceCount = (sliceCount == 0) ? sliceCountPerTile : std::min(sliceCount, sliceCountPerTile);
553+
subSliceCount = (subSliceCount == 0) ? subSliceCountPerTile : std::min(subSliceCount, subSliceCountPerTile);
554+
euPerDss = (euPerDss == 0) ? euPerDssPerTile : std::min(euPerDss, euPerDssPerTile);
555+
l3BankCount = (l3BankCount == 0) ? l3BankCountPerTile : std::min(l3BankCount, l3BankCountPerTile);
556+
557+
// pick max config
558+
topologyData.maxSubSlicesPerSlice = std::max(topologyData.maxSubSlicesPerSlice, subSliceCountPerTile);
559+
topologyData.maxEusPerSubSlice = std::max(topologyData.maxEusPerSubSlice, euPerDssPerTile);
560+
}
561+
562+
topologyData.sliceCount = sliceCount;
563+
topologyData.subSliceCount = subSliceCount;
564+
topologyData.euCount = subSliceCount * euPerDss;
565+
topologyData.maxSlices = sliceCount;
566+
topologyData.numL3Banks = l3BankCount;
578567
return receivedDssInfo;
579568
}
580569

shared/source/os_interface/linux/xe/ioctl_helper_xe.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ class IoctlHelperXe : public IoctlHelper {
113113
std::unique_ptr<MemoryInfo> createMemoryInfo() override;
114114
size_t getLocalMemoryRegionsSize(const MemoryInfo *memoryInfo, uint32_t subDevicesCount, uint32_t deviceBitfield) const override;
115115
void setupIpVersion() override;
116-
void getTopologyData(size_t nTiles, std::vector<std::bitset<8>> *geomDss, std::vector<std::bitset<8>> *computeDss, std::vector<std::bitset<8>> *euDss, std::vector<std::bitset<8>> *l3BanksMask, DrmQueryTopologyData &topologyData, bool &isComputeDssEmpty);
117-
void getTopologyMap(size_t nTiles, std::vector<std::bitset<8>> *dssInfo, TopologyMap &topologyMap);
118116

119117
bool setGpuCpuTimes(TimeStampData *pGpuCpuTime, OSTime *osTime) override;
120118
void fillBindInfoForIpcHandle(uint32_t handle, size_t size) override;

shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ TEST(IoctlHelperXeTest, givenGeomDssWhenGetTopologyDataAndMapThenResultsAreCorre
695695
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
696696
auto drm = DrmMockXe::create(*executionEnvironment->rootDeviceEnvironments[0]);
697697
auto xeIoctlHelper = static_cast<MockIoctlHelperXe *>(drm->getIoctlHelper());
698-
auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo();
698+
auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo();
699699

700700
xeIoctlHelper->initialize();
701701

@@ -708,6 +708,7 @@ TEST(IoctlHelperXeTest, givenGeomDssWhenGetTopologyDataAndMapThenResultsAreCorre
708708
DrmQueryTopologyData topologyData{};
709709
TopologyMap topologyMap{};
710710

711+
hwInfo.gtSystemInfo.MaxSubSlicesSupported = 64;
711712
auto result = xeIoctlHelper->getTopologyDataAndMap(hwInfo, topologyData, topologyMap);
712713
ASSERT_TRUE(result);
713714

@@ -744,7 +745,7 @@ TEST(IoctlHelperXeTest, givenUnknownTopologyTypeWhenGetTopologyDataAndMapThenNot
744745
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
745746
auto drm = DrmMockXe::create(*executionEnvironment->rootDeviceEnvironments[0]);
746747
auto xeIoctlHelper = static_cast<MockIoctlHelperXe *>(drm->getIoctlHelper());
747-
auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo();
748+
auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo();
748749
xeIoctlHelper->initialize();
749750

750751
constexpr int16_t unknownTopology = -1;
@@ -759,6 +760,7 @@ TEST(IoctlHelperXeTest, givenUnknownTopologyTypeWhenGetTopologyDataAndMapThenNot
759760
DrmQueryTopologyData topologyData{};
760761
TopologyMap topologyMap{};
761762

763+
hwInfo.gtSystemInfo.MaxSubSlicesSupported = 64;
762764
auto result = xeIoctlHelper->getTopologyDataAndMap(hwInfo, topologyData, topologyMap);
763765
ASSERT_TRUE(result);
764766

@@ -795,7 +797,7 @@ TEST(IoctlHelperXeTest, givenComputeDssWhenGetTopologyDataAndMapThenResultsAreCo
795797
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
796798
auto drm = DrmMockXe::create(*executionEnvironment->rootDeviceEnvironments[0]);
797799
auto xeIoctlHelper = static_cast<MockIoctlHelperXe *>(drm->getIoctlHelper());
798-
auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo();
800+
auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo();
799801
xeIoctlHelper->initialize();
800802

801803
uint16_t tileId = 0;
@@ -808,17 +810,18 @@ TEST(IoctlHelperXeTest, givenComputeDssWhenGetTopologyDataAndMapThenResultsAreCo
808810
DrmQueryTopologyData topologyData{};
809811
TopologyMap topologyMap{};
810812

813+
hwInfo.gtSystemInfo.MaxSubSlicesSupported = 32u;
811814
auto result = xeIoctlHelper->getTopologyDataAndMap(hwInfo, topologyData, topologyMap);
812815
ASSERT_TRUE(result);
813816

814817
// verify topology data
815818
EXPECT_EQ(1, topologyData.sliceCount);
816819
EXPECT_EQ(1, topologyData.maxSlices);
817820

818-
EXPECT_EQ(64, topologyData.subSliceCount);
819-
EXPECT_EQ(64, topologyData.maxSubSlicesPerSlice);
821+
EXPECT_EQ(32, topologyData.subSliceCount);
822+
EXPECT_EQ(32, topologyData.maxSubSlicesPerSlice);
820823

821-
EXPECT_EQ(512, topologyData.euCount);
824+
EXPECT_EQ(256, topologyData.euCount);
822825
EXPECT_EQ(8, topologyData.maxEusPerSubSlice);
823826

824827
// verify topology map
@@ -832,7 +835,7 @@ TEST(IoctlHelperXeTest, givenComputeDssWhenGetTopologyDataAndMapThenResultsAreCo
832835

833836
std::vector<int> expectedSubSliceIndices;
834837
expectedSubSliceIndices.reserve(64u);
835-
for (auto i = 0u; i < 64; i++) {
838+
for (auto i = 0u; i < hwInfo.gtSystemInfo.MaxSubSlicesSupported; i++) {
836839
expectedSubSliceIndices.emplace_back(i);
837840
}
838841

@@ -877,8 +880,8 @@ TEST(IoctlHelperXeTest, givenOnlyMediaTypeWhenGetTopologyDataAndMapThenSubsliceI
877880
EXPECT_FALSE(result);
878881

879882
// verify topology data
880-
EXPECT_EQ(1, topologyData.sliceCount);
881-
EXPECT_EQ(1, topologyData.maxSlices);
883+
EXPECT_EQ(0, topologyData.sliceCount);
884+
EXPECT_EQ(0, topologyData.maxSlices);
882885

883886
EXPECT_EQ(0, topologyData.subSliceCount);
884887
EXPECT_EQ(0, topologyData.maxSubSlicesPerSlice);
@@ -936,7 +939,7 @@ TEST(IoctlHelperXeTest, givenMainAndMediaTypesWhenGetTopologyDataAndMapThenResul
936939
0x100, // slow mem regions
937940
};
938941

939-
auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo();
942+
auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo();
940943
auto xeIoctlHelper = static_cast<MockIoctlHelperXe *>(drm->getIoctlHelper());
941944
xeIoctlHelper->initialize();
942945
for (auto tileId = 0; tileId < 4; tileId++) {
@@ -948,6 +951,8 @@ TEST(IoctlHelperXeTest, givenMainAndMediaTypesWhenGetTopologyDataAndMapThenResul
948951
DrmQueryTopologyData topologyData{};
949952
TopologyMap topologyMap{};
950953

954+
hwInfo.gtSystemInfo.MaxSubSlicesSupported = 64;
955+
951956
auto result = xeIoctlHelper->getTopologyDataAndMap(hwInfo, topologyData, topologyMap);
952957
ASSERT_TRUE(result);
953958

@@ -973,7 +978,7 @@ TEST(IoctlHelperXeTest, given2TileAndComputeDssWhenGetTopologyDataAndMapThenResu
973978
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
974979
auto drm = DrmMockXe::create(*executionEnvironment->rootDeviceEnvironments[0]);
975980
auto xeIoctlHelper = static_cast<MockIoctlHelperXe *>(drm->getIoctlHelper());
976-
auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo();
981+
auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo();
977982
xeIoctlHelper->initialize();
978983

979984
for (auto gtId = 0u; gtId < 4u; gtId++) {
@@ -985,6 +990,7 @@ TEST(IoctlHelperXeTest, given2TileAndComputeDssWhenGetTopologyDataAndMapThenResu
985990
DrmQueryTopologyData topologyData{};
986991
TopologyMap topologyMap{};
987992

993+
hwInfo.gtSystemInfo.MaxSubSlicesSupported = 64;
988994
auto result = xeIoctlHelper->getTopologyDataAndMap(hwInfo, topologyData, topologyMap);
989995
ASSERT_TRUE(result);
990996

@@ -1028,7 +1034,7 @@ TEST(IoctlHelperXeTest, given2TileWithDisabledDssOn1TileAndComputeDssWhenGetTopo
10281034
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
10291035
auto drm = DrmMockXe::create(*executionEnvironment->rootDeviceEnvironments[0]);
10301036
auto xeIoctlHelper = static_cast<MockIoctlHelperXe *>(drm->getIoctlHelper());
1031-
auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo();
1037+
auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo();
10321038
xeIoctlHelper->initialize();
10331039

10341040
for (auto gtId = 0u; gtId < 4u; gtId++) {
@@ -1045,6 +1051,7 @@ TEST(IoctlHelperXeTest, given2TileWithDisabledDssOn1TileAndComputeDssWhenGetTopo
10451051
DrmQueryTopologyData topologyData{};
10461052
TopologyMap topologyMap{};
10471053

1054+
hwInfo.gtSystemInfo.MaxSubSlicesSupported = 64;
10481055
auto result = xeIoctlHelper->getTopologyDataAndMap(hwInfo, topologyData, topologyMap);
10491056
ASSERT_TRUE(result);
10501057

@@ -1095,7 +1102,7 @@ TEST(IoctlHelperXeTest, given2TileWithDisabledEvenDssAndComputeDssWhenGetTopolog
10951102
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
10961103
auto drm = DrmMockXe::create(*executionEnvironment->rootDeviceEnvironments[0]);
10971104
auto xeIoctlHelper = static_cast<MockIoctlHelperXe *>(drm->getIoctlHelper());
1098-
auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo();
1105+
auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo();
10991106
xeIoctlHelper->initialize();
11001107

11011108
// even dss disabled
@@ -1110,6 +1117,7 @@ TEST(IoctlHelperXeTest, given2TileWithDisabledEvenDssAndComputeDssWhenGetTopolog
11101117
DrmQueryTopologyData topologyData{};
11111118
TopologyMap topologyMap{};
11121119

1120+
hwInfo.gtSystemInfo.MaxSubSlicesSupported = 64;
11131121
auto result = xeIoctlHelper->getTopologyDataAndMap(hwInfo, topologyData, topologyMap);
11141122
ASSERT_TRUE(result);
11151123

@@ -1182,7 +1190,7 @@ TEST(IoctlHelperXeTest, givenMissingEuPerDssInTopologyWhenGetTopologyDataAndMapT
11821190
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
11831191
auto drm = DrmMockXe::create(*executionEnvironment->rootDeviceEnvironments[0]);
11841192
auto xeIoctlHelper = static_cast<MockIoctlHelperXe *>(drm->getIoctlHelper());
1185-
auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo();
1193+
auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo();
11861194
xeIoctlHelper->initialize();
11871195

11881196
const auto &tileIdToGtId = xeIoctlHelper->tileIdToGtId;
@@ -1199,6 +1207,7 @@ TEST(IoctlHelperXeTest, givenMissingEuPerDssInTopologyWhenGetTopologyDataAndMapT
11991207
drm->addMockedQueryTopologyData(tileIdToGtId[tileId], DRM_XE_TOPO_DSS_GEOMETRY, 8, {0, 0, 0, 0, 0, 0, 0, 0});
12001208
drm->addMockedQueryTopologyData(tileIdToGtId[tileId], DRM_XE_TOPO_DSS_COMPUTE, 8, {0b1111'1111, 0b1111'1111, 0, 0, 0, 0, 0, 0});
12011209
}
1210+
hwInfo.gtSystemInfo.MaxSubSlicesSupported = 64;
12021211
auto result = xeIoctlHelper->getTopologyDataAndMap(hwInfo, topologyData, topologyMap);
12031212
EXPECT_TRUE(result);
12041213

0 commit comments

Comments
 (0)