Refactor DeviceFactory::getDevices

Change-Id: If3b20cc8ed74bdb1c32ae17c23374b7c267933a3
Signed-off-by: Dunajski, Bartosz <bartosz.dunajski@intel.com>
This commit is contained in:
Dunajski, Bartosz 2019-03-19 15:09:33 +01:00 committed by sys_ocldev
parent 432591a88a
commit 7f2bf217f1
7 changed files with 74 additions and 95 deletions

View File

@ -19,26 +19,26 @@ bool DeviceFactory::getDevicesForProductFamilyOverride(HardwareInfo **pHWInfos,
auto productFamily = DebugManager.flags.ProductFamilyOverride.get();
auto hwInfoConst = *platformDevices;
getHwInfoForPlatformString(productFamily.c_str(), hwInfoConst);
std::unique_ptr<HardwareInfo[]> tempHwInfos(new HardwareInfo[totalDeviceCount]);
numDevices = 0;
std::string hwInfoConfig;
DebugManager.getHardwareInfoOverride(hwInfoConfig);
while (numDevices < totalDeviceCount) {
tempHwInfos[numDevices].pPlatform = new PLATFORM(*hwInfoConst->pPlatform);
tempHwInfos[numDevices].pSkuTable = new FeatureTable(*hwInfoConst->pSkuTable);
tempHwInfos[numDevices].pWaTable = new WorkaroundTable(*hwInfoConst->pWaTable);
tempHwInfos[numDevices].pSysInfo = new GT_SYSTEM_INFO(*hwInfoConst->pSysInfo);
tempHwInfos[numDevices].capabilityTable = hwInfoConst->capabilityTable;
hardwareInfoSetup[hwInfoConst->pPlatform->eProductFamily](const_cast<GT_SYSTEM_INFO *>(tempHwInfos[numDevices].pSysInfo),
const_cast<FeatureTable *>(tempHwInfos[numDevices].pSkuTable),
true, hwInfoConfig);
numDevices++;
}
*pHWInfos = tempHwInfos.get();
auto hardwareInfo = std::make_unique<HardwareInfo>();
hardwareInfo->pPlatform = new PLATFORM(*hwInfoConst->pPlatform);
hardwareInfo->pSkuTable = new FeatureTable(*hwInfoConst->pSkuTable);
hardwareInfo->pWaTable = new WorkaroundTable(*hwInfoConst->pWaTable);
hardwareInfo->pSysInfo = new GT_SYSTEM_INFO(*hwInfoConst->pSysInfo);
hardwareInfo->capabilityTable = hwInfoConst->capabilityTable;
hardwareInfoSetup[hwInfoConst->pPlatform->eProductFamily](const_cast<GT_SYSTEM_INFO *>(hardwareInfo->pSysInfo),
const_cast<FeatureTable *>(hardwareInfo->pSkuTable),
true, hwInfoConfig);
*pHWInfos = hardwareInfo.release();
executionEnvironment.setHwInfo(*pHWInfos);
numDevices = totalDeviceCount;
DeviceFactory::numDevices = numDevices;
DeviceFactory::hwInfos = tempHwInfos.get();
tempHwInfos.release();
DeviceFactory::hwInfo = *pHWInfos;
return true;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2018 Intel Corporation
* Copyright (C) 2017-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -21,7 +21,7 @@ class DeviceFactory {
protected:
static size_t numDevices;
static HardwareInfo *hwInfos;
static HardwareInfo *hwInfo;
};
class DeviceFactoryCleaner {

View File

@ -20,12 +20,10 @@
#include <vector>
namespace OCLRT {
size_t DeviceFactory::numDevices = 0;
HardwareInfo *DeviceFactory::hwInfos = nullptr;
HardwareInfo *DeviceFactory::hwInfo = nullptr;
bool DeviceFactory::getDevices(HardwareInfo **pHWInfos, size_t &numDevices, ExecutionEnvironment &executionEnvironment) {
std::vector<HardwareInfo> tHwInfos;
unsigned int devNum = 0;
size_t requiredDeviceCount = 1;
@ -41,28 +39,19 @@ bool DeviceFactory::getDevices(HardwareInfo **pHWInfos, size_t &numDevices, Exec
executionEnvironment.osInterface.reset(new OSInterface());
executionEnvironment.osInterface->get()->setDrm(drm);
auto hardwareInfo = std::make_unique<HardwareInfo>();
const HardwareInfo *pCurrDevice = platformDevices[devNum];
while (devNum < requiredDeviceCount) {
HardwareInfo tmpHwInfo;
HwInfoConfig *hwConfig = HwInfoConfig::get(pCurrDevice->pPlatform->eProductFamily);
if (hwConfig->configureHwInfo(pCurrDevice, &tmpHwInfo, executionEnvironment.osInterface.get())) {
return false;
}
tHwInfos.push_back(tmpHwInfo);
devNum++;
HwInfoConfig *hwConfig = HwInfoConfig::get(pCurrDevice->pPlatform->eProductFamily);
if (hwConfig->configureHwInfo(pCurrDevice, hardwareInfo.get(), executionEnvironment.osInterface.get())) {
return false;
}
HardwareInfo *ptr = new HardwareInfo[devNum];
for (size_t i = 0; i < tHwInfos.size(); i++)
ptr[i] = tHwInfos[i];
numDevices = devNum;
*pHWInfos = ptr;
numDevices = requiredDeviceCount;
*pHWInfos = hardwareInfo.release();
executionEnvironment.setHwInfo(*pHWInfos);
DeviceFactory::numDevices = devNum;
DeviceFactory::hwInfos = ptr;
DeviceFactory::numDevices = numDevices;
DeviceFactory::hwInfo = *pHWInfos;
return true;
}
@ -71,14 +60,14 @@ void DeviceFactory::releaseDevices() {
if (DeviceFactory::numDevices > 0) {
for (unsigned int i = 0; i < DeviceFactory::numDevices; ++i) {
Drm::closeDevice(i);
delete hwInfos[i].pSysInfo;
delete hwInfos[i].pSkuTable;
delete hwInfos[i].pWaTable;
delete hwInfos[i].pPlatform;
}
delete[] hwInfos;
delete hwInfo->pSysInfo;
delete hwInfo->pSkuTable;
delete hwInfo->pWaTable;
delete hwInfo->pPlatform;
delete hwInfo;
}
DeviceFactory::hwInfos = nullptr;
DeviceFactory::hwInfo = nullptr;
DeviceFactory::numDevices = 0;
}

View File

@ -9,6 +9,7 @@
#include "runtime/command_stream/preemption.h"
#include "runtime/device/device.h"
#include "runtime/helpers/device_helpers.h"
#include "runtime/os_interface/debug_settings_manager.h"
#include "runtime/os_interface/device_factory.h"
#include "runtime/os_interface/hw_info_config.h"
@ -20,36 +21,31 @@ namespace OCLRT {
extern const HardwareInfo *hardwareInfoTable[IGFX_MAX_PRODUCT];
size_t DeviceFactory::numDevices = 0;
HardwareInfo *DeviceFactory::hwInfos = nullptr;
HardwareInfo *DeviceFactory::hwInfo = nullptr;
bool DeviceFactory::getDevices(HardwareInfo **pHWInfos, size_t &numDevices, ExecutionEnvironment &executionEnvironment) {
auto totalDeviceCount = 1u;
if (DebugManager.flags.CreateMultipleDevices.get()) {
totalDeviceCount = DebugManager.flags.CreateMultipleDevices.get();
}
std::unique_ptr<HardwareInfo[]> tempHwInfos(new HardwareInfo[totalDeviceCount]);
numDevices = 0;
while (numDevices < totalDeviceCount) {
std::unique_ptr<Wddm> wddm(Wddm ::createWddm());
if (!wddm->enumAdapters(tempHwInfos[numDevices])) {
return false;
}
executionEnvironment.osInterface.reset(new OSInterface());
executionEnvironment.osInterface->get()->setWddm(wddm.release());
HwInfoConfig *hwConfig = HwInfoConfig::get(tempHwInfos[numDevices].pPlatform->eProductFamily);
if (hwConfig->configureHwInfo(&tempHwInfos[numDevices], &tempHwInfos[numDevices], nullptr)) {
return false;
}
numDevices++;
auto hardwareInfo = std::make_unique<HardwareInfo>();
std::unique_ptr<Wddm> wddm(Wddm ::createWddm());
if (!wddm->enumAdapters(*hardwareInfo)) {
return false;
}
*pHWInfos = tempHwInfos.get();
auto totalDeviceCount = DeviceHelper::getDevicesCount(hardwareInfo.get());
executionEnvironment.osInterface.reset(new OSInterface());
executionEnvironment.osInterface->get()->setWddm(wddm.release());
HwInfoConfig *hwConfig = HwInfoConfig::get(hardwareInfo->pPlatform->eProductFamily);
if (hwConfig->configureHwInfo(hardwareInfo.get(), hardwareInfo.get(), nullptr)) {
return false;
}
*pHWInfos = hardwareInfo.release();
numDevices = totalDeviceCount;
DeviceFactory::numDevices = numDevices;
DeviceFactory::hwInfos = tempHwInfos.get();
tempHwInfos.release();
DeviceFactory::hwInfo = *pHWInfos;
executionEnvironment.setHwInfo(*pHWInfos);
executionEnvironment.initGmm();
@ -62,15 +58,13 @@ bool DeviceFactory::getDevices(HardwareInfo **pHWInfos, size_t &numDevices, Exec
void DeviceFactory::releaseDevices() {
if (DeviceFactory::numDevices > 0) {
for (unsigned int i = 0; i < DeviceFactory::numDevices; ++i) {
delete hwInfos[i].pPlatform;
delete hwInfos[i].pSkuTable;
delete hwInfos[i].pWaTable;
delete hwInfos[i].pSysInfo;
}
delete[] hwInfos;
delete hwInfo->pPlatform;
delete hwInfo->pSkuTable;
delete hwInfo->pWaTable;
delete hwInfo->pSysInfo;
delete hwInfo;
}
DeviceFactory::hwInfos = nullptr;
DeviceFactory::hwInfo = nullptr;
DeviceFactory::numDevices = 0;
}

View File

@ -151,7 +151,7 @@ bool Platform::initialize() {
this->devices.resize(numDevicesReturned);
for (uint32_t deviceOrdinal = 0; deviceOrdinal < numDevicesReturned; ++deviceOrdinal) {
auto pDevice = Device::create<OCLRT::Device>(&hwInfo[deviceOrdinal], executionEnvironment, deviceOrdinal);
auto pDevice = Device::create<OCLRT::Device>(hwInfo, executionEnvironment, deviceOrdinal);
DEBUG_BREAK_IF(!pDevice);
if (pDevice) {
this->devices[deviceOrdinal] = pDevice;

View File

@ -41,6 +41,8 @@ struct GetDevicesTest : ::testing::Test {
};
HWTEST_F(GetDevicesTest, givenGetDevicesWhenCsrIsSetToVariousTypesThenTheFunctionReturnsTheExpectedValueOfHardwareInfo) {
uint32_t expectedDevices = 1;
DebugManager.flags.CreateMultipleDevices.set(expectedDevices);
for (int productFamilyIndex = 0; productFamilyIndex < IGFX_MAX_PRODUCT; productFamilyIndex++) {
const char *hwPrefix = hardwarePrefix[productFamilyIndex];
if (hwPrefix == nullptr) {
@ -68,7 +70,7 @@ HWTEST_F(GetDevicesTest, givenGetDevicesWhenCsrIsSetToVariousTypesThenTheFunctio
case CSR_HW_WITH_AUB:
EXPECT_TRUE(ret);
EXPECT_NE(nullptr, hwInfo);
EXPECT_EQ(1u, numDevices);
EXPECT_EQ(expectedDevices, numDevices);
DeviceFactory::releaseDevices();
break;
case CSR_AUB:
@ -76,7 +78,7 @@ HWTEST_F(GetDevicesTest, givenGetDevicesWhenCsrIsSetToVariousTypesThenTheFunctio
case CSR_TBX_WITH_AUB:
EXPECT_TRUE(ret);
EXPECT_NE(nullptr, hwInfo);
EXPECT_EQ(1u, numDevices);
EXPECT_EQ(expectedDevices, numDevices);
for (i = 0; i < IGFX_MAX_PRODUCT; i++) {
auto hardwareInfo = hardwareInfoTable[i];
if (hardwareInfo == nullptr)
@ -100,6 +102,8 @@ HWTEST_F(GetDevicesTest, givenGetDevicesWhenCsrIsSetToVariousTypesThenTheFunctio
}
HWTEST_F(GetDevicesTest, givenGetDevicesAndUnknownProductFamilyWhenCsrIsSetToValidTypeThenTheFunctionReturnsTheExpectedValueOfHardwareInfo) {
uint32_t expectedDevices = 1;
DebugManager.flags.CreateMultipleDevices.set(expectedDevices);
for (int csrTypes = 0; csrTypes <= CSR_TYPES_NUM; csrTypes++) {
CommandStreamReceiverType csrType = static_cast<CommandStreamReceiverType>(csrTypes);
std::string productFamily("unk");
@ -115,7 +119,7 @@ HWTEST_F(GetDevicesTest, givenGetDevicesAndUnknownProductFamilyWhenCsrIsSetToVal
case CSR_HW_WITH_AUB:
EXPECT_TRUE(ret);
EXPECT_NE(nullptr, hwInfo);
EXPECT_EQ(1u, numDevices);
EXPECT_EQ(expectedDevices, numDevices);
DeviceFactory::releaseDevices();
break;
case CSR_AUB:
@ -123,7 +127,7 @@ HWTEST_F(GetDevicesTest, givenGetDevicesAndUnknownProductFamilyWhenCsrIsSetToVal
case CSR_TBX_WITH_AUB: {
EXPECT_TRUE(ret);
EXPECT_NE(nullptr, hwInfo);
EXPECT_EQ(1u, numDevices);
EXPECT_EQ(expectedDevices, numDevices);
for (i = 0; i < IGFX_MAX_PRODUCT; i++) {
auto hardwareInfo = hardwareInfoTable[i];
if (hardwareInfo == nullptr)

View File

@ -156,14 +156,10 @@ TEST_F(DeviceFactoryTest, givenCreateMultipleDevicesDebugFlagWhenGetDevicesIsCal
bool success = DeviceFactory::getDevices(&hwInfo, numDevices, *executionEnvironment);
ASSERT_NE(nullptr, hwInfo);
for (auto deviceIndex = 0u; deviceIndex < requiredDeviceCount; deviceIndex++) {
EXPECT_NE(nullptr, hwInfo[deviceIndex].pPlatform);
EXPECT_NE(nullptr, hwInfo[deviceIndex].pSkuTable);
EXPECT_NE(nullptr, hwInfo[deviceIndex].pSysInfo);
EXPECT_NE(nullptr, hwInfo[deviceIndex].pWaTable);
}
EXPECT_EQ(hwInfo[0].pPlatform->eDisplayCoreFamily, hwInfo[1].pPlatform->eDisplayCoreFamily);
EXPECT_NE(nullptr, hwInfo->pPlatform);
EXPECT_NE(nullptr, hwInfo->pSkuTable);
EXPECT_NE(nullptr, hwInfo->pSysInfo);
EXPECT_NE(nullptr, hwInfo->pWaTable);
ASSERT_TRUE(success);
EXPECT_EQ(requiredDeviceCount, numDevices);
@ -179,14 +175,10 @@ TEST_F(DeviceFactoryTest, givenCreateMultipleDevicesDebugFlagWhenGetDevicesForPr
bool success = DeviceFactory::getDevicesForProductFamilyOverride(&hwInfo, numDevices, *executionEnvironment);
ASSERT_NE(nullptr, hwInfo);
for (auto deviceIndex = 0u; deviceIndex < requiredDeviceCount; deviceIndex++) {
EXPECT_NE(nullptr, hwInfo[deviceIndex].pPlatform);
EXPECT_NE(nullptr, hwInfo[deviceIndex].pSkuTable);
EXPECT_NE(nullptr, hwInfo[deviceIndex].pSysInfo);
EXPECT_NE(nullptr, hwInfo[deviceIndex].pWaTable);
}
EXPECT_EQ(hwInfo[0].pPlatform->eDisplayCoreFamily, hwInfo[1].pPlatform->eDisplayCoreFamily);
EXPECT_NE(nullptr, hwInfo->pPlatform);
EXPECT_NE(nullptr, hwInfo->pSkuTable);
EXPECT_NE(nullptr, hwInfo->pSysInfo);
EXPECT_NE(nullptr, hwInfo->pWaTable);
ASSERT_TRUE(success);
EXPECT_EQ(requiredDeviceCount, numDevices);