2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-02-12 17:56:27 +08:00
|
|
|
* Copyright (C) 2018-2019 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "runtime/device/device.h"
|
2019-03-08 19:18:02 +08:00
|
|
|
#include "runtime/helpers/hw_helper.h"
|
2019-03-19 18:57:45 +08:00
|
|
|
#include "unit_tests/fixtures/mock_aub_center_fixture.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "unit_tests/libult/ult_command_stream_receiver.h"
|
2018-12-12 01:56:37 +08:00
|
|
|
#include "unit_tests/mocks/mock_allocation_properties.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
class OSTime;
|
2018-10-19 19:41:42 +08:00
|
|
|
class FailMemoryManager;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-02-27 17:06:14 +08:00
|
|
|
extern CommandStreamReceiver *createCommandStream(ExecutionEnvironment &executionEnvironment);
|
2018-07-12 16:04:07 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
class MockDevice : public Device {
|
|
|
|
public:
|
2019-06-17 19:33:44 +08:00
|
|
|
using Device::enabledClVersion;
|
2019-03-23 21:26:06 +08:00
|
|
|
using Device::engines;
|
2018-07-11 20:16:35 +08:00
|
|
|
using Device::executionEnvironment;
|
2018-01-26 23:53:18 +08:00
|
|
|
using Device::initializeCaps;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
void setOSTime(OSTime *osTime);
|
|
|
|
void setDriverInfo(DriverInfo *driverInfo);
|
|
|
|
bool hasDriverInfo();
|
|
|
|
|
|
|
|
bool getCpuTime(uint64_t *timeStamp) { return true; };
|
|
|
|
void *peekSlmWindowStartAddress() const {
|
|
|
|
return this->slmWindowStartAddress;
|
|
|
|
}
|
2019-05-06 18:33:44 +08:00
|
|
|
MockDevice();
|
|
|
|
MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
DeviceInfo *getDeviceInfoToModify() {
|
|
|
|
return &this->deviceInfo;
|
|
|
|
}
|
|
|
|
|
2018-04-10 19:49:26 +08:00
|
|
|
void initializeCaps() override {
|
2017-12-21 07:45:38 +08:00
|
|
|
Device::initializeCaps();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPreemptionMode(PreemptionMode mode) {
|
|
|
|
preemptionMode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
const WhitelistedRegisters &getWhitelistedRegisters() override {
|
|
|
|
if (forceWhitelistedRegs) {
|
|
|
|
return mockWhitelistedRegs;
|
|
|
|
}
|
|
|
|
return Device::getWhitelistedRegisters();
|
|
|
|
}
|
|
|
|
|
|
|
|
const WorkaroundTable *getWaTable() const override { return &mockWaTable; }
|
|
|
|
|
|
|
|
void setForceWhitelistedRegs(bool force, WhitelistedRegisters *mockRegs = nullptr) {
|
|
|
|
forceWhitelistedRegs = force;
|
|
|
|
if (mockRegs) {
|
|
|
|
mockWhitelistedRegs = *mockRegs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-09 17:50:58 +08:00
|
|
|
void injectMemoryManager(MemoryManager *);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
void setPerfCounters(PerformanceCounters *perfCounters) {
|
|
|
|
performanceCounters = std::unique_ptr<PerformanceCounters>(perfCounters);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
UltCommandStreamReceiver<T> &getUltCommandStreamReceiver() {
|
2018-11-29 18:39:10 +08:00
|
|
|
return reinterpret_cast<UltCommandStreamReceiver<T> &>(*engines[defaultEngineIndex].commandStreamReceiver);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-11-29 18:39:10 +08:00
|
|
|
CommandStreamReceiver &getCommandStreamReceiver() const { return *engines[defaultEngineIndex].commandStreamReceiver; }
|
2018-11-22 20:57:10 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
void resetCommandStreamReceiver(CommandStreamReceiver *newCsr);
|
2019-03-22 21:04:25 +08:00
|
|
|
void resetCommandStreamReceiver(CommandStreamReceiver *newCsr, uint32_t engineIndex);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-04-10 19:49:26 +08:00
|
|
|
void setSourceLevelDebuggerActive(bool active) {
|
|
|
|
this->deviceInfo.sourceLevelDebuggerActive = active;
|
|
|
|
}
|
2018-07-20 15:01:58 +08:00
|
|
|
|
2018-04-23 22:08:57 +08:00
|
|
|
template <typename T>
|
2018-09-11 17:28:19 +08:00
|
|
|
static T *createWithExecutionEnvironment(const HardwareInfo *pHwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) {
|
2019-05-06 18:33:44 +08:00
|
|
|
pHwInfo = pHwInfo ? pHwInfo : platformDevices[0];
|
2019-01-23 18:59:54 +08:00
|
|
|
executionEnvironment->setHwInfo(pHwInfo);
|
2019-05-06 18:33:44 +08:00
|
|
|
T *device = new T(executionEnvironment, deviceIndex);
|
2018-07-20 15:01:58 +08:00
|
|
|
executionEnvironment->memoryManager = std::move(device->mockMemoryManager);
|
2019-05-06 18:33:44 +08:00
|
|
|
return createDeviceInternals(device);
|
2018-07-03 16:00:12 +08:00
|
|
|
}
|
2018-04-10 19:49:26 +08:00
|
|
|
|
2018-08-21 21:47:21 +08:00
|
|
|
template <typename T>
|
|
|
|
static T *createWithNewExecutionEnvironment(const HardwareInfo *pHwInfo) {
|
2019-01-23 18:59:54 +08:00
|
|
|
ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment();
|
2019-05-06 18:33:44 +08:00
|
|
|
pHwInfo = pHwInfo ? pHwInfo : platformDevices[0];
|
2019-01-23 18:59:54 +08:00
|
|
|
executionEnvironment->setHwInfo(pHwInfo);
|
|
|
|
return createWithExecutionEnvironment<T>(pHwInfo, executionEnvironment, 0u);
|
2018-08-21 21:47:21 +08:00
|
|
|
}
|
|
|
|
|
2018-07-20 15:01:58 +08:00
|
|
|
std::unique_ptr<MemoryManager> mockMemoryManager;
|
2018-05-11 19:30:07 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
private:
|
|
|
|
bool forceWhitelistedRegs = false;
|
|
|
|
WhitelistedRegisters mockWhitelistedRegs = {0};
|
|
|
|
WorkaroundTable mockWaTable = {};
|
|
|
|
};
|
|
|
|
|
2018-07-20 15:01:58 +08:00
|
|
|
template <>
|
|
|
|
inline Device *MockDevice::createWithNewExecutionEnvironment<Device>(const HardwareInfo *pHwInfo) {
|
2019-03-08 19:18:02 +08:00
|
|
|
auto executionEnvironment = new ExecutionEnvironment();
|
2019-03-19 18:57:45 +08:00
|
|
|
MockAubCenterFixture::setMockAubCenter(executionEnvironment);
|
2019-05-06 18:33:44 +08:00
|
|
|
auto hwInfo = pHwInfo ? pHwInfo : *platformDevices;
|
|
|
|
executionEnvironment->setHwInfo(hwInfo);
|
2019-03-15 17:22:35 +08:00
|
|
|
executionEnvironment->initializeMemoryManager();
|
2019-05-06 18:33:44 +08:00
|
|
|
return Device::create<Device>(executionEnvironment, 0u);
|
2018-07-20 15:01:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class FailDevice : public MockDevice {
|
2017-12-21 07:45:38 +08:00
|
|
|
public:
|
2019-05-06 18:33:44 +08:00
|
|
|
FailDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex);
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
2018-07-20 15:01:58 +08:00
|
|
|
class FailDeviceAfterOne : public MockDevice {
|
2017-12-21 07:45:38 +08:00
|
|
|
public:
|
2019-05-06 18:33:44 +08:00
|
|
|
FailDeviceAfterOne(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex);
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
2018-01-26 23:53:18 +08:00
|
|
|
class MockAlignedMallocManagerDevice : public MockDevice {
|
|
|
|
public:
|
2019-05-06 18:33:44 +08:00
|
|
|
MockAlignedMallocManagerDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex);
|
2018-01-26 23:53:18 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|