2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2025-01-10 23:02:25 +08:00
|
|
|
* Copyright (C) 2018-2025 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"
|
2022-12-16 01:32:03 +08:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2022-11-16 22:01:52 +08:00
|
|
|
#include "shared/test/common/helpers/default_hw_info.h"
|
2024-08-23 21:20:08 +08:00
|
|
|
#include "shared/test/common/helpers/unit_test_helper.h"
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/helpers/variable_backup.h"
|
2024-03-20 19:45:31 +08:00
|
|
|
#include "shared/test/common/mocks/mock_memory_operations_handler.h"
|
2020-02-22 16:28:27 +08:00
|
|
|
|
2024-09-11 19:21:09 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2020-03-19 21:26:08 +08:00
|
|
|
class CommandStreamReceiver;
|
|
|
|
class DriverInfo;
|
|
|
|
|
|
|
|
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 {
|
2021-12-13 20:45:24 +08:00
|
|
|
using Device::allEngines;
|
2021-05-10 03:41:56 +08:00
|
|
|
using Device::createEngines;
|
2025-01-10 23:02:25 +08:00
|
|
|
using Device::maxAllocationsSavedForReuseSize;
|
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;
|
|
|
|
|
2024-09-11 19:21:09 +08:00
|
|
|
~MockSubDevice() override {
|
|
|
|
EXPECT_EQ(nullptr, this->getDebugSurface());
|
|
|
|
}
|
|
|
|
|
2019-11-05 20:38:20 +08:00
|
|
|
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;
|
2021-04-29 01:46:13 +08:00
|
|
|
|
|
|
|
bool failOnCreateEngine = false;
|
2024-06-25 06:55:08 +08:00
|
|
|
bool createEngine(EngineTypeUsage engineTypeUsage) override;
|
2019-11-05 20:38:20 +08:00
|
|
|
};
|
|
|
|
|
2019-08-27 15:34:20 +08:00
|
|
|
class MockDevice : public RootDevice {
|
2017-12-21 07:45:38 +08:00
|
|
|
public:
|
2021-09-16 22:53:49 +08:00
|
|
|
using Device::addEngineToEngineGroup;
|
2021-12-13 20:45:24 +08:00
|
|
|
using Device::allEngines;
|
2024-09-11 19:21:09 +08:00
|
|
|
using Device::allocateDebugSurface;
|
2024-12-16 18:19:12 +08:00
|
|
|
using Device::bufferPoolCount;
|
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;
|
2021-04-27 17:51:03 +08:00
|
|
|
using Device::createSubDevices;
|
2021-09-28 07:27:46 +08:00
|
|
|
using Device::deviceBitfield;
|
2019-08-26 21:36:24 +08:00
|
|
|
using Device::deviceInfo;
|
2018-07-11 20:16:35 +08:00
|
|
|
using Device::executionEnvironment;
|
2023-01-05 22:01:17 +08:00
|
|
|
using Device::generateUuidFromPciBusInfo;
|
2024-12-06 05:46:55 +08:00
|
|
|
using Device::getGlobalMemorySize;
|
2018-01-26 23:53:18 +08:00
|
|
|
using Device::initializeCaps;
|
2025-01-10 23:02:25 +08:00
|
|
|
using Device::initUsmReuseMaxSize;
|
|
|
|
using Device::maxAllocationsSavedForReuseSize;
|
2024-12-16 18:19:12 +08:00
|
|
|
using Device::maxBufferPoolCount;
|
2024-12-11 18:18:07 +08:00
|
|
|
using Device::microsecondResolution;
|
2024-02-15 01:42:39 +08:00
|
|
|
using Device::preemptionMode;
|
2021-12-13 20:45:24 +08:00
|
|
|
using Device::regularEngineGroups;
|
2021-10-13 05:28:34 +08:00
|
|
|
using Device::rootCsrCreated;
|
2024-10-08 00:41:15 +08:00
|
|
|
using Device::rtDispatchGlobalsInfos;
|
2021-02-27 06:02:57 +08:00
|
|
|
using Device::rtMemoryBackedBuffer;
|
2024-06-26 21:47:59 +08:00
|
|
|
using Device::secondaryCsrs;
|
2023-11-15 17:01:43 +08:00
|
|
|
using Device::secondaryEngines;
|
2023-01-05 22:01:17 +08:00
|
|
|
using Device::uuid;
|
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);
|
|
|
|
|
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
|
|
|
|
2022-07-07 01:44:49 +08:00
|
|
|
void setPerfCounters(std::unique_ptr<PerformanceCounters> perfCounters) {
|
|
|
|
performanceCounters = std::move(perfCounters);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2021-12-27 20:44:57 +08:00
|
|
|
size_t getMaxParameterSizeFromIGC() const override {
|
2021-12-29 00:44:23 +08:00
|
|
|
if (callBaseGetMaxParameterSizeFromIGC) {
|
|
|
|
return Device::getMaxParameterSizeFromIGC();
|
|
|
|
}
|
2021-12-27 20:44:57 +08:00
|
|
|
return maxParameterSizeFromIGC;
|
|
|
|
}
|
|
|
|
|
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() {
|
2021-12-13 20:45:24 +08:00
|
|
|
return reinterpret_cast<UltCommandStreamReceiver<T> &>(*allEngines[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) {
|
2021-12-13 20:45:24 +08:00
|
|
|
return reinterpret_cast<UltCommandStreamReceiver<T> &>(*allEngines[index].commandStreamReceiver);
|
2019-08-28 17:13:04 +08:00
|
|
|
}
|
2021-12-13 20:45:24 +08:00
|
|
|
CommandStreamReceiver &getGpgpuCommandStreamReceiver() const { return *allEngines[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-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();
|
2023-01-03 18:27:35 +08:00
|
|
|
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->setHwInfoAndInitHelpers(pHwInfo);
|
2024-08-23 21:20:08 +08:00
|
|
|
UnitTestSetter::setRcsExposure(*executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]);
|
|
|
|
UnitTestSetter::setCcsExposure(*executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]);
|
|
|
|
|
2024-03-20 19:45:31 +08:00
|
|
|
if (!executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface) {
|
|
|
|
executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = std::make_unique<MockMemoryOperations>();
|
|
|
|
}
|
2024-08-26 23:12:39 +08:00
|
|
|
|
|
|
|
executionEnvironment->calculateMaxOsContextCount();
|
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
|
|
|
|
2023-01-02 17:56:45 +08:00
|
|
|
static ExecutionEnvironment *prepareExecutionEnvironment(const HardwareInfo *pHwInfo, uint32_t rootDeviceIndex);
|
2021-09-14 00:49:13 +08:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static T *createWithNewExecutionEnvironment(const HardwareInfo *pHwInfo, uint32_t rootDeviceIndex = 0) {
|
|
|
|
auto executionEnvironment = prepareExecutionEnvironment(pHwInfo, rootDeviceIndex);
|
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
|
|
|
|
2022-05-11 22:08:18 +08:00
|
|
|
bool verifyAdapterLuid() override;
|
|
|
|
|
2023-01-02 17:56:45 +08:00
|
|
|
void finalizeRayTracing();
|
2022-07-22 02:44:54 +08:00
|
|
|
|
2024-09-18 20:38:06 +08:00
|
|
|
ReleaseHelper *getReleaseHelper() const override;
|
|
|
|
AILConfiguration *getAilConfigurationHelper() const override;
|
|
|
|
|
2022-07-22 02:44:54 +08:00
|
|
|
void setRTDispatchGlobalsForceAllocation() {
|
|
|
|
rtDispatchGlobalsForceAllocation = true;
|
|
|
|
}
|
2023-06-27 23:50:33 +08:00
|
|
|
|
2023-10-06 19:47:33 +08:00
|
|
|
void stopDirectSubmissionAndWaitForCompletion() override {
|
2023-06-27 23:50:33 +08:00
|
|
|
stopDirectSubmissionCalled = true;
|
2023-10-06 19:47:33 +08:00
|
|
|
Device::stopDirectSubmissionAndWaitForCompletion();
|
2023-06-27 23:50:33 +08:00
|
|
|
}
|
2024-12-16 18:19:12 +08:00
|
|
|
|
|
|
|
uint64_t getGlobalMemorySize(uint32_t deviceBitfield) const override {
|
|
|
|
if (callBaseGetGlobalMemorySize) {
|
|
|
|
return Device::getGlobalMemorySize(deviceBitfield);
|
|
|
|
}
|
|
|
|
return getGlobalMemorySizeReturn;
|
|
|
|
}
|
|
|
|
|
2025-01-22 00:36:41 +08:00
|
|
|
EngineControl *getSecondaryEngineCsr(EngineTypeUsage engineTypeUsage, bool allocateInterrupt) override;
|
|
|
|
|
2022-11-16 23:50:07 +08:00
|
|
|
static ExecutionEnvironment *prepareExecutionEnvironment(const HardwareInfo *pHwInfo);
|
2020-01-20 14:02:07 +08:00
|
|
|
static decltype(&createCommandStream) createCommandStreamReceiverFunc;
|
2021-04-16 20:52:30 +08:00
|
|
|
|
2021-12-29 00:44:23 +08:00
|
|
|
bool callBaseGetMaxParameterSizeFromIGC = false;
|
2022-05-11 22:08:18 +08:00
|
|
|
bool callBaseVerifyAdapterLuid = true;
|
|
|
|
bool verifyAdapterLuidReturnValue = true;
|
2021-12-27 20:44:57 +08:00
|
|
|
size_t maxParameterSizeFromIGC = 0u;
|
2022-07-22 02:44:54 +08:00
|
|
|
bool rtDispatchGlobalsForceAllocation = true;
|
2023-06-27 23:50:33 +08:00
|
|
|
bool stopDirectSubmissionCalled = false;
|
2024-09-18 20:38:06 +08:00
|
|
|
ReleaseHelper *mockReleaseHelper = nullptr;
|
|
|
|
AILConfiguration *mockAilConfigurationHelper = nullptr;
|
2024-12-16 18:19:12 +08:00
|
|
|
uint64_t getGlobalMemorySizeReturn = 0u;
|
|
|
|
bool callBaseGetGlobalMemorySize = true;
|
2025-01-22 00:36:41 +08:00
|
|
|
bool disableSecondaryEngines = 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) {
|
2022-11-16 23:50:07 +08:00
|
|
|
auto executionEnvironment = MockDevice::prepareExecutionEnvironment(pHwInfo);
|
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
|