2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2024-03-20 11:45:31 +00:00
|
|
|
* Copyright (C) 2018-2024 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2021-01-21 13:10:13 +01:00
|
|
|
#include "shared/test/common/mocks/mock_device.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2020-03-19 14:26:08 +01:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/command_stream/preemption.h"
|
2023-01-13 15:18:40 +00:00
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
2023-02-06 09:05:43 +00:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2023-01-13 15:18:40 +00:00
|
|
|
#include "shared/source/memory_manager/multi_graphics_allocation.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/os_interface/os_context.h"
|
2022-11-16 15:50:07 +00:00
|
|
|
#include "shared/test/common/fixtures/mock_aub_center_fixture.h"
|
2024-08-23 13:20:08 +00:00
|
|
|
#include "shared/test/common/helpers/unit_test_helper.h"
|
2021-07-06 15:44:16 +02:00
|
|
|
#include "shared/test/common/mocks/mock_execution_environment.h"
|
2021-10-05 12:54:33 +00:00
|
|
|
#include "shared/test/common/mocks/mock_memory_manager.h"
|
2021-10-21 14:50:10 +00:00
|
|
|
#include "shared/test/common/mocks/mock_ostime.h"
|
2021-01-21 13:10:13 +01:00
|
|
|
#include "shared/test/common/mocks/ult_device_factory.h"
|
2022-08-17 10:17:02 +00:00
|
|
|
#include "shared/test/common/tests_configuration.h"
|
2020-02-24 10:22:30 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
using namespace NEO;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-10-07 12:42:28 +02:00
|
|
|
bool MockDevice::createSingleDevice = true;
|
2020-01-14 14:32:11 +01:00
|
|
|
|
2019-11-05 13:38:20 +01:00
|
|
|
decltype(&createCommandStream) MockSubDevice::createCommandStreamReceiverFunc = createCommandStream;
|
|
|
|
|
decltype(&createCommandStream) MockDevice::createCommandStreamReceiverFunc = createCommandStream;
|
2019-10-07 12:42:28 +02:00
|
|
|
|
2019-05-06 12:33:44 +02:00
|
|
|
MockDevice::MockDevice()
|
|
|
|
|
: MockDevice(new MockExecutionEnvironment(), 0u) {
|
2021-01-12 21:39:04 +00:00
|
|
|
UltDeviceFactory::initializeMemoryManager(*executionEnvironment);
|
|
|
|
|
CommandStreamReceiver *commandStreamReceiver = createCommandStream(*executionEnvironment, this->getRootDeviceIndex(), this->getDeviceBitfield());
|
2019-11-05 13:38:20 +01:00
|
|
|
commandStreamReceivers.resize(1);
|
|
|
|
|
commandStreamReceivers[0].reset(commandStreamReceiver);
|
2021-08-11 17:36:00 +00:00
|
|
|
|
2023-12-11 11:02:15 +00:00
|
|
|
EngineDescriptor engineDescriptor = {EngineTypeUsage{aub_stream::ENGINE_CCS, EngineUsage::regular}, this->getDeviceBitfield(), PreemptionMode::Disabled, true, false};
|
2021-08-11 17:36:00 +00:00
|
|
|
|
|
|
|
|
OsContext *osContext = getMemoryManager()->createAndRegisterOsContext(commandStreamReceiver, engineDescriptor);
|
2021-03-19 09:44:36 +00:00
|
|
|
commandStreamReceiver->setupContext(*osContext);
|
2021-12-13 12:45:24 +00:00
|
|
|
this->allEngines.resize(1);
|
|
|
|
|
this->allEngines[0] = {commandStreamReceiver, osContext};
|
2019-09-25 14:23:04 +02:00
|
|
|
initializeCaps();
|
2018-07-10 17:14:20 +02:00
|
|
|
}
|
2019-05-06 12:33:44 +02:00
|
|
|
|
2019-11-29 10:30:14 +01:00
|
|
|
const char *MockDevice::getProductAbbrev() const {
|
|
|
|
|
return hardwarePrefix[getHardwareInfo().platform.eProductFamily];
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-05 13:38:20 +01:00
|
|
|
MockDevice::MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex)
|
|
|
|
|
: RootDevice(executionEnvironment, rootDeviceIndex) {
|
2021-01-12 21:39:04 +00:00
|
|
|
UltDeviceFactory::initializeMemoryManager(*executionEnvironment);
|
2024-04-30 10:59:04 +00:00
|
|
|
auto &hwInfo = getHardwareInfo();
|
2021-09-24 10:51:57 +00:00
|
|
|
if (!getOSTime()) {
|
|
|
|
|
getRootDeviceEnvironmentRef().osTime = MockOSTime::create();
|
2024-04-30 10:59:04 +00:00
|
|
|
getRootDeviceEnvironmentRef().osTime->setDeviceTimerResolution(hwInfo);
|
2021-09-24 10:51:57 +00:00
|
|
|
}
|
2023-01-03 10:27:35 +00:00
|
|
|
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfoAndInitHelpers(&hwInfo);
|
2024-08-23 13:20:08 +00:00
|
|
|
UnitTestSetter::setRcsExposure(*executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]);
|
|
|
|
|
UnitTestSetter::setCcsExposure(*executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]);
|
2022-06-08 08:23:02 +00:00
|
|
|
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->initGmm();
|
2024-08-23 13:20:08 +00:00
|
|
|
|
2024-03-20 11:45:31 +00:00
|
|
|
if (!executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface) {
|
|
|
|
|
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = std::make_unique<MockMemoryOperations>();
|
|
|
|
|
}
|
2022-06-08 08:23:02 +00:00
|
|
|
|
2019-09-25 14:23:04 +02:00
|
|
|
initializeCaps();
|
2020-02-17 13:10:01 +01:00
|
|
|
preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfo);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2019-10-07 12:42:28 +02:00
|
|
|
bool MockDevice::createDeviceImpl() {
|
|
|
|
|
if (MockDevice::createSingleDevice) {
|
|
|
|
|
return Device::createDeviceImpl();
|
|
|
|
|
}
|
|
|
|
|
return RootDevice::createDeviceImpl();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
void MockDevice::setOSTime(OSTime *osTime) {
|
2021-09-24 10:51:57 +00:00
|
|
|
getRootDeviceEnvironmentRef().osTime.reset(osTime);
|
|
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-10-09 11:50:58 +02:00
|
|
|
void MockDevice::injectMemoryManager(MemoryManager *memoryManager) {
|
2018-10-11 11:19:49 +02:00
|
|
|
executionEnvironment->memoryManager.reset(memoryManager);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) {
|
2019-03-22 14:04:25 +01:00
|
|
|
resetCommandStreamReceiver(newCsr, defaultEngineIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr, uint32_t engineIndex) {
|
2019-09-02 13:23:25 +02:00
|
|
|
|
2021-12-13 12:45:24 +00:00
|
|
|
auto osContext = this->allEngines[engineIndex].osContext;
|
2019-09-02 13:23:25 +02:00
|
|
|
auto memoryManager = executionEnvironment->memoryManager.get();
|
2021-12-13 12:45:24 +00:00
|
|
|
auto registeredEngine = *memoryManager->getRegisteredEngineForCsr(allEngines[engineIndex].commandStreamReceiver);
|
2019-09-02 13:23:25 +02:00
|
|
|
|
|
|
|
|
registeredEngine.commandStreamReceiver = newCsr;
|
2021-12-13 12:45:24 +00:00
|
|
|
allEngines[engineIndex].commandStreamReceiver = newCsr;
|
2023-04-27 15:42:17 +00:00
|
|
|
const_cast<EngineControlContainer &>(memoryManager->getRegisteredEngines(rootDeviceIndex)).emplace_back(registeredEngine);
|
2019-09-02 13:23:25 +02:00
|
|
|
osContext->incRefInternal();
|
|
|
|
|
newCsr->setupContext(*osContext);
|
2024-06-06 15:23:40 +00:00
|
|
|
osContext->ensureContextInitialized(false);
|
2019-11-05 13:38:20 +01:00
|
|
|
commandStreamReceivers[engineIndex].reset(newCsr);
|
|
|
|
|
commandStreamReceivers[engineIndex]->initializeTagAllocation();
|
2020-02-05 20:00:08 +01:00
|
|
|
commandStreamReceivers[engineIndex]->createGlobalFenceAllocation();
|
2019-06-27 21:33:05 +02:00
|
|
|
|
2023-08-04 09:19:46 +00:00
|
|
|
if (preemptionMode == PreemptionMode::MidThread) {
|
2019-11-05 13:38:20 +01:00
|
|
|
commandStreamReceivers[engineIndex]->createPreemptionAllocation();
|
2019-06-27 21:33:05 +02:00
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-02 09:56:45 +00:00
|
|
|
ExecutionEnvironment *MockDevice::prepareExecutionEnvironment(const HardwareInfo *pHwInfo, uint32_t rootDeviceIndex) {
|
|
|
|
|
ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment();
|
2023-11-30 08:32:25 +00:00
|
|
|
auto numRootDevices = debugManager.flags.CreateMultipleRootDevices.get() ? debugManager.flags.CreateMultipleRootDevices.get() : rootDeviceIndex + 1;
|
2023-01-02 09:56:45 +00:00
|
|
|
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
|
|
|
|
|
pHwInfo = pHwInfo ? pHwInfo : defaultHwInfo.get();
|
|
|
|
|
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
|
2023-01-03 10:27:35 +00:00
|
|
|
executionEnvironment->rootDeviceEnvironments[i]->setHwInfoAndInitHelpers(pHwInfo);
|
2024-08-23 13:20:08 +00:00
|
|
|
|
|
|
|
|
UnitTestSetter::setRcsExposure(*executionEnvironment->rootDeviceEnvironments[i]);
|
|
|
|
|
UnitTestSetter::setCcsExposure(*executionEnvironment->rootDeviceEnvironments[i]);
|
2023-01-02 09:56:45 +00:00
|
|
|
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
|
|
|
|
|
}
|
2023-10-05 23:12:34 +00:00
|
|
|
executionEnvironment->setDeviceHierarchy(executionEnvironment->rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
|
2023-01-02 09:56:45 +00:00
|
|
|
executionEnvironment->calculateMaxOsContextCount();
|
|
|
|
|
return executionEnvironment;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 14:08:18 +00:00
|
|
|
bool MockDevice::verifyAdapterLuid() {
|
|
|
|
|
if (callBaseVerifyAdapterLuid)
|
|
|
|
|
return Device::verifyAdapterLuid();
|
|
|
|
|
return verifyAdapterLuidReturnValue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-02 09:56:45 +00:00
|
|
|
void MockDevice::finalizeRayTracing() {
|
|
|
|
|
for (unsigned int i = 0; i < rtDispatchGlobalsInfos.size(); i++) {
|
|
|
|
|
auto rtDispatchGlobalsInfo = rtDispatchGlobalsInfos[i];
|
|
|
|
|
if (rtDispatchGlobalsForceAllocation == true && rtDispatchGlobalsInfo != nullptr) {
|
|
|
|
|
for (unsigned int j = 0; j < rtDispatchGlobalsInfo->rtStacks.size(); j++) {
|
|
|
|
|
delete rtDispatchGlobalsInfo->rtStacks[j];
|
|
|
|
|
rtDispatchGlobalsInfo->rtStacks[j] = nullptr;
|
|
|
|
|
}
|
|
|
|
|
delete rtDispatchGlobalsInfo->rtDispatchGlobalsArray;
|
|
|
|
|
rtDispatchGlobalsInfo->rtDispatchGlobalsArray = nullptr;
|
|
|
|
|
delete rtDispatchGlobalsInfos[i];
|
|
|
|
|
rtDispatchGlobalsInfos[i] = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Device::finalizeRayTracing();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 15:50:07 +00:00
|
|
|
ExecutionEnvironment *MockDevice::prepareExecutionEnvironment(const HardwareInfo *pHwInfo) {
|
|
|
|
|
auto executionEnvironment = new ExecutionEnvironment();
|
|
|
|
|
executionEnvironment->prepareRootDeviceEnvironments(1);
|
|
|
|
|
|
|
|
|
|
auto hwInfo = pHwInfo ? pHwInfo : defaultHwInfo.get();
|
|
|
|
|
|
2023-01-03 10:27:35 +00:00
|
|
|
executionEnvironment->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(hwInfo);
|
2024-08-23 13:20:08 +00:00
|
|
|
UnitTestSetter::setRcsExposure(*executionEnvironment->rootDeviceEnvironments[0]);
|
|
|
|
|
UnitTestSetter::setCcsExposure(*executionEnvironment->rootDeviceEnvironments[0]);
|
|
|
|
|
|
2023-10-05 23:12:34 +00:00
|
|
|
executionEnvironment->setDeviceHierarchy(executionEnvironment->rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
|
2022-11-16 15:50:07 +00:00
|
|
|
|
|
|
|
|
MockAubCenterFixture::setMockAubCenter(*executionEnvironment->rootDeviceEnvironments[0]);
|
|
|
|
|
executionEnvironment->initializeMemoryManager();
|
|
|
|
|
return executionEnvironment;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-18 12:38:06 +00:00
|
|
|
ReleaseHelper *MockDevice::getReleaseHelper() const {
|
|
|
|
|
if (mockReleaseHelper) {
|
|
|
|
|
return mockReleaseHelper;
|
|
|
|
|
}
|
|
|
|
|
return Device::getReleaseHelper();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AILConfiguration *MockDevice::getAilConfigurationHelper() const {
|
|
|
|
|
if (mockAilConfigurationHelper) {
|
|
|
|
|
return mockAilConfigurationHelper;
|
|
|
|
|
}
|
|
|
|
|
return Device::getAilConfigurationHelper();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-24 22:55:08 +00:00
|
|
|
bool MockSubDevice::createEngine(EngineTypeUsage engineTypeUsage) {
|
2021-04-28 17:46:13 +00:00
|
|
|
if (failOnCreateEngine) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-06-24 22:55:08 +00:00
|
|
|
return SubDevice::createEngine(engineTypeUsage);
|
2021-04-28 17:46:13 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-24 13:34:25 +02:00
|
|
|
MockAlignedMallocManagerDevice::MockAlignedMallocManagerDevice(ExecutionEnvironment *executionEnvironment, uint32_t internalDeviceIndex) : MockDevice(executionEnvironment, internalDeviceIndex) {
|
2021-01-11 15:20:18 +00:00
|
|
|
executionEnvironment->memoryManager.reset(new MockAllocSysMemAgnosticMemoryManager(*executionEnvironment));
|
2018-01-26 16:53:18 +01:00
|
|
|
}
|
2019-05-06 12:33:44 +02:00
|
|
|
FailDevice::FailDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex)
|
|
|
|
|
: MockDevice(executionEnvironment, deviceIndex) {
|
2021-01-11 15:20:18 +00:00
|
|
|
executionEnvironment->memoryManager.reset(new FailMemoryManager(*executionEnvironment));
|
2018-10-19 13:41:42 +02:00
|
|
|
}
|
2019-05-06 12:33:44 +02:00
|
|
|
FailDeviceAfterOne::FailDeviceAfterOne(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex)
|
|
|
|
|
: MockDevice(executionEnvironment, deviceIndex) {
|
2021-01-11 15:20:18 +00:00
|
|
|
executionEnvironment->memoryManager.reset(new FailMemoryManager(1, *executionEnvironment));
|
2019-03-22 14:04:25 +01:00
|
|
|
}
|