From 2d033f5dea74b31eca6f883473e278fd74ef2909 Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Tue, 12 Jan 2021 21:39:04 +0000 Subject: [PATCH] Update UltDeviceFactory Use MockMemoryManager by default in UltDeviceFactory. Signed-off-by: Filip Hazubski --- .../fixtures/multi_root_device_fixture.h | 12 +----------- .../mem_obj/image2d_from_buffer_tests.cpp | 4 ++-- .../unit_test/mocks/ult_cl_device_factory.cpp | 8 ++------ .../os_interface/device_factory_tests.cpp | 8 +++++--- shared/source/os_interface/device_factory.cpp | 8 ++++---- shared/source/os_interface/device_factory.h | 4 ++-- shared/test/unit_test/mocks/mock_device.cpp | 16 ++++------------ shared/test/unit_test/mocks/mock_device.h | 3 --- .../test/unit_test/mocks/ult_device_factory.cpp | 16 ++++++++++++++-- shared/test/unit_test/mocks/ult_device_factory.h | 3 ++- 10 files changed, 36 insertions(+), 46 deletions(-) diff --git a/opencl/test/unit_test/fixtures/multi_root_device_fixture.h b/opencl/test/unit_test/fixtures/multi_root_device_fixture.h index 59a40f45d9..80e2fabe8e 100644 --- a/opencl/test/unit_test/fixtures/multi_root_device_fixture.h +++ b/opencl/test/unit_test/fixtures/multi_root_device_fixture.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 Intel Corporation + * Copyright (C) 2019-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -19,10 +19,6 @@ namespace NEO { class MultiRootDeviceFixture : public ::testing::Test { public: void SetUp() override { - createMemoryManagerFuncBackup = [](ExecutionEnvironment &executionEnvironment) -> void { - executionEnvironment.memoryManager = std::make_unique(executionEnvironment); - }; - deviceFactory = std::make_unique(3, 0); device1 = deviceFactory->rootDevices[1]; device2 = deviceFactory->rootDevices[2]; @@ -40,15 +36,10 @@ class MultiRootDeviceFixture : public ::testing::Test { MockClDevice *device2 = nullptr; std::unique_ptr context; MockMemoryManager *mockMemoryManager; - VariableBackup createMemoryManagerFuncBackup{&DeviceFactory::createMemoryManagerFunc}; }; class MultiRootDeviceWithSubDevicesFixture : public ::testing::Test { public: void SetUp() override { - createMemoryManagerFuncBackup = [](ExecutionEnvironment &executionEnvironment) -> void { - executionEnvironment.memoryManager = std::make_unique(executionEnvironment); - }; - deviceFactory = std::make_unique(3, 2); device1 = deviceFactory->rootDevices[1]; device2 = deviceFactory->rootDevices[2]; @@ -66,6 +57,5 @@ class MultiRootDeviceWithSubDevicesFixture : public ::testing::Test { MockClDevice *device2 = nullptr; std::unique_ptr context; MockMemoryManager *mockMemoryManager; - VariableBackup createMemoryManagerFuncBackup{&DeviceFactory::createMemoryManagerFunc}; }; }; // namespace NEO diff --git a/opencl/test/unit_test/mem_obj/image2d_from_buffer_tests.cpp b/opencl/test/unit_test/mem_obj/image2d_from_buffer_tests.cpp index d1bf592b6c..baf9b8f29e 100644 --- a/opencl/test/unit_test/mem_obj/image2d_from_buffer_tests.cpp +++ b/opencl/test/unit_test/mem_obj/image2d_from_buffer_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -27,7 +27,7 @@ extern HwHelper *hwHelperFactory[IGFX_MAX_CORE]; } // Tests for cl_khr_image2d_from_buffer -class Image2dFromBufferTest : public ClDeviceFixture, public ::testing::Test { +class Image2dFromBufferTest : public ::testing::Test { public: Image2dFromBufferTest() {} diff --git a/opencl/test/unit_test/mocks/ult_cl_device_factory.cpp b/opencl/test/unit_test/mocks/ult_cl_device_factory.cpp index 2ad9450ab5..d42421d284 100644 --- a/opencl/test/unit_test/mocks/ult_cl_device_factory.cpp +++ b/opencl/test/unit_test/mocks/ult_cl_device_factory.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,11 +18,7 @@ using namespace NEO; UltClDeviceFactory::UltClDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevicesCount) { - - auto executionEnvironment = new ClExecutionEnvironment(); - UltDeviceFactory::prepareDeviceEnvironments(*executionEnvironment, rootDevicesCount); - - pUltDeviceFactory = std::make_unique(rootDevicesCount, subDevicesCount, *executionEnvironment); + pUltDeviceFactory = std::make_unique(rootDevicesCount, subDevicesCount, *(new ClExecutionEnvironment)); for (auto &pRootDevice : pUltDeviceFactory->rootDevices) { auto pRootClDevice = new MockClDevice{pRootDevice}; diff --git a/opencl/test/unit_test/os_interface/device_factory_tests.cpp b/opencl/test/unit_test/os_interface/device_factory_tests.cpp index 0095826e9b..c0524c8235 100644 --- a/opencl/test/unit_test/os_interface/device_factory_tests.cpp +++ b/opencl/test/unit_test/os_interface/device_factory_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -275,8 +275,10 @@ TEST(DiscoverDevices, whenDiscoverDevicesAndForceDeviceIdIsDifferentFromTheExist using UltDeviceFactoryTest = DeviceFactoryTest; -TEST_F(UltDeviceFactoryTest, givenUltDeviceFactoryPrepareDeviceEnvironmentsCallWhenItIsDoneThenMockMemoryManagerIsAllocated) { - UltDeviceFactory::prepareDeviceEnvironments(*executionEnvironment, 2u); +TEST_F(UltDeviceFactoryTest, givenExecutionEnvironmentWhenCreatingUltDeviceFactoryThenMockMemoryManagerIsAllocated) { + executionEnvironment->rootDeviceEnvironments.clear(); + executionEnvironment->memoryManager.reset(); + UltDeviceFactory ultDeviceFactory{2, 0, *executionEnvironment}; EXPECT_EQ(2u, executionEnvironment->rootDeviceEnvironments.size()); EXPECT_NE(nullptr, executionEnvironment->memoryManager.get()); diff --git a/shared/source/os_interface/device_factory.cpp b/shared/source/os_interface/device_factory.cpp index 6e2b609b54..f3eb89d39b 100644 --- a/shared/source/os_interface/device_factory.cpp +++ b/shared/source/os_interface/device_factory.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -131,7 +131,7 @@ std::vector> DeviceFactory::createDevices(ExecutionEnvir return devices; } - if (!executionEnvironment.initializeMemoryManager()) { + if (!DeviceFactory::createMemoryManagerFunc(executionEnvironment)) { return devices; } @@ -148,8 +148,8 @@ std::unique_ptr (*DeviceFactory::createRootDeviceFunc)(ExecutionEnvironm return std::unique_ptr(Device::create(&executionEnvironment, rootDeviceIndex)); }; -void (*DeviceFactory::createMemoryManagerFunc)(ExecutionEnvironment &) = [](ExecutionEnvironment &executionEnvironment) -> void { - executionEnvironment.initializeMemoryManager(); +bool (*DeviceFactory::createMemoryManagerFunc)(ExecutionEnvironment &) = [](ExecutionEnvironment &executionEnvironment) -> bool { + return executionEnvironment.initializeMemoryManager(); }; } // namespace NEO diff --git a/shared/source/os_interface/device_factory.h b/shared/source/os_interface/device_factory.h index c92c779534..61f3e74219 100644 --- a/shared/source/os_interface/device_factory.h +++ b/shared/source/os_interface/device_factory.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -23,6 +23,6 @@ class DeviceFactory { static bool isHwModeSelected(); static std::unique_ptr (*createRootDeviceFunc)(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex); - static void (*createMemoryManagerFunc)(ExecutionEnvironment &executionEnvironment); + static bool (*createMemoryManagerFunc)(ExecutionEnvironment &executionEnvironment); }; } // namespace NEO diff --git a/shared/test/unit_test/mocks/mock_device.cpp b/shared/test/unit_test/mocks/mock_device.cpp index bfed33048c..47ee60b665 100644 --- a/shared/test/unit_test/mocks/mock_device.cpp +++ b/shared/test/unit_test/mocks/mock_device.cpp @@ -10,6 +10,7 @@ #include "shared/source/command_stream/command_stream_receiver.h" #include "shared/source/command_stream/preemption.h" #include "shared/source/os_interface/os_context.h" +#include "shared/test/unit_test/mocks/ult_device_factory.h" #include "shared/test/unit_test/tests_configuration.h" #include "opencl/test/unit_test/mocks/mock_execution_environment.h" @@ -25,8 +26,8 @@ decltype(&createCommandStream) MockDevice::createCommandStreamReceiverFunc = cre MockDevice::MockDevice() : MockDevice(new MockExecutionEnvironment(), 0u) { - initializeMemoryManager(); - CommandStreamReceiver *commandStreamReceiver = createCommandStream(*this->executionEnvironment, this->getRootDeviceIndex(), this->getDeviceBitfield()); + UltDeviceFactory::initializeMemoryManager(*executionEnvironment); + CommandStreamReceiver *commandStreamReceiver = createCommandStream(*executionEnvironment, this->getRootDeviceIndex(), this->getDeviceBitfield()); commandStreamReceivers.resize(1); commandStreamReceivers[0].reset(commandStreamReceiver); this->engines.resize(1); @@ -41,7 +42,7 @@ const char *MockDevice::getProductAbbrev() const { MockDevice::MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex) : RootDevice(executionEnvironment, rootDeviceIndex) { - initializeMemoryManager(); + UltDeviceFactory::initializeMemoryManager(*executionEnvironment); this->osTime = MockOSTime::create(); this->engineGroups.resize(static_cast(EngineGroupType::MaxEngineGroups)); auto &hwInfo = getHardwareInfo(); @@ -89,15 +90,6 @@ void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr, uint3 } } -void MockDevice::initializeMemoryManager() const { - if (executionEnvironment->memoryManager == nullptr) { - auto &hwInfo = getHardwareInfo(); - bool enableLocalMemory = HwHelper::get(hwInfo.platform.eRenderCoreFamily).getEnableLocalMemory(hwInfo); - bool aubUsage = (testMode == TestMode::AubTests) || (testMode == TestMode::AubTestsWithTbx); - executionEnvironment->memoryManager.reset(new MockMemoryManager(false, enableLocalMemory, aubUsage, *executionEnvironment)); - } -} - MockAlignedMallocManagerDevice::MockAlignedMallocManagerDevice(ExecutionEnvironment *executionEnvironment, uint32_t internalDeviceIndex) : MockDevice(executionEnvironment, internalDeviceIndex) { executionEnvironment->memoryManager.reset(new MockAllocSysMemAgnosticMemoryManager(*executionEnvironment)); } diff --git a/shared/test/unit_test/mocks/mock_device.h b/shared/test/unit_test/mocks/mock_device.h index 41116b8405..0bbb205dba 100644 --- a/shared/test/unit_test/mocks/mock_device.h +++ b/shared/test/unit_test/mocks/mock_device.h @@ -128,9 +128,6 @@ class MockDevice : public RootDevice { } static decltype(&createCommandStream) createCommandStreamReceiverFunc; - - private: - void initializeMemoryManager() const; }; template <> diff --git a/shared/test/unit_test/mocks/ult_device_factory.cpp b/shared/test/unit_test/mocks/ult_device_factory.cpp index c841e0a413..8cdbbd8def 100644 --- a/shared/test/unit_test/mocks/ult_device_factory.cpp +++ b/shared/test/unit_test/mocks/ult_device_factory.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -12,6 +12,8 @@ #include "shared/test/unit_test/helpers/variable_backup.h" #include "shared/test/unit_test/mocks/mock_device.h" +#include "opencl/test/unit_test/mocks/mock_memory_manager.h" + using namespace NEO; UltDeviceFactory::UltDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevicesCount) @@ -22,12 +24,14 @@ UltDeviceFactory::UltDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevice DebugManagerStateRestore restorer; VariableBackup createSingleDeviceBackup{&MockDevice::createSingleDevice, false}; VariableBackup createRootDeviceFuncBackup{&DeviceFactory::createRootDeviceFunc}; + VariableBackup createMemoryManagerFuncBackup{&DeviceFactory::createMemoryManagerFunc}; DebugManager.flags.CreateMultipleRootDevices.set(rootDevicesCount); DebugManager.flags.CreateMultipleSubDevices.set(subDevicesCount); createRootDeviceFuncBackup = [](ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) -> std::unique_ptr { return std::unique_ptr(MockDevice::create(&executionEnvironment, rootDeviceIndex)); }; + createMemoryManagerFuncBackup = UltDeviceFactory::initializeMemoryManager; auto createdDevices = DeviceFactory::createDevices(executionEnvironment); @@ -46,7 +50,7 @@ UltDeviceFactory::~UltDeviceFactory() { } } -void NEO::UltDeviceFactory::prepareDeviceEnvironments(ExecutionEnvironment &executionEnvironment, uint32_t rootDevicesCount) { +void UltDeviceFactory::prepareDeviceEnvironments(ExecutionEnvironment &executionEnvironment, uint32_t rootDevicesCount) { uint32_t numRootDevices = rootDevicesCount; executionEnvironment.prepareRootDeviceEnvironments(numRootDevices); for (auto i = 0u; i < numRootDevices; i++) { @@ -59,3 +63,11 @@ void NEO::UltDeviceFactory::prepareDeviceEnvironments(ExecutionEnvironment &exec executionEnvironment.calculateMaxOsContextCount(); DeviceFactory::createMemoryManagerFunc(executionEnvironment); } +bool UltDeviceFactory::initializeMemoryManager(ExecutionEnvironment &executionEnvironment) { + if (executionEnvironment.memoryManager == nullptr) { + bool enableLocalMemory = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getEnableLocalMemory(*defaultHwInfo); + bool aubUsage = (testMode == TestMode::AubTests) || (testMode == TestMode::AubTestsWithTbx); + executionEnvironment.memoryManager.reset(new MockMemoryManager(false, enableLocalMemory, aubUsage, executionEnvironment)); + } + return true; +} diff --git a/shared/test/unit_test/mocks/ult_device_factory.h b/shared/test/unit_test/mocks/ult_device_factory.h index 68a40d8174..9b741cfde8 100644 --- a/shared/test/unit_test/mocks/ult_device_factory.h +++ b/shared/test/unit_test/mocks/ult_device_factory.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -20,6 +20,7 @@ struct UltDeviceFactory { ~UltDeviceFactory(); static void prepareDeviceEnvironments(ExecutionEnvironment &executionEnvironment, uint32_t rootDevicesCount); + static bool initializeMemoryManager(ExecutionEnvironment &executionEnvironment); std::vector rootDevices; std::vector subDevices;