2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-12-30 21:36:22 +08:00
|
|
|
* Copyright (C) 2017-2021 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-04-02 15:35:50 +08:00
|
|
|
#include "shared/test/unit_test/mocks/mock_device.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-03-19 21:26:08 +08:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/preemption.h"
|
|
|
|
#include "shared/source/os_interface/os_context.h"
|
2020-03-25 17:51:31 +08:00
|
|
|
#include "shared/test/unit_test/tests_configuration.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 22:20:22 +08: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 16:28:27 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-10-07 18:42:28 +08:00
|
|
|
bool MockDevice::createSingleDevice = true;
|
2020-01-14 21:32:11 +08:00
|
|
|
|
2019-11-05 20:38:20 +08:00
|
|
|
decltype(&createCommandStream) MockSubDevice::createCommandStreamReceiverFunc = createCommandStream;
|
|
|
|
decltype(&createCommandStream) MockDevice::createCommandStreamReceiverFunc = createCommandStream;
|
2019-10-07 18:42:28 +08:00
|
|
|
|
2019-05-06 18:33:44 +08:00
|
|
|
MockDevice::MockDevice()
|
|
|
|
: MockDevice(new MockExecutionEnvironment(), 0u) {
|
2021-01-11 23:20:18 +08:00
|
|
|
initializeMemoryManager();
|
2020-10-28 23:08:37 +08:00
|
|
|
CommandStreamReceiver *commandStreamReceiver = createCommandStream(*this->executionEnvironment, this->getRootDeviceIndex(), this->getDeviceBitfield());
|
2019-11-05 20:38:20 +08:00
|
|
|
commandStreamReceivers.resize(1);
|
|
|
|
commandStreamReceivers[0].reset(commandStreamReceiver);
|
|
|
|
this->engines.resize(1);
|
|
|
|
this->engines[0] = {commandStreamReceiver, nullptr};
|
2020-12-30 21:36:22 +08:00
|
|
|
this->engineGroups.resize(static_cast<uint32_t>(EngineGroupType::MaxEngineGroups));
|
2019-09-25 20:23:04 +08:00
|
|
|
initializeCaps();
|
2018-07-10 23:14:20 +08:00
|
|
|
}
|
2019-05-06 18:33:44 +08:00
|
|
|
|
2019-11-29 17:30:14 +08:00
|
|
|
const char *MockDevice::getProductAbbrev() const {
|
|
|
|
return hardwarePrefix[getHardwareInfo().platform.eProductFamily];
|
|
|
|
}
|
|
|
|
|
2019-11-05 20:38:20 +08:00
|
|
|
MockDevice::MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex)
|
|
|
|
: RootDevice(executionEnvironment, rootDeviceIndex) {
|
2021-01-11 23:20:18 +08:00
|
|
|
initializeMemoryManager();
|
2017-12-21 07:45:38 +08:00
|
|
|
this->osTime = MockOSTime::create();
|
2020-12-30 21:36:22 +08:00
|
|
|
this->engineGroups.resize(static_cast<uint32_t>(EngineGroupType::MaxEngineGroups));
|
2021-01-11 23:20:18 +08:00
|
|
|
auto &hwInfo = getHardwareInfo();
|
2020-03-04 15:51:02 +08:00
|
|
|
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfo(&hwInfo);
|
2019-09-25 20:23:04 +08:00
|
|
|
initializeCaps();
|
2020-02-17 20:10:01 +08:00
|
|
|
preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfo);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2019-10-07 18:42:28 +08:00
|
|
|
bool MockDevice::createDeviceImpl() {
|
|
|
|
if (MockDevice::createSingleDevice) {
|
|
|
|
return Device::createDeviceImpl();
|
|
|
|
}
|
|
|
|
return RootDevice::createDeviceImpl();
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
void MockDevice::setOSTime(OSTime *osTime) {
|
|
|
|
this->osTime.reset(osTime);
|
|
|
|
};
|
|
|
|
|
2018-10-09 17:50:58 +08:00
|
|
|
void MockDevice::injectMemoryManager(MemoryManager *memoryManager) {
|
2018-10-11 17:19:49 +08:00
|
|
|
executionEnvironment->memoryManager.reset(memoryManager);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) {
|
2019-03-22 21:04:25 +08:00
|
|
|
resetCommandStreamReceiver(newCsr, defaultEngineIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr, uint32_t engineIndex) {
|
2019-09-02 19:23:25 +08: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 20:38:20 +08:00
|
|
|
commandStreamReceivers[engineIndex].reset(newCsr);
|
|
|
|
commandStreamReceivers[engineIndex]->initializeTagAllocation();
|
2020-02-06 03:00:08 +08:00
|
|
|
commandStreamReceivers[engineIndex]->createGlobalFenceAllocation();
|
2019-06-28 03:33:05 +08:00
|
|
|
|
2020-02-10 22:57:49 +08:00
|
|
|
if (preemptionMode == PreemptionMode::MidThread || isDebuggerActive()) {
|
2019-11-05 20:38:20 +08:00
|
|
|
commandStreamReceivers[engineIndex]->createPreemptionAllocation();
|
2019-06-28 03:33:05 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2021-01-11 23:20:18 +08:00
|
|
|
void MockDevice::initializeMemoryManager() const {
|
|
|
|
if (executionEnvironment->memoryManager == nullptr) {
|
|
|
|
auto &hwInfo = getHardwareInfo();
|
|
|
|
bool enableLocalMemory = HwHelper::get(hwInfo.platform.eRenderCoreFamily).getEnableLocalMemory(hwInfo);
|
|
|
|
bool aubUsage = (testMode == TestMode::AubTests) || (testMode == TestMode::AubTestsWithTbx);
|
|
|
|
executionEnvironment->memoryManager.reset(new MockMemoryManager(false, enableLocalMemory, aubUsage, *executionEnvironment));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-24 19:34:25 +08:00
|
|
|
MockAlignedMallocManagerDevice::MockAlignedMallocManagerDevice(ExecutionEnvironment *executionEnvironment, uint32_t internalDeviceIndex) : MockDevice(executionEnvironment, internalDeviceIndex) {
|
2021-01-11 23:20:18 +08:00
|
|
|
executionEnvironment->memoryManager.reset(new MockAllocSysMemAgnosticMemoryManager(*executionEnvironment));
|
2018-01-26 23:53:18 +08:00
|
|
|
}
|
2019-05-06 18:33:44 +08:00
|
|
|
FailDevice::FailDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex)
|
|
|
|
: MockDevice(executionEnvironment, deviceIndex) {
|
2021-01-11 23:20:18 +08:00
|
|
|
executionEnvironment->memoryManager.reset(new FailMemoryManager(*executionEnvironment));
|
2018-10-19 19:41:42 +08:00
|
|
|
}
|
2019-05-06 18:33:44 +08:00
|
|
|
FailDeviceAfterOne::FailDeviceAfterOne(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex)
|
|
|
|
: MockDevice(executionEnvironment, deviceIndex) {
|
2021-01-11 23:20:18 +08:00
|
|
|
executionEnvironment->memoryManager.reset(new FailMemoryManager(1, *executionEnvironment));
|
2019-03-22 21:04:25 +08:00
|
|
|
}
|