Use DeviceHelper to calculate number of sub devices

Related-To: NEO-3691

Change-Id: I390b7919fe8960b74cf290923f5daf128d824674
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2019-10-07 12:42:28 +02:00
parent 77d7d9f740
commit b93817fe7c
18 changed files with 141 additions and 91 deletions

View File

@ -116,7 +116,7 @@ class Device : public BaseObject<_cl_device_id> {
virtual bool createDeviceImpl();
virtual DeviceBitfield getDeviceBitfieldForOsContext() const = 0;
bool createEngines();
virtual bool createEngines();
bool createEngine(uint32_t deviceIndex, uint32_t deviceCsrIndex, aub_stream::EngineType engineType);
MOCKABLE_VIRTUAL void initializeCaps();

View File

@ -8,6 +8,7 @@
#include "runtime/device/root_device.h"
#include "runtime/device/sub_device.h"
#include "runtime/helpers/device_helpers.h"
#include "runtime/os_interface/debug_settings_manager.h"
namespace NEO {
@ -39,13 +40,12 @@ Device *RootDevice::getDeviceById(uint32_t deviceId) const {
RootDevice::RootDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) : Device(executionEnvironment, deviceIndex) {}
bool RootDevice::createDeviceImpl() {
auto status = Device::createDeviceImpl();
if (!status) {
return status;
auto numSubDevices = DeviceHelper::getDevicesCount(&getHardwareInfo());
if (numSubDevices == 1) {
numSubDevices = 0;
}
auto numSubDevices = DebugManager.flags.CreateMultipleSubDevices.get();
subdevices.reserve(numSubDevices);
for (int i = 0; i < numSubDevices; i++) {
for (auto i = 0u; i < numSubDevices; i++) {
auto subDevice = Device::create<SubDevice>(executionEnvironment, deviceIndex + i + 1, i, *this);
if (!subDevice) {
@ -53,6 +53,10 @@ bool RootDevice::createDeviceImpl() {
}
subdevices.push_back(std::unique_ptr<SubDevice>(subDevice));
}
auto status = Device::createDeviceImpl();
if (!status) {
return status;
}
return true;
}
@ -70,4 +74,19 @@ DeviceBitfield RootDevice::getDeviceBitfieldForOsContext() const {
deviceBitfield.set(deviceIndex);
return deviceBitfield;
}
bool RootDevice::createEngines() {
if (!executionEnvironment->initializeRootCommandStreamReceiver(*this)) {
return Device::createEngines();
}
return true;
}
void RootDevice::setupRootEngine(EngineControl engine) {
if (engines.size() > 0u) {
return;
}
defaultEngineIndex = 0;
engines.emplace_back(engine);
}
} // namespace NEO

View File

@ -21,13 +21,14 @@ class RootDevice : public Device {
uint32_t getNumSubDevices() const;
uint32_t getRootDeviceIndex() const override;
Device *getDeviceById(uint32_t deviceId) const override;
/* We hide the retain and release function of BaseObject. */
void retain() override;
unique_ptr_if_unused<Device> release() override;
void setupRootEngine(EngineControl engineControl);
protected:
DeviceBitfield getDeviceBitfieldForOsContext() const override;
bool createEngines() override;
std::vector<std::unique_ptr<SubDevice>> subdevices;
};
} // namespace NEO

View File

@ -120,14 +120,6 @@ BuiltIns *ExecutionEnvironment::getBuiltIns() {
return this->builtins.get();
}
EngineControl *ExecutionEnvironment::getEngineControlForSpecialCsr() {
EngineControl *engine = nullptr;
if (specialCommandStreamReceiver.get()) {
engine = memoryManager->getRegisteredEngineForCsr(specialCommandStreamReceiver.get());
}
return engine;
}
bool ExecutionEnvironment::isFullRangeSvm() const {
return hwInfo->capabilityTable.gpuAddressSpace >= maxNBitValue<47>;
}

View File

@ -24,6 +24,7 @@ class GmmHelper;
class MemoryManager;
class SourceLevelDebugger;
class OSInterface;
class RootDevice;
class MemoryOperationsHandler;
struct EngineControl;
struct HardwareInfo;
@ -44,7 +45,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
MOCKABLE_VIRTUAL void initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType);
void initGmm();
bool initializeCommandStreamReceiver(uint32_t deviceIndex, uint32_t deviceCsrIndex);
void initializeSpecialCommandStreamReceiver();
MOCKABLE_VIRTUAL bool initializeRootCommandStreamReceiver(RootDevice &rootDevice);
void initializeMemoryManager();
void initSourceLevelDebugger();
void setHwInfo(const HardwareInfo *hwInfo);
@ -55,14 +56,12 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
GmmHelper *getGmmHelper() const;
MOCKABLE_VIRTUAL CompilerInterface *getCompilerInterface();
BuiltIns *getBuiltIns();
EngineControl *getEngineControlForSpecialCsr();
std::unique_ptr<OSInterface> osInterface;
std::unique_ptr<MemoryOperationsHandler> memoryOperationsInterface;
std::unique_ptr<MemoryManager> memoryManager;
std::unique_ptr<AubCenter> aubCenter;
CsrContainer commandStreamReceivers;
std::unique_ptr<CommandStreamReceiver> specialCommandStreamReceiver;
std::unique_ptr<BuiltIns> builtins;
std::unique_ptr<CompilerInterface> compilerInterface;
std::unique_ptr<SourceLevelDebugger> sourceLevelDebugger;

View File

@ -8,7 +8,8 @@
#include "runtime/execution_environment/execution_environment.h"
namespace NEO {
void ExecutionEnvironment::initializeSpecialCommandStreamReceiver() {
bool ExecutionEnvironment::initializeRootCommandStreamReceiver(RootDevice &device) {
return false;
}
} // namespace NEO

View File

@ -14,7 +14,7 @@ namespace NEO {
void DeviceHelper::getExtraDeviceInfo(const HardwareInfo &hwInfo, cl_device_info paramName, cl_uint &param, const void *&src, size_t &size, size_t &retSize) {}
uint32_t DeviceHelper::getDevicesCount(const HardwareInfo *pHwInfo) {
return DebugManager.flags.CreateMultipleRootDevices.get() > 0 ? DebugManager.flags.CreateMultipleRootDevices.get() : 1u;
return DebugManager.flags.CreateMultipleSubDevices.get() > 0 ? DebugManager.flags.CreateMultipleSubDevices.get() : 1u;
}
uint32_t DeviceHelper::getEnginesCount(const HardwareInfo &hwInfo) {

View File

@ -8,7 +8,6 @@
#ifdef _WIN32
#include "runtime/device/device.h"
#include "runtime/helpers/device_helpers.h"
#include "runtime/os_interface/debug_settings_manager.h"
#include "runtime/os_interface/device_factory.h"
#include "runtime/os_interface/hw_info_config.h"
@ -31,7 +30,10 @@ bool DeviceFactory::getDevices(size_t &numDevices, ExecutionEnvironment &executi
return false;
}
auto totalDeviceCount = DeviceHelper::getDevicesCount(hardwareInfo);
auto totalDeviceCount = 1u;
if (DebugManager.flags.CreateMultipleRootDevices.get()) {
totalDeviceCount = DebugManager.flags.CreateMultipleRootDevices.get();
}
executionEnvironment.memoryOperationsInterface = std::make_unique<WddmMemoryOperationsHandler>(wddm.get());
executionEnvironment.osInterface.reset(new OSInterface());

View File

@ -173,7 +173,6 @@ bool Platform::initialize() {
return false;
}
}
executionEnvironment->initializeSpecialCommandStreamReceiver();
auto hwInfo = executionEnvironment->getHardwareInfo();

View File

@ -8,13 +8,14 @@
#include "core/unit_tests/helpers/debug_manager_state_restore.h"
#include "runtime/command_queue/command_queue.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/device/device.h"
#include "runtime/device_queue/device_queue.h"
#include "runtime/helpers/hw_helper.h"
#include "runtime/os_interface/os_context.h"
#include "unit_tests/fixtures/memory_management_fixture.h"
#include "unit_tests/helpers/unit_test_helper.h"
#include "unit_tests/helpers/variable_backup.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_device.h"
#include "CL/cl_ext.h"
#include "cl_api_tests.h"
@ -382,6 +383,7 @@ HWTEST_F(clCreateCommandQueueWithPropertiesApi, GivenLowPriorityWhenCreatingComm
using LowPriorityCommandQueueTest = ::testing::Test;
HWTEST_F(LowPriorityCommandQueueTest, GivenDeviceWithSubdevicesWhenCreatingLowPriorityCommandQueueThenEngineFromFirstSubdeviceIsTaken) {
DebugManagerStateRestore restorer;
VariableBackup<bool> mockDeviceFlagBackup{&MockDevice::createSingleDevice, false};
DebugManager.flags.CreateMultipleSubDevices.set(2);
MockContext context;
cl_queue_properties properties[] = {CL_QUEUE_PRIORITY_KHR, CL_QUEUE_PRIORITY_LOW_KHR, 0};

View File

@ -33,7 +33,7 @@ TEST(AubHelper, WhenGetPtEntryBitsIsCalledThenEntryBitsAreNotMasked) {
EXPECT_EQ(entryBits, maskedEntryBits);
}
TEST(AubHelper, GivenMultipleDevicesWhenGettingDeviceCountThenCorrectValueIsReturned) {
TEST(AubHelper, GivenMultipleSubDevicesWhenGettingDeviceCountThenCorrectValueIsReturned) {
DebugManagerStateRestore stateRestore;
FeatureTable featureTable = {};
WorkaroundTable workaroundTable = {};
@ -41,12 +41,12 @@ TEST(AubHelper, GivenMultipleDevicesWhenGettingDeviceCountThenCorrectValueIsRetu
GT_SYSTEM_INFO sysInfo = {};
PLATFORM platform = {};
HardwareInfo hwInfo{&platform, &featureTable, &workaroundTable, &sysInfo, capTable};
DebugManager.flags.CreateMultipleRootDevices.set(2);
DebugManager.flags.CreateMultipleSubDevices.set(2);
uint32_t devicesCount = DeviceHelper::getDevicesCount(&hwInfo);
EXPECT_EQ(devicesCount, 2u);
DebugManager.flags.CreateMultipleRootDevices.set(0);
DebugManager.flags.CreateMultipleSubDevices.set(0);
devicesCount = DeviceHelper::getDevicesCount(&hwInfo);
EXPECT_EQ(devicesCount, 1u);
}

View File

@ -24,6 +24,7 @@
#include "unit_tests/fixtures/image_fixture.h"
#include "unit_tests/fixtures/memory_management_fixture.h"
#include "unit_tests/helpers/unit_test_helper.h"
#include "unit_tests/helpers/variable_backup.h"
#include "unit_tests/libult/ult_command_stream_receiver.h"
#include "unit_tests/mocks/mock_command_queue.h"
#include "unit_tests/mocks/mock_context.h"
@ -219,6 +220,7 @@ TEST(CommandQueue, givenDeviceNotSupportingBlitOperationsWhenQueueIsCreatedThenD
using CommandQueueWithSubDevicesTest = ::testing::Test;
HWTEST_F(CommandQueueWithSubDevicesTest, givenDeviceWithSubDevicesSupportingBlitOperationsWhenQueueIsCreatedThenBcsIsTakenFromFirstSubDevice) {
DebugManagerStateRestore restorer;
VariableBackup<bool> mockDeviceFlagBackup{&MockDevice::createSingleDevice, false};
DebugManager.flags.CreateMultipleSubDevices.set(2);
DebugManager.flags.EnableBlitterOperationsForReadWriteBuffers.set(1);
HardwareInfo hwInfo = *platformDevices[0];

View File

@ -173,7 +173,12 @@ TEST(DeviceCreation, givenDefaultHwCsrInDebugVarsWhenDeviceIsCreatedThenIsSimula
TEST(DeviceCreation, givenDeviceWhenItIsCreatedThenOsContextIsRegistredInMemoryManager) {
auto device = std::unique_ptr<Device>(MockDevice::createWithNewExecutionEnvironment<Device>(nullptr));
auto memoryManager = device->getMemoryManager();
EXPECT_EQ(HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances().size(), memoryManager->getRegisteredEnginesCount());
auto numEnginesForDevice = HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances().size();
if (device->getNumAvailableDevices() > 1) {
numEnginesForDevice *= device->getNumAvailableDevices();
numEnginesForDevice += device->getExecutionEnvironment()->commandStreamReceivers[0].size();
}
EXPECT_EQ(numEnginesForDevice, memoryManager->getRegisteredEnginesCount());
}
TEST(DeviceCreation, givenMultiDeviceWhenTheyAreCreatedThenEachOsContextHasUniqueId) {

View File

@ -25,6 +25,7 @@ TEST(SubDevicesTest, givenDefaultConfigWhenCreateRootDeviceThenItDoesntContainSu
TEST(SubDevicesTest, givenCreateMultipleSubDevicesFlagSetWhenCreateRootDeviceThenItsSubdevicesHaveProperRootIdSet) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleSubDevices.set(2);
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(*platformDevices));
EXPECT_EQ(2u, device->getNumSubDevices());
@ -40,6 +41,7 @@ TEST(SubDevicesTest, givenCreateMultipleSubDevicesFlagSetWhenCreateRootDeviceThe
TEST(SubDevicesTest, givenCreateMultipleSubDevicesFlagSetWhenCreateRootDeviceThenItContainsSubDevices) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleSubDevices.set(2);
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(*platformDevices));
EXPECT_EQ(2u, device->getNumSubDevices());
@ -56,6 +58,7 @@ TEST(SubDevicesTest, givenCreateMultipleSubDevicesFlagSetWhenCreateRootDeviceThe
TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceRefcountsAreChangedThenChangeIsPropagatedToRootDevice) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleSubDevices.set(2);
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(*platformDevices));
auto subDevice0 = device->subdevices.at(0).get();
@ -93,17 +96,20 @@ TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceCreationFailThenWhole
TEST(SubDevicesTest, givenCreateMultipleRootDevicesFlagsEnabledWhenDevicesAreCreatedThenEachHasUniqueDeviceIndex) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleRootDevices.set(2);
DebugManager.flags.CreateMultipleSubDevices.set(3);
DebugManager.flags.CreateMultipleSubDevices.set(2);
VariableBackup<bool> backup(&overrideDeviceWithDefaultHardwareInfo, false);
platform()->initialize();
EXPECT_EQ(0u, platform()->getDevice(0)->getDeviceIndex());
EXPECT_EQ(4u, platform()->getDevice(1)->getDeviceIndex());
auto device = static_cast<RootDevice *>(platform()->getDevice(0));
EXPECT_EQ(0u, device->getDeviceIndex());
EXPECT_EQ(2u, device->getNumSubDevices());
EXPECT_EQ(1u, device->getDeviceById(0)->getDeviceIndex());
EXPECT_EQ(2u, device->getDeviceById(1)->getDeviceIndex());
}
TEST(SubDevicesTest, givenSubDeviceWhenOsContextIsCreatedThenItsBitfieldBasesOnSubDeviceId) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleSubDevices.set(2);
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(*platformDevices));
EXPECT_EQ(2u, device->getNumSubDevices());
@ -127,6 +133,7 @@ TEST(SubDevicesTest, givenDeviceWithoutSubDevicesWhenGettingDeviceByIdZeroThenGe
TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenGettingDeviceByIdThenGetCorrectSubDevice) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleSubDevices.set(2);
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(*platformDevices));
EXPECT_EQ(2u, device->getNumSubDevices());
EXPECT_EQ(device->subdevices.at(0).get(), device->getDeviceById(0));
@ -137,6 +144,7 @@ TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenGettingDeviceByIdThenGetCorrec
TEST(SubDevicesTest, givenSubDevicesWhenGettingDeviceByIdZeroThenGetThisSubDevice) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleSubDevices.set(2);
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(*platformDevices));
EXPECT_EQ(2u, device->getNumSubDevices());
auto subDevice = device->subdevices.at(0).get();
@ -144,3 +152,45 @@ TEST(SubDevicesTest, givenSubDevicesWhenGettingDeviceByIdZeroThenGetThisSubDevic
EXPECT_EQ(subDevice, subDevice->getDeviceById(0));
EXPECT_THROW(subDevice->getDeviceById(1), std::exception);
}
TEST(SubDevicesTest, givenRootDeviceWithSubdevicesWhenSetupRootEngineOnceAgainThenDontOverrideEngine) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleSubDevices.set(2);
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(*platformDevices));
EXPECT_EQ(2u, device->getNumSubDevices());
auto subDevice = device->subdevices.at(0).get();
auto subDeviceEngine = subDevice->getDefaultEngine();
auto rootDeviceEngine = device->getDefaultEngine();
EXPECT_NE(subDeviceEngine.commandStreamReceiver, rootDeviceEngine.commandStreamReceiver);
EXPECT_NE(subDeviceEngine.osContext, rootDeviceEngine.osContext);
device->setupRootEngine(subDeviceEngine);
rootDeviceEngine = device->getDefaultEngine();
EXPECT_NE(subDeviceEngine.commandStreamReceiver, rootDeviceEngine.commandStreamReceiver);
EXPECT_NE(subDeviceEngine.osContext, rootDeviceEngine.osContext);
}
TEST(SubDevicesTest, givenRootDeviceWithoutEngineWhenSetupRootEngine) {
auto executionEnvironment = platform()->peekExecutionEnvironment();
MockDevice device(executionEnvironment, 0);
EXPECT_EQ(0u, device.engines.size());
EngineControl dummyEngine{reinterpret_cast<CommandStreamReceiver *>(0x123), reinterpret_cast<OsContext *>(0x456)};
device.setupRootEngine(dummyEngine);
EXPECT_EQ(1u, device.engines.size());
EXPECT_EQ(dummyEngine.commandStreamReceiver, device.engines[0].commandStreamReceiver);
EXPECT_EQ(dummyEngine.osContext, device.engines[0].osContext);
device.engines.clear();
}
TEST(SubDevicesTest, givenRootDeviceWhenExecutionEnvironmentInitializesRootCommandStreamReceiverThenDeviceDoesntCreateExtraEngines) {
auto executionEnvironment = new MockExecutionEnvironment;
executionEnvironment->initRootCommandStreamReceiver = true;
executionEnvironment->initializeMemoryManager();
std::unique_ptr<MockDevice> device(MockDevice::createWithExecutionEnvironment<MockDevice>(*platformDevices, executionEnvironment, 0u));
EXPECT_EQ(0u, device->engines.size());
}

View File

@ -55,12 +55,19 @@ TEST(ExecutionEnvironment, givenPlatformWhenItIsInitializedAndCreatesDevicesThen
std::unique_ptr<Platform> platform(new Platform);
auto executionEnvironment = platform->peekExecutionEnvironment();
auto expectedRefCounts = executionEnvironment->getRefInternalCount();
platform->initialize();
EXPECT_LT(0u, platform->getNumDevices());
EXPECT_EQ(static_cast<int32_t>(1u + platform->getNumDevices()), executionEnvironment->getRefInternalCount());
EXPECT_LT(0u, platform->getDevice(0)->getNumAvailableDevices());
if (platform->getDevice(0)->getNumAvailableDevices() > 1) {
expectedRefCounts++;
}
expectedRefCounts += platform->getDevice(0)->getNumAvailableDevices();
EXPECT_EQ(expectedRefCounts, executionEnvironment->getRefInternalCount());
}
TEST(ExecutionEnvironment, givenDeviceThatHaveRefferencesAfterPlatformIsDestroyedThenDeviceIsStillUsable) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleSubDevices.set(1);
std::unique_ptr<Platform> platform(new Platform);
auto executionEnvironment = platform->peekExecutionEnvironment();
platform->initialize();
@ -81,20 +88,6 @@ TEST(ExecutionEnvironment, givenPlatformWhenItIsCreatedThenItCreatesCommandStrea
EXPECT_NE(nullptr, executionEnvironment->commandStreamReceivers[0][0].get());
}
TEST(ExecutionEnvironment, whenPlatformIsInitializedThenOnlySpecialCommandStreamReceiverIsMultiOsContextCapable) {
Platform platform;
auto executionEnvironment = platform.peekExecutionEnvironment();
platform.initialize();
for (auto &csrContainer : executionEnvironment->commandStreamReceivers) {
for (auto &csr : csrContainer) {
EXPECT_FALSE(csr->isMultiOsContextCapable());
}
}
if (executionEnvironment->specialCommandStreamReceiver) {
EXPECT_TRUE(executionEnvironment->specialCommandStreamReceiver->isMultiOsContextCapable());
}
}
TEST(ExecutionEnvironment, givenPlatformWhenItIsCreatedThenItCreatesMemoryManagerInExecutionEnvironment) {
Platform platform;
auto executionEnvironment = platform.peekExecutionEnvironment();
@ -194,7 +187,6 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerI
EXPECT_NE(nullptr, executionEnvironment->memoryManager);
}
static_assert(sizeof(ExecutionEnvironment) == sizeof(std::vector<std::unique_ptr<CommandStreamReceiver>>) +
sizeof(std::unique_ptr<CommandStreamReceiver>) +
sizeof(std::mutex) +
sizeof(std::unique_ptr<HardwareInfo>) +
(is64bit ? 88 : 48),
@ -206,27 +198,24 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe
struct MockExecutionEnvironment : ExecutionEnvironment {
using ExecutionEnvironment::gmmHelper;
};
struct GmmHelperMock : public DestructorCounted<GmmHelper, 9> {
struct GmmHelperMock : public DestructorCounted<GmmHelper, 8> {
GmmHelperMock(uint32_t &destructorId, const HardwareInfo *hwInfo) : DestructorCounted(destructorId, hwInfo) {}
};
struct OsInterfaceMock : public DestructorCounted<OSInterface, 8> {
struct OsInterfaceMock : public DestructorCounted<OSInterface, 7> {
OsInterfaceMock(uint32_t &destructorId) : DestructorCounted(destructorId) {}
};
struct MemoryOperationsHandlerMock : public DestructorCounted<MockMemoryOperationsHandler, 7> {
struct MemoryOperationsHandlerMock : public DestructorCounted<MockMemoryOperationsHandler, 6> {
MemoryOperationsHandlerMock(uint32_t &destructorId) : DestructorCounted(destructorId) {}
};
struct MemoryMangerMock : public DestructorCounted<MockMemoryManager, 6> {
struct MemoryMangerMock : public DestructorCounted<MockMemoryManager, 5> {
MemoryMangerMock(uint32_t &destructorId, ExecutionEnvironment &executionEnvironment) : DestructorCounted(destructorId, executionEnvironment) {}
};
struct AubCenterMock : public DestructorCounted<AubCenter, 5> {
struct AubCenterMock : public DestructorCounted<AubCenter, 4> {
AubCenterMock(uint32_t &destructorId) : DestructorCounted(destructorId, platformDevices[0], false, "", CommandStreamReceiverType::CSR_AUB) {}
};
struct CommandStreamReceiverMock : public DestructorCounted<MockCommandStreamReceiver, 4> {
struct CommandStreamReceiverMock : public DestructorCounted<MockCommandStreamReceiver, 3> {
CommandStreamReceiverMock(uint32_t &destructorId, ExecutionEnvironment &executionEnvironment) : DestructorCounted(destructorId, executionEnvironment) {}
};
struct SpecialCommandStreamReceiverMock : public DestructorCounted<MockCommandStreamReceiver, 3> {
SpecialCommandStreamReceiverMock(uint32_t &destructorId, ExecutionEnvironment &executionEnvironment) : DestructorCounted(destructorId, executionEnvironment) {}
};
struct BuiltinsMock : public DestructorCounted<BuiltIns, 2> {
BuiltinsMock(uint32_t &destructorId) : DestructorCounted(destructorId) {}
};
@ -246,13 +235,12 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe
executionEnvironment->memoryManager = std::make_unique<MemoryMangerMock>(destructorId, *executionEnvironment);
executionEnvironment->aubCenter = std::make_unique<AubCenterMock>(destructorId);
executionEnvironment->commandStreamReceivers[0].push_back(std::make_unique<CommandStreamReceiverMock>(destructorId, *executionEnvironment));
executionEnvironment->specialCommandStreamReceiver = std::make_unique<SpecialCommandStreamReceiverMock>(destructorId, *executionEnvironment);
executionEnvironment->builtins = std::make_unique<BuiltinsMock>(destructorId);
executionEnvironment->compilerInterface = std::make_unique<CompilerInterfaceMock>(destructorId);
executionEnvironment->sourceLevelDebugger = std::make_unique<SourceLevelDebuggerMock>(destructorId);
executionEnvironment.reset(nullptr);
EXPECT_EQ(10u, destructorId);
EXPECT_EQ(9u, destructorId);
}
TEST(ExecutionEnvironment, givenMultipleDevicesWhenTheyAreCreatedTheyAllReuseTheSameMemoryManagerAndCommandStreamReceiver) {
@ -294,33 +282,6 @@ HWTEST_F(ExecutionEnvironmentHw, givenHwHelperInputWhenInitializingCsrThenCreate
EXPECT_EQ(UnitTestHelper<FamilyType>::isPageTableManagerSupported(*hwInfo), csr2->createPageTableManagerCalled);
}
TEST(ExecutionEnvironment, whenSpecialCsrNotExistThenReturnNullSpecialEngineControl) {
ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment();
executionEnvironment->initializeCommandStreamReceiver(0, 0);
executionEnvironment->initializeMemoryManager();
EXPECT_NE(nullptr, executionEnvironment->memoryManager);
auto engineControl = executionEnvironment->getEngineControlForSpecialCsr();
EXPECT_EQ(nullptr, engineControl);
}
TEST(ExecutionEnvironment, whenSpecialCsrExistsThenReturnSpecialEngineControl) {
ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment();
executionEnvironment->initializeCommandStreamReceiver(0, 0);
executionEnvironment->initializeMemoryManager();
EXPECT_NE(nullptr, executionEnvironment->memoryManager);
executionEnvironment->specialCommandStreamReceiver.reset(createCommandStream(*executionEnvironment));
auto engineType = HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0];
auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(executionEnvironment->specialCommandStreamReceiver.get(),
engineType, 1,
PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false);
executionEnvironment->specialCommandStreamReceiver->setupContext(*osContext);
auto engineControl = executionEnvironment->getEngineControlForSpecialCsr();
ASSERT_NE(nullptr, engineControl);
EXPECT_EQ(executionEnvironment->specialCommandStreamReceiver.get(), engineControl->commandStreamReceiver);
}
TEST(ExecutionEnvironment, givenUnproperSetCsrFlagValueWhenInitializingMemoryManagerThenCreateDefaultMemoryManager) {
DebugManagerStateRestore restorer;
DebugManager.flags.SetCommandStreamReceiver.set(10);

View File

@ -16,6 +16,8 @@
using namespace NEO;
bool MockDevice::createSingleDevice = true;
MockDevice::MockDevice()
: MockDevice(new MockExecutionEnvironment(), 0u) {
CommandStreamReceiver *commandStreamReceiver = createCommandStream(*this->executionEnvironment);
@ -40,6 +42,13 @@ MockDevice::MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t devi
initializeCaps();
}
bool MockDevice::createDeviceImpl() {
if (MockDevice::createSingleDevice) {
return Device::createDeviceImpl();
}
return RootDevice::createDeviceImpl();
}
void MockDevice::setOSTime(OSTime *osTime) {
this->osTime.reset(osTime);
};

View File

@ -33,6 +33,9 @@ class MockDevice : public RootDevice {
void setDriverInfo(DriverInfo *driverInfo);
bool hasDriverInfo();
static bool createSingleDevice;
bool createDeviceImpl() override;
bool getCpuTime(uint64_t *timeStamp) { return true; };
MockDevice();
MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex);

View File

@ -32,10 +32,14 @@ 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>
@ -44,11 +48,12 @@ struct MockExecutionEnvironmentWithCsr : public ExecutionEnvironment {
MockExecutionEnvironmentWithCsr(const HardwareInfo &hwInfo, uint32_t devicesCount) {
setHwInfo(&hwInfo);
auto &gpgpuEngines = HwHelper::get(hwInfo.platform.eRenderCoreFamily).getGpgpuEngineInstances();
commandStreamReceivers.resize(devicesCount);
auto offset = devicesCount > 1 ? 1u : 0u;
commandStreamReceivers.resize(devicesCount + offset);
for (uint32_t csrIndex = 0; csrIndex < gpgpuEngines.size(); csrIndex++) {
for (auto &csr : commandStreamReceivers) {
csr.push_back(std::unique_ptr<CommandStreamReceiver>(new CsrType(*this)));
for (uint32_t deviceIndex = 0; deviceIndex < devicesCount; deviceIndex++) {
for (uint32_t csrIndex = 0; csrIndex < gpgpuEngines.size(); csrIndex++) {
commandStreamReceivers[deviceIndex + offset].push_back(std::unique_ptr<CommandStreamReceiver>(new CsrType(*this)));
}
}
}