2020-04-02 16:37:59 +08:00
|
|
|
/*
|
2022-09-08 19:05:08 +08:00
|
|
|
* Copyright (C) 2020-2022 Intel Corporation
|
2020-04-02 16:37:59 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/mocks/ult_device_factory.h"
|
2020-04-02 16:37:59 +08:00
|
|
|
|
|
|
|
#include "shared/source/os_interface/device_factory.h"
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
|
|
|
#include "shared/test/common/helpers/variable_backup.h"
|
|
|
|
#include "shared/test/common/mocks/mock_device.h"
|
2021-10-05 20:54:33 +08:00
|
|
|
#include "shared/test/common/mocks/mock_memory_manager.h"
|
2022-11-16 22:01:52 +08:00
|
|
|
#include "shared/test/common/tests_configuration.h"
|
2021-01-13 05:39:04 +08:00
|
|
|
|
2020-04-02 16:37:59 +08:00
|
|
|
using namespace NEO;
|
|
|
|
|
|
|
|
UltDeviceFactory::UltDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevicesCount)
|
|
|
|
: UltDeviceFactory(rootDevicesCount, subDevicesCount, *(new ExecutionEnvironment)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
UltDeviceFactory::UltDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevicesCount, ExecutionEnvironment &executionEnvironment) {
|
|
|
|
DebugManagerStateRestore restorer;
|
|
|
|
VariableBackup<bool> createSingleDeviceBackup{&MockDevice::createSingleDevice, false};
|
|
|
|
VariableBackup<decltype(DeviceFactory::createRootDeviceFunc)> createRootDeviceFuncBackup{&DeviceFactory::createRootDeviceFunc};
|
2021-01-13 05:39:04 +08:00
|
|
|
VariableBackup<decltype(DeviceFactory::createMemoryManagerFunc)> createMemoryManagerFuncBackup{&DeviceFactory::createMemoryManagerFunc};
|
2020-04-02 16:37:59 +08:00
|
|
|
|
|
|
|
DebugManager.flags.CreateMultipleRootDevices.set(rootDevicesCount);
|
|
|
|
DebugManager.flags.CreateMultipleSubDevices.set(subDevicesCount);
|
|
|
|
createRootDeviceFuncBackup = [](ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) -> std::unique_ptr<Device> {
|
|
|
|
return std::unique_ptr<Device>(MockDevice::create<MockDevice>(&executionEnvironment, rootDeviceIndex));
|
|
|
|
};
|
2021-01-13 05:39:04 +08:00
|
|
|
createMemoryManagerFuncBackup = UltDeviceFactory::initializeMemoryManager;
|
2020-04-02 16:37:59 +08:00
|
|
|
|
|
|
|
auto createdDevices = DeviceFactory::createDevices(executionEnvironment);
|
|
|
|
|
|
|
|
for (auto &pCreatedDevice : createdDevices) {
|
|
|
|
pCreatedDevice->incRefInternal();
|
2021-09-01 00:49:46 +08:00
|
|
|
if (pCreatedDevice->getNumSubDevices() > 1) {
|
|
|
|
for (uint32_t i = 0; i < pCreatedDevice->getNumSubDevices(); i++) {
|
2021-08-26 03:01:44 +08:00
|
|
|
this->subDevices.push_back(static_cast<SubDevice *>(pCreatedDevice->getSubDevice(i)));
|
|
|
|
}
|
2020-04-02 16:37:59 +08:00
|
|
|
}
|
|
|
|
this->rootDevices.push_back(static_cast<MockDevice *>(pCreatedDevice.release()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UltDeviceFactory::~UltDeviceFactory() {
|
|
|
|
for (auto &pDevice : rootDevices) {
|
|
|
|
pDevice->decRefInternal();
|
|
|
|
}
|
|
|
|
}
|
2020-11-20 19:04:46 +08:00
|
|
|
|
2021-01-13 05:39:04 +08:00
|
|
|
void UltDeviceFactory::prepareDeviceEnvironments(ExecutionEnvironment &executionEnvironment, uint32_t rootDevicesCount) {
|
2020-11-20 19:04:46 +08:00
|
|
|
uint32_t numRootDevices = rootDevicesCount;
|
|
|
|
executionEnvironment.prepareRootDeviceEnvironments(numRootDevices);
|
|
|
|
for (auto i = 0u; i < numRootDevices; i++) {
|
|
|
|
if (executionEnvironment.rootDeviceEnvironments[i]->getHardwareInfo() == nullptr ||
|
|
|
|
(executionEnvironment.rootDeviceEnvironments[i]->getHardwareInfo()->platform.eProductFamily == IGFX_UNKNOWN &&
|
|
|
|
executionEnvironment.rootDeviceEnvironments[i]->getHardwareInfo()->platform.eRenderCoreFamily == IGFX_UNKNOWN_CORE)) {
|
|
|
|
executionEnvironment.rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get());
|
|
|
|
}
|
|
|
|
}
|
2022-09-08 19:05:08 +08:00
|
|
|
executionEnvironment.parseAffinityMask();
|
2020-11-20 19:04:46 +08:00
|
|
|
executionEnvironment.calculateMaxOsContextCount();
|
|
|
|
DeviceFactory::createMemoryManagerFunc(executionEnvironment);
|
|
|
|
}
|
2021-01-13 05:39:04 +08:00
|
|
|
bool UltDeviceFactory::initializeMemoryManager(ExecutionEnvironment &executionEnvironment) {
|
|
|
|
if (executionEnvironment.memoryManager == nullptr) {
|
|
|
|
bool enableLocalMemory = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getEnableLocalMemory(*defaultHwInfo);
|
|
|
|
bool aubUsage = (testMode == TestMode::AubTests) || (testMode == TestMode::AubTestsWithTbx);
|
|
|
|
executionEnvironment.memoryManager.reset(new MockMemoryManager(false, enableLocalMemory, aubUsage, executionEnvironment));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|