mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-04 07:14:10 +08:00
Remove csrsContainer from root device environment
improve mocking: - add method to create RootDevice in Platform - add method to create SubDevice in RootDevice - add method to create CommandStreamReceiver in Device Related-To: NEO-3691 Change-Id: Ie9fe3de260492604333c8ca93796bfbffae518c4 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
4102b9cf3d
commit
5a8f455a84
@@ -162,9 +162,10 @@ struct MockAubCsr : public AUBCommandStreamReceiverHw<GfxFamily> {
|
||||
struct AubExecutionEnvironment {
|
||||
std::unique_ptr<ExecutionEnvironment> executionEnvironment;
|
||||
GraphicsAllocation *commandBuffer = nullptr;
|
||||
std::unique_ptr<CommandStreamReceiver> commandStreamReceiver;
|
||||
template <typename CsrType>
|
||||
CsrType *getCsr() {
|
||||
return static_cast<CsrType *>(executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0].get());
|
||||
return static_cast<CsrType *>(commandStreamReceiver.get());
|
||||
}
|
||||
~AubExecutionEnvironment() {
|
||||
if (commandBuffer) {
|
||||
@@ -179,23 +180,23 @@ std::unique_ptr<AubExecutionEnvironment> getEnvironment(bool createTagAllocation
|
||||
executionEnvironment->setHwInfo(*platformDevices);
|
||||
executionEnvironment->rootDeviceEnvironments[0].aubCenter.reset(new AubCenter());
|
||||
|
||||
executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.resize(1);
|
||||
executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::make_unique<CsrType>("", standalone, *executionEnvironment, 0));
|
||||
executionEnvironment->initializeMemoryManager();
|
||||
auto commandStreamReceiver = std::make_unique<CsrType>("", standalone, *executionEnvironment, 0);
|
||||
if (createTagAllocation) {
|
||||
executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->initializeTagAllocation();
|
||||
commandStreamReceiver->initializeTagAllocation();
|
||||
}
|
||||
|
||||
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0].get(),
|
||||
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(commandStreamReceiver.get(),
|
||||
getChosenEngineType(*platformDevices[0]), 1,
|
||||
PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false);
|
||||
executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->setupContext(*osContext);
|
||||
commandStreamReceiver->setupContext(*osContext);
|
||||
|
||||
std::unique_ptr<AubExecutionEnvironment> aubExecutionEnvironment(new AubExecutionEnvironment);
|
||||
if (allocateCommandBuffer) {
|
||||
aubExecutionEnvironment->commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
|
||||
}
|
||||
aubExecutionEnvironment->executionEnvironment = std::move(executionEnvironment);
|
||||
aubExecutionEnvironment->commandStreamReceiver = std::move(commandStreamReceiver);
|
||||
return aubExecutionEnvironment;
|
||||
}
|
||||
} // namespace NEO
|
||||
|
||||
@@ -17,21 +17,22 @@
|
||||
using namespace NEO;
|
||||
|
||||
bool MockDevice::createSingleDevice = true;
|
||||
decltype(&createCommandStream) MockSubDevice::createCommandStreamReceiverFunc = createCommandStream;
|
||||
decltype(&createCommandStream) MockDevice::createCommandStreamReceiverFunc = createCommandStream;
|
||||
|
||||
MockDevice::MockDevice()
|
||||
: MockDevice(new MockExecutionEnvironment(), 0u) {
|
||||
CommandStreamReceiver *commandStreamReceiver = createCommandStream(*this->executionEnvironment, this->getRootDeviceIndex());
|
||||
executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.resize(internalDeviceIndex + 1);
|
||||
executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[internalDeviceIndex].resize(defaultEngineIndex + 1);
|
||||
executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[internalDeviceIndex][defaultEngineIndex].reset(commandStreamReceiver);
|
||||
commandStreamReceivers.resize(1);
|
||||
commandStreamReceivers[0].reset(commandStreamReceiver);
|
||||
this->executionEnvironment->memoryManager = std::move(this->mockMemoryManager);
|
||||
this->engines.resize(defaultEngineIndex + 1);
|
||||
this->engines[defaultEngineIndex] = {commandStreamReceiver, nullptr};
|
||||
this->engines.resize(1);
|
||||
this->engines[0] = {commandStreamReceiver, nullptr};
|
||||
initializeCaps();
|
||||
}
|
||||
|
||||
MockDevice::MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex)
|
||||
: RootDevice(executionEnvironment, deviceIndex) {
|
||||
MockDevice::MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex)
|
||||
: RootDevice(executionEnvironment, rootDeviceIndex) {
|
||||
auto &hwInfo = getHardwareInfo();
|
||||
bool enableLocalMemory = HwHelper::get(hwInfo.platform.eRenderCoreFamily).getEnableLocalMemory(hwInfo);
|
||||
bool aubUsage = (testMode == TestMode::AubTests) || (testMode == TestMode::AubTestsWithTbx);
|
||||
@@ -70,7 +71,6 @@ void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) {
|
||||
}
|
||||
|
||||
void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr, uint32_t engineIndex) {
|
||||
UNRECOVERABLE_IF(internalDeviceIndex != 0u);
|
||||
|
||||
auto osContext = this->engines[engineIndex].osContext;
|
||||
auto memoryManager = executionEnvironment->memoryManager.get();
|
||||
@@ -81,11 +81,11 @@ void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr, uint3
|
||||
memoryManager->getRegisteredEngines().emplace_back(registeredEngine);
|
||||
osContext->incRefInternal();
|
||||
newCsr->setupContext(*osContext);
|
||||
executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[internalDeviceIndex][engineIndex].reset(newCsr);
|
||||
executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[internalDeviceIndex][engineIndex]->initializeTagAllocation();
|
||||
commandStreamReceivers[engineIndex].reset(newCsr);
|
||||
commandStreamReceivers[engineIndex]->initializeTagAllocation();
|
||||
|
||||
if (preemptionMode == PreemptionMode::MidThread || isSourceLevelDebuggerActive()) {
|
||||
executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[internalDeviceIndex][engineIndex]->createPreemptionAllocation();
|
||||
commandStreamReceivers[engineIndex]->createPreemptionAllocation();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
|
||||
#pragma once
|
||||
#include "runtime/device/root_device.h"
|
||||
#include "runtime/device/sub_device.h"
|
||||
#include "runtime/helpers/hw_helper.h"
|
||||
#include "unit_tests/fixtures/mock_aub_center_fixture.h"
|
||||
#include "unit_tests/helpers/variable_backup.h"
|
||||
#include "unit_tests/libult/ult_command_stream_receiver.h"
|
||||
#include "unit_tests/mocks/mock_allocation_properties.h"
|
||||
|
||||
@@ -18,8 +20,18 @@ class FailMemoryManager;
|
||||
|
||||
extern CommandStreamReceiver *createCommandStream(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex);
|
||||
|
||||
struct MockSubDevice : public SubDevice {
|
||||
using SubDevice::SubDevice;
|
||||
|
||||
std::unique_ptr<CommandStreamReceiver> createCommandStreamReceiver() const override {
|
||||
return std::unique_ptr<CommandStreamReceiver>(createCommandStreamReceiverFunc(*executionEnvironment, getRootDeviceIndex()));
|
||||
}
|
||||
static decltype(&createCommandStream) createCommandStreamReceiverFunc;
|
||||
};
|
||||
|
||||
class MockDevice : public RootDevice {
|
||||
public:
|
||||
using Device::commandStreamReceivers;
|
||||
using Device::createDeviceInternals;
|
||||
using Device::createEngine;
|
||||
using Device::deviceInfo;
|
||||
@@ -27,7 +39,7 @@ class MockDevice : public RootDevice {
|
||||
using Device::engines;
|
||||
using Device::executionEnvironment;
|
||||
using Device::initializeCaps;
|
||||
using Device::internalDeviceIndex;
|
||||
using RootDevice::createEngines;
|
||||
using RootDevice::subdevices;
|
||||
|
||||
void setOSTime(OSTime *osTime);
|
||||
@@ -39,7 +51,7 @@ class MockDevice : public RootDevice {
|
||||
|
||||
bool getCpuTime(uint64_t *timeStamp) { return true; };
|
||||
MockDevice();
|
||||
MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex);
|
||||
MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex);
|
||||
|
||||
void setPreemptionMode(PreemptionMode mode) {
|
||||
preemptionMode = mode;
|
||||
@@ -73,10 +85,10 @@ class MockDevice : public RootDevice {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T *createWithExecutionEnvironment(const HardwareInfo *pHwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) {
|
||||
static T *createWithExecutionEnvironment(const HardwareInfo *pHwInfo, ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex) {
|
||||
pHwInfo = pHwInfo ? pHwInfo : platformDevices[0];
|
||||
executionEnvironment->setHwInfo(pHwInfo);
|
||||
T *device = new T(executionEnvironment, deviceIndex);
|
||||
T *device = new T(executionEnvironment, rootDeviceIndex);
|
||||
executionEnvironment->memoryManager = std::move(device->mockMemoryManager);
|
||||
return createDeviceInternals(device);
|
||||
}
|
||||
@@ -90,6 +102,24 @@ class MockDevice : public RootDevice {
|
||||
executionEnvironment->setHwInfo(pHwInfo);
|
||||
return createWithExecutionEnvironment<T>(pHwInfo, executionEnvironment, 0u);
|
||||
}
|
||||
bool initializeRootCommandStreamReceiver() override {
|
||||
if (callBaseInitializeRootCommandStreamReceiver) {
|
||||
return RootDevice::initializeRootCommandStreamReceiver();
|
||||
}
|
||||
return initializeRootCommandStreamReceiverReturnValue;
|
||||
}
|
||||
|
||||
SubDevice *createSubDevice(uint32_t subDeviceIndex) override {
|
||||
return Device::create<MockSubDevice>(executionEnvironment, subDeviceIndex, *this);
|
||||
}
|
||||
|
||||
std::unique_ptr<CommandStreamReceiver> createCommandStreamReceiver() const override {
|
||||
return std::unique_ptr<CommandStreamReceiver>(createCommandStreamReceiverFunc(*executionEnvironment, getRootDeviceIndex()));
|
||||
}
|
||||
static decltype(&createCommandStream) createCommandStreamReceiverFunc;
|
||||
|
||||
bool callBaseInitializeRootCommandStreamReceiver = true;
|
||||
bool initializeRootCommandStreamReceiverReturnValue = false;
|
||||
|
||||
std::unique_ptr<MemoryManager> mockMemoryManager;
|
||||
};
|
||||
@@ -118,4 +148,20 @@ class MockAlignedMallocManagerDevice : public MockDevice {
|
||||
public:
|
||||
MockAlignedMallocManagerDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex);
|
||||
};
|
||||
|
||||
struct EnvironmentWithCsrWrapper {
|
||||
template <typename CsrType>
|
||||
void setCsrType() {
|
||||
createSubDeviceCsrFuncBackup = EnvironmentWithCsrWrapper::createCommandStreamReceiver<CsrType>;
|
||||
createRootDeviceCsrFuncBackup = EnvironmentWithCsrWrapper::createCommandStreamReceiver<CsrType>;
|
||||
}
|
||||
|
||||
template <typename CsrType>
|
||||
static CommandStreamReceiver *createCommandStreamReceiver(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) {
|
||||
return new CsrType(executionEnvironment, 0);
|
||||
}
|
||||
|
||||
VariableBackup<decltype(MockSubDevice::createCommandStreamReceiverFunc)> createSubDeviceCsrFuncBackup{&MockSubDevice::createCommandStreamReceiverFunc};
|
||||
VariableBackup<decltype(MockDevice::createCommandStreamReceiverFunc)> createRootDeviceCsrFuncBackup{&MockDevice::createCommandStreamReceiverFunc};
|
||||
};
|
||||
} // namespace NEO
|
||||
|
||||
@@ -32,30 +32,9 @@ struct MockExecutionEnvironment : ExecutionEnvironment {
|
||||
}
|
||||
ExecutionEnvironment::initAubCenter(localMemoryEnabled, aubFileName, csrType);
|
||||
}
|
||||
bool initializeRootCommandStreamReceiver(RootDevice &device) override {
|
||||
return initRootCommandStreamReceiver;
|
||||
}
|
||||
bool initAubCenterCalled = false;
|
||||
bool localMemoryEnabledReceived = false;
|
||||
std::string aubFileNameReceived = "";
|
||||
bool useMockAubCenter = true;
|
||||
bool initRootCommandStreamReceiver = false;
|
||||
};
|
||||
|
||||
template <typename CsrType>
|
||||
struct MockExecutionEnvironmentWithCsr : public ExecutionEnvironment {
|
||||
MockExecutionEnvironmentWithCsr() = delete;
|
||||
MockExecutionEnvironmentWithCsr(const HardwareInfo &hwInfo, uint32_t devicesCount) {
|
||||
setHwInfo(&hwInfo);
|
||||
auto &gpgpuEngines = HwHelper::get(hwInfo.platform.eRenderCoreFamily).getGpgpuEngineInstances();
|
||||
auto offset = devicesCount > 1 ? 1u : 0u;
|
||||
rootDeviceEnvironments[0].commandStreamReceivers.resize(devicesCount + offset);
|
||||
|
||||
for (uint32_t deviceIndex = 0; deviceIndex < devicesCount; deviceIndex++) {
|
||||
for (uint32_t csrIndex = 0; csrIndex < gpgpuEngines.size(); csrIndex++) {
|
||||
rootDeviceEnvironments[0].commandStreamReceivers[deviceIndex + offset].push_back(std::unique_ptr<CommandStreamReceiver>(new CsrType(*this, 0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace NEO
|
||||
|
||||
Reference in New Issue
Block a user