From 878fd43a1a9cbd61ea5ab066b684ee0e0860d781 Mon Sep 17 00:00:00 2001 From: "Jobczyk, Lukasz" Date: Tue, 19 Feb 2019 08:55:11 +0100 Subject: [PATCH] Reverse logic of creating Memory Manager - part 1 -remove CSR::createMemoryManager method -create MM from platform before creating devices Change-Id: I0e7f091c53b0e60ae7101e82a305253af626330e Signed-off-by: Jobczyk, Lukasz --- runtime/aub/aub_center.cpp | 8 ++++--- .../aub_command_stream_receiver_hw.h | 5 ---- .../command_stream/command_stream_receiver.h | 1 - .../command_stream_receiver_with_aub_dump.h | 1 - .../create_command_stream_impl.cpp | 10 ++++++-- .../tbx_command_stream_receiver_hw.h | 3 --- runtime/device/device.cpp | 16 ++++++------- runtime/device/device.h | 1 + runtime/device/device_caps.cpp | 4 ++++ runtime/dll/CMakeLists.txt | 2 ++ .../dll/linux/create_drm_memory_manager.cpp | 18 ++++++++++++++ runtime/dll/linux/drm_neo_create.cpp | 1 - .../windows/create_wddm_memory_manager.cpp | 19 +++++++++++++++ .../execution_environment.cpp | 23 ++++++++++++++++-- .../execution_environment.h | 2 +- runtime/memory_manager/memory_manager.h | 2 +- runtime/os_interface/debug_variables_base.inl | 2 +- .../os_interface/linux/drm_command_stream.h | 1 - .../os_interface/linux/drm_command_stream.inl | 5 ---- runtime/os_interface/linux/drm_neo_create.cpp | 1 - .../os_interface/windows/wddm/wddm_create.cpp | 3 +-- .../windows/wddm_device_command_stream.h | 3 +-- .../windows/wddm_device_command_stream.inl | 5 ---- runtime/platform/platform.cpp | 6 +++++ unit_tests/aub/aub_center_tests.cpp | 1 + .../aub_command_stream_receiver_1_tests.cpp | 17 +++++++------ .../aub_command_stream_receiver_2_tests.cpp | 16 ++++--------- ...and_stream_receiver_flush_task_2_tests.cpp | 2 -- ...nd_stream_receiver_with_aub_dump_tests.cpp | 4 ++-- .../create_command_stream_receiver_tests.cpp | 2 +- .../tbx_command_stream_fixture.cpp | 2 +- unit_tests/device/device_tests.cpp | 6 ----- .../execution_environment_tests.cpp | 17 +++++++++---- unit_tests/libult/CMakeLists.txt | 2 ++ unit_tests/libult/create_command_stream.h | 3 ++- .../libult/ult_command_stream_receiver.h | 4 ---- unit_tests/linux/CMakeLists.txt | 2 ++ unit_tests/memory_manager/surface_tests.cpp | 2 +- unit_tests/mocks/mock_aub_csr.h | 2 +- unit_tests/mocks/mock_tbx_csr.h | 2 +- .../linux/create_drm_memory_manager.cpp | 24 +++++++++++++++++++ .../linux/drm_command_stream_mm_tests.cpp | 4 ++-- .../linux/drm_command_stream_tests.cpp | 4 ++-- .../windows/create_wddm_memory_manager.cpp | 24 +++++++++++++++++++ .../windows/device_command_stream_tests.cpp | 10 ++++---- .../os_interface/windows/wddm_create.cpp | 3 +-- unit_tests/tbx/CMakeLists.txt | 2 ++ unit_tests/tbx/main_tbx.cpp | 4 ++-- unit_tests/test_files/igdrcl.config | 2 +- 49 files changed, 198 insertions(+), 105 deletions(-) create mode 100644 runtime/dll/linux/create_drm_memory_manager.cpp create mode 100644 runtime/dll/windows/create_wddm_memory_manager.cpp create mode 100644 unit_tests/os_interface/linux/create_drm_memory_manager.cpp create mode 100644 unit_tests/os_interface/windows/create_wddm_memory_manager.cpp diff --git a/runtime/aub/aub_center.cpp b/runtime/aub/aub_center.cpp index 7b276f8035..667eb5a9f8 100644 --- a/runtime/aub/aub_center.cpp +++ b/runtime/aub/aub_center.cpp @@ -23,9 +23,11 @@ AubCenter::AubCenter(const HardwareInfo *pHwInfo, bool localMemoryEnabled, const if (DebugManager.flags.UseAubStream.get()) { auto devicesCount = AubHelper::getDevicesCount(pHwInfo); auto memoryBankSize = AubHelper::getMemBankSize(pHwInfo); - CommandStreamReceiverType type = static_cast(DebugManager.flags.SetCommandStreamReceiver.get() != CommandStreamReceiverType::CSR_HW - ? DebugManager.flags.SetCommandStreamReceiver.get() - : csrType); + CommandStreamReceiverType type = csrType; + if (DebugManager.flags.SetCommandStreamReceiver.get() >= CommandStreamReceiverType::CSR_HW) { + type = static_cast(DebugManager.flags.SetCommandStreamReceiver.get()); + } + aubStreamMode = getAubStreamMode(aubFileName, type); if (DebugManager.flags.AubDumpAddMmioRegistersList.get() != "unk") { diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.h b/runtime/command_stream/aub_command_stream_receiver_hw.h index 5819216cb7..64cb218567 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.h +++ b/runtime/command_stream/aub_command_stream_receiver_hw.h @@ -86,11 +86,6 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHwexecutionEnvironment); - } - AubSubCaptureManager *subCaptureManager = nullptr; uint32_t aubDeviceId; bool standalone; diff --git a/runtime/command_stream/command_stream_receiver.h b/runtime/command_stream/command_stream_receiver.h index a06e793874..1fb996366a 100644 --- a/runtime/command_stream/command_stream_receiver.h +++ b/runtime/command_stream/command_stream_receiver.h @@ -85,7 +85,6 @@ class CommandStreamReceiver { void ensureCommandBufferAllocation(LinearStream &commandStream, size_t minimumRequiredSize, size_t additionalAllocationSize); MemoryManager *getMemoryManager() const; - virtual MemoryManager *createMemoryManager(bool enable64kbPages, bool enableLocalMemory) { return nullptr; } ResidencyContainer &getResidencyAllocations(); ResidencyContainer &getEvictionAllocations(); diff --git a/runtime/command_stream/command_stream_receiver_with_aub_dump.h b/runtime/command_stream/command_stream_receiver_with_aub_dump.h index f0a61b4468..9c9f1a6300 100644 --- a/runtime/command_stream/command_stream_receiver_with_aub_dump.h +++ b/runtime/command_stream/command_stream_receiver_with_aub_dump.h @@ -18,7 +18,6 @@ class CommandStreamReceiverWithAUBDump : public BaseCSR { using BaseCSR::osContext; public: - using BaseCSR::createMemoryManager; CommandStreamReceiverWithAUBDump(const HardwareInfo &hwInfoIn, const std::string &baseName, ExecutionEnvironment &executionEnvironment); CommandStreamReceiverWithAUBDump(const CommandStreamReceiverWithAUBDump &) = delete; diff --git a/runtime/command_stream/create_command_stream_impl.cpp b/runtime/command_stream/create_command_stream_impl.cpp index d64324abbf..5d0b11b60c 100644 --- a/runtime/command_stream/create_command_stream_impl.cpp +++ b/runtime/command_stream/create_command_stream_impl.cpp @@ -22,7 +22,10 @@ CommandStreamReceiver *createCommandStreamImpl(const HardwareInfo *pHwInfo, Exec return nullptr; } CommandStreamReceiver *commandStreamReceiver = nullptr; - int32_t csr = DebugManager.flags.SetCommandStreamReceiver.get(); + int32_t csr = CommandStreamReceiverType::CSR_HW; + if (DebugManager.flags.SetCommandStreamReceiver.get() >= 0) { + csr = DebugManager.flags.SetCommandStreamReceiver.get(); + } if (csr) { switch (csr) { case CSR_AUB: @@ -48,7 +51,10 @@ CommandStreamReceiver *createCommandStreamImpl(const HardwareInfo *pHwInfo, Exec bool getDevicesImpl(HardwareInfo **hwInfo, size_t &numDevicesReturned, ExecutionEnvironment &executionEnvironment) { bool result; - int32_t csr = DebugManager.flags.SetCommandStreamReceiver.get(); + int32_t csr = CommandStreamReceiverType::CSR_HW; + if (DebugManager.flags.SetCommandStreamReceiver.get() >= 0) { + csr = DebugManager.flags.SetCommandStreamReceiver.get(); + } if (csr) { switch (csr) { case CSR_AUB: diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.h b/runtime/command_stream/tbx_command_stream_receiver_hw.h index e9ed18ba0f..4bf5d20634 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.h +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.h @@ -64,9 +64,6 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHwexecutionEnvironment); - } TbxMemoryManager *getMemoryManager() { return (TbxMemoryManager *)CommandStreamReceiver::getMemoryManager(); } diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index ec24573f68..407ed6cf61 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -95,15 +95,13 @@ Device::~Device() { executionEnvironment->sourceLevelDebugger->notifyDeviceDestruction(); } - if (executionEnvironment->memoryManager) { - if (preemptionAllocation) { - executionEnvironment->memoryManager->freeGraphicsMemory(preemptionAllocation); - preemptionAllocation = nullptr; - } - executionEnvironment->memoryManager->waitForDeletions(); - - alignedFree(this->slmWindowStartAddress); + if (preemptionAllocation) { + executionEnvironment->memoryManager->freeGraphicsMemory(preemptionAllocation); + preemptionAllocation = nullptr; } + executionEnvironment->memoryManager->waitForDeletions(); + + alignedFree(this->slmWindowStartAddress); executionEnvironment->decRefInternal(); } @@ -174,7 +172,7 @@ bool Device::createEngines(const HardwareInfo *pHwInfo) { if (!executionEnvironment->initializeCommandStreamReceiver(pHwInfo, getDeviceIndex(), deviceCsrIndex)) { return false; } - executionEnvironment->initializeMemoryManager(getEnabled64kbPages(), enableLocalMemory, getDeviceIndex(), deviceCsrIndex); + executionEnvironment->initializeMemoryManager(getEnabled64kbPages(), enableLocalMemory); auto commandStreamReceiver = executionEnvironment->commandStreamReceivers[getDeviceIndex()][deviceCsrIndex].get(); diff --git a/runtime/device/device.h b/runtime/device/device.h index 51bf62f1ba..daa7d5505b 100644 --- a/runtime/device/device.h +++ b/runtime/device/device.h @@ -112,6 +112,7 @@ class Device : public BaseObject<_cl_device_id> { std::string deviceExtensions; std::string name; bool getEnabled64kbPages() const; + static bool getEnabled64kbPages(const HardwareInfo &hwInfo); bool isSourceLevelDebuggerActive() const; SourceLevelDebugger *getSourceLevelDebugger() { return executionEnvironment->sourceLevelDebugger.get(); } ExecutionEnvironment *getExecutionEnvironment() const { return executionEnvironment; } diff --git a/runtime/device/device_caps.cpp b/runtime/device/device_caps.cpp index 66ed62f7de..cb48f68d69 100644 --- a/runtime/device/device_caps.cpp +++ b/runtime/device/device_caps.cpp @@ -43,6 +43,10 @@ static constexpr cl_device_fp_config defaultFpFlags = static_casthwInfo); +} + +bool Device::getEnabled64kbPages(const HardwareInfo &hwInfo) { if (DebugManager.flags.Enable64kbpages.get() == -1) { // assign value according to os and hw configuration return OSInterface::osEnabled64kbPages && hwInfo.capabilityTable.ftr64KBpages; diff --git a/runtime/dll/CMakeLists.txt b/runtime/dll/CMakeLists.txt index 818132b2b2..f35bcd5580 100644 --- a/runtime/dll/CMakeLists.txt +++ b/runtime/dll/CMakeLists.txt @@ -34,6 +34,7 @@ set(RUNTIME_SRCS_DLL_BASE set(RUNTIME_SRCS_DLL_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/linux/allocator_helper.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/linux/create_drm_memory_manager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/linux/devices${BRANCH_DIR_SUFFIX}/devices.inl ${CMAKE_CURRENT_SOURCE_DIR}/linux/devices/devices_base.inl ${CMAKE_CURRENT_SOURCE_DIR}/linux/drm_neo_create.cpp @@ -42,6 +43,7 @@ set(RUNTIME_SRCS_DLL_LINUX ) set(RUNTIME_SRCS_DLL_WINDOWS + ${CMAKE_CURRENT_SOURCE_DIR}/windows/create_wddm_memory_manager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/windows/environment_variables.cpp ${CMAKE_CURRENT_SOURCE_DIR}/windows/options.cpp ${CMAKE_CURRENT_SOURCE_DIR}/windows/os_interface.cpp diff --git a/runtime/dll/linux/create_drm_memory_manager.cpp b/runtime/dll/linux/create_drm_memory_manager.cpp new file mode 100644 index 0000000000..74400b9a03 --- /dev/null +++ b/runtime/dll/linux/create_drm_memory_manager.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/execution_environment/execution_environment.h" +#include "runtime/memory_manager/memory_manager.h" +#include "runtime/os_interface/linux/drm_memory_manager.h" +#include "runtime/os_interface/linux/os_interface.h" +#include "runtime/os_interface/os_interface.h" + +namespace OCLRT { +std::unique_ptr MemoryManager::createMemoryManager(bool enable64KBpages, bool enableLocalMemory, ExecutionEnvironment &executionEnvironment) { + return std::make_unique(executionEnvironment.osInterface->get()->getDrm(), gemCloseWorkerMode::gemCloseWorkerActive, DebugManager.flags.EnableForcePin.get(), true, executionEnvironment); +} +} // namespace OCLRT diff --git a/runtime/dll/linux/drm_neo_create.cpp b/runtime/dll/linux/drm_neo_create.cpp index 8cb78674d2..31f2b8c87c 100644 --- a/runtime/dll/linux/drm_neo_create.cpp +++ b/runtime/dll/linux/drm_neo_create.cpp @@ -191,5 +191,4 @@ Drm *Drm::create(int32_t deviceOrdinal) { drms[deviceOrdinal % drms.size()] = drmObject.release(); return drms[deviceOrdinal % drms.size()]; } - } // namespace OCLRT diff --git a/runtime/dll/windows/create_wddm_memory_manager.cpp b/runtime/dll/windows/create_wddm_memory_manager.cpp new file mode 100644 index 0000000000..2b897e67b2 --- /dev/null +++ b/runtime/dll/windows/create_wddm_memory_manager.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/execution_environment/execution_environment.h" +#include "runtime/memory_manager/memory_manager.h" +#include "runtime/os_interface/debug_settings_manager.h" +#include "runtime/os_interface/os_interface.h" +#include "runtime/os_interface/windows/os_interface.h" +#include "runtime/os_interface/windows/wddm_memory_manager.h" + +namespace OCLRT { +std::unique_ptr MemoryManager::createMemoryManager(bool enable64KBpages, bool enableLocalMemory, ExecutionEnvironment &executionEnvironment) { + return std::make_unique(enable64KBpages, enableLocalMemory, executionEnvironment.osInterface->get()->getWddm(), executionEnvironment); +} +} // namespace OCLRT diff --git a/runtime/execution_environment/execution_environment.cpp b/runtime/execution_environment/execution_environment.cpp index da7ed6b533..fd10821469 100644 --- a/runtime/execution_environment/execution_environment.cpp +++ b/runtime/execution_environment/execution_environment.cpp @@ -11,6 +11,7 @@ #include "runtime/built_ins/built_ins.h" #include "runtime/built_ins/sip.h" #include "runtime/command_stream/command_stream_receiver.h" +#include "runtime/command_stream/tbx_command_stream_receiver_hw.h" #include "runtime/compiler_interface/compiler_interface.h" #include "runtime/gmm_helper/gmm_helper.h" #include "runtime/helpers/hw_helper.h" @@ -56,12 +57,30 @@ bool ExecutionEnvironment::initializeCommandStreamReceiver(const HardwareInfo *p this->commandStreamReceivers[deviceIndex][deviceCsrIndex] = std::move(commandStreamReceiver); return true; } -void ExecutionEnvironment::initializeMemoryManager(bool enable64KBpages, bool enableLocalMemory, uint32_t deviceIndex, uint32_t deviceCsrIndex) { +void ExecutionEnvironment::initializeMemoryManager(bool enable64KBpages, bool enableLocalMemory) { if (this->memoryManager) { return; } - memoryManager.reset(commandStreamReceivers[deviceIndex][deviceCsrIndex]->createMemoryManager(enable64KBpages, enableLocalMemory)); + int32_t setCommandStreamReceiverType = CommandStreamReceiverType::CSR_HW; + if (DebugManager.flags.SetCommandStreamReceiver.get() >= 0) { + setCommandStreamReceiverType = DebugManager.flags.SetCommandStreamReceiver.get(); + } + + switch (setCommandStreamReceiverType) { + case CommandStreamReceiverType::CSR_TBX: + case CommandStreamReceiverType::CSR_TBX_WITH_AUB: + memoryManager = std::make_unique(enable64KBpages, enableLocalMemory, *this); + break; + case CommandStreamReceiverType::CSR_AUB: + memoryManager = std::make_unique(enable64KBpages, enableLocalMemory, *this); + break; + case CommandStreamReceiverType::CSR_HW: + case CommandStreamReceiverType::CSR_HW_WITH_AUB: + default: + memoryManager = MemoryManager::createMemoryManager(enable64KBpages, enableLocalMemory, *this); + break; + } DEBUG_BREAK_IF(!this->memoryManager); } void ExecutionEnvironment::initSourceLevelDebugger(const HardwareInfo &hwInfo) { diff --git a/runtime/execution_environment/execution_environment.h b/runtime/execution_environment/execution_environment.h index e0a286a926..a0b55f68d3 100644 --- a/runtime/execution_environment/execution_environment.h +++ b/runtime/execution_environment/execution_environment.h @@ -45,7 +45,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject void initGmm(const HardwareInfo *hwInfo); bool initializeCommandStreamReceiver(const HardwareInfo *pHwInfo, uint32_t deviceIndex, uint32_t deviceCsrIndex); void initializeSpecialCommandStreamReceiver(const HardwareInfo &hwInfo); - void initializeMemoryManager(bool enable64KBpages, bool enableLocalMemory, uint32_t deviceIndex, uint32_t deviceCsrIndex); + void initializeMemoryManager(bool enable64KBpages, bool enableLocalMemory); void initSourceLevelDebugger(const HardwareInfo &hwInfo); GmmHelper *getGmmHelper() const; diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index 17984832f4..96c78ee7e8 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -192,8 +192,8 @@ class MemoryManager { HostPtrManager *getHostPtrManager() const { return hostPtrManager.get(); } void setDefaultEngineIndex(uint32_t index) { defaultEngineIndex = index; } virtual bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, uint32_t sizeToCopy) const; - static HeapIndex selectHeap(const GraphicsAllocation *allocation, const void *ptr, const HardwareInfo &hwInfo); + static std::unique_ptr createMemoryManager(bool enable64KBpages, bool enableLocalMemory, ExecutionEnvironment &exeEnv); protected: struct AllocationData { diff --git a/runtime/os_interface/debug_variables_base.inl b/runtime/os_interface/debug_variables_base.inl index 87da855e23..acfbb8a51a 100644 --- a/runtime/os_interface/debug_variables_base.inl +++ b/runtime/os_interface/debug_variables_base.inl @@ -25,7 +25,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, AUBDumpFilterKernelEndIdx, -1, "End index of ker DECLARE_DEBUG_VARIABLE(int32_t, AUBDumpToggleCaptureOnOff, 0, "Toggle AUB capture on/off") DECLARE_DEBUG_VARIABLE(int32_t, AubDumpOverrideMmioRegister, 0, "Override mmio offset from list with new value from AubDumpOverrideMmioRegisterValue") DECLARE_DEBUG_VARIABLE(int32_t, AubDumpOverrideMmioRegisterValue, 0, "Value to override mmio offset from AubDumpOverrideMmioRegister") -DECLARE_DEBUG_VARIABLE(int32_t, SetCommandStreamReceiver, 0, "Set command stream receiver to: 0 - HW, 1 - AUB, 2 - TBX, 3 - HW & AUB, 4 - TBX & AUB") +DECLARE_DEBUG_VARIABLE(int32_t, SetCommandStreamReceiver, -1, "Set command stream receiver to: 0 - HW, 1 - AUB, 2 - TBX, 3 - HW & AUB, 4 - TBX & AUB") DECLARE_DEBUG_VARIABLE(int32_t, TbxPort, 4321, "TCP-IP port of TBX server") DECLARE_DEBUG_VARIABLE(bool, FlattenBatchBufferForAUBDump, false, "Dump multi-level batch buffers to AUB as single, flat batch buffer") DECLARE_DEBUG_VARIABLE(bool, AddPatchInfoCommentsForAUBDump, false, "Dump comments containing allocations and patching information") diff --git a/runtime/os_interface/linux/drm_command_stream.h b/runtime/os_interface/linux/drm_command_stream.h index 0f3bcc05ea..b8099142f7 100644 --- a/runtime/os_interface/linux/drm_command_stream.h +++ b/runtime/os_interface/linux/drm_command_stream.h @@ -44,7 +44,6 @@ class DrmCommandStreamReceiver : public DeviceCommandStreamReceiver { bool waitForFlushStamp(FlushStamp &flushStampToWait) override; DrmMemoryManager *getMemoryManager(); - MemoryManager *createMemoryManager(bool enable64kbPages, bool enableLocalMemory) override; gemCloseWorkerMode peekGemCloseWorkerOperationMode() { return this->gemCloseWorkerOperationMode; diff --git a/runtime/os_interface/linux/drm_command_stream.inl b/runtime/os_interface/linux/drm_command_stream.inl index 32fad58536..8e9c28c77b 100644 --- a/runtime/os_interface/linux/drm_command_stream.inl +++ b/runtime/os_interface/linux/drm_command_stream.inl @@ -147,11 +147,6 @@ DrmMemoryManager *DrmCommandStreamReceiver::getMemoryManager() { return (DrmMemoryManager *)CommandStreamReceiver::getMemoryManager(); } -template -MemoryManager *DrmCommandStreamReceiver::createMemoryManager(bool enable64kbPages, bool enableLocalMemory) { - return new DrmMemoryManager(this->drm, this->gemCloseWorkerOperationMode, DebugManager.flags.EnableForcePin.get(), true, this->executionEnvironment); -} - template bool DrmCommandStreamReceiver::waitForFlushStamp(FlushStamp &flushStamp) { drm_i915_gem_wait wait = {}; diff --git a/runtime/os_interface/linux/drm_neo_create.cpp b/runtime/os_interface/linux/drm_neo_create.cpp index a71b68822b..a5096e3baf 100644 --- a/runtime/os_interface/linux/drm_neo_create.cpp +++ b/runtime/os_interface/linux/drm_neo_create.cpp @@ -5,7 +5,6 @@ * */ -#include "runtime/helpers/options.h" #include "runtime/os_interface/linux/drm_neo.h" namespace OCLRT { diff --git a/runtime/os_interface/windows/wddm/wddm_create.cpp b/runtime/os_interface/windows/wddm/wddm_create.cpp index efc791dc16..1ea901298a 100644 --- a/runtime/os_interface/windows/wddm/wddm_create.cpp +++ b/runtime/os_interface/windows/wddm/wddm_create.cpp @@ -1,11 +1,10 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * */ -#include "runtime/os_interface/debug_settings_manager.h" #include "runtime/os_interface/windows/wddm/wddm.h" namespace OCLRT { diff --git a/runtime/os_interface/windows/wddm_device_command_stream.h b/runtime/os_interface/windows/wddm_device_command_stream.h index ec605f3445..1f00242396 100644 --- a/runtime/os_interface/windows/wddm_device_command_stream.h +++ b/runtime/os_interface/windows/wddm_device_command_stream.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -31,7 +31,6 @@ class WddmCommandStreamReceiver : public DeviceCommandStreamReceiver bool waitForFlushStamp(FlushStamp &flushStampToWait) override; WddmMemoryManager *getMemoryManager(); - MemoryManager *createMemoryManager(bool enable64kbPages, bool enableLocalMemory); Wddm *peekWddm() { return wddm; } diff --git a/runtime/os_interface/windows/wddm_device_command_stream.inl b/runtime/os_interface/windows/wddm_device_command_stream.inl index eefce4b675..ae88ab221d 100644 --- a/runtime/os_interface/windows/wddm_device_command_stream.inl +++ b/runtime/os_interface/windows/wddm_device_command_stream.inl @@ -137,11 +137,6 @@ WddmMemoryManager *WddmCommandStreamReceiver::getMemoryManager() { return static_cast(CommandStreamReceiver::getMemoryManager()); } -template -MemoryManager *WddmCommandStreamReceiver::createMemoryManager(bool enable64kbPages, bool enableLocalMemory) { - return new WddmMemoryManager(enable64kbPages, enableLocalMemory, this->wddm, executionEnvironment); -} - template bool WddmCommandStreamReceiver::waitForFlushStamp(FlushStamp &flushStampToWait) { return wddm->waitFromCpu(flushStampToWait, static_cast(osContext)->getResidencyController().getMonitoredFence()); diff --git a/runtime/platform/platform.cpp b/runtime/platform/platform.cpp index c0f9a5d86e..923eb95d9c 100644 --- a/runtime/platform/platform.cpp +++ b/runtime/platform/platform.cpp @@ -23,6 +23,7 @@ #include "runtime/helpers/string.h" #include "runtime/os_interface/debug_settings_manager.h" #include "runtime/os_interface/device_factory.h" +#include "runtime/os_interface/os_interface.h" #include "runtime/platform/extensions.h" #include "runtime/sharings/sharing_factory.h" #include "runtime/source_level_debugger/source_level_debugger.h" @@ -140,6 +141,11 @@ bool Platform::initialize() { return false; } + auto &hwHelper = HwHelper::get(hwInfo->pPlatform->eRenderCoreFamily); + auto enableLocalMemory = hwHelper.getEnableLocalMemory(*hwInfo); + + executionEnvironment->initializeMemoryManager(Device::getEnabled64kbPages(*hwInfo), enableLocalMemory); + DEBUG_BREAK_IF(this->platformInfo); this->platformInfo.reset(new PlatformInfo); diff --git a/unit_tests/aub/aub_center_tests.cpp b/unit_tests/aub/aub_center_tests.cpp index 00cbe987cf..fcd9877254 100644 --- a/unit_tests/aub/aub_center_tests.cpp +++ b/unit_tests/aub/aub_center_tests.cpp @@ -89,6 +89,7 @@ TEST(AubCenter, GivenCsrTypeWhenGettingAubStreamModeThenCorrectModeIsReturned) { TEST(AubCenter, GivenSetCommandStreamReceiverFlagEqualDefaultHwWhenAubManagerIsCreatedThenCsrTypeDefinesAubStreamMode) { DebugManagerStateRestore restorer; DebugManager.flags.UseAubStream.set(true); + DebugManager.flags.SetCommandStreamReceiver.set(-1); std::vector aubTypes = {CommandStreamReceiverType::CSR_HW, CommandStreamReceiverType::CSR_HW_WITH_AUB, diff --git a/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp index f54d2c5ea6..b1471a214b 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp @@ -129,7 +129,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrWhenItIsCreatedWithDebugSetti HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenItIsCreatedThenMemoryManagerIsNotNull) { std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(**platformDevices, "", true, *pDevice->executionEnvironment)); - std::unique_ptr memoryManager(aubCsr->createMemoryManager(false, false)); + std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false, *pDevice->executionEnvironment)); EXPECT_NE(nullptr, memoryManager.get()); } @@ -251,7 +251,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptur HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWhenMakeResidentCalledMultipleTimesAffectsResidencyOnce) { std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); - memoryManager.reset(aubCsr->createMemoryManager(false, false)); + memoryManager.reset(new OsAgnosticMemoryManager(false, false, *pDevice->executionEnvironment)); aubCsr->setupContext(*pDevice->getDefaultEngine().osContext); auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); @@ -693,8 +693,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMe std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); aubCsr->setupContext(*pDevice->getDefaultEngine().osContext); - - memoryManager.reset(aubCsr->createMemoryManager(false, false)); + memoryManager.reset(new OsAgnosticMemoryManager(false, false, *pDevice->executionEnvironment)); auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); @@ -718,7 +717,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMe HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcessResidencyIsCalledOnBufferAndImageAllocationsThenAllocationsTypesShouldBeMadeNonAubWritable) { std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); - memoryManager.reset(aubCsr->createMemoryManager(false, false)); + memoryManager.reset(new OsAgnosticMemoryManager(false, false, *pDevice->executionEnvironment)); aubCsr->setupContext(*pDevice->getDefaultEngine().osContext); auto gfxBufferAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER}); @@ -739,7 +738,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptur DebugManagerStateRestore stateRestore; std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new MockAubCsrToTestDumpAubNonWritable(*platformDevices[0], "", true, *pDevice->executionEnvironment)); - memoryManager.reset(aubCsr->createMemoryManager(false, false)); + memoryManager.reset(new OsAgnosticMemoryManager(false, false, *pDevice->executionEnvironment)); aubCsr->setupContext(*pDevice->getDefaultEngine().osContext); auto gfxBufferAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER}); @@ -764,7 +763,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess DebugManagerStateRestore stateRestore; std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new MockAubCsrToTestDumpAubNonWritable(*platformDevices[0], "", true, *pDevice->executionEnvironment)); - memoryManager.reset(aubCsr->createMemoryManager(false, false)); + memoryManager.reset(new OsAgnosticMemoryManager(false, false, *pDevice->executionEnvironment)); aubCsr->setupContext(*pDevice->getDefaultEngine().osContext); auto gfxBufferAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER}); @@ -803,7 +802,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGraphic std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); aubCsr->setupContext(*pDevice->getDefaultEngine().osContext); - memoryManager.reset(aubCsr->createMemoryManager(false, false)); + memoryManager.reset(new OsAgnosticMemoryManager(false, false, *pDevice->executionEnvironment)); auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); @@ -815,7 +814,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGraphic HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGraphicsAllocationTypeIsNonAubWritableThenWriteMemoryIsNotAllowed) { std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); - memoryManager.reset(aubCsr->createMemoryManager(false, false)); + memoryManager.reset(new OsAgnosticMemoryManager(false, false, *pDevice->executionEnvironment)); auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); diff --git a/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp index 1ebc76d18d..b79b1e8dce 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp @@ -51,9 +51,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedBatchBufferFlatteningInImmediateDispatchModeThenNewCombinedBatchBufferIsCreated) { - std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); - memoryManager.reset(aubCsr->createMemoryManager(false, false)); + std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false, *pDevice->executionEnvironment)); auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(*pDevice->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(flatBatchBufferHelper); @@ -81,9 +80,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedBatchBufferInImmediateDispatchModeAndNoChainedBatchBufferThenCombinedBatchBufferIsNotCreated) { - std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); - memoryManager.reset(aubCsr->createMemoryManager(false, false)); + std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false, *pDevice->executionEnvironment)); auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(*pDevice->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(flatBatchBufferHelper); @@ -105,9 +103,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedBatchBufferAndNotImmediateOrBatchedDispatchModeThenCombinedBatchBufferIsNotCreated) { - std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); - memoryManager.reset(aubCsr->createMemoryManager(false, false)); + std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false, *pDevice->executionEnvironment)); auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(*pDevice->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(flatBatchBufferHelper); @@ -389,9 +386,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGetIndi HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGetIndirectPatchCommandsIsCalledForNonEmptyPatchInfoListThenIndirectPatchCommandBufferIsCreated) { typedef typename FamilyType::MI_STORE_DATA_IMM MI_STORE_DATA_IMM; - std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); - memoryManager.reset(aubCsr->createMemoryManager(false, false)); PatchInfoData patchInfo1(0xA000, 0u, PatchInfoAllocationType::KernelArg, 0x6000, 0x100, PatchInfoAllocationType::IndirectObjectHeap); PatchInfoData patchInfo2(0xB000, 0u, PatchInfoAllocationType::KernelArg, 0x6000, 0x200, PatchInfoAllocationType::IndirectObjectHeap); @@ -416,9 +411,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAddBatc DebugManagerStateRestore dbgRestore; DebugManager.flags.FlattenBatchBufferForAUBDump.set(true); - std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); - memoryManager.reset(aubCsr->createMemoryManager(false, false)); MI_BATCH_BUFFER_START bbStart; @@ -657,11 +650,10 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMemoryIsCalledThenGraphicsAllocationSizeIsReadCorrectly) { - std::unique_ptr memoryManager(nullptr); pDevice->executionEnvironment->aubCenter.reset(new AubCenter()); auto aubCsr = std::make_unique>(*platformDevices[0], "", false, *pDevice->executionEnvironment); - memoryManager.reset(aubCsr->createMemoryManager(false, false)); + std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false, *pDevice->executionEnvironment)); PhysicalAddressAllocator allocator; struct PpgttMock : std::conditional::type { diff --git a/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp b/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp index a7fc5f8ebd..ed426aa3c3 100644 --- a/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp @@ -388,8 +388,6 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, CreateCommandStreamReceiverHw) { auto csrHw = CommandStreamReceiverHw::create(hwInfo, executionEnvironment); EXPECT_NE(nullptr, csrHw); - MemoryManager *mm = csrHw->createMemoryManager(false, false); - EXPECT_EQ(nullptr, mm); GmmPageTableMngr *ptm = csrHw->createPageTableManager(); EXPECT_EQ(nullptr, ptm); delete csrHw; diff --git a/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp b/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp index f931b466c7..11060bc32a 100644 --- a/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp @@ -105,8 +105,8 @@ struct CommandStreamReceiverWithAubDumpTest : public ::testing::TestWithParam(DEFAULT_TEST_PLATFORM::hwInfo, createAubCSR, executionEnvironment); ASSERT_NE(nullptr, csrWithAubDump); - memoryManager = csrWithAubDump->createMemoryManager(false, false); - executionEnvironment.memoryManager.reset(memoryManager); + executionEnvironment.initializeMemoryManager(false, false); + memoryManager = executionEnvironment.memoryManager.get(); ASSERT_NE(nullptr, memoryManager); auto osContext = executionEnvironment.memoryManager->createAndRegisterOsContext(csrWithAubDump, 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 c26d45b399..4cf6f11f96 100644 --- a/unit_tests/command_stream/create_command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/create_command_stream_receiver_tests.cpp @@ -49,7 +49,7 @@ HWTEST_P(CreateCommandStreamReceiverTest, givenCreateCommandStreamWhenCsrIsSetTo if (csrType < CommandStreamReceiverType::CSR_TYPES_NUM) { EXPECT_NE(nullptr, executionEnvironment->commandStreamReceivers[0][0].get()); - executionEnvironment->memoryManager.reset(executionEnvironment->commandStreamReceivers[0][0]->createMemoryManager(false, false)); + executionEnvironment->initializeMemoryManager(false, false); EXPECT_NE(nullptr, executionEnvironment->memoryManager.get()); } else { EXPECT_EQ(nullptr, executionEnvironment->commandStreamReceivers[0][0]); diff --git a/unit_tests/command_stream/tbx_command_stream_fixture.cpp b/unit_tests/command_stream/tbx_command_stream_fixture.cpp index 20214c9a61..ef3fbd7e30 100644 --- a/unit_tests/command_stream/tbx_command_stream_fixture.cpp +++ b/unit_tests/command_stream/tbx_command_stream_fixture.cpp @@ -22,7 +22,7 @@ void TbxCommandStreamFixture::SetUp(MockDevice *pDevice) { const auto &hwInfo = pDevice->getHardwareInfo(); pCommandStreamReceiver = TbxCommandStreamReceiver::create(hwInfo, "", false, *pDevice->executionEnvironment); ASSERT_NE(nullptr, pCommandStreamReceiver); - mmTbx = pCommandStreamReceiver->createMemoryManager(false, false); + mmTbx = new TbxMemoryManager(false, false, *pDevice->executionEnvironment); pDevice->resetCommandStreamReceiver(pCommandStreamReceiver); } diff --git a/unit_tests/device/device_tests.cpp b/unit_tests/device/device_tests.cpp index dace5eaccb..a0b849e158 100644 --- a/unit_tests/device/device_tests.cpp +++ b/unit_tests/device/device_tests.cpp @@ -143,9 +143,6 @@ TEST(DeviceCreation, givenHwWithAubCsrInDebugVarsWhenDeviceIsCreatedThenIsSimula } TEST(DeviceCreation, givenDefaultHwCsrInDebugVarsWhenDeviceIsCreatedThenIsSimulationReturnsFalse) { - int32_t defaultHwCsr = CommandStreamReceiverType::CSR_HW; - EXPECT_EQ(defaultHwCsr, DebugManager.flags.SetCommandStreamReceiver.get()); - auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); EXPECT_FALSE(device->isSimulation()); } @@ -230,9 +227,6 @@ TEST(DeviceCreation, givenFtrSimulationModeFlagTrueWhenNoOtherSimulationFlagsAre HardwareInfo hwInfo = {platformDevices[0]->pPlatform, &skuTable, platformDevices[0]->pWaTable, platformDevices[0]->pSysInfo, platformDevices[0]->capabilityTable}; - int32_t defaultHwCsr = CommandStreamReceiverType::CSR_HW; - EXPECT_EQ(defaultHwCsr, DebugManager.flags.SetCommandStreamReceiver.get()); - bool simulationFromDeviceId = hwInfo.capabilityTable.isSimulation(hwInfo.pPlatform->usDeviceID); EXPECT_FALSE(simulationFromDeviceId); diff --git a/unit_tests/execution_environment/execution_environment_tests.cpp b/unit_tests/execution_environment/execution_environment_tests.cpp index e104d7e911..a68ad1d54b 100644 --- a/unit_tests/execution_environment/execution_environment_tests.cpp +++ b/unit_tests/execution_environment/execution_environment_tests.cpp @@ -179,14 +179,14 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerI auto executionEnvironment = device->getExecutionEnvironment(); executionEnvironment->initializeCommandStreamReceiver(hwInfo, 0, 0); auto enableLocalMemory = HwHelper::get(hwInfo->pPlatform->eRenderCoreFamily).getEnableLocalMemory(*hwInfo); - executionEnvironment->initializeMemoryManager(false, enableLocalMemory, 0, 0); + executionEnvironment->initializeMemoryManager(false, enableLocalMemory); EXPECT_EQ(enableLocalMemory, executionEnvironment->memoryManager->isLocalMemorySupported()); } TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerIsCalledThenItIsInitalized) { auto executionEnvironment = std::make_unique(); executionEnvironment->initializeCommandStreamReceiver(platformDevices[0], 0, 0); - executionEnvironment->initializeMemoryManager(false, false, 0, 0); + executionEnvironment->initializeMemoryManager(false, false); EXPECT_NE(nullptr, executionEnvironment->memoryManager); } static_assert(sizeof(ExecutionEnvironment) == sizeof(std::vector>) + @@ -284,7 +284,7 @@ HWTEST_F(ExecutionEnvironmentHw, givenHwHelperInputWhenInitializingCsrThenCreate TEST(ExecutionEnvironment, whenSpecialCsrNotExistThenReturnNullSpecialEngineControl) { auto executionEnvironment = std::make_unique(); executionEnvironment->initializeCommandStreamReceiver(platformDevices[0], 0, 0); - executionEnvironment->initializeMemoryManager(false, false, 0, 0); + executionEnvironment->initializeMemoryManager(false, false); EXPECT_NE(nullptr, executionEnvironment->memoryManager); auto engineControl = executionEnvironment->getEngineControlForSpecialCsr(); EXPECT_EQ(nullptr, engineControl); @@ -293,7 +293,7 @@ TEST(ExecutionEnvironment, whenSpecialCsrNotExistThenReturnNullSpecialEngineCont TEST(ExecutionEnvironment, whenSpecialCsrExistsThenReturnSpecialEngineControl) { auto executionEnvironment = std::make_unique(); executionEnvironment->initializeCommandStreamReceiver(platformDevices[0], 0, 0); - executionEnvironment->initializeMemoryManager(false, false, 0, 0); + executionEnvironment->initializeMemoryManager(false, false); EXPECT_NE(nullptr, executionEnvironment->memoryManager); executionEnvironment->specialCommandStreamReceiver.reset(createCommandStream(platformDevices[0], *executionEnvironment)); @@ -308,3 +308,12 @@ TEST(ExecutionEnvironment, whenSpecialCsrExistsThenReturnSpecialEngineControl) { ASSERT_NE(nullptr, engineControl); EXPECT_EQ(executionEnvironment->specialCommandStreamReceiver.get(), engineControl->commandStreamReceiver); } + +TEST(ExecutionEnvironment, givenUnproperSetCsrFlagValueWhenInitializingMemoryManagerThenCreateDefaultMemoryManager) { + DebugManagerStateRestore restorer; + DebugManager.flags.SetCommandStreamReceiver.set(10); + + auto executionEnvironment = std::make_unique(); + executionEnvironment->initializeMemoryManager(false, false); + EXPECT_NE(nullptr, executionEnvironment->memoryManager); +} diff --git a/unit_tests/libult/CMakeLists.txt b/unit_tests/libult/CMakeLists.txt index cfbc7bc689..39e991ef3f 100644 --- a/unit_tests/libult/CMakeLists.txt +++ b/unit_tests/libult/CMakeLists.txt @@ -95,6 +95,7 @@ add_library (igdrcl_libult_env OBJECT ) set(IGDRCL_SRCS_LIB_ULT_ENV_WINDOWS + ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/create_wddm_memory_manager.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/options.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/sys_calls.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/ult_dxgi_factory.cpp @@ -103,6 +104,7 @@ set(IGDRCL_SRCS_LIB_ULT_ENV_WINDOWS ) set(IGDRCL_SRCS_LIB_ULT_ENV_LINUX + ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/linux/create_drm_memory_manager.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/linux/options.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/linux/allocator_helper.cpp ) diff --git a/unit_tests/libult/create_command_stream.h b/unit_tests/libult/create_command_stream.h index 21dfa33e69..f11f62eef6 100644 --- a/unit_tests/libult/create_command_stream.h +++ b/unit_tests/libult/create_command_stream.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -10,6 +10,7 @@ namespace OCLRT { extern bool overrideCommandStreamReceiverCreation; extern bool overrideDeviceWithDefaultHardwareInfo; +extern bool overrideMemoryManagerCreation; extern CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo, ExecutionEnvironment &executionEnvironment); extern bool getDevices(HardwareInfo **hwInfo, size_t &numDevicesReturned, ExecutionEnvironment &executionEnvironment); diff --git a/unit_tests/libult/ult_command_stream_receiver.h b/unit_tests/libult/ult_command_stream_receiver.h index 51ae11eaa1..17dfd7bd8e 100644 --- a/unit_tests/libult/ult_command_stream_receiver.h +++ b/unit_tests/libult/ult_command_stream_receiver.h @@ -80,10 +80,6 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw, publ return new UltCommandStreamReceiver(hwInfoIn, executionEnvironment); } - virtual MemoryManager *createMemoryManager(bool enable64kbPages, bool enableLocalMemory) override { - return new OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, executionEnvironment); - } - virtual GmmPageTableMngr *createPageTableManager() override { createPageTableManagerCalled = true; return nullptr; diff --git a/unit_tests/linux/CMakeLists.txt b/unit_tests/linux/CMakeLists.txt index 9fba3b352e..cb65c7cf18 100644 --- a/unit_tests/linux/CMakeLists.txt +++ b/unit_tests/linux/CMakeLists.txt @@ -10,6 +10,7 @@ set(IGDRCL_SRCS_linux_tests ${IGDRCL_SOURCE_DIR}/unit_tests/aub_stream_mocks/aub_stream_interface_mock.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/libult/os_interface.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/linux/allocator_helper.cpp + ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/linux/create_drm_memory_manager.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/linux/options.cpp ) @@ -25,6 +26,7 @@ set(IGDRCL_SRCS_linux_dll_tests ${IGDRCL_SOURCE_DIR}/runtime/dll/linux/options.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/aub_stream_mocks/aub_stream_interface_mock.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/libult/os_interface.cpp + ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/linux/create_drm_memory_manager.cpp ) if(IGDRCL__LIBVA_FOUND) diff --git a/unit_tests/memory_manager/surface_tests.cpp b/unit_tests/memory_manager/surface_tests.cpp index a80f02f760..81e34b15be 100644 --- a/unit_tests/memory_manager/surface_tests.cpp +++ b/unit_tests/memory_manager/surface_tests.cpp @@ -64,7 +64,7 @@ HWTEST_TYPED_TEST(SurfaceTest, GivenSurfaceWhenInterfaceIsUsedThenSurfaceBehaves executionEnvironment.commandStreamReceivers.resize(1); MockCsr *csr = new MockCsr(execStamp, executionEnvironment); executionEnvironment.commandStreamReceivers[0].push_back(std::unique_ptr(csr)); - executionEnvironment.memoryManager.reset(csr->createMemoryManager(false, false)); + executionEnvironment.initializeMemoryManager(false, false); auto engine = HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0]; auto osContext = executionEnvironment.memoryManager->createAndRegisterOsContext(csr, engine, 1, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])); csr->setupContext(*osContext); diff --git a/unit_tests/mocks/mock_aub_csr.h b/unit_tests/mocks/mock_aub_csr.h index 216ce8625e..84102303cd 100644 --- a/unit_tests/mocks/mock_aub_csr.h +++ b/unit_tests/mocks/mock_aub_csr.h @@ -165,7 +165,7 @@ std::unique_ptr getEnvironment(bool createTagAllocation executionEnvironment->commandStreamReceivers.resize(1); executionEnvironment->commandStreamReceivers[0].push_back(std::make_unique(*platformDevices[0], "", standalone, *executionEnvironment)); - executionEnvironment->memoryManager.reset(executionEnvironment->commandStreamReceivers[0][0]->createMemoryManager(false, false)); + executionEnvironment->initializeMemoryManager(false, false); if (createTagAllocation) { executionEnvironment->commandStreamReceivers[0][0]->initializeTagAllocation(); } diff --git a/unit_tests/mocks/mock_tbx_csr.h b/unit_tests/mocks/mock_tbx_csr.h index 5fff4093b7..d190350563 100644 --- a/unit_tests/mocks/mock_tbx_csr.h +++ b/unit_tests/mocks/mock_tbx_csr.h @@ -98,7 +98,7 @@ std::unique_ptr getEnvironment(bool createTagAllocation executionEnvironment->commandStreamReceivers.resize(1); executionEnvironment->commandStreamReceivers[0].push_back(std::make_unique(*platformDevices[0], *executionEnvironment)); - executionEnvironment->memoryManager.reset(executionEnvironment->commandStreamReceivers[0][0]->createMemoryManager(false, false)); + executionEnvironment->initializeMemoryManager(false, false); if (createTagAllocation) { executionEnvironment->commandStreamReceivers[0][0]->initializeTagAllocation(); } diff --git a/unit_tests/os_interface/linux/create_drm_memory_manager.cpp b/unit_tests/os_interface/linux/create_drm_memory_manager.cpp new file mode 100644 index 0000000000..7cb67d4a7d --- /dev/null +++ b/unit_tests/os_interface/linux/create_drm_memory_manager.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/execution_environment/execution_environment.h" +#include "runtime/memory_manager/os_agnostic_memory_manager.h" +#include "runtime/os_interface/linux/drm_memory_manager.h" +#include "runtime/os_interface/linux/os_interface.h" +#include "runtime/os_interface/os_interface.h" +#include "unit_tests/libult/create_command_stream.h" + +namespace OCLRT { +bool overrideMemoryManagerCreation = true; + +std::unique_ptr MemoryManager::createMemoryManager(bool enable64KBpages, bool enableLocalMemory, ExecutionEnvironment &executionEnvironment) { + if (overrideMemoryManagerCreation) { + return std::make_unique(enable64KBpages, enableLocalMemory, executionEnvironment); + } + return std::make_unique(executionEnvironment.osInterface->get()->getDrm(), gemCloseWorkerMode::gemCloseWorkerInactive, DebugManager.flags.EnableForcePin.get(), true, executionEnvironment); +} +} // namespace OCLRT diff --git a/unit_tests/os_interface/linux/drm_command_stream_mm_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_mm_tests.cpp index 3975589d20..4f380a1f20 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_mm_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_mm_tests.cpp @@ -31,7 +31,7 @@ HWTEST_F(DrmCommandStreamMMTest, MMwithPinBB) { DrmCommandStreamReceiver csr(*platformDevices[0], executionEnvironment, gemCloseWorkerMode::gemCloseWorkerInactive); - auto memoryManager = static_cast(csr.createMemoryManager(false, false)); + auto memoryManager = new DrmMemoryManager(executionEnvironment.osInterface->get()->getDrm(), gemCloseWorkerInactive, DebugManager.flags.EnableForcePin.get(), true, executionEnvironment); executionEnvironment.memoryManager.reset(memoryManager); ASSERT_NE(nullptr, memoryManager); EXPECT_NE(nullptr, memoryManager->getPinBB()); @@ -50,7 +50,7 @@ HWTEST_F(DrmCommandStreamMMTest, givenForcePinDisabledWhenMemoryManagerIsCreated DrmCommandStreamReceiver csr(*platformDevices[0], executionEnvironment, gemCloseWorkerMode::gemCloseWorkerInactive); - auto memoryManager = static_cast(csr.createMemoryManager(false, false)); + auto memoryManager = new DrmMemoryManager(executionEnvironment.osInterface->get()->getDrm(), gemCloseWorkerInactive, DebugManager.flags.EnableForcePin.get(), true, executionEnvironment); executionEnvironment.memoryManager.reset(memoryManager); ASSERT_NE(nullptr, memoryManager); EXPECT_NE(nullptr, memoryManager->getPinBB()); diff --git a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp index aff4d94816..792f25eb4e 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -54,7 +54,7 @@ class DrmCommandStreamFixture { // Memory manager creates pinBB with ioctl, expect one call EXPECT_CALL(*mock, ioctl(::testing::_, ::testing::_)) .Times(1); - memoryManager = static_cast(csr->createMemoryManager(false, false)); + memoryManager = new DrmMemoryManager(executionEnvironment.osInterface->get()->getDrm(), gemCloseWorkerActive, DebugManager.flags.EnableForcePin.get(), true, executionEnvironment); executionEnvironment.memoryManager.reset(memoryManager); ::testing::Mock::VerifyAndClearExpectations(mock.get()); @@ -577,7 +577,7 @@ class DrmCommandStreamEnhancedFixture tCsr = new TestedDrmCommandStreamReceiver(*executionEnvironment); csr = tCsr; ASSERT_NE(nullptr, csr); - mm = reinterpret_cast(csr->createMemoryManager(false, false)); + mm = new DrmMemoryManager(executionEnvironment->osInterface->get()->getDrm(), gemCloseWorkerInactive, DebugManager.flags.EnableForcePin.get(), true, *executionEnvironment); ASSERT_NE(nullptr, mm); executionEnvironment->memoryManager.reset(mm); device.reset(MockDevice::create(platformDevices[0], executionEnvironment, 0u)); diff --git a/unit_tests/os_interface/windows/create_wddm_memory_manager.cpp b/unit_tests/os_interface/windows/create_wddm_memory_manager.cpp new file mode 100644 index 0000000000..05531a3868 --- /dev/null +++ b/unit_tests/os_interface/windows/create_wddm_memory_manager.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/execution_environment/execution_environment.h" +#include "runtime/memory_manager/os_agnostic_memory_manager.h" +#include "runtime/os_interface/os_interface.h" +#include "runtime/os_interface/windows/os_interface.h" +#include "runtime/os_interface/windows/wddm_memory_manager.h" +#include "unit_tests/libult/create_command_stream.h" + +namespace OCLRT { +bool overrideMemoryManagerCreation = true; + +std::unique_ptr MemoryManager::createMemoryManager(bool enable64KBpages, bool enableLocalMemory, ExecutionEnvironment &executionEnvironment) { + if (overrideMemoryManagerCreation) { + return std::make_unique(enable64KBpages, enableLocalMemory, executionEnvironment); + } + return std::make_unique(enable64KBpages, enableLocalMemory, executionEnvironment.osInterface->get()->getWddm(), executionEnvironment); +} +} // namespace OCLRT diff --git a/unit_tests/os_interface/windows/device_command_stream_tests.cpp b/unit_tests/os_interface/windows/device_command_stream_tests.cpp index 38b5ae630c..f89d06cbf6 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -124,7 +124,7 @@ class WddmCommandStreamWithMockGdiFixture { ASSERT_NE(wddm, nullptr); DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::ImmediateDispatch)); this->csr = new MockWddmCsr(*platformDevices[0], *executionEnvironment); - memoryManager = csr->createMemoryManager(false, false); + memoryManager = new WddmMemoryManager(false, false, wddm, *executionEnvironment); ASSERT_NE(nullptr, memoryManager); executionEnvironment->memoryManager.reset(memoryManager); device = std::unique_ptr(Device::create(platformDevices[0], executionEnvironment, 0u)); @@ -245,7 +245,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOf executionEnvironment->commandStreamReceivers.resize(1); executionEnvironment->commandStreamReceivers[0].push_back( std::make_unique>(hwInfo[0], *executionEnvironment)); - executionEnvironment->memoryManager.reset(executionEnvironment->commandStreamReceivers[0][0]->createMemoryManager(false, false)); + executionEnvironment->memoryManager.reset(new WddmMemoryManager(false, false, wddm, *executionEnvironment)); executionEnvironment->commandStreamReceivers[0][0]->overrideDispatchPolicy(DispatchMode::ImmediateDispatch); OsContextWin osContext(*wddm, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*hwInfo)); executionEnvironment->commandStreamReceivers[0][0]->setupContext(osContext); @@ -270,7 +270,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOn executionEnvironment->commandStreamReceivers.resize(1); executionEnvironment->commandStreamReceivers[0].push_back(std::make_unique>(hwInfo[0], *executionEnvironment)); - executionEnvironment->memoryManager.reset(executionEnvironment->commandStreamReceivers[0][0]->createMemoryManager(false, false)); + executionEnvironment->memoryManager.reset(new WddmMemoryManager(false, false, wddm, *executionEnvironment)); executionEnvironment->commandStreamReceivers[0][0]->overrideDispatchPolicy(DispatchMode::ImmediateDispatch); OsContextWin osContext(*wddm, 0u, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*hwInfo)); executionEnvironment->commandStreamReceivers[0][0]->setupContext(osContext); @@ -886,7 +886,7 @@ HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenFlushingThenInitTra auto mockWddmCsr = new MockWddmCsr(hwInfo[0], *executionEnvironment); mockWddmCsr->createPageTableManager(); mockWddmCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); - executionEnvironment->memoryManager.reset(mockWddmCsr->createMemoryManager(false, false)); + executionEnvironment->memoryManager.reset(new WddmMemoryManager(false, false, executionEnvironment->osInterface->get()->getWddm(), *executionEnvironment)); auto mockMngr = reinterpret_cast(myMockWddm->getPageTableManager()); std::unique_ptr device(Device::create(hwInfo, executionEnvironment, 0u)); @@ -928,7 +928,7 @@ HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenFlushingThenDontIn auto mockWddmCsr = new MockWddmCsr(hwInfo[0], *executionEnvironment); mockWddmCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); - executionEnvironment->memoryManager.reset(mockWddmCsr->createMemoryManager(false, false)); + executionEnvironment->memoryManager.reset(new WddmMemoryManager(false, false, executionEnvironment->osInterface->get()->getWddm(), *executionEnvironment)); std::unique_ptr device(Device::create(hwInfo, executionEnvironment, 0u)); device->resetCommandStreamReceiver(mockWddmCsr); diff --git a/unit_tests/os_interface/windows/wddm_create.cpp b/unit_tests/os_interface/windows/wddm_create.cpp index 6902153900..96483382cf 100644 --- a/unit_tests/os_interface/windows/wddm_create.cpp +++ b/unit_tests/os_interface/windows/wddm_create.cpp @@ -1,12 +1,11 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "unit_tests/mocks/mock_wddm.h" -#include "unit_tests/mocks/mock_wddm_interface23.h" namespace OCLRT { Wddm *Wddm::createWddm() { diff --git a/unit_tests/tbx/CMakeLists.txt b/unit_tests/tbx/CMakeLists.txt index d1b157d1a3..5f9dba25ba 100644 --- a/unit_tests/tbx/CMakeLists.txt +++ b/unit_tests/tbx/CMakeLists.txt @@ -23,6 +23,7 @@ if(WIN32) ) target_sources(igdrcl_tbx_tests PRIVATE ${IGDRCL_SOURCE_DIR}/runtime/dll/windows/options.cpp + ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/create_wddm_memory_manager.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/sys_calls.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/wddm_calls.cpp ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/wddm_create.cpp @@ -32,6 +33,7 @@ else() target_sources(igdrcl_tbx_tests PRIVATE ${IGDRCL_SOURCE_DIR}/runtime/dll/linux/allocator_helper.cpp ${IGDRCL_SOURCE_DIR}/runtime/dll/linux/options.cpp + ${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/linux/create_drm_memory_manager.cpp ) endif() diff --git a/unit_tests/tbx/main_tbx.cpp b/unit_tests/tbx/main_tbx.cpp index 18bdccaa89..1957cacaf1 100644 --- a/unit_tests/tbx/main_tbx.cpp +++ b/unit_tests/tbx/main_tbx.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -15,7 +15,7 @@ using namespace OCLRT; namespace OCLRT { bool getDevices(HardwareInfo **hwInfo, size_t &numDevicesReturned, ExecutionEnvironment &executionEnvironment); -} +} // namespace OCLRT TEST(CSRTests, getDevices) { HardwareInfo *hwInfo = nullptr; diff --git a/unit_tests/test_files/igdrcl.config b/unit_tests/test_files/igdrcl.config index 528ec276ef..15151b5bf4 100644 --- a/unit_tests/test_files/igdrcl.config +++ b/unit_tests/test_files/igdrcl.config @@ -15,7 +15,7 @@ LogAllocationMemoryPool = 0 LogMemoryObject = 0 ForceLinearImages = 0 ForceSLML3Config = 0 -SetCommandStreamReceiver = 0 +SetCommandStreamReceiver = -1 ForceOCLVersion = 0 Force32bitAddressing = 0 EnableVaLibCalls = 1