Skip to content

Commit f2c4231

Browse files
Extend DRM mock and queryTopology tests - part 1
Signed-off-by: Daniel Chabrowski [email protected] Related-To: NEO-6591
1 parent 452de80 commit f2c4231

30 files changed

+818
-84
lines changed

level_zero/tools/test/unit_tests/sources/sysman/engine/linux/test_zes_engine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ZesEngineFixture : public SysmanDeviceFixture {
5050

5151
EngineHandleContext *pEngineHandleContext = pSysmanDeviceImp->pEngineHandleContext;
5252
pDrm = std::make_unique<NiceMock<Mock<EngineNeoDrm>>>(const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment()));
53-
pDrm->setupIoctlHelper();
53+
pDrm->setupIoctlHelper(neoDevice->getRootDeviceEnvironment().getHardwareInfo()->platform.eProductFamily);
5454
pPmuInterface = std::make_unique<NiceMock<Mock<MockPmuInterfaceImp>>>(pLinuxSysmanImp);
5555
pOriginalDrm = pLinuxSysmanImp->pDrm;
5656
pOriginalPmuInterface = pLinuxSysmanImp->pPmuInterface;

level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ constexpr int mockFd = 0;
3232
class SysmanMockDrm : public Drm {
3333
public:
3434
SysmanMockDrm(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceIdDrm>(mockFd, ""), rootDeviceEnvironment) {
35-
setupIoctlHelper();
35+
setupIoctlHelper(rootDeviceEnvironment.getHardwareInfo()->platform.eProductFamily);
3636
}
3737
};
3838

opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class DrmCommandStreamTest : public ::testing::Test {
4040

4141
auto hwInfo = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo();
4242
mock->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(hwInfo));
43-
mock->setupIoctlHelper();
43+
mock->setupIoctlHelper(hwInfo->platform.eProductFamily);
4444
osContext = std::make_unique<OsContextLinux>(*mock, 0u,
4545
EngineDescriptorHelper::getDefaultDescriptor(HwHelper::get(hwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0],
4646
PreemptionHelper::getDefaultPreemptionMode(*hwInfo)));

opencl/test/unit_test/os_interface/linux/drm_mock_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DrmTipMock : public DrmMock {
2020
DrmTipMock(RootDeviceEnvironment &rootDeviceEnvironment) : DrmTipMock(rootDeviceEnvironment, defaultHwInfo.get()) {}
2121
DrmTipMock(RootDeviceEnvironment &rootDeviceEnvironment, const HardwareInfo *inputHwInfo) : DrmMock(rootDeviceEnvironment) {
2222
rootDeviceEnvironment.setHwInfo(inputHwInfo);
23-
setupIoctlHelper();
23+
setupIoctlHelper(inputHwInfo->platform.eProductFamily);
2424
}
2525

2626
uint32_t i915QuerySuccessCount = std::numeric_limits<uint32_t>::max();

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ TEST(DrmQueryTest, GivenDrmWhenSetupHardwareInfoCalledThenCorrectMaxValuesInGtSy
736736
auto setupHardwareInfo = [](HardwareInfo *, bool) {};
737737
DeviceDescriptor device = {0, hwInfo, setupHardwareInfo};
738738

739+
drm.ioctlHelper.reset();
739740
drm.setupHardwareInfo(&device, false);
740741
EXPECT_NE(nullptr, drm.getIoctlHelper());
741742
EXPECT_EQ(NEO::defaultHwInfo->gtSystemInfo.MaxSlicesSupported, hwInfo->gtSystemInfo.MaxSlicesSupported);
@@ -1005,7 +1006,8 @@ TEST(DrmQueryTest, givenUapiPrelimVersionWithInvalidPathThenReturnEmptyString) {
10051006
}
10061007

10071008
TEST(DrmTest, givenInvalidUapiPrelimVersionThenFallbackToBasePrelim) {
1008-
std::unique_ptr<IoctlHelper> ioctlHelper(IoctlHelper::get(defaultHwInfo.get(), "-1"));
1009+
const auto productFamily = defaultHwInfo.get()->platform.eProductFamily;
1010+
std::unique_ptr<IoctlHelper> ioctlHelper(IoctlHelper::get(productFamily, "-1"));
10091011
EXPECT_NE(nullptr, ioctlHelper.get());
10101012
}
10111013

@@ -1192,7 +1194,9 @@ TEST(DrmTest, givenSetupIoctlHelperThenIoctlHelperNotNull) {
11921194
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
11931195

11941196
drm.ioctlHelper.reset(nullptr);
1195-
drm.setupIoctlHelper();
1197+
1198+
const auto productFamily = executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo()->platform.eProductFamily;
1199+
drm.setupIoctlHelper(productFamily);
11961200

11971201
EXPECT_NE(nullptr, drm.ioctlHelper.get());
11981202
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class IoctlHelperPrelimFixture : public ::testing::Test {
4545
executionEnvironment = std::make_unique<ExecutionEnvironment>();
4646
executionEnvironment->prepareRootDeviceEnvironments(1);
4747
drm = std::make_unique<DrmPrelimMock>(*executionEnvironment->rootDeviceEnvironments[0]);
48-
drm->setupIoctlHelper();
48+
drm->setupIoctlHelper(executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo()->platform.eProductFamily);
4949
}
5050

5151
std::unique_ptr<ExecutionEnvironment> executionEnvironment;

opencl/test/unit_test/test_files/igdrcl.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,4 @@ ForceExtendedBufferSize = -1
369369
MakeIndirectAllocationsResidentAsPack = -1
370370
EnableChipsetUniqueUUID = -1
371371
ForceSimdMessageSizeInWalker = -1
372+
UseNewQueryTopoIoctl = 1

shared/source/debug_settings/debug_variables_base.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ DECLARE_DEBUG_VARIABLE(bool, AllowMixingRegularAndCooperativeKernels, false, "tr
7373
DECLARE_DEBUG_VARIABLE(bool, AllowPatchingVfeStateInCommandLists, false, "true: MEDIA_VFE_STATE may be programmed in a command list")
7474
DECLARE_DEBUG_VARIABLE(bool, PrintMemoryRegionSizes, false, "print memory bank type, instance and it's size")
7575
DECLARE_DEBUG_VARIABLE(bool, UpdateCrossThreadDataSize, false, "Turn on cross thread data size calculation for PATCH TOKEN binary")
76+
DECLARE_DEBUG_VARIABLE(bool, UseNewQueryTopoIoctl, true, "Use DRM_I915_QUERY_COMPUTE_SLICES")
7677
DECLARE_DEBUG_VARIABLE(std::string, ForceDeviceId, std::string("unk"), "DeviceId selected for testing")
7778
DECLARE_DEBUG_VARIABLE(std::string, FilterDeviceId, std::string("unk"), "Device id filter, adapter matching device id will be opened. Ignored when unk.")
7879
DECLARE_DEBUG_VARIABLE(std::string, FilterBdfPath, std::string("unk"), "Linux-only, BDF path filter, only matching paths will be opened. Ignored when unk.")

shared/source/os_interface/linux/drm_neo.cpp

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@ int Drm::setupHardwareInfo(DeviceDescriptor *device, bool setupFeatureTableAndWo
481481
HardwareInfo *hwInfo = const_cast<HardwareInfo *>(device->pHwInfo);
482482
int ret;
483483

484+
const auto productFamily = hwInfo->platform.eProductFamily;
485+
setupIoctlHelper(productFamily);
486+
484487
Drm::QueryTopologyData topologyData = {};
485488

486489
bool status = queryTopology(*hwInfo, topologyData);
@@ -506,7 +509,6 @@ int Drm::setupHardwareInfo(DeviceDescriptor *device, bool setupFeatureTableAndWo
506509
hwInfo->gtSystemInfo.DualSubSliceCount = static_cast<uint32_t>(topologyData.subSliceCount);
507510
hwInfo->gtSystemInfo.EUCount = static_cast<uint32_t>(topologyData.euCount);
508511
rootDeviceEnvironment.setHwInfo(hwInfo);
509-
setupIoctlHelper();
510512

511513
status = querySystemInfo();
512514
if (status) {
@@ -1081,11 +1083,82 @@ bool Drm::completionFenceSupport() {
10811083
return completionFenceSupported;
10821084
}
10831085

1084-
void Drm::setupIoctlHelper() {
1085-
auto hwInfo = rootDeviceEnvironment.getHardwareInfo();
1086+
void Drm::setupIoctlHelper(const PRODUCT_FAMILY productFamily) {
10861087
std::string prelimVersion = "";
10871088
getPrelimVersion(prelimVersion);
1088-
this->ioctlHelper.reset(IoctlHelper::get(hwInfo, prelimVersion));
1089+
this->ioctlHelper.reset(IoctlHelper::get(productFamily, prelimVersion));
1090+
}
1091+
1092+
bool Drm::queryTopology(const HardwareInfo &hwInfo, QueryTopologyData &topologyData) {
1093+
topologyData.sliceCount = 0;
1094+
topologyData.subSliceCount = 0;
1095+
topologyData.euCount = 0;
1096+
1097+
int sliceCount = 0;
1098+
int subSliceCount = 0;
1099+
int euCount = 0;
1100+
1101+
const auto queryComputeSlicesIoctl = ioctlHelper->getComputeSlicesIoctlVal();
1102+
if (DebugManager.flags.UseNewQueryTopoIoctl.get() && this->engineInfo && hwInfo.gtSystemInfo.MultiTileArchInfo.TileCount > 0 && queryComputeSlicesIoctl != 0) {
1103+
bool success = true;
1104+
1105+
for (uint32_t i = 0; i < hwInfo.gtSystemInfo.MultiTileArchInfo.TileCount; i++) {
1106+
auto classInstance = this->engineInfo->getEngineInstance(i, hwInfo.capabilityTable.defaultEngineType);
1107+
UNRECOVERABLE_IF(!classInstance);
1108+
1109+
uint32_t flags = classInstance->engineClass;
1110+
flags |= (classInstance->engineInstance << 8);
1111+
1112+
auto dataQuery = this->query(queryComputeSlicesIoctl, flags);
1113+
if (dataQuery.empty()) {
1114+
success = false;
1115+
break;
1116+
}
1117+
auto data = reinterpret_cast<drm_i915_query_topology_info *>(dataQuery.data());
1118+
1119+
QueryTopologyData tileTopologyData = {};
1120+
TopologyMapping mapping;
1121+
if (!translateTopologyInfo(data, tileTopologyData, mapping)) {
1122+
success = false;
1123+
break;
1124+
}
1125+
1126+
// pick smallest config
1127+
sliceCount = (sliceCount == 0) ? tileTopologyData.sliceCount : std::min(sliceCount, tileTopologyData.sliceCount);
1128+
subSliceCount = (subSliceCount == 0) ? tileTopologyData.subSliceCount : std::min(subSliceCount, tileTopologyData.subSliceCount);
1129+
euCount = (euCount == 0) ? tileTopologyData.euCount : std::min(euCount, tileTopologyData.euCount);
1130+
1131+
topologyData.maxSliceCount = std::max(topologyData.maxSliceCount, tileTopologyData.maxSliceCount);
1132+
topologyData.maxSubSliceCount = std::max(topologyData.maxSubSliceCount, tileTopologyData.maxSubSliceCount);
1133+
topologyData.maxEuCount = std::max(topologyData.maxEuCount, static_cast<int>(data->max_eus_per_subslice));
1134+
1135+
this->topologyMap[i] = mapping;
1136+
}
1137+
1138+
if (success) {
1139+
topologyData.sliceCount = sliceCount;
1140+
topologyData.subSliceCount = subSliceCount;
1141+
topologyData.euCount = euCount;
1142+
return true;
1143+
}
1144+
}
1145+
1146+
// fallback to DRM_I915_QUERY_TOPOLOGY_INFO
1147+
1148+
auto dataQuery = this->query(DRM_I915_QUERY_TOPOLOGY_INFO, DrmQueryItemFlags::topology);
1149+
if (dataQuery.empty()) {
1150+
return false;
1151+
}
1152+
auto data = reinterpret_cast<drm_i915_query_topology_info *>(dataQuery.data());
1153+
1154+
TopologyMapping mapping;
1155+
auto retVal = translateTopologyInfo(data, topologyData, mapping);
1156+
topologyData.maxEuCount = data->max_eus_per_subslice;
1157+
1158+
this->topologyMap.clear();
1159+
this->topologyMap[0] = mapping;
1160+
1161+
return retVal;
10891162
}
10901163

10911164
} // namespace NEO

shared/source/os_interface/linux/drm_neo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class Drm : public DriverModel {
267267
std::string getSysFsPciPath();
268268
std::vector<uint8_t> query(uint32_t queryId, uint32_t queryItemFlags);
269269
void printIoctlStatistics();
270-
void setupIoctlHelper();
270+
void setupIoctlHelper(const PRODUCT_FAMILY productFamily);
271271

272272
#pragma pack(1)
273273
struct PCIConfig {

0 commit comments

Comments
 (0)