2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-09-18 15:11:08 +08:00
|
|
|
* Copyright (C) 2017-2018 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unit_tests/mocks/mock_device.h"
|
|
|
|
#include "runtime/command_stream/command_stream_receiver.h"
|
2018-07-13 20:11:04 +08:00
|
|
|
#include "runtime/device/driver_info.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
|
|
|
|
#include "runtime/os_interface/os_time.h"
|
|
|
|
#include "unit_tests/mocks/mock_memory_manager.h"
|
2018-07-13 20:11:04 +08:00
|
|
|
#include "unit_tests/mocks/mock_ostime.h"
|
2018-09-28 13:19:14 +08:00
|
|
|
#include "unit_tests/tests_configuration.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
using namespace OCLRT;
|
|
|
|
|
2018-06-29 15:12:40 +08:00
|
|
|
MockDevice::MockDevice(const HardwareInfo &hwInfo)
|
2018-09-11 17:28:19 +08:00
|
|
|
: MockDevice(hwInfo, new ExecutionEnvironment, 0u) {
|
2018-08-08 19:49:09 +08:00
|
|
|
CommandStreamReceiver *commandStreamReceiver = createCommandStream(&hwInfo, *this->executionEnvironment);
|
2018-09-11 21:55:04 +08:00
|
|
|
executionEnvironment->commandStreamReceivers.resize(getDeviceIndex() + 1);
|
|
|
|
executionEnvironment->commandStreamReceivers[getDeviceIndex()].reset(commandStreamReceiver);
|
2018-07-20 15:01:58 +08:00
|
|
|
commandStreamReceiver->setMemoryManager(this->mockMemoryManager.get());
|
|
|
|
this->executionEnvironment->memoryManager = std::move(this->mockMemoryManager);
|
2018-09-11 16:43:50 +08:00
|
|
|
this->commandStreamReceiver = commandStreamReceiver;
|
2018-07-10 23:14:20 +08:00
|
|
|
}
|
2018-09-11 17:28:19 +08:00
|
|
|
OCLRT::MockDevice::MockDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex)
|
|
|
|
: Device(hwInfo, executionEnvironment, deviceIndex) {
|
2018-09-28 13:19:14 +08:00
|
|
|
bool aubUsage = (testMode == TestMode::AubTests) || (testMode == TestMode::AubTestsWithTbx);
|
2018-10-01 22:10:54 +08:00
|
|
|
this->mockMemoryManager.reset(new OsAgnosticMemoryManager(false, this->getHardwareCapabilities().localMemorySupported, aubUsage, *executionEnvironment));
|
2017-12-21 07:45:38 +08:00
|
|
|
this->osTime = MockOSTime::create();
|
|
|
|
mockWaTable = *hwInfo.pWaTable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MockDevice::setMemoryManager(MemoryManager *memoryManager) {
|
2018-07-11 22:47:49 +08:00
|
|
|
executionEnvironment->memoryManager.reset(memoryManager);
|
2018-09-11 21:55:04 +08:00
|
|
|
for (auto &commandStreamReceiver : executionEnvironment->commandStreamReceivers) {
|
|
|
|
if (commandStreamReceiver) {
|
|
|
|
commandStreamReceiver->setMemoryManager(memoryManager);
|
|
|
|
}
|
2018-07-20 15:01:58 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MockDevice::setOSTime(OSTime *osTime) {
|
|
|
|
this->osTime.reset(osTime);
|
|
|
|
};
|
|
|
|
|
|
|
|
void MockDevice::setDriverInfo(DriverInfo *driverInfo) {
|
|
|
|
this->driverInfo.reset(driverInfo);
|
|
|
|
};
|
|
|
|
|
|
|
|
bool MockDevice::hasDriverInfo() {
|
|
|
|
return driverInfo.get() != nullptr;
|
|
|
|
};
|
|
|
|
|
2018-10-09 17:50:58 +08:00
|
|
|
void MockDevice::injectMemoryManager(MemoryManager *memoryManager) {
|
2018-09-11 21:55:04 +08:00
|
|
|
executionEnvironment->commandStreamReceivers[getDeviceIndex()]->setMemoryManager(memoryManager);
|
2017-12-21 07:45:38 +08:00
|
|
|
setMemoryManager(memoryManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) {
|
2018-09-11 21:55:04 +08:00
|
|
|
executionEnvironment->commandStreamReceivers[getDeviceIndex()].reset(newCsr);
|
|
|
|
executionEnvironment->commandStreamReceivers[getDeviceIndex()]->setMemoryManager(executionEnvironment->memoryManager.get());
|
|
|
|
executionEnvironment->commandStreamReceivers[getDeviceIndex()]->initializeTagAllocation();
|
|
|
|
executionEnvironment->commandStreamReceivers[getDeviceIndex()]->setPreemptionCsrAllocation(preemptionAllocation);
|
2018-09-11 16:43:50 +08:00
|
|
|
this->commandStreamReceiver = newCsr;
|
2018-10-01 22:10:54 +08:00
|
|
|
UNRECOVERABLE_IF(getDeviceIndex() != 0u);
|
2018-09-11 21:55:04 +08:00
|
|
|
this->tagAddress = executionEnvironment->commandStreamReceivers[getDeviceIndex()]->getTagAddress();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-10-01 22:10:54 +08:00
|
|
|
OCLRT::FailMemoryManager::FailMemoryManager() {
|
2017-12-21 07:45:38 +08:00
|
|
|
agnostic = nullptr;
|
|
|
|
fail = 0;
|
|
|
|
}
|
|
|
|
|
2018-10-01 22:10:54 +08:00
|
|
|
OCLRT::FailMemoryManager::FailMemoryManager(int32_t fail) {
|
2017-12-21 07:45:38 +08:00
|
|
|
allocations.reserve(fail);
|
2018-10-01 22:10:54 +08:00
|
|
|
agnostic = new OsAgnosticMemoryManager(false, false, executionEnvironment);
|
2017-12-21 07:45:38 +08:00
|
|
|
this->fail = fail;
|
|
|
|
}
|
2018-01-26 23:53:18 +08:00
|
|
|
|
2018-09-11 17:28:19 +08:00
|
|
|
MockAlignedMallocManagerDevice::MockAlignedMallocManagerDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) : MockDevice(hwInfo, executionEnvironment, deviceIndex) {
|
2018-10-01 22:10:54 +08:00
|
|
|
this->mockMemoryManager.reset(new MockAllocSysMemAgnosticMemoryManager(*executionEnvironment));
|
2018-01-26 23:53:18 +08:00
|
|
|
}
|