2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-01-11 23:20:18 +08:00
|
|
|
* Copyright (C) 2018-2021 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
|
2020-03-19 21:26:08 +08:00
|
|
|
|
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/device/root_device.h"
|
|
|
|
#include "shared/source/device/sub_device.h"
|
2020-03-19 21:26:08 +08:00
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/helpers/variable_backup.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/fixtures/mock_aub_center_fixture.h"
|
2020-02-22 16:28:27 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2020-03-19 21:26:08 +08:00
|
|
|
class CommandStreamReceiver;
|
|
|
|
class DriverInfo;
|
2017-12-21 07:45:38 +08:00
|
|
|
class OSTime;
|
2020-03-19 21:26:08 +08:00
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
class UltCommandStreamReceiver;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-10-29 22:33:35 +08:00
|
|
|
extern CommandStreamReceiver *createCommandStream(ExecutionEnvironment &executionEnvironment,
|
|
|
|
uint32_t rootDeviceIndex,
|
|
|
|
const DeviceBitfield deviceBitfield);
|
2018-07-12 16:04:07 +08:00
|
|
|
|
2019-11-05 20:38:20 +08:00
|
|
|
struct MockSubDevice : public SubDevice {
|
2020-10-30 17:27:48 +08:00
|
|
|
using SubDevice::getDeviceBitfield;
|
2020-04-16 20:44:03 +08:00
|
|
|
using SubDevice::getGlobalMemorySize;
|
2019-11-05 20:38:20 +08:00
|
|
|
using SubDevice::SubDevice;
|
|
|
|
|
|
|
|
std::unique_ptr<CommandStreamReceiver> createCommandStreamReceiver() const override {
|
2020-10-28 23:08:37 +08:00
|
|
|
return std::unique_ptr<CommandStreamReceiver>(createCommandStreamReceiverFunc(*executionEnvironment, getRootDeviceIndex(), getDeviceBitfield()));
|
2019-11-05 20:38:20 +08:00
|
|
|
}
|
|
|
|
static decltype(&createCommandStream) createCommandStreamReceiverFunc;
|
|
|
|
};
|
|
|
|
|
2019-08-27 15:34:20 +08:00
|
|
|
class MockDevice : public RootDevice {
|
2017-12-21 07:45:38 +08:00
|
|
|
public:
|
2019-11-05 20:38:20 +08:00
|
|
|
using Device::commandStreamReceivers;
|
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;
|
2020-09-25 22:42:45 +08:00
|
|
|
using Device::engineGroups;
|
2019-03-23 21:26:06 +08:00
|
|
|
using Device::engines;
|
2018-07-11 20:16:35 +08:00
|
|
|
using Device::executionEnvironment;
|
2020-04-16 20:44:03 +08:00
|
|
|
using Device::getGlobalMemorySize;
|
2018-01-26 23:53:18 +08:00
|
|
|
using Device::initializeCaps;
|
2021-04-16 20:52:30 +08:00
|
|
|
using Device::isDebuggerActive;
|
2019-11-05 20:38:20 +08:00
|
|
|
using RootDevice::createEngines;
|
2020-05-25 18:11:30 +08:00
|
|
|
using RootDevice::defaultEngineIndex;
|
2020-06-02 16:04:25 +08:00
|
|
|
using RootDevice::getDeviceBitfield;
|
2020-09-15 16:11:12 +08:00
|
|
|
using RootDevice::initializeRootCommandStreamReceiver;
|
2021-01-25 17:24:00 +08:00
|
|
|
using RootDevice::numSubDevices;
|
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);
|
|
|
|
|
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();
|
2019-11-05 20:38:20 +08:00
|
|
|
MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex);
|
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
|
|
|
}
|
|
|
|
|
2019-11-29 17:30:14 +08:00
|
|
|
const char *getProductAbbrev() const;
|
|
|
|
|
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
|
|
|
|
2020-02-10 22:57:49 +08:00
|
|
|
void setDebuggerActive(bool active) {
|
|
|
|
this->deviceInfo.debuggerActive = active;
|
2018-04-10 19:49:26 +08:00
|
|
|
}
|
2018-07-20 15:01:58 +08:00
|
|
|
|
2018-04-23 22:08:57 +08:00
|
|
|
template <typename T>
|
2019-11-05 20:38:20 +08:00
|
|
|
static T *createWithExecutionEnvironment(const HardwareInfo *pHwInfo, ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex) {
|
2020-03-25 00:04:08 +08:00
|
|
|
pHwInfo = pHwInfo ? pHwInfo : defaultHwInfo.get();
|
2020-03-04 15:51:02 +08:00
|
|
|
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfo(pHwInfo);
|
2019-11-05 20:38:20 +08:00
|
|
|
T *device = new T(executionEnvironment, rootDeviceIndex);
|
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>
|
2019-12-04 20:45:32 +08:00
|
|
|
static T *createWithNewExecutionEnvironment(const HardwareInfo *pHwInfo, uint32_t rootDeviceIndex = 0) {
|
2019-01-23 18:59:54 +08:00
|
|
|
ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment();
|
2020-10-08 17:36:31 +08:00
|
|
|
auto numRootDevices = DebugManager.flags.CreateMultipleRootDevices.get() ? DebugManager.flags.CreateMultipleRootDevices.get() : rootDeviceIndex + 1;
|
2019-11-15 16:59:48 +08:00
|
|
|
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
|
2020-03-25 00:04:08 +08:00
|
|
|
pHwInfo = pHwInfo ? pHwInfo : defaultHwInfo.get();
|
2020-03-04 15:51:02 +08:00
|
|
|
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
|
|
|
|
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(pHwInfo);
|
|
|
|
}
|
2019-12-04 20:45:32 +08:00
|
|
|
return createWithExecutionEnvironment<T>(pHwInfo, executionEnvironment, rootDeviceIndex);
|
2018-08-21 21:47:21 +08:00
|
|
|
}
|
2019-11-05 20:38:20 +08:00
|
|
|
|
|
|
|
SubDevice *createSubDevice(uint32_t subDeviceIndex) override {
|
|
|
|
return Device::create<MockSubDevice>(executionEnvironment, subDeviceIndex, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<CommandStreamReceiver> createCommandStreamReceiver() const override {
|
2020-10-28 23:08:37 +08:00
|
|
|
return std::unique_ptr<CommandStreamReceiver>(createCommandStreamReceiverFunc(*executionEnvironment, getRootDeviceIndex(), getDeviceBitfield()));
|
2019-11-05 20:38:20 +08:00
|
|
|
}
|
2018-08-21 21:47:21 +08:00
|
|
|
|
2021-04-16 20:52:30 +08:00
|
|
|
bool isDebuggerActive() const override {
|
|
|
|
if (isDebuggerActiveParentCall) {
|
|
|
|
return Device::isDebuggerActive();
|
|
|
|
}
|
|
|
|
return isDebuggerActiveReturn;
|
|
|
|
}
|
|
|
|
|
2020-01-20 14:02:07 +08:00
|
|
|
static decltype(&createCommandStream) createCommandStreamReceiverFunc;
|
2021-04-16 20:52:30 +08:00
|
|
|
|
|
|
|
bool isDebuggerActiveParentCall = true;
|
|
|
|
bool isDebuggerActiveReturn = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
2018-07-20 15:01:58 +08:00
|
|
|
template <>
|
2019-12-04 20:45:32 +08:00
|
|
|
inline Device *MockDevice::createWithNewExecutionEnvironment<Device>(const HardwareInfo *pHwInfo, uint32_t rootDeviceIndex) {
|
2019-03-08 19:18:02 +08:00
|
|
|
auto executionEnvironment = new ExecutionEnvironment();
|
2019-11-15 16:59:48 +08:00
|
|
|
executionEnvironment->prepareRootDeviceEnvironments(1);
|
2021-03-05 19:14:21 +08:00
|
|
|
|
2020-03-25 00:04:08 +08:00
|
|
|
auto hwInfo = pHwInfo ? pHwInfo : defaultHwInfo.get();
|
2021-03-05 19:14:21 +08:00
|
|
|
|
2020-03-04 15:51:02 +08:00
|
|
|
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(hwInfo);
|
2021-03-05 19:14:21 +08:00
|
|
|
|
|
|
|
MockAubCenterFixture::setMockAubCenter(*executionEnvironment->rootDeviceEnvironments[0]);
|
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-11-05 20:38:20 +08:00
|
|
|
|
|
|
|
struct EnvironmentWithCsrWrapper {
|
|
|
|
template <typename CsrType>
|
|
|
|
void setCsrType() {
|
|
|
|
createSubDeviceCsrFuncBackup = EnvironmentWithCsrWrapper::createCommandStreamReceiver<CsrType>;
|
|
|
|
createRootDeviceCsrFuncBackup = EnvironmentWithCsrWrapper::createCommandStreamReceiver<CsrType>;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename CsrType>
|
2020-10-29 22:33:35 +08:00
|
|
|
static CommandStreamReceiver *createCommandStreamReceiver(ExecutionEnvironment &executionEnvironment,
|
|
|
|
uint32_t rootDeviceIndex,
|
|
|
|
const DeviceBitfield deviceBitfield) {
|
2020-10-28 23:08:37 +08:00
|
|
|
return new CsrType(executionEnvironment, rootDeviceIndex, deviceBitfield);
|
2019-11-05 20:38:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
VariableBackup<decltype(MockSubDevice::createCommandStreamReceiverFunc)> createSubDeviceCsrFuncBackup{&MockSubDevice::createCommandStreamReceiverFunc};
|
|
|
|
VariableBackup<decltype(MockDevice::createCommandStreamReceiverFunc)> createRootDeviceCsrFuncBackup{&MockDevice::createCommandStreamReceiverFunc};
|
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|