2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2020-12-30 13:36:22 +00:00
|
|
|
* Copyright (C) 2017-2021 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
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-04-02 09:35:50 +02:00
|
|
|
#include "shared/test/unit_test/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"
|
|
|
|
|
#include "shared/source/os_interface/os_context.h"
|
2021-01-12 21:39:04 +00:00
|
|
|
#include "shared/test/unit_test/mocks/ult_device_factory.h"
|
2020-03-25 10:51:31 +01:00
|
|
|
#include "shared/test/unit_test/tests_configuration.h"
|
2020-02-24 10:22:30 +01:00
|
|
|
|
2020-02-23 15:20:22 +01:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_execution_environment.h"
|
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_ostime.h"
|
2020-02-22 09:28:27 +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);
|
|
|
|
|
this->engines.resize(1);
|
|
|
|
|
this->engines[0] = {commandStreamReceiver, nullptr};
|
2020-12-30 13:36:22 +00:00
|
|
|
this->engineGroups.resize(static_cast<uint32_t>(EngineGroupType::MaxEngineGroups));
|
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);
|
2017-12-21 00:45:38 +01:00
|
|
|
this->osTime = MockOSTime::create();
|
2020-12-30 13:36:22 +00:00
|
|
|
this->engineGroups.resize(static_cast<uint32_t>(EngineGroupType::MaxEngineGroups));
|
2021-01-11 15:20:18 +00:00
|
|
|
auto &hwInfo = getHardwareInfo();
|
2020-03-04 08:51:02 +01:00
|
|
|
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfo(&hwInfo);
|
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) {
|
|
|
|
|
this->osTime.reset(osTime);
|
|
|
|
|
};
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
auto osContext = this->engines[engineIndex].osContext;
|
|
|
|
|
auto memoryManager = executionEnvironment->memoryManager.get();
|
|
|
|
|
auto registeredEngine = *memoryManager->getRegisteredEngineForCsr(engines[engineIndex].commandStreamReceiver);
|
|
|
|
|
|
|
|
|
|
registeredEngine.commandStreamReceiver = newCsr;
|
|
|
|
|
engines[engineIndex].commandStreamReceiver = newCsr;
|
|
|
|
|
memoryManager->getRegisteredEngines().emplace_back(registeredEngine);
|
|
|
|
|
osContext->incRefInternal();
|
|
|
|
|
newCsr->setupContext(*osContext);
|
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
|
|
|
|
2020-02-10 15:57:49 +01:00
|
|
|
if (preemptionMode == PreemptionMode::MidThread || isDebuggerActive()) {
|
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
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|