From 4386d10e4023f560b791f9fee06aef750a87892c Mon Sep 17 00:00:00 2001 From: "Jobczyk, Lukasz" Date: Fri, 8 Mar 2019 12:18:02 +0100 Subject: [PATCH] Reverse logic of creating Memory Manager - part 2 -remove MM initialization from Device::CreateEngines method Change-Id: Iaee268b002cb0f0a4edd07907c12da6dd6076b3a Signed-off-by: Jobczyk, Lukasz --- runtime/device/device.cpp | 5 +---- unit_tests/api/cl_enqueue_verify_memory.inl | 4 ++-- .../create_command_stream_receiver_tests.cpp | 4 +--- unit_tests/device/device_tests.cpp | 8 ++++---- .../execution_environment_tests.cpp | 1 + unit_tests/helpers/execution_environment_helper.cpp | 5 +++++ unit_tests/mocks/mock_device.cpp | 2 +- unit_tests/mocks/mock_device.h | 13 ++++++++++++- .../source_level_debugger_tests.cpp | 8 ++++---- 9 files changed, 31 insertions(+), 19 deletions(-) diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index 407ed6cf61..86d7496cbd 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -164,15 +164,12 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo) { bool Device::createEngines(const HardwareInfo *pHwInfo) { auto defaultEngineType = getChosenEngineType(*pHwInfo); - auto &hwHelper = HwHelper::get(pHwInfo->pPlatform->eRenderCoreFamily); - auto &gpgpuEngines = hwHelper.getGpgpuEngineInstances(); - auto enableLocalMemory = hwHelper.getEnableLocalMemory(*pHwInfo); + auto &gpgpuEngines = HwHelper::get(pHwInfo->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances(); for (uint32_t deviceCsrIndex = 0; deviceCsrIndex < gpgpuEngines.size(); deviceCsrIndex++) { if (!executionEnvironment->initializeCommandStreamReceiver(pHwInfo, getDeviceIndex(), deviceCsrIndex)) { return false; } - executionEnvironment->initializeMemoryManager(getEnabled64kbPages(), enableLocalMemory); auto commandStreamReceiver = executionEnvironment->commandStreamReceivers[getDeviceIndex()][deviceCsrIndex].get(); diff --git a/unit_tests/api/cl_enqueue_verify_memory.inl b/unit_tests/api/cl_enqueue_verify_memory.inl index c443435954..aa3047b956 100644 --- a/unit_tests/api/cl_enqueue_verify_memory.inl +++ b/unit_tests/api/cl_enqueue_verify_memory.inl @@ -14,8 +14,8 @@ using namespace OCLRT; TEST(CheckVerifyMemoryRelatedApiConstants, givenVerifyMemoryRelatedApiConstantsWhenVerifyingTheirValueThenCorrectValuesAreReturned) { - EXPECT_EQ(CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareEqual, CL_MEM_COMPARE_EQUAL); - EXPECT_EQ(CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareNotEqual, CL_MEM_COMPARE_NOT_EQUAL); + EXPECT_EQ(AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareEqual, CL_MEM_COMPARE_EQUAL); + EXPECT_EQ(AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareNotEqual, CL_MEM_COMPARE_NOT_EQUAL); } struct clEnqueueVerifyMemorySettings { diff --git a/unit_tests/command_stream/create_command_stream_receiver_tests.cpp b/unit_tests/command_stream/create_command_stream_receiver_tests.cpp index 4cf6f11f96..eb4d93942f 100644 --- a/unit_tests/command_stream/create_command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/create_command_stream_receiver_tests.cpp @@ -49,12 +49,10 @@ HWTEST_P(CreateCommandStreamReceiverTest, givenCreateCommandStreamWhenCsrIsSetTo if (csrType < CommandStreamReceiverType::CSR_TYPES_NUM) { EXPECT_NE(nullptr, executionEnvironment->commandStreamReceivers[0][0].get()); - executionEnvironment->initializeMemoryManager(false, false); - EXPECT_NE(nullptr, executionEnvironment->memoryManager.get()); } else { EXPECT_EQ(nullptr, executionEnvironment->commandStreamReceivers[0][0]); - EXPECT_EQ(nullptr, executionEnvironment->memoryManager.get()); } + EXPECT_NE(nullptr, executionEnvironment->memoryManager.get()); } static CommandStreamReceiverType commandStreamReceiverTypes[] = { diff --git a/unit_tests/device/device_tests.cpp b/unit_tests/device/device_tests.cpp index a0b849e158..5e0d71d3b3 100644 --- a/unit_tests/device/device_tests.cpp +++ b/unit_tests/device/device_tests.cpp @@ -159,8 +159,8 @@ TEST(DeviceCreation, givenMultiDeviceWhenTheyAreCreatedThenEachOsContextHasUniqu const size_t numDevices = 2; const auto &numGpgpuEngines = static_cast(HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances().size()); - auto device1 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 0u)); - auto device2 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 1u)); + auto device1 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 0u)); + auto device2 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 1u)); auto ®isteredEngines = executionEnvironment.memoryManager->getRegisteredEngines(); EXPECT_EQ(numGpgpuEngines * numDevices, registeredEngines.size()); @@ -182,8 +182,8 @@ TEST(DeviceCreation, givenMultiDeviceWhenTheyAreCreatedThenEachOsContextHasUniqu TEST(DeviceCreation, givenMultiDeviceWhenTheyAreCreatedThenEachDeviceHasSeperateDeviceIndex) { ExecutionEnvironment executionEnvironment; executionEnvironment.incRefInternal(); - auto device = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 0u)); - auto device2 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 1u)); + auto device = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 0u)); + auto device2 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 1u)); EXPECT_EQ(0u, device->getDeviceIndex()); EXPECT_EQ(1u, device2->getDeviceIndex()); diff --git a/unit_tests/execution_environment/execution_environment_tests.cpp b/unit_tests/execution_environment/execution_environment_tests.cpp index a68ad1d54b..619d0dc954 100644 --- a/unit_tests/execution_environment/execution_environment_tests.cpp +++ b/unit_tests/execution_environment/execution_environment_tests.cpp @@ -104,6 +104,7 @@ TEST(ExecutionEnvironment, givenPlatformWhenItIsCreatedThenItCreatesMemoryManage TEST(ExecutionEnvironment, givenDeviceWhenItIsDestroyedThenMemoryManagerIsStillAvailable) { std::unique_ptr executionEnvironment(new ExecutionEnvironment); executionEnvironment->incRefInternal(); + executionEnvironment->initializeMemoryManager(false, false); std::unique_ptr device(Device::create(nullptr, executionEnvironment.get(), 0u)); device.reset(nullptr); EXPECT_NE(nullptr, executionEnvironment->memoryManager); diff --git a/unit_tests/helpers/execution_environment_helper.cpp b/unit_tests/helpers/execution_environment_helper.cpp index e4366d51e7..77568be4a3 100644 --- a/unit_tests/helpers/execution_environment_helper.cpp +++ b/unit_tests/helpers/execution_environment_helper.cpp @@ -7,6 +7,8 @@ #include "unit_tests/helpers/execution_environment_helper.h" +#include "runtime/device/device.h" +#include "runtime/helpers/hw_helper.h" #include "runtime/os_interface/device_factory.h" namespace OCLRT { @@ -16,6 +18,9 @@ ExecutionEnvironment *getExecutionEnvironmentImpl(HardwareInfo *&hwInfo) { size_t numDevicesReturned = 0; hwInfo = nullptr; DeviceFactory::getDevices(&hwInfo, numDevicesReturned, *executionEnvironment); + bool enableLocalMemory = HwHelper::get(hwInfo->pPlatform->eRenderCoreFamily).getEnableLocalMemory(*hwInfo); + executionEnvironment->initializeMemoryManager(Device::getEnabled64kbPages(*hwInfo), enableLocalMemory); + return executionEnvironment; } } // namespace OCLRT diff --git a/unit_tests/mocks/mock_device.cpp b/unit_tests/mocks/mock_device.cpp index 01ceb1e1f9..4e7fb4bd31 100644 --- a/unit_tests/mocks/mock_device.cpp +++ b/unit_tests/mocks/mock_device.cpp @@ -8,7 +8,6 @@ #include "unit_tests/mocks/mock_device.h" #include "runtime/device/driver_info.h" -#include "runtime/helpers/hw_helper.h" #include "runtime/os_interface/os_context.h" #include "unit_tests/mocks/mock_memory_manager.h" #include "unit_tests/mocks/mock_ostime.h" @@ -33,6 +32,7 @@ MockDevice::MockDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executi this->mockMemoryManager.reset(new OsAgnosticMemoryManager(false, enableLocalMemory, aubUsage, *executionEnvironment)); this->osTime = MockOSTime::create(); mockWaTable = *hwInfo.pWaTable; + executionEnvironment->initializeMemoryManager(getEnabled64kbPages(hwInfo), enableLocalMemory); } void MockDevice::setOSTime(OSTime *osTime) { diff --git a/unit_tests/mocks/mock_device.h b/unit_tests/mocks/mock_device.h index 3364dc39ce..9261b270db 100644 --- a/unit_tests/mocks/mock_device.h +++ b/unit_tests/mocks/mock_device.h @@ -7,6 +7,7 @@ #pragma once #include "runtime/device/device.h" +#include "runtime/helpers/hw_helper.h" #include "unit_tests/libult/ult_command_stream_receiver.h" #include "unit_tests/mocks/mock_allocation_properties.h" @@ -113,7 +114,17 @@ class MockDevice : public Device { template <> inline Device *MockDevice::createWithNewExecutionEnvironment(const HardwareInfo *pHwInfo) { - return Device::create(pHwInfo, new ExecutionEnvironment, 0u); + auto executionEnvironment = new ExecutionEnvironment(); + + bool enableLocalMemory = false; + bool enable64kbPages = false; + if (pHwInfo != nullptr) { + enableLocalMemory = HwHelper::get(pHwInfo->pPlatform->eRenderCoreFamily).getEnableLocalMemory(*pHwInfo); + enable64kbPages = getEnabled64kbPages(*pHwInfo); + } + executionEnvironment->initializeMemoryManager(enable64kbPages, enableLocalMemory); + + return Device::create(pHwInfo, executionEnvironment, 0u); } class FailDevice : public MockDevice { diff --git a/unit_tests/source_level_debugger/source_level_debugger_tests.cpp b/unit_tests/source_level_debugger/source_level_debugger_tests.cpp index 4296684db0..4505b0f85f 100644 --- a/unit_tests/source_level_debugger/source_level_debugger_tests.cpp +++ b/unit_tests/source_level_debugger/source_level_debugger_tests.cpp @@ -531,12 +531,12 @@ TEST(SourceLevelDebugger, givenTwoDevicesWhenSecondIsCreatedThenNotCreatingNewSo std::unique_ptr executionEnvironment(new ExecutionEnvironment); executionEnvironment->incRefInternal(); - std::unique_ptr device1(Device::create(nullptr, executionEnvironment.get(), 0u)); + std::unique_ptr device1(Device::create(nullptr, executionEnvironment.get(), 0u)); EXPECT_NE(nullptr, executionEnvironment->memoryManager); EXPECT_TRUE(interceptor.initCalled); interceptor.initCalled = false; - std::unique_ptr device2(Device::create(nullptr, executionEnvironment.get(), 1u)); + std::unique_ptr device2(Device::create(nullptr, executionEnvironment.get(), 1u)); EXPECT_NE(nullptr, executionEnvironment->memoryManager); EXPECT_FALSE(interceptor.initCalled); } @@ -550,9 +550,9 @@ TEST(SourceLevelDebugger, givenMultipleDevicesWhenTheyAreCreatedTheyAllReuseTheS DebuggerLibrary::setDebuggerActive(true); auto executionEnvironment = new ExecutionEnvironment; - std::unique_ptr device1(Device::create(nullptr, executionEnvironment, 0u)); + std::unique_ptr device1(Device::create(nullptr, executionEnvironment, 0u)); auto sourceLevelDebugger = device1->getSourceLevelDebugger(); - std::unique_ptr device2(Device::create(nullptr, executionEnvironment, 1u)); + std::unique_ptr device2(Device::create(nullptr, executionEnvironment, 1u)); EXPECT_EQ(sourceLevelDebugger, device2->getSourceLevelDebugger()); } }