2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-09-18 15:11:08 +08:00
|
|
|
* Copyright (C) 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "runtime/device/device.h"
|
|
|
|
#include "unit_tests/libult/ult_command_stream_receiver.h"
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
class OSTime;
|
2018-10-19 19:41:42 +08:00
|
|
|
class FailMemoryManager;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-08-08 19:49:09 +08:00
|
|
|
extern CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo, ExecutionEnvironment &executionEnvironment);
|
2018-07-12 16:04:07 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
class MockDevice : public Device {
|
|
|
|
public:
|
2018-04-23 20:26:03 +08:00
|
|
|
using Device::createDeviceImpl;
|
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;
|
|
|
|
}
|
2018-06-29 15:12:40 +08:00
|
|
|
MockDevice(const HardwareInfo &hwInfo);
|
2018-09-11 17:28:19 +08:00
|
|
|
MockDevice(const HardwareInfo &hwInfo, 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() {
|
|
|
|
return reinterpret_cast<UltCommandStreamReceiver<T> &>(getCommandStreamReceiver());
|
|
|
|
}
|
|
|
|
|
|
|
|
void resetCommandStreamReceiver(CommandStreamReceiver *newCsr);
|
|
|
|
|
2018-07-16 20:25:52 +08:00
|
|
|
GraphicsAllocation *getTagAllocation() { return this->getCommandStreamReceiver().getTagAllocation(); }
|
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) {
|
2018-07-20 15:01:58 +08:00
|
|
|
pHwInfo = getDeviceInitHwInfo(pHwInfo);
|
2018-09-11 17:28:19 +08:00
|
|
|
T *device = new T(*pHwInfo, executionEnvironment, deviceIndex);
|
2018-07-20 15:01:58 +08:00
|
|
|
executionEnvironment->memoryManager = std::move(device->mockMemoryManager);
|
|
|
|
return createDeviceInternals(pHwInfo, 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) {
|
2018-09-11 17:28:19 +08:00
|
|
|
return createWithExecutionEnvironment<T>(pHwInfo, new ExecutionEnvironment(), 0u);
|
2018-08-21 21:47:21 +08:00
|
|
|
}
|
|
|
|
|
2018-05-11 19:30:07 +08:00
|
|
|
void allocatePreemptionAllocationIfNotPresent() {
|
|
|
|
if (this->preemptionAllocation == nullptr) {
|
|
|
|
if (preemptionMode == PreemptionMode::MidThread || isSourceLevelDebuggerActive()) {
|
|
|
|
size_t requiredSize = hwInfo.capabilityTable.requiredPreemptionSurfaceSize;
|
|
|
|
size_t alignment = 256 * MemoryConstants::kiloByte;
|
|
|
|
bool uncacheable = getWaTable()->waCSRUncachable;
|
2018-07-11 22:47:49 +08:00
|
|
|
this->preemptionAllocation = executionEnvironment->memoryManager->allocateGraphicsMemory(requiredSize, alignment, false, uncacheable);
|
2018-11-21 16:57:51 +08:00
|
|
|
this->engines[0].commandStreamReceiver->setPreemptionCsrAllocation(preemptionAllocation);
|
2018-05-11 19:30:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-20 15:01:58 +08:00
|
|
|
std::unique_ptr<MemoryManager> mockMemoryManager;
|
2018-05-11 19:30:07 +08:00
|
|
|
|
2018-10-12 21:20:02 +08:00
|
|
|
void setHWCapsLocalMemorySupported(bool localMemorySupported);
|
|
|
|
|
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) {
|
2018-09-11 17:28:19 +08:00
|
|
|
return Device::create<Device>(pHwInfo, new ExecutionEnvironment, 0u);
|
2018-07-20 15:01:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class FailDevice : public MockDevice {
|
2017-12-21 07:45:38 +08:00
|
|
|
public:
|
2018-10-19 19:41:42 +08:00
|
|
|
FailDevice(const HardwareInfo &hwInfo, 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:
|
2018-10-19 19:41:42 +08:00
|
|
|
FailDeviceAfterOne(const HardwareInfo &hwInfo, 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:
|
2018-09-11 17:28:19 +08:00
|
|
|
MockAlignedMallocManagerDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex);
|
2018-01-26 23:53:18 +08:00
|
|
|
};
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
} // namespace OCLRT
|