From 096e4244283f7a29669a1cb6e52d489338ca3fa6 Mon Sep 17 00:00:00 2001 From: Compute-Runtime-Validation Date: Thu, 19 Oct 2023 07:11:43 +0200 Subject: [PATCH] Revert "fix: initialize tile only when gt type main on xe kmd" This reverts commit cbde47d638cf0e834706e3286ef621c42b9728ce. Signed-off-by: Compute-Runtime-Validation --- .../os_interface/linux/xe/ioctl_helper_xe.cpp | 81 +++---- .../os_interface/linux/xe/ioctl_helper_xe.h | 6 +- .../linux/xe/ioctl_helper_xe_tests.cpp | 228 ++---------------- 3 files changed, 56 insertions(+), 259 deletions(-) diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp index 7fc1968799..3e73a55716 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp @@ -45,7 +45,7 @@ namespace NEO { int IoctlHelperXe::xeGetQuery(Query *data) { if (data->numItems == 1) { QueryItem *queryItem = reinterpret_cast(data->itemsPtr); - std::vector *queryData = nullptr; + std::vector *queryData = nullptr; switch (queryItem->queryId) { case static_cast(DrmParam::QueryHwconfigTable): queryData = &hwconfigFakei915; @@ -54,7 +54,7 @@ int IoctlHelperXe::xeGetQuery(Query *data) { xeLog("error: bad query 0x%x\n", queryItem->queryId); return -1; } - auto queryDataSize = static_cast(queryData->size() * sizeof(uint32_t)); + auto queryDataSize = static_cast(queryData->size() * sizeof(uint64_t)); if (queryItem->length == 0) { queryItem->length = queryDataSize; return 0; @@ -165,8 +165,7 @@ bool IoctlHelperXe::initialize() { memset(&queryConfig, 0, sizeof(queryConfig)); queryConfig.query = DRM_XE_DEVICE_QUERY_HWCONFIG; IoctlHelper::ioctl(DrmIoctl::Query, &queryConfig); - auto newSize = queryConfig.size / sizeof(uint32_t); - hwconfigFakei915.resize(newSize); + hwconfigFakei915.resize(queryConfig.size); queryConfig.data = castToUint64(hwconfigFakei915.data()); IoctlHelper::ioctl(DrmIoctl::Query, &queryConfig); @@ -292,20 +291,17 @@ std::unique_ptr IoctlHelperXe::createMemoryInfo() { } for (auto i = 0u; i < xeGtsData->num_gt; i++) { - if (xeGtsData->gts[i].type == XE_QUERY_GT_TYPE_MAIN) { - uint64_t nativeMemRegions = xeGtsData->gts[i].native_mem_regions; - auto regionIndex = Math::log2(nativeMemRegions); - UNRECOVERABLE_IF(!memoryRegionInstances[regionIndex]); - regionsContainer.push_back(createMemoryRegionFromXeMemRegion(*memoryRegionInstances[regionIndex])); + uint64_t nativeMemRegions = xeGtsData->gts[i].native_mem_regions; + auto regionIndex = Math::log2(nativeMemRegions); + UNRECOVERABLE_IF(!memoryRegionInstances[regionIndex]); + regionsContainer.push_back(createMemoryRegionFromXeMemRegion(*memoryRegionInstances[regionIndex])); - xeTimestampFrequency = xeGtsData->gts[i].clock_freq; - } + xeTimestampFrequency = xeGtsData->gts[i].clock_freq; } return std::make_unique(regionsContainer, drm); } -void IoctlHelperXe::getTopologyData(size_t nTiles, std::vector> *geomDss, std::vector> *computeDss, - std::vector> *euDss, DrmQueryTopologyData &topologyData, bool &isComputeDssEmpty) { +void IoctlHelperXe::getTopologyData(uint32_t nTiles, std::vector> geomDss[2], std::vector> computeDss[2], std::vector> euDss[2], DrmQueryTopologyData &topologyData, bool &isComputeDssEmpty) { int subSliceCount = 0; int euPerDss = 0; @@ -344,7 +340,7 @@ void IoctlHelperXe::getTopologyData(size_t nTiles, std::vector> * topologyData.maxSliceCount = 1; } -void IoctlHelperXe::getTopologyMap(size_t nTiles, std::vector> *dssInfo, TopologyMap &topologyMap) { +void IoctlHelperXe::getTopologyMap(uint32_t nTiles, std::vector> dssInfo[2], TopologyMap &topologyMap) { for (auto tileId = 0u; tileId < nTiles; tileId++) { std::vector sliceIndices; std::vector subSliceIndices; @@ -375,49 +371,34 @@ bool IoctlHelperXe::getTopologyDataAndMap(const HardwareInfo &hwInfo, DrmQueryTo } }; - StackVec>, 2> geomDss; - StackVec>, 2> computeDss; - StackVec>, 2> euDss; - StackVec gtIdToTile{-1}; - + std::vector> geomDss[2]; + std::vector> computeDss[2]; + std::vector> euDss[2]; auto topologySize = queryGtTopology.size(); auto dataPtr = queryGtTopology.data(); - auto gtsData = queryData(DRM_XE_DEVICE_QUERY_GTS); - auto xeGtsData = reinterpret_cast(gtsData.data()); - gtIdToTile.resize(xeGtsData->num_gt, -1); + auto nTiles = 1u; - auto tileIndex = 0u; - for (auto gt = 0u; gt < gtIdToTile.size(); gt++) { - if (xeGtsData->gts[gt].type == XE_QUERY_GT_TYPE_MAIN) { - gtIdToTile[gt] = tileIndex++; - } - } - - geomDss.resize(tileIndex); - computeDss.resize(tileIndex); - euDss.resize(tileIndex); while (topologySize >= sizeof(drm_xe_query_topology_mask)) { drm_xe_query_topology_mask *topo = reinterpret_cast(dataPtr); UNRECOVERABLE_IF(topo == nullptr); - uint32_t gtId = topo->gt_id; + uint32_t tileId = topo->gt_id; + nTiles = std::max(tileId + 1, nTiles); - if (xeGtsData->gts[gtId].type == XE_QUERY_GT_TYPE_MAIN) { - switch (topo->type) { - case XE_TOPO_DSS_GEOMETRY: - fillMask(geomDss[gtIdToTile[gtId]], topo); - break; - case XE_TOPO_DSS_COMPUTE: - fillMask(computeDss[gtIdToTile[gtId]], topo); - break; - case XE_TOPO_EU_PER_DSS: - fillMask(euDss[gtIdToTile[gtId]], topo); - break; - default: - xeLog("Unhandle GT Topo type: %d\n", topo->type); - return false; - } + switch (topo->type) { + case XE_TOPO_DSS_GEOMETRY: + fillMask(geomDss[tileId], topo); + break; + case XE_TOPO_DSS_COMPUTE: + fillMask(computeDss[tileId], topo); + break; + case XE_TOPO_EU_PER_DSS: + fillMask(euDss[tileId], topo); + break; + default: + xeLog("Unhandle GT Topo type: %d\n", topo->type); + return false; } uint32_t itemSize = sizeof(drm_xe_query_topology_mask) + topo->num_bytes; @@ -426,10 +407,10 @@ bool IoctlHelperXe::getTopologyDataAndMap(const HardwareInfo &hwInfo, DrmQueryTo } bool isComputeDssEmpty = false; - getTopologyData(tileIndex, geomDss.begin(), computeDss.begin(), euDss.begin(), topologyData, isComputeDssEmpty); + getTopologyData(nTiles, geomDss, computeDss, euDss, topologyData, isComputeDssEmpty); auto &dssInfo = isComputeDssEmpty ? geomDss : computeDss; - getTopologyMap(tileIndex, dssInfo.begin(), topologyMap); + getTopologyMap(nTiles, dssInfo, topologyMap); return true; } diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h index 3c50e90fde..40d403c81e 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h @@ -105,8 +105,8 @@ class IoctlHelperXe : public IoctlHelper { bool isWaitBeforeBindRequired(bool bind) const override; std::unique_ptr createEngineInfo(bool isSysmanEnabled) override; std::unique_ptr createMemoryInfo() override; - void getTopologyData(size_t nTiles, std::vector> *geomDss, std::vector> *computeDss, std::vector> *euDss, DrmQueryTopologyData &topologyData, bool &isComputeDssEmpty); - void getTopologyMap(size_t nTiles, std::vector> *dssInfo, TopologyMap &topologyMap); + void getTopologyData(uint32_t nTiles, std::vector> geomDss[2], std::vector> computeDss[2], std::vector> euDss[2], DrmQueryTopologyData &topologyData, bool &isComputeDssEmpty); + void getTopologyMap(uint32_t nTiles, std::vector> dssInfo[2], TopologyMap &topologyMap); void fillBindInfoForIpcHandle(uint32_t handle, size_t size) override; bool isImmediateVmBindRequired() const override; @@ -146,7 +146,7 @@ class IoctlHelperXe : public IoctlHelper { std::vector bindInfo; int instance = 0; uint32_t xeTimestampFrequency = 0; - std::vector hwconfigFakei915; + std::vector hwconfigFakei915; std::vector contextParamEngine; std::vector allEngines; }; diff --git a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp index a2b50e0bd1..df42ef3c51 100644 --- a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp @@ -145,8 +145,8 @@ class DrmMockXe : public DrmMockCustom { MemoryConstants::gigaByte // used size }; - auto xeQueryGts = reinterpret_cast(queryGts.begin()); - xeQueryGts->num_gt = 3; + auto xeQueryGts = reinterpret_cast(queryGts); + xeQueryGts->num_gt = 2; xeQueryGts->gts[0] = { XE_QUERY_GT_TYPE_MAIN, // type 0, // instance @@ -157,22 +157,13 @@ class DrmMockXe : public DrmMockCustom { 0 // inaccessible mem regions }; xeQueryGts->gts[1] = { - XE_QUERY_GT_TYPE_MEDIA, // type - 1, // instance - 12500000, // clock freq - 0, // features - 0b001, // native mem regions - 0x110, // slow mem regions - 0 // inaccessible mem regions - }; - xeQueryGts->gts[2] = { - XE_QUERY_GT_TYPE_MAIN, // type - 0, // instance - 12500000, // clock freq - 0, // features - 0b010, // native mem regions - 0x101, // slow mem regions - 0 // inaccessible mem regions + XE_QUERY_GT_TYPE_REMOTE, // type + 1, // instance + 12500000, // clock freq + 0, // features + 0b010, // native mem regions + 0x101, // slow mem regions + 0 // inaccessible mem regions }; } @@ -259,7 +250,7 @@ class DrmMockXe : public DrmMockCustom { break; case DRM_XE_DEVICE_QUERY_GTS: if (deviceQuery->data) { - memcpy_s(reinterpret_cast(deviceQuery->data), deviceQuery->size, queryGts.begin(), sizeof(queryGts)); + memcpy_s(reinterpret_cast(deviceQuery->data), deviceQuery->size, queryGts, sizeof(queryGts)); } deviceQuery->size = sizeof(queryGts); break; @@ -336,7 +327,7 @@ class DrmMockXe : public DrmMockCustom { static_assert(sizeof(drm_xe_query_mem_region) == 12 * sizeof(uint64_t), ""); uint64_t queryMemUsage[37]{}; // 1 qword for num regions and 12 qwords per region static_assert(sizeof(drm_xe_query_gts::drm_xe_query_gt) == 13 * sizeof(uint64_t), ""); - StackVec queryGts{}; // 1 qword for num gts and 13 qwords per gt + uint64_t queryGts[27]{}; // 1 qword for num gts and 13 qwords per gt std::vector queryTopology; StackVec waitUserFenceInputs; StackVec vmBindInputs; @@ -941,11 +932,11 @@ TEST(IoctlHelperXeTest, givenGeomDssWhenGetTopologyDataAndMapThenResultsAreCorre auto xeIoctlHelper = std::make_unique(drm); uint16_t tileId = 0; - for (auto gtId = 0u; gtId < 3u; gtId++) { - drm.addMockedQueryTopologyData(gtId, XE_TOPO_DSS_GEOMETRY, 8, {0b11'1111, 0, 0, 0, 0, 0, 0, 0}); - drm.addMockedQueryTopologyData(gtId, XE_TOPO_DSS_COMPUTE, 8, {0, 0, 0, 0, 0, 0, 0, 0}); - drm.addMockedQueryTopologyData(gtId, XE_TOPO_EU_PER_DSS, 8, {0b1111'1111, 0b1111'1111, 0, 0, 0, 0, 0, 0}); - } + + drm.addMockedQueryTopologyData(tileId, XE_TOPO_DSS_GEOMETRY, 8, {0b11'1111, 0, 0, 0, 0, 0, 0, 0}); + drm.addMockedQueryTopologyData(tileId, XE_TOPO_DSS_COMPUTE, 8, {0, 0, 0, 0, 0, 0, 0, 0}); + drm.addMockedQueryTopologyData(tileId, XE_TOPO_EU_PER_DSS, 8, {0b1111'1111, 0b1111'1111, 0, 0, 0, 0, 0, 0}); + DrmQueryTopologyData topologyData{}; TopologyMap topologyMap{}; @@ -988,11 +979,9 @@ TEST(IoctlHelperXeTest, givenComputeDssWhenGetTopologyDataAndMapThenResultsAreCo auto xeIoctlHelper = std::make_unique(drm); uint16_t tileId = 0; - for (auto gtId = 0u; gtId < 3u; gtId++) { - drm.addMockedQueryTopologyData(gtId, XE_TOPO_DSS_GEOMETRY, 8, {0, 0, 0, 0, 0, 0, 0, 0}); - drm.addMockedQueryTopologyData(gtId, XE_TOPO_DSS_COMPUTE, 8, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}); - drm.addMockedQueryTopologyData(gtId, XE_TOPO_EU_PER_DSS, 8, {0b1111'1111, 0, 0, 0, 0, 0, 0, 0}); - } + drm.addMockedQueryTopologyData(tileId, XE_TOPO_DSS_GEOMETRY, 8, {0, 0, 0, 0, 0, 0, 0, 0}); + drm.addMockedQueryTopologyData(tileId, XE_TOPO_DSS_COMPUTE, 8, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}); + drm.addMockedQueryTopologyData(tileId, XE_TOPO_EU_PER_DSS, 8, {0b1111'1111, 0, 0, 0, 0, 0, 0, 0}); DrmQueryTopologyData topologyData{}; TopologyMap topologyMap{}; @@ -1033,183 +1022,10 @@ TEST(IoctlHelperXeTest, givenComputeDssWhenGetTopologyDataAndMapThenResultsAreCo } } -TEST(IoctlHelperXeTest, givenOnlyMediaTypeWhenGetTopologyDataAndMapThenSubsliceIndicesNotSet) { - - auto executionEnvironment = std::make_unique(); - DrmMockXe drm{*executionEnvironment->rootDeviceEnvironments[0]}; - auto xeQueryGts = reinterpret_cast(drm.queryGts.begin()); - xeQueryGts->num_gt = 1; - xeQueryGts->gts[0] = { - XE_QUERY_GT_TYPE_MEDIA, // type - 0, // instance - 12500000, // clock freq - 0, // features - 0b100, // native mem regions - 0x011, // slow mem regions - 0 // inaccessible mem regions - }; - - auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo(); - auto xeIoctlHelper = std::make_unique(drm); - - uint16_t tileId = 0; - drm.addMockedQueryTopologyData(tileId, XE_TOPO_DSS_GEOMETRY, 8, {0, 0, 0, 0, 0, 0, 0, 0}); - drm.addMockedQueryTopologyData(tileId, XE_TOPO_DSS_COMPUTE, 8, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}); - drm.addMockedQueryTopologyData(tileId, XE_TOPO_EU_PER_DSS, 8, {0b1111'1111, 0, 0, 0, 0, 0, 0, 0}); - - DrmQueryTopologyData topologyData{}; - TopologyMap topologyMap{}; - - auto result = xeIoctlHelper->getTopologyDataAndMap(hwInfo, topologyData, topologyMap); - ASSERT_TRUE(result); - - // verify topology data - EXPECT_EQ(1, topologyData.sliceCount); - EXPECT_EQ(1, topologyData.maxSliceCount); - - EXPECT_EQ(0, topologyData.subSliceCount); - EXPECT_EQ(0, topologyData.maxSubSliceCount); - - EXPECT_EQ(0, topologyData.euCount); - EXPECT_EQ(0, topologyData.maxEuPerSubSlice); - - // verify topology map - ASSERT_EQ(0u, topologyMap[tileId].sliceIndices.size()); - - ASSERT_EQ(0u, topologyMap[tileId].subsliceIndices.size()); -} - -TEST(IoctlHelperXeTest, givenMainAndMediaTypesWhenGetTopologyDataAndMapThenResultsAreCorrect) { - - auto executionEnvironment = std::make_unique(); - DrmMockXe drm{*executionEnvironment->rootDeviceEnvironments[0]}; - drm.queryGts.resize(53); - auto xeQueryGts = reinterpret_cast(drm.queryGts.begin()); - xeQueryGts->num_gt = 4; - xeQueryGts->gts[0] = { - XE_QUERY_GT_TYPE_MAIN, // type - 0, // instance - 12500000, // clock freq - 0, // features - 0b100, // native mem regions - 0x011, // slow mem regions - 0 // inaccessible mem regions - }; - xeQueryGts->gts[1] = { - XE_QUERY_GT_TYPE_MEDIA, // type - 0, // instance - 12500000, // clock freq - 0, // features - 0b100, // native mem regions - 0x011, // slow mem regions - 0 // inaccessible mem regions - }; - xeQueryGts->gts[2] = { - XE_QUERY_GT_TYPE_MAIN, // type - 0, // instance - 12500000, // clock freq - 0, // features - 0b010, // native mem regions - 0x101, // slow mem regions - 0 // inaccessible mem regions - }; - xeQueryGts->gts[3] = { - XE_QUERY_GT_TYPE_MEDIA, // type - 0, // instance - 12500000, // clock freq - 0, // features - 0b001, // native mem regions - 0x100, // slow mem regions - 0 // inaccessible mem regions - }; - - auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo(); - auto xeIoctlHelper = std::make_unique(drm); - for (auto tileId = 0; tileId < 4; tileId++) { - drm.addMockedQueryTopologyData(tileId, XE_TOPO_DSS_GEOMETRY, 8, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}); - drm.addMockedQueryTopologyData(tileId, XE_TOPO_DSS_COMPUTE, 8, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}); - drm.addMockedQueryTopologyData(tileId, XE_TOPO_EU_PER_DSS, 8, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}); - } - - DrmQueryTopologyData topologyData{}; - TopologyMap topologyMap{}; - - auto result = xeIoctlHelper->getTopologyDataAndMap(hwInfo, topologyData, topologyMap); - ASSERT_TRUE(result); - - // verify topology data - EXPECT_EQ(1, topologyData.sliceCount); - EXPECT_EQ(1, topologyData.maxSliceCount); - - EXPECT_EQ(64, topologyData.subSliceCount); - EXPECT_EQ(64, topologyData.maxSubSliceCount); - - EXPECT_EQ(4096, topologyData.euCount); - EXPECT_EQ(64, topologyData.maxEuPerSubSlice); - EXPECT_EQ(2u, topologyMap.size()); - // verify topology map - for (auto tileId : {0u, 1u}) { - ASSERT_EQ(1u, topologyMap[tileId].sliceIndices.size()); - ASSERT_EQ(64u, topologyMap[tileId].subsliceIndices.size()); - } -} - -struct DrmMockXe2T : public DrmMockXe { - DrmMockXe2T(RootDeviceEnvironment &rootDeviceEnvironment) : DrmMockXe(rootDeviceEnvironment) { - auto xeQueryMemUsage = reinterpret_cast(queryMemUsage); - xeQueryMemUsage->num_regions = 3; - xeQueryMemUsage->regions[0] = { - XE_MEM_REGION_CLASS_VRAM, // class - 1, // instance - 0, // padding - MemoryConstants::pageSize, // min page size - 2 * MemoryConstants::gigaByte, // total size - MemoryConstants::megaByte // used size - }; - xeQueryMemUsage->regions[1] = { - XE_MEM_REGION_CLASS_SYSMEM, // class - 0, // instance - 0, // padding - MemoryConstants::pageSize, // min page size - MemoryConstants::gigaByte, // total size - MemoryConstants::kiloByte // used size - }; - xeQueryMemUsage->regions[2] = { - XE_MEM_REGION_CLASS_VRAM, // class - 2, // instance - 0, // padding - MemoryConstants::pageSize, // min page size - 4 * MemoryConstants::gigaByte, // total size - MemoryConstants::gigaByte // used size - }; - queryGts.resize(27); - auto xeQueryGts = reinterpret_cast(queryGts.begin()); - xeQueryGts->num_gt = 2; - xeQueryGts->gts[0] = { - XE_QUERY_GT_TYPE_MAIN, // type - 0, // instance - 12500000, // clock freq - 0, // features - 0b100, // native mem regions - 0x011, // slow mem regions - 0 // inaccessible mem regions - }; - xeQueryGts->gts[1] = { - XE_QUERY_GT_TYPE_MAIN, // type - 0, // instance - 12500000, // clock freq - 0, // features - 0b010, // native mem regions - 0x101, // slow mem regions - 0 // inaccessible mem regions - }; - } -}; - TEST(IoctlHelperXeTest, given2TileAndComputeDssWhenGetTopologyDataAndMapThenResultsAreCorrect) { auto executionEnvironment = std::make_unique(); - DrmMockXe2T drm{*executionEnvironment->rootDeviceEnvironments[0]}; + DrmMockXe drm{*executionEnvironment->rootDeviceEnvironments[0]}; auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo(); auto xeIoctlHelper = std::make_unique(drm); @@ -1264,7 +1080,7 @@ TEST(IoctlHelperXeTest, given2TileAndComputeDssWhenGetTopologyDataAndMapThenResu TEST(IoctlHelperXeTest, given2TileWithDisabledDssOn1TileAndComputeDssWhenGetTopologyDataAndMapThenResultsAreCorrect) { auto executionEnvironment = std::make_unique(); - DrmMockXe2T drm{*executionEnvironment->rootDeviceEnvironments[0]}; + DrmMockXe drm{*executionEnvironment->rootDeviceEnvironments[0]}; auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo(); auto xeIoctlHelper = std::make_unique(drm); @@ -1330,7 +1146,7 @@ TEST(IoctlHelperXeTest, given2TileWithDisabledDssOn1TileAndComputeDssWhenGetTopo TEST(IoctlHelperXeTest, given2TileWithDisabledEvenDssAndComputeDssWhenGetTopologyDataAndMapThenResultsAreCorrect) { auto executionEnvironment = std::make_unique(); - DrmMockXe2T drm{*executionEnvironment->rootDeviceEnvironments[0]}; + DrmMockXe drm{*executionEnvironment->rootDeviceEnvironments[0]}; auto &hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo(); auto xeIoctlHelper = std::make_unique(drm);