2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-01-12 21:18:53 +08:00
|
|
|
* Copyright (c) 2017 - 2018, Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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"
|
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-06 16:53:35 +08:00
|
|
|
this->mockMemoryManager.reset(new OsAgnosticMemoryManager(false, this->getHardwareCapabilities().localMemorySupported));
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
void MockDevice::injectMemoryManager(MockMemoryManager *memoryManager) {
|
2018-09-11 21:55:04 +08:00
|
|
|
memoryManager->setCommandStreamReceiver(executionEnvironment->commandStreamReceivers[getDeviceIndex()].get());
|
|
|
|
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);
|
|
|
|
executionEnvironment->memoryManager->csr = executionEnvironment->commandStreamReceivers[getDeviceIndex()].get();
|
2018-09-11 16:43:50 +08:00
|
|
|
this->commandStreamReceiver = newCsr;
|
2018-09-11 21:55:04 +08:00
|
|
|
this->tagAddress = executionEnvironment->commandStreamReceivers[getDeviceIndex()]->getTagAddress();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-02-09 05:52:58 +08:00
|
|
|
OCLRT::FailMemoryManager::FailMemoryManager() : MockMemoryManager() {
|
2017-12-21 07:45:38 +08:00
|
|
|
agnostic = nullptr;
|
|
|
|
fail = 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 05:52:58 +08:00
|
|
|
OCLRT::FailMemoryManager::FailMemoryManager(int32_t fail) : MockMemoryManager() {
|
2017-12-21 07:45:38 +08:00
|
|
|
allocations.reserve(fail);
|
2018-09-06 16:53:35 +08:00
|
|
|
agnostic = new OsAgnosticMemoryManager(false, false);
|
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-07-20 15:01:58 +08:00
|
|
|
this->mockMemoryManager.reset(new MockAllocSysMemAgnosticMemoryManager());
|
2018-01-26 23:53:18 +08:00
|
|
|
}
|