Refactor Drm::queryTopology() to take struct

- set max values in SystemInfo based on topology

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2021-04-27 14:45:13 +00:00
committed by Compute-Runtime-Automation
parent c0b0013bfc
commit 2d07d6a3d7
8 changed files with 196 additions and 31 deletions

View File

@ -45,6 +45,7 @@ class DrmMock : public Drm {
using Drm::requirePerContextVM;
using Drm::sliceCountChangeSupported;
using Drm::systemInfo;
using Drm::translateTopologyInfo;
using Drm::virtualMemoryIds;
DrmMock(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceId>(fd, ""), rootDeviceEnvironment) {

View File

@ -595,3 +595,27 @@ TEST(DrmTest, givenProgramDebuggingAndContextDebugAvailableWhenCreatingContextFo
EXPECT_EQ(static_cast<uint32_t>(-1), drmMock.passedContextDebugId);
}
TEST(DrmQueryTest, GivenDrmWhenSetupHardwareInfoCalledThenCorrectMaxValuesInGtSystemInfoAreSet) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
*executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo() = *NEO::defaultHwInfo.get();
auto hwInfo = executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo();
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
drm.failRetTopology = true;
drm.StoredEUVal = 48;
drm.StoredSSVal = 6;
hwInfo->gtSystemInfo.SliceCount = 2;
auto setupHardwareInfo = [](HardwareInfo *, bool) {};
DeviceDescriptor device = {0, hwInfo, setupHardwareInfo, GTTYPE_UNDEFINED};
drm.setupHardwareInfo(&device, false);
EXPECT_EQ(hwInfo->gtSystemInfo.SliceCount, hwInfo->gtSystemInfo.MaxSlicesSupported);
EXPECT_EQ(6u, hwInfo->gtSystemInfo.MaxSubSlicesSupported);
EXPECT_EQ(8u, hwInfo->gtSystemInfo.MaxEuPerSubSlice);
}

View File

@ -301,8 +301,8 @@ TEST_F(HwInfoConfigTestLinuxDummy, givenInvalidTopologyDataWhenConfiguringThenRe
drm->StoredSSVal = storedSSVal;
drm->StoredEUVal = 0;
int sliceCount, subSliceCount, euCount;
EXPECT_FALSE(drm->queryTopology(outHwInfo, sliceCount, subSliceCount, euCount));
Drm::QueryTopologyData topologyData = {};
EXPECT_FALSE(drm->queryTopology(outHwInfo, topologyData));
}
{
@ -311,8 +311,8 @@ TEST_F(HwInfoConfigTestLinuxDummy, givenInvalidTopologyDataWhenConfiguringThenRe
drm->StoredSSVal = 0;
drm->StoredEUVal = storedEUVal;
int sliceCount, subSliceCount, euCount;
EXPECT_FALSE(drm->queryTopology(outHwInfo, sliceCount, subSliceCount, euCount));
Drm::QueryTopologyData topologyData = {};
EXPECT_FALSE(drm->queryTopology(outHwInfo, topologyData));
}
{
@ -321,8 +321,8 @@ TEST_F(HwInfoConfigTestLinuxDummy, givenInvalidTopologyDataWhenConfiguringThenRe
drm->StoredSSVal = storedSSVal;
drm->StoredEUVal = storedEUVal;
int sliceCount, subSliceCount, euCount;
EXPECT_FALSE(drm->queryTopology(outHwInfo, sliceCount, subSliceCount, euCount));
Drm::QueryTopologyData topologyData = {};
EXPECT_FALSE(drm->queryTopology(outHwInfo, topologyData));
}
}
@ -552,3 +552,52 @@ TEST(HwInfoConfigLinuxTest, whenAdjustPlatformForProductFamilyCalledThenDoNothin
EXPECT_EQ(GFXCORE_FAMILY::IGFX_UNKNOWN_CORE, localHwInfo.platform.eRenderCoreFamily);
EXPECT_EQ(GFXCORE_FAMILY::IGFX_UNKNOWN_CORE, localHwInfo.platform.eDisplayCoreFamily);
}
using HwConfigLinux = ::testing::Test;
HWTEST2_F(HwConfigLinux, GivenDifferentValuesFromTopologyQueryWhenConfiguringHwInfoThenMaxValuesAreSetInGtSystemInfo, MatchAny) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
*executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo() = *NEO::defaultHwInfo.get();
auto drm = new DrmMock(*executionEnvironment->rootDeviceEnvironments[0]);
drm->setGtType(GTTYPE_GT1);
auto osInterface = std::make_unique<OSInterface>();
osInterface->get()->setDrm(static_cast<Drm *>(drm));
auto hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo();
HardwareInfo outHwInfo;
auto hwConfig = HwInfoConfigHw<productFamily>::get();
hwInfo.gtSystemInfo.MaxSubSlicesSupported = drm->StoredSSVal * 2;
hwInfo.gtSystemInfo.MaxDualSubSlicesSupported = drm->StoredSSVal * 2;
hwInfo.gtSystemInfo.MaxEuPerSubSlice = 16;
hwInfo.gtSystemInfo.MaxSlicesSupported = drm->StoredSVal * 4;
int ret = hwConfig->configureHwInfo(&hwInfo, &outHwInfo, osInterface.get());
EXPECT_EQ(0, ret);
EXPECT_EQ(static_cast<uint32_t>(drm->StoredSSVal * 2), outHwInfo.gtSystemInfo.MaxSubSlicesSupported);
EXPECT_EQ(static_cast<uint32_t>(drm->StoredSSVal * 2), outHwInfo.gtSystemInfo.MaxDualSubSlicesSupported);
EXPECT_EQ(16u, outHwInfo.gtSystemInfo.MaxEuPerSubSlice);
EXPECT_EQ(static_cast<uint32_t>(drm->StoredSVal * 4), outHwInfo.gtSystemInfo.MaxSlicesSupported);
drm->StoredSVal = 3;
drm->StoredSSVal = 12;
drm->StoredEUVal = 12 * 8;
hwInfo.gtSystemInfo.MaxSubSlicesSupported = drm->StoredSSVal / 2;
hwInfo.gtSystemInfo.MaxDualSubSlicesSupported = drm->StoredSSVal / 2;
hwInfo.gtSystemInfo.MaxEuPerSubSlice = 1;
hwInfo.gtSystemInfo.MaxSlicesSupported = drm->StoredSVal / 2;
ret = hwConfig->configureHwInfo(&hwInfo, &outHwInfo, osInterface.get());
EXPECT_EQ(0, ret);
EXPECT_EQ(12u, outHwInfo.gtSystemInfo.MaxSubSlicesSupported);
EXPECT_EQ(static_cast<uint32_t>(drm->StoredEUVal / drm->StoredSSVal), outHwInfo.gtSystemInfo.MaxEuPerSubSlice);
EXPECT_EQ(static_cast<uint32_t>(drm->StoredSVal), outHwInfo.gtSystemInfo.MaxSlicesSupported);
EXPECT_EQ(hwInfo.gtSystemInfo.MaxDualSubSlicesSupported, outHwInfo.gtSystemInfo.MaxDualSubSlicesSupported);
}

View File

@ -307,33 +307,40 @@ int Drm::getErrno() {
int Drm::setupHardwareInfo(DeviceDescriptor *device, bool setupFeatureTableAndWorkaroundTable) {
HardwareInfo *hwInfo = const_cast<HardwareInfo *>(device->pHwInfo);
int ret;
int sliceTotal;
int subSliceTotal;
int euTotal;
bool status = queryTopology(*hwInfo, sliceTotal, subSliceTotal, euTotal);
Drm::QueryTopologyData topologyData = {};
bool status = queryTopology(*hwInfo, topologyData);
if (!status) {
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "WARNING: Topology query failed!\n");
sliceTotal = hwInfo->gtSystemInfo.SliceCount;
topologyData.sliceCount = hwInfo->gtSystemInfo.SliceCount;
ret = getEuTotal(euTotal);
ret = getEuTotal(topologyData.euCount);
if (ret != 0) {
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "FATAL: Cannot query EU total parameter!\n");
return ret;
}
ret = getSubsliceTotal(subSliceTotal);
ret = getSubsliceTotal(topologyData.subSliceCount);
if (ret != 0) {
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "FATAL: Cannot query subslice total parameter!\n");
return ret;
}
topologyData.maxEuCount = topologyData.euCount / topologyData.subSliceCount;
topologyData.maxSliceCount = topologyData.sliceCount;
topologyData.maxSubSliceCount = topologyData.subSliceCount / topologyData.sliceCount;
}
hwInfo->gtSystemInfo.SliceCount = static_cast<uint32_t>(sliceTotal);
hwInfo->gtSystemInfo.SubSliceCount = static_cast<uint32_t>(subSliceTotal);
hwInfo->gtSystemInfo.EUCount = static_cast<uint32_t>(euTotal);
hwInfo->gtSystemInfo.SliceCount = static_cast<uint32_t>(topologyData.sliceCount);
hwInfo->gtSystemInfo.SubSliceCount = static_cast<uint32_t>(topologyData.subSliceCount);
hwInfo->gtSystemInfo.EUCount = static_cast<uint32_t>(topologyData.euCount);
hwInfo->gtSystemInfo.MaxEuPerSubSlice = topologyData.maxEuCount;
hwInfo->gtSystemInfo.MaxSubSlicesSupported = topologyData.maxSubSliceCount * topologyData.maxSliceCount;
hwInfo->gtSystemInfo.MaxSlicesSupported = topologyData.maxSliceCount;
status = querySystemInfo();
if (!status) {
@ -514,16 +521,20 @@ uint32_t Drm::getVirtualMemoryAddressSpace(uint32_t vmId) {
return 0;
}
bool Drm::translateTopologyInfo(const drm_i915_query_topology_info *queryTopologyInfo, int &sliceCount, int &subSliceCount, int &euCount) {
bool Drm::translateTopologyInfo(const drm_i915_query_topology_info *queryTopologyInfo, int &sliceCount, int &subSliceCount, int &euCount, int &maxSliceCount) {
sliceCount = 0;
subSliceCount = 0;
euCount = 0;
maxSliceCount = queryTopologyInfo->max_slices;
std::vector<int> sliceIndices;
sliceIndices.reserve(maxSliceCount);
for (int x = 0; x < queryTopologyInfo->max_slices; x++) {
bool isSliceEnable = (queryTopologyInfo->data[x / 8] >> (x % 8)) & 1;
if (!isSliceEnable) {
continue;
}
sliceIndices.push_back(x);
sliceCount++;
for (int y = 0; y < queryTopologyInfo->max_subslices; y++) {
size_t yOffset = (queryTopologyInfo->subslice_offset + x * queryTopologyInfo->subslice_stride + y / 8);
@ -543,6 +554,9 @@ bool Drm::translateTopologyInfo(const drm_i915_query_topology_info *queryTopolog
}
}
if (sliceIndices.size()) {
maxSliceCount = sliceIndices[sliceIndices.size() - 1] + 1;
}
return (sliceCount && subSliceCount && euCount);
}

View File

@ -66,6 +66,16 @@ class Drm {
MaxSize
};
struct QueryTopologyData {
int sliceCount;
int subSliceCount;
int euCount;
int maxSliceCount;
int maxSubSliceCount;
int maxEuCount;
};
virtual ~Drm();
virtual int ioctl(unsigned long request, void *arg);
@ -106,7 +116,7 @@ class Drm {
MOCKABLE_VIRTUAL bool querySystemInfo();
MOCKABLE_VIRTUAL bool queryEngineInfo();
MOCKABLE_VIRTUAL bool queryMemoryInfo();
bool queryTopology(const HardwareInfo &hwInfo, int &sliceCount, int &subSliceCount, int &euCount);
bool queryTopology(const HardwareInfo &hwInfo, QueryTopologyData &data);
bool createVirtualMemoryAddressSpace(uint32_t vmCount);
void destroyVirtualMemoryAddressSpace();
uint32_t getVirtualMemoryAddressSpace(uint32_t vmId);
@ -182,7 +192,7 @@ class Drm {
protected:
int getQueueSliceCount(drm_i915_gem_context_param_sseu *sseu);
bool translateTopologyInfo(const drm_i915_query_topology_info *queryTopologyInfo, int &sliceCount, int &subSliceCount, int &euCount);
bool translateTopologyInfo(const drm_i915_query_topology_info *queryTopologyInfo, int &sliceCount, int &subSliceCount, int &euCount, int &maxSliceCount);
std::string generateUUID();
std::string generateElfUUID(const void *data);
bool sliceCountChangeSupported = false;

View File

@ -11,7 +11,7 @@
namespace NEO {
bool Drm::queryTopology(const HardwareInfo &hwInfo, int &sliceCount, int &subSliceCount, int &euCount) {
bool Drm::queryTopology(const HardwareInfo &hwInfo, QueryTopologyData &topologyData) {
int32_t length;
auto dataQuery = this->query(DRM_I915_QUERY_TOPOLOGY_INFO, DrmQueryItemFlags::topology, length);
auto data = reinterpret_cast<drm_i915_query_topology_info *>(dataQuery.get());
@ -20,7 +20,10 @@ bool Drm::queryTopology(const HardwareInfo &hwInfo, int &sliceCount, int &subSli
return false;
}
return translateTopologyInfo(data, sliceCount, subSliceCount, euCount);
topologyData.maxSliceCount = data->max_slices;
topologyData.maxSubSliceCount = data->max_subslices;
topologyData.maxEuCount = data->max_eus_per_subslice;
return translateTopologyInfo(data, topologyData.sliceCount, topologyData.subSliceCount, topologyData.euCount, topologyData.maxSliceCount);
}
bool Drm::isDebugAttachAvailable() {

View File

@ -90,37 +90,43 @@ int HwInfoConfig::configureHwInfo(const HardwareInfo *inHwInfo, HardwareInfo *ou
}
platform->usRevId = static_cast<unsigned short>(val);
int sliceCount;
int subSliceCount;
int euCount;
Drm::QueryTopologyData topologyData = {};
bool status = drm->queryTopology(*outHwInfo, sliceCount, subSliceCount, euCount);
bool status = drm->queryTopology(*outHwInfo, topologyData);
if (!status) {
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "WARNING: Topology query failed!\n");
sliceCount = gtSystemInfo->SliceCount;
topologyData.sliceCount = gtSystemInfo->SliceCount;
ret = drm->getEuTotal(euCount);
ret = drm->getEuTotal(topologyData.euCount);
if (ret != 0) {
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "FATAL: Cannot query EU total parameter!\n");
*outHwInfo = {};
return ret;
}
ret = drm->getSubsliceTotal(subSliceCount);
ret = drm->getSubsliceTotal(topologyData.subSliceCount);
if (ret != 0) {
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "FATAL: Cannot query subslice total parameter!\n");
*outHwInfo = {};
return ret;
}
topologyData.maxEuCount = topologyData.euCount / topologyData.subSliceCount;
topologyData.maxSliceCount = topologyData.sliceCount;
topologyData.maxSubSliceCount = topologyData.subSliceCount / topologyData.sliceCount;
}
gtSystemInfo->SliceCount = static_cast<uint32_t>(sliceCount);
gtSystemInfo->SubSliceCount = static_cast<uint32_t>(subSliceCount);
gtSystemInfo->EUCount = static_cast<uint32_t>(euCount);
gtSystemInfo->SliceCount = static_cast<uint32_t>(topologyData.sliceCount);
gtSystemInfo->SubSliceCount = static_cast<uint32_t>(topologyData.subSliceCount);
gtSystemInfo->EUCount = static_cast<uint32_t>(topologyData.euCount);
gtSystemInfo->ThreadCount = this->threadsPerEu * gtSystemInfo->EUCount;
gtSystemInfo->MaxEuPerSubSlice = std::max(static_cast<uint32_t>(topologyData.maxEuCount), gtSystemInfo->MaxEuPerSubSlice);
gtSystemInfo->MaxSubSlicesSupported = std::max(static_cast<uint32_t>(topologyData.maxSubSliceCount * topologyData.maxSliceCount), gtSystemInfo->MaxSubSlicesSupported);
gtSystemInfo->MaxSlicesSupported = std::max(static_cast<uint32_t>(topologyData.maxSliceCount), gtSystemInfo->MaxSlicesSupported);
uint64_t gttSizeQuery = 0;
featureTable->ftrSVM = true;

View File

@ -7,9 +7,12 @@
#include "shared/source/helpers/file_io.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/os_interface/hw_info_config.h"
#include "shared/source/os_interface/linux/os_interface.h"
#include "shared/test/common/helpers/default_hw_info.h"
#include "opencl/test/unit_test/os_interface/linux/drm_mock.h"
#include "test.h"
#include "gtest/gtest.h"
@ -43,3 +46,58 @@ TEST(DrmQueryTest, WhenCallingIsDebugAttachAvailableThenReturnValueIsFalse) {
EXPECT_FALSE(drm.isDebugAttachAvailable());
}
TEST(DrmQueryTest, GivenDrmWhenQueryingTopologyInfoCorrectMaxValuesAreSet) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
*executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo() = *NEO::defaultHwInfo.get();
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
Drm::QueryTopologyData topologyData = {};
EXPECT_TRUE(drm.queryTopology(*executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo(), topologyData));
EXPECT_EQ(drm.StoredSVal, topologyData.sliceCount);
EXPECT_EQ(drm.StoredSSVal, topologyData.subSliceCount);
EXPECT_EQ(drm.StoredEUVal, topologyData.euCount);
EXPECT_EQ(drm.StoredSVal, topologyData.maxSliceCount);
EXPECT_EQ(drm.StoredSSVal / drm.StoredSVal, topologyData.maxSubSliceCount);
EXPECT_EQ(drm.StoredEUVal / drm.StoredSSVal, topologyData.maxEuCount);
}
using HwConfigTopologyQuery = ::testing::Test;
HWTEST2_F(HwConfigTopologyQuery, WhenGettingTopologyFailsThenSetMaxValuesBasedOnEuAndSubsliceIoctlQueries, MatchAny) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
*executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo() = *NEO::defaultHwInfo.get();
auto drm = new DrmMock(*executionEnvironment->rootDeviceEnvironments[0]);
drm->setGtType(GTTYPE_GT1);
auto osInterface = std::make_unique<OSInterface>();
osInterface->get()->setDrm(static_cast<Drm *>(drm));
drm->failRetTopology = true;
auto hwInfo = *executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo();
HardwareInfo outHwInfo;
hwInfo.gtSystemInfo.MaxSlicesSupported = 0;
hwInfo.gtSystemInfo.MaxSubSlicesSupported = 0;
hwInfo.gtSystemInfo.MaxEuPerSubSlice = 0;
auto hwConfig = HwInfoConfigHw<productFamily>::get();
int ret = hwConfig->configureHwInfo(&hwInfo, &outHwInfo, osInterface.get());
EXPECT_NE(-1, ret);
EXPECT_EQ(outHwInfo.gtSystemInfo.EUCount / outHwInfo.gtSystemInfo.SubSliceCount, outHwInfo.gtSystemInfo.MaxEuPerSubSlice);
EXPECT_EQ(outHwInfo.gtSystemInfo.SubSliceCount, outHwInfo.gtSystemInfo.MaxSubSlicesSupported);
EXPECT_EQ(hwInfo.gtSystemInfo.SliceCount, outHwInfo.gtSystemInfo.MaxSlicesSupported);
EXPECT_EQ(static_cast<uint32_t>(drm->StoredEUVal), outHwInfo.gtSystemInfo.EUCount);
EXPECT_EQ(static_cast<uint32_t>(drm->StoredSSVal), outHwInfo.gtSystemInfo.SubSliceCount);
}