2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2019-02-12 10:56:27 +01:00
|
|
|
* Copyright (C) 2018-2019 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
#include "runtime/device/device.h"
|
2019-03-08 12:18:02 +01:00
|
|
|
#include "runtime/helpers/hw_helper.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "unit_tests/libult/ult_command_stream_receiver.h"
|
2018-12-11 18:56:37 +01:00
|
|
|
#include "unit_tests/mocks/mock_allocation_properties.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
class OSTime;
|
2018-10-19 13:41:42 +02:00
|
|
|
class FailMemoryManager;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-08-08 13:49:09 +02:00
|
|
|
extern CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo, ExecutionEnvironment &executionEnvironment);
|
2018-07-12 10:04:07 +02:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
class MockDevice : public Device {
|
|
|
|
|
public:
|
2018-07-11 14:16:35 +02:00
|
|
|
using Device::executionEnvironment;
|
2018-01-26 16:53:18 +01:00
|
|
|
using Device::initializeCaps;
|
2017-12-21 00:45:38 +01: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 09:12:40 +02:00
|
|
|
MockDevice(const HardwareInfo &hwInfo);
|
2018-09-11 11:28:19 +02:00
|
|
|
MockDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
DeviceInfo *getDeviceInfoToModify() {
|
|
|
|
|
return &this->deviceInfo;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-10 13:49:26 +02:00
|
|
|
void initializeCaps() override {
|
2017-12-21 00:45:38 +01: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 11:50:58 +02:00
|
|
|
void injectMemoryManager(MemoryManager *);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
void setPerfCounters(PerformanceCounters *perfCounters) {
|
|
|
|
|
performanceCounters = std::unique_ptr<PerformanceCounters>(perfCounters);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
UltCommandStreamReceiver<T> &getUltCommandStreamReceiver() {
|
2018-11-29 11:39:10 +01:00
|
|
|
return reinterpret_cast<UltCommandStreamReceiver<T> &>(*engines[defaultEngineIndex].commandStreamReceiver);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2018-11-29 11:39:10 +01:00
|
|
|
CommandStreamReceiver &getCommandStreamReceiver() const { return *engines[defaultEngineIndex].commandStreamReceiver; }
|
2018-11-22 13:57:10 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
void resetCommandStreamReceiver(CommandStreamReceiver *newCsr);
|
|
|
|
|
|
2018-04-10 13:49:26 +02:00
|
|
|
void setSourceLevelDebuggerActive(bool active) {
|
|
|
|
|
this->deviceInfo.sourceLevelDebuggerActive = active;
|
|
|
|
|
}
|
2018-07-20 09:01:58 +02:00
|
|
|
|
2018-04-23 16:08:57 +02:00
|
|
|
template <typename T>
|
2018-09-11 11:28:19 +02:00
|
|
|
static T *createWithExecutionEnvironment(const HardwareInfo *pHwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) {
|
2018-07-20 09:01:58 +02:00
|
|
|
pHwInfo = getDeviceInitHwInfo(pHwInfo);
|
2018-09-11 11:28:19 +02:00
|
|
|
T *device = new T(*pHwInfo, executionEnvironment, deviceIndex);
|
2018-07-20 09:01:58 +02:00
|
|
|
executionEnvironment->memoryManager = std::move(device->mockMemoryManager);
|
|
|
|
|
return createDeviceInternals(pHwInfo, device);
|
2018-07-03 10:00:12 +02:00
|
|
|
}
|
2018-04-10 13:49:26 +02:00
|
|
|
|
2018-08-21 15:47:21 +02:00
|
|
|
template <typename T>
|
|
|
|
|
static T *createWithNewExecutionEnvironment(const HardwareInfo *pHwInfo) {
|
2018-09-11 11:28:19 +02:00
|
|
|
return createWithExecutionEnvironment<T>(pHwInfo, new ExecutionEnvironment(), 0u);
|
2018-08-21 15:47:21 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-11 13:30:07 +02:00
|
|
|
void allocatePreemptionAllocationIfNotPresent() {
|
|
|
|
|
if (this->preemptionAllocation == nullptr) {
|
|
|
|
|
if (preemptionMode == PreemptionMode::MidThread || isSourceLevelDebuggerActive()) {
|
2018-12-11 18:56:37 +01:00
|
|
|
MockAllocationProperties allocationProperties(hwInfo.capabilityTable.requiredPreemptionSurfaceSize);
|
2018-11-30 11:01:33 +01:00
|
|
|
allocationProperties.flags.uncacheable = getWaTable()->waCSRUncachable;
|
|
|
|
|
allocationProperties.alignment = 256 * MemoryConstants::kiloByte;
|
|
|
|
|
this->preemptionAllocation = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(allocationProperties);
|
2018-11-29 11:39:10 +01:00
|
|
|
this->engines[defaultEngineIndex].commandStreamReceiver->setPreemptionCsrAllocation(preemptionAllocation);
|
2018-05-11 13:30:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-20 09:01:58 +02:00
|
|
|
std::unique_ptr<MemoryManager> mockMemoryManager;
|
2018-05-11 13:30:07 +02:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
private:
|
|
|
|
|
bool forceWhitelistedRegs = false;
|
|
|
|
|
WhitelistedRegisters mockWhitelistedRegs = {0};
|
|
|
|
|
WorkaroundTable mockWaTable = {};
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-20 09:01:58 +02:00
|
|
|
template <>
|
|
|
|
|
inline Device *MockDevice::createWithNewExecutionEnvironment<Device>(const HardwareInfo *pHwInfo) {
|
2019-03-08 12:18:02 +01:00
|
|
|
auto executionEnvironment = new ExecutionEnvironment();
|
|
|
|
|
|
|
|
|
|
bool enableLocalMemory = false;
|
|
|
|
|
bool enable64kbPages = false;
|
|
|
|
|
if (pHwInfo != nullptr) {
|
|
|
|
|
enableLocalMemory = HwHelper::get(pHwInfo->pPlatform->eRenderCoreFamily).getEnableLocalMemory(*pHwInfo);
|
|
|
|
|
enable64kbPages = getEnabled64kbPages(*pHwInfo);
|
|
|
|
|
}
|
|
|
|
|
executionEnvironment->initializeMemoryManager(enable64kbPages, enableLocalMemory);
|
|
|
|
|
|
|
|
|
|
return Device::create<Device>(pHwInfo, executionEnvironment, 0u);
|
2018-07-20 09:01:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class FailDevice : public MockDevice {
|
2017-12-21 00:45:38 +01:00
|
|
|
public:
|
2018-10-19 13:41:42 +02:00
|
|
|
FailDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex);
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
|
|
|
|
|
2018-07-20 09:01:58 +02:00
|
|
|
class FailDeviceAfterOne : public MockDevice {
|
2017-12-21 00:45:38 +01:00
|
|
|
public:
|
2018-10-19 13:41:42 +02:00
|
|
|
FailDeviceAfterOne(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex);
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
|
|
|
|
|
2018-01-26 16:53:18 +01:00
|
|
|
class MockAlignedMallocManagerDevice : public MockDevice {
|
|
|
|
|
public:
|
2018-09-11 11:28:19 +02:00
|
|
|
MockAlignedMallocManagerDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex);
|
2018-01-26 16:53:18 +01:00
|
|
|
};
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
} // namespace OCLRT
|