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
|
2019-08-27 15:34:20 +08:00
|
|
|
#include "runtime/device/root_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-10-29 15:01:53 +08:00
|
|
|
extern CommandStreamReceiver *createCommandStream(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex);
|
2018-07-12 16:04:07 +08:00
|
|
|
|
2019-08-27 15:34:20 +08:00
|
|
|
class MockDevice : public RootDevice {
|
2017-12-21 07:45:38 +08:00
|
|
|
public:
|
2019-08-07 00:01:26 +08:00
|
|
|
using Device::createDeviceInternals;
|
2019-07-16 15:23:02 +08:00
|
|
|
using Device::createEngine;
|
2019-08-26 21:36:24 +08:00
|
|
|
using Device::deviceInfo;
|
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;
|
2019-10-24 19:34:25 +08:00
|
|
|
using Device::internalDeviceIndex;
|
2019-08-28 19:12:44 +08:00
|
|
|
using RootDevice::subdevices;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
void setOSTime(OSTime *osTime);
|
|
|
|
void setDriverInfo(DriverInfo *driverInfo);
|
|
|
|
bool hasDriverInfo();
|
|
|
|
|
2019-10-07 18:42:28 +08:00
|
|
|
static bool createSingleDevice;
|
|
|
|
bool createDeviceImpl() override;
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
bool getCpuTime(uint64_t *timeStamp) { return true; };
|
2019-05-06 18:33:44 +08:00
|
|
|
MockDevice();
|
|
|
|
MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
void setPreemptionMode(PreemptionMode mode) {
|
|
|
|
preemptionMode = mode;
|
|
|
|
}
|
|
|
|
|
2018-10-09 17:50:58 +08:00
|
|
|
void injectMemoryManager(MemoryManager *);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
void setPerfCounters(PerformanceCounters *perfCounters) {
|
2019-05-20 17:19:27 +08:00
|
|
|
if (perfCounters) {
|
|
|
|
performanceCounters = std::unique_ptr<PerformanceCounters>(perfCounters);
|
|
|
|
} else {
|
|
|
|
performanceCounters.release();
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-08-28 17:13:04 +08:00
|
|
|
template <typename T>
|
|
|
|
UltCommandStreamReceiver<T> &getUltCommandStreamReceiverFromIndex(uint32_t index) {
|
|
|
|
return reinterpret_cast<UltCommandStreamReceiver<T> &>(*engines[index].commandStreamReceiver);
|
|
|
|
}
|
2019-07-15 20:28:09 +08:00
|
|
|
CommandStreamReceiver &getGpgpuCommandStreamReceiver() const { return *engines[defaultEngineIndex].commandStreamReceiver; }
|
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-10-24 19:34:25 +08:00
|
|
|
auto numRootDevices = DebugManager.flags.CreateMultipleRootDevices.get() ? DebugManager.flags.CreateMultipleRootDevices.get() : 1u;
|
|
|
|
executionEnvironment->rootDeviceEnvironments.resize(numRootDevices);
|
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;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
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-09-17 16:44:49 +08:00
|
|
|
return Device::create<RootDevice>(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
|