diff --git a/core/memory_manager/CMakeLists.txt b/core/memory_manager/CMakeLists.txt index 204dd0dd8c..780f5dbb63 100644 --- a/core/memory_manager/CMakeLists.txt +++ b/core/memory_manager/CMakeLists.txt @@ -7,7 +7,7 @@ set(NEO_CORE_MEMORY_MANAGER ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/eviction_status.h - ${CMAKE_CURRENT_SOURCE_DIR}/residency_handler.h + ${CMAKE_CURRENT_SOURCE_DIR}/memory_operations_handler.h ) set_property(GLOBAL PROPERTY NEO_CORE_MEMORY_MANAGER ${NEO_CORE_MEMORY_MANAGER}) diff --git a/core/memory_manager/residency_handler.h b/core/memory_manager/memory_operations_handler.h similarity index 75% rename from core/memory_manager/residency_handler.h rename to core/memory_manager/memory_operations_handler.h index e105a26137..15ce967c8e 100644 --- a/core/memory_manager/residency_handler.h +++ b/core/memory_manager/memory_operations_handler.h @@ -11,10 +11,10 @@ namespace NEO { class GraphicsAllocation; -class ResidencyHandler { +class MemoryOperationsHandler { public: - ResidencyHandler() = default; - virtual ~ResidencyHandler() = default; + MemoryOperationsHandler() = default; + virtual ~MemoryOperationsHandler() = default; virtual bool makeResident(GraphicsAllocation &gfxAllocation) = 0; virtual bool evict(GraphicsAllocation &gfxAllocation) = 0; diff --git a/core/os_interface/CMakeLists.txt b/core/os_interface/CMakeLists.txt new file mode 100644 index 0000000000..6c805c8474 --- /dev/null +++ b/core/os_interface/CMakeLists.txt @@ -0,0 +1,14 @@ +# +# Copyright (C) 2018-2019 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +set(NEO_CORE_OS_INTERFACE_AUB + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/aub_memory_operations_handler.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/aub_memory_operations_handler.h +) + +set_property(GLOBAL PROPERTY NEO_CORE_OS_INTERFACE_AUB ${NEO_CORE_OS_INTERFACE_AUB}) +add_subdirectories() diff --git a/core/os_interface/aub_memory_operations_handler.cpp b/core/os_interface/aub_memory_operations_handler.cpp new file mode 100644 index 0000000000..3d398b1b65 --- /dev/null +++ b/core/os_interface/aub_memory_operations_handler.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "core/os_interface/aub_memory_operations_handler.h" + +#include "runtime/aub_mem_dump/aub_mem_dump.h" +#include "runtime/memory_manager/graphics_allocation.h" + +#include + +namespace NEO { + +AubMemoryOperationsHandler::AubMemoryOperationsHandler(aub_stream::AubManager *aubManager) { + this->aubManager = aubManager; +} + +bool AubMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) { + if (!aubManager) { + return false; + } + auto lock = acquireLock(resourcesLock); + int hint = AubMemDump::DataTypeHintValues::TraceNotype; + aubManager->writeMemory(gfxAllocation.getGpuAddress(), gfxAllocation.getUnderlyingBuffer(), gfxAllocation.getUnderlyingBufferSize(), gfxAllocation.storageInfo.getMemoryBanks(), hint, gfxAllocation.getUsedPageSize()); + residentAllocations.push_back(&gfxAllocation); + return true; +} + +bool AubMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) { + auto lock = acquireLock(resourcesLock); + auto itor = std::find(residentAllocations.begin(), residentAllocations.end(), &gfxAllocation); + if (itor == residentAllocations.end()) { + return false; + } else { + residentAllocations.erase(itor, itor + 1); + return true; + } +} + +bool AubMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) { + auto lock = acquireLock(resourcesLock); + auto itor = std::find(residentAllocations.begin(), residentAllocations.end(), &gfxAllocation); + if (itor == residentAllocations.end()) { + return false; + } else { + return true; + } +} +void AubMemoryOperationsHandler::setAubManager(aub_stream::AubManager *aubManager) { + this->aubManager = aubManager; +} + +} // namespace NEO diff --git a/core/os_interface/aub_memory_operations_handler.h b/core/os_interface/aub_memory_operations_handler.h new file mode 100644 index 0000000000..bbaf5bb43e --- /dev/null +++ b/core/os_interface/aub_memory_operations_handler.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "core/memory_manager/memory_operations_handler.h" +#include "core/utilities/spinlock.h" + +#include "third_party/aub_stream/headers/aub_manager.h" + +#include +#include + +namespace NEO { + +class AubMemoryOperationsHandler : public MemoryOperationsHandler { + public: + AubMemoryOperationsHandler(aub_stream::AubManager *aubManager); + ~AubMemoryOperationsHandler() override = default; + + bool makeResident(GraphicsAllocation &gfxAllocation) override; + bool evict(GraphicsAllocation &gfxAllocation) override; + bool isResident(GraphicsAllocation &gfxAllocation) override; + void setAubManager(aub_stream::AubManager *aubManager); + + protected: + MOCKABLE_VIRTUAL std::unique_lock acquireLock(SpinLock &lock) { + return std::unique_lock{lock}; + } + aub_stream::AubManager *aubManager = nullptr; + std::vector residentAllocations; + SpinLock resourcesLock; +}; +} // namespace NEO diff --git a/core/unit_tests/os_interface/CMakeLists.txt b/core/unit_tests/os_interface/CMakeLists.txt new file mode 100644 index 0000000000..109c8f489a --- /dev/null +++ b/core/unit_tests/os_interface/CMakeLists.txt @@ -0,0 +1,14 @@ +# +# Copyright (C) 2018-2019 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +set(NEO_CORE_OS_INTERFACE_AUB_TESTS + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/aub_memory_operations_handler_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/aub_memory_operations_handler_tests.h +) + +set_property(GLOBAL PROPERTY NEO_CORE_OS_INTERFACE_AUB_TESTS ${NEO_CORE_OS_INTERFACE_AUB_TESTS}) +add_subdirectories() diff --git a/core/unit_tests/os_interface/aub_memory_operations_handler_tests.cpp b/core/unit_tests/os_interface/aub_memory_operations_handler_tests.cpp new file mode 100644 index 0000000000..a40bca1585 --- /dev/null +++ b/core/unit_tests/os_interface/aub_memory_operations_handler_tests.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2017-2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "core/unit_tests/os_interface/aub_memory_operations_handler_tests.h" + +#include "runtime/aub_mem_dump/aub_mem_dump.h" +#include "unit_tests/mocks/mock_aub_manager.h" + +TEST_F(AubMemoryOperationsHandlerTests, givenNullPtrAsAubManagerWhenMakeResidentCalledThenFalseReturned) { + getMemoryOperationsHandler()->setAubManager(nullptr); + auto memoryOperationsInterface = getMemoryOperationsHandler(); + bool result = memoryOperationsInterface->makeResident(allocation); + EXPECT_FALSE(result); +} + +TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledThenTrueReturnedAndWriteCalled) { + MockAubManager aubManager; + getMemoryOperationsHandler()->setAubManager(&aubManager); + auto memoryOperationsInterface = getMemoryOperationsHandler(); + bool result = memoryOperationsInterface->makeResident(allocation); + EXPECT_TRUE(result); + EXPECT_TRUE(aubManager.writeMemoryCalled); +} + +TEST_F(AubMemoryOperationsHandlerTests, givenAllocationWhenMakeResidentCalledThenTraceNotypeHintReturned) { + MockAubManager aubManager; + getMemoryOperationsHandler()->setAubManager(&aubManager); + auto memoryOperationsInterface = getMemoryOperationsHandler(); + memoryOperationsInterface->makeResident(allocation); + EXPECT_EQ(aubManager.hintToWriteMemory, AubMemDump::DataTypeHintValues::TraceNotype); +} +TEST_F(AubMemoryOperationsHandlerTests, givenNonResidentAllocationWhenIsResidentCalledThenFalseReturned) { + MockAubManager aubManager; + getMemoryOperationsHandler()->setAubManager(&aubManager); + auto memoryOperationsInterface = getMemoryOperationsHandler(); + bool result = memoryOperationsInterface->isResident(allocation); + EXPECT_FALSE(result); +} +TEST_F(AubMemoryOperationsHandlerTests, givenResidentAllocationWhenIsResidentCalledThenTrueReturned) { + MockAubManager aubManager; + getMemoryOperationsHandler()->setAubManager(&aubManager); + auto memoryOperationsInterface = getMemoryOperationsHandler(); + memoryOperationsInterface->makeResident(allocation); + bool result = memoryOperationsInterface->isResident(allocation); + EXPECT_TRUE(result); +} +TEST_F(AubMemoryOperationsHandlerTests, givenNonResidentAllocationWhenEvictCalledThenFalseReturned) { + MockAubManager aubManager; + getMemoryOperationsHandler()->setAubManager(&aubManager); + auto memoryOperationsInterface = getMemoryOperationsHandler(); + bool result = memoryOperationsInterface->evict(allocation); + EXPECT_FALSE(result); +} +TEST_F(AubMemoryOperationsHandlerTests, givenResidentAllocationWhenEvictCalledThenTrueReturned) { + MockAubManager aubManager; + getMemoryOperationsHandler()->setAubManager(&aubManager); + auto memoryOperationsInterface = getMemoryOperationsHandler(); + memoryOperationsInterface->makeResident(allocation); + bool result = memoryOperationsInterface->evict(allocation); + EXPECT_TRUE(result); +} \ No newline at end of file diff --git a/core/unit_tests/os_interface/aub_memory_operations_handler_tests.h b/core/unit_tests/os_interface/aub_memory_operations_handler_tests.h new file mode 100644 index 0000000000..881803cd20 --- /dev/null +++ b/core/unit_tests/os_interface/aub_memory_operations_handler_tests.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2017-2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "core/os_interface/aub_memory_operations_handler.h" +#include "core/unit_tests/helpers/debug_manager_state_restore.h" +#include "runtime/helpers/hw_info.h" +#include "runtime/helpers/options.h" +#include "runtime/os_interface/device_factory.h" +#include "unit_tests/mocks/mock_graphics_allocation.h" + +#include "gtest/gtest.h" + +using namespace NEO; + +class AubMemoryOperationsHandlerTests : public ::testing::Test { + public: + void SetUp() override { + DebugManager.flags.SetCommandStreamReceiver.set(2); + residencyHandler = std::unique_ptr(new AubMemoryOperationsHandler(nullptr)); + } + + AubMemoryOperationsHandler *getMemoryOperationsHandler() { + return residencyHandler.get(); + } + + MockGraphicsAllocation allocation; + DebugManagerStateRestore dbgRestore; + std::unique_ptr residencyHandler; +}; diff --git a/runtime/execution_environment/execution_environment.cpp b/runtime/execution_environment/execution_environment.cpp index fb6761da47..0f68557b49 100644 --- a/runtime/execution_environment/execution_environment.cpp +++ b/runtime/execution_environment/execution_environment.cpp @@ -7,6 +7,7 @@ #include "runtime/execution_environment/execution_environment.h" +#include "core/memory_manager/memory_operations_handler.h" #include "runtime/aub/aub_center.h" #include "runtime/built_ins/built_ins.h" #include "runtime/built_ins/sip.h" @@ -127,5 +128,4 @@ EngineControl *ExecutionEnvironment::getEngineControlForSpecialCsr() { } return engine; } - } // namespace NEO diff --git a/runtime/execution_environment/execution_environment.h b/runtime/execution_environment/execution_environment.h index 9fd75147f1..4816db0986 100644 --- a/runtime/execution_environment/execution_environment.h +++ b/runtime/execution_environment/execution_environment.h @@ -26,6 +26,7 @@ class GmmHelper; class MemoryManager; class SourceLevelDebugger; class OSInterface; +class MemoryOperationsHandler; struct EngineControl; struct HardwareInfo; @@ -63,6 +64,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject EngineControl *getEngineControlForSpecialCsr(); std::unique_ptr osInterface; + std::unique_ptr memoryOperationsInterface; std::unique_ptr memoryManager; std::unique_ptr aubCenter; CsrContainer commandStreamReceivers; diff --git a/runtime/os_interface/CMakeLists.txt b/runtime/os_interface/CMakeLists.txt index 388cbe3244..a9af2335fb 100644 --- a/runtime/os_interface/CMakeLists.txt +++ b/runtime/os_interface/CMakeLists.txt @@ -31,6 +31,9 @@ set(RUNTIME_SRCS_OS_INTERFACE_BASE ${CMAKE_CURRENT_SOURCE_DIR}/print.h ) +get_property(NEO_CORE_OS_INTERFACE_AUB GLOBAL PROPERTY NEO_CORE_OS_INTERFACE_AUB) +list(APPEND RUNTIME_SRCS_OS_INTERFACE_BASE ${NEO_CORE_OS_INTERFACE_AUB}) + target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_OS_INTERFACE_BASE}) set_property(GLOBAL PROPERTY RUNTIME_SRCS_OS_INTERFACE_BASE ${RUNTIME_SRCS_OS_INTERFACE_BASE}) add_subdirectories() diff --git a/runtime/os_interface/device_factory.cpp b/runtime/os_interface/device_factory.cpp index 33839529ba..2047e92813 100644 --- a/runtime/os_interface/device_factory.cpp +++ b/runtime/os_interface/device_factory.cpp @@ -5,6 +5,8 @@ * */ +#include "core/os_interface/aub_memory_operations_handler.h" +#include "runtime/aub/aub_center.h" #include "runtime/device/device.h" #include "runtime/helpers/options.h" #include "runtime/os_interface/debug_settings_manager.h" @@ -34,7 +36,12 @@ bool DeviceFactory::getDevicesForProductFamilyOverride(size_t &numDevices, Execu numDevices = totalDeviceCount; DeviceFactory::numDevices = numDevices; - + auto csr = DebugManager.flags.SetCommandStreamReceiver.get(); + if (csr > 0) { + executionEnvironment.initAubCenter(DebugManager.flags.EnableLocalMemory.get(), "", static_cast(csr)); + auto aubCenter = executionEnvironment.aubCenter.get(); + executionEnvironment.memoryOperationsInterface = std::make_unique(aubCenter->getAubManager()); + } return true; } diff --git a/runtime/os_interface/linux/CMakeLists.txt b/runtime/os_interface/linux/CMakeLists.txt index 04a96d1977..9b95ee0108 100644 --- a/runtime/os_interface/linux/CMakeLists.txt +++ b/runtime/os_interface/linux/CMakeLists.txt @@ -31,8 +31,8 @@ set(RUNTIME_SRCS_OS_INTERFACE_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/drm_neo_create.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_null_device.h ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_query.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drm_residency_handler.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drm_residency_handler.h + ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_operations_handler.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_operations_handler.h ${CMAKE_CURRENT_SOURCE_DIR}/engine_info.h ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config.cpp ${CMAKE_CURRENT_SOURCE_DIR}/linux_inc.cpp diff --git a/runtime/os_interface/linux/device_factory_linux.cpp b/runtime/os_interface/linux/device_factory_linux.cpp index c7913ba052..f03783be03 100644 --- a/runtime/os_interface/linux/device_factory_linux.cpp +++ b/runtime/os_interface/linux/device_factory_linux.cpp @@ -11,6 +11,7 @@ #include "runtime/helpers/options.h" #include "runtime/os_interface/device_factory.h" #include "runtime/os_interface/hw_info_config.h" +#include "runtime/os_interface/linux/drm_memory_operations_handler.h" #include "runtime/os_interface/linux/drm_neo.h" #include "runtime/os_interface/linux/os_interface.h" @@ -35,6 +36,7 @@ bool DeviceFactory::getDevices(size_t &numDevices, ExecutionEnvironment &executi return false; } + executionEnvironment.memoryOperationsInterface = std::make_unique(); executionEnvironment.osInterface.reset(new OSInterface()); executionEnvironment.osInterface->get()->setDrm(drm); diff --git a/runtime/os_interface/linux/drm_memory_operations_handler.cpp b/runtime/os_interface/linux/drm_memory_operations_handler.cpp new file mode 100644 index 0000000000..94fdfbe4c6 --- /dev/null +++ b/runtime/os_interface/linux/drm_memory_operations_handler.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/os_interface/linux/drm_memory_operations_handler.h" + +namespace NEO { + +DrmMemoryOperationsHandler::DrmMemoryOperationsHandler() { +} + +bool DrmMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) { + return false; +} + +bool DrmMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) { + return false; +} + +bool DrmMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) { + return false; +} + +} // namespace NEO diff --git a/runtime/os_interface/linux/drm_residency_handler.h b/runtime/os_interface/linux/drm_memory_operations_handler.h similarity index 61% rename from runtime/os_interface/linux/drm_residency_handler.h rename to runtime/os_interface/linux/drm_memory_operations_handler.h index 885148e7e7..fac0d585e5 100644 --- a/runtime/os_interface/linux/drm_residency_handler.h +++ b/runtime/os_interface/linux/drm_memory_operations_handler.h @@ -6,14 +6,14 @@ */ #pragma once -#include "core/memory_manager/residency_handler.h" +#include "core/memory_manager/memory_operations_handler.h" namespace NEO { -class DrmResidencyHandler : public ResidencyHandler { +class DrmMemoryOperationsHandler : public MemoryOperationsHandler { public: - DrmResidencyHandler(); - ~DrmResidencyHandler() override = default; + DrmMemoryOperationsHandler(); + ~DrmMemoryOperationsHandler() override = default; bool makeResident(GraphicsAllocation &gfxAllocation) override; bool evict(GraphicsAllocation &gfxAllocation) override; diff --git a/runtime/os_interface/linux/drm_residency_handler.cpp b/runtime/os_interface/linux/drm_residency_handler.cpp deleted file mode 100644 index 9d78d90012..0000000000 --- a/runtime/os_interface/linux/drm_residency_handler.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "runtime/os_interface/linux/drm_residency_handler.h" - -namespace NEO { - -DrmResidencyHandler::DrmResidencyHandler() { -} - -bool DrmResidencyHandler::makeResident(GraphicsAllocation &gfxAllocation) { - return false; -} - -bool DrmResidencyHandler::evict(GraphicsAllocation &gfxAllocation) { - return false; -} - -bool DrmResidencyHandler::isResident(GraphicsAllocation &gfxAllocation) { - return false; -} - -} // namespace NEO diff --git a/runtime/os_interface/linux/os_interface.cpp b/runtime/os_interface/linux/os_interface.cpp index 4829c6575e..0dcbae9caa 100644 --- a/runtime/os_interface/linux/os_interface.cpp +++ b/runtime/os_interface/linux/os_interface.cpp @@ -27,8 +27,4 @@ uint32_t OSInterface::getDeviceHandle() const { return 0; } -ResidencyHandler *OSInterface::getResidencyInterface() const { - return osInterfaceImpl->getResidencyInterface(); -} - -} // namespace NEO \ No newline at end of file +} // namespace NEO diff --git a/runtime/os_interface/linux/os_interface.h b/runtime/os_interface/linux/os_interface.h index 76f2dcb613..57546a56f9 100644 --- a/runtime/os_interface/linux/os_interface.h +++ b/runtime/os_interface/linux/os_interface.h @@ -6,7 +6,7 @@ */ #pragma once -#include "runtime/os_interface/linux/drm_residency_handler.h" +#include "runtime/os_interface/linux/drm_memory_operations_handler.h" #include "runtime/os_interface/os_interface.h" #include "drm_neo.h" @@ -18,7 +18,6 @@ class OSInterface::OSInterfaceImpl { public: OSInterfaceImpl() { drm = nullptr; - residencyInterface = std::make_unique(); } Drm *getDrm() const { return drm; @@ -27,12 +26,7 @@ class OSInterface::OSInterfaceImpl { this->drm = drm; } - DrmResidencyHandler *getResidencyInterface() const { - return residencyInterface.get(); - } - protected: Drm *drm; - std::unique_ptr residencyInterface; }; } // namespace NEO diff --git a/runtime/os_interface/os_interface.h b/runtime/os_interface/os_interface.h index 0b297b45d8..2f0bb08a13 100644 --- a/runtime/os_interface/os_interface.h +++ b/runtime/os_interface/os_interface.h @@ -9,8 +9,6 @@ namespace NEO { -class ResidencyHandler; - class OSInterface { public: @@ -27,7 +25,6 @@ class OSInterface { static bool osEnableLocalMemory; static bool are64kbPagesEnabled(); unsigned int getDeviceHandle() const; - ResidencyHandler *getResidencyInterface() const; protected: OSInterfaceImpl *osInterfaceImpl = nullptr; diff --git a/runtime/os_interface/windows/CMakeLists.txt b/runtime/os_interface/windows/CMakeLists.txt index b17f48bc89..b41683f2c4 100644 --- a/runtime/os_interface/windows/CMakeLists.txt +++ b/runtime/os_interface/windows/CMakeLists.txt @@ -63,8 +63,8 @@ set(RUNTIME_SRCS_OS_INTERFACE_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/wddm_residency_allocations_container.h ${CMAKE_CURRENT_SOURCE_DIR}/wddm_residency_controller.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wddm_residency_controller.h - ${CMAKE_CURRENT_SOURCE_DIR}/wddm_residency_handler.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/wddm_residency_handler.h + ${CMAKE_CURRENT_SOURCE_DIR}/wddm_memory_operations_handler.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/wddm_memory_operations_handler.h ${CMAKE_CURRENT_SOURCE_DIR}/windows_defs.h ${CMAKE_CURRENT_SOURCE_DIR}/windows_inc.cpp ${CMAKE_CURRENT_SOURCE_DIR}/windows_wrapper.h diff --git a/runtime/os_interface/windows/device_factory_win.cpp b/runtime/os_interface/windows/device_factory_win.cpp index aa6b119645..46ab215ff1 100644 --- a/runtime/os_interface/windows/device_factory_win.cpp +++ b/runtime/os_interface/windows/device_factory_win.cpp @@ -14,6 +14,7 @@ #include "runtime/os_interface/hw_info_config.h" #include "runtime/os_interface/windows/os_interface.h" #include "runtime/os_interface/windows/wddm/wddm.h" +#include "runtime/os_interface/windows/wddm_memory_operations_handler.h" namespace NEO { @@ -32,6 +33,7 @@ bool DeviceFactory::getDevices(size_t &numDevices, ExecutionEnvironment &executi auto totalDeviceCount = DeviceHelper::getDevicesCount(hardwareInfo); + executionEnvironment.memoryOperationsInterface = std::make_unique(wddm.get()); executionEnvironment.osInterface.reset(new OSInterface()); executionEnvironment.osInterface->get()->setWddm(wddm.release()); diff --git a/runtime/os_interface/windows/os_interface.cpp b/runtime/os_interface/windows/os_interface.cpp index bbe5d322ac..21ebe51117 100644 --- a/runtime/os_interface/windows/os_interface.cpp +++ b/runtime/os_interface/windows/os_interface.cpp @@ -9,7 +9,7 @@ #include "runtime/os_interface/windows/sys_calls.h" #include "runtime/os_interface/windows/wddm/wddm.h" -#include "runtime/os_interface/windows/wddm_residency_handler.h" +#include "runtime/os_interface/windows/wddm_memory_operations_handler.h" namespace NEO { @@ -27,10 +27,6 @@ uint32_t OSInterface::getDeviceHandle() const { return static_cast(osInterfaceImpl->getDeviceHandle()); } -ResidencyHandler *OSInterface::getResidencyInterface() const { - return osInterfaceImpl->getResidencyInterface(); -} - OSInterface::OSInterfaceImpl::OSInterfaceImpl() = default; D3DKMT_HANDLE OSInterface::OSInterfaceImpl::getAdapterHandle() const { @@ -62,7 +58,6 @@ Wddm *OSInterface::OSInterfaceImpl::getWddm() const { void OSInterface::OSInterfaceImpl::setWddm(Wddm *wddm) { this->wddm.reset(wddm); - this->residencyInterface = std::make_unique(wddm); } HANDLE OSInterface::OSInterfaceImpl::createEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, diff --git a/runtime/os_interface/windows/os_interface.h b/runtime/os_interface/windows/os_interface.h index 9d7229729c..8cae10d7ac 100644 --- a/runtime/os_interface/windows/os_interface.h +++ b/runtime/os_interface/windows/os_interface.h @@ -8,6 +8,7 @@ #pragma once #include "runtime/os_interface/os_interface.h" +#include "runtime/os_interface/windows/wddm/wddm.h" #include "runtime/os_interface/windows/windows_wrapper.h" #include "profileapi.h" @@ -18,7 +19,7 @@ namespace NEO { class Wddm; -class WddmResidencyHandler; +class WddmMemoryOperationsHandler; class OSInterface::OSInterfaceImpl { public: @@ -30,9 +31,6 @@ class OSInterface::OSInterfaceImpl { D3DKMT_HANDLE getDeviceHandle() const; PFND3DKMT_ESCAPE getEscapeHandle() const; uint32_t getHwContextId() const; - WddmResidencyHandler *getResidencyInterface() const { - return residencyInterface.get(); - } MOCKABLE_VIRTUAL HANDLE createEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCSTR lpName); @@ -40,6 +38,5 @@ class OSInterface::OSInterfaceImpl { protected: std::unique_ptr wddm; - std::unique_ptr residencyInterface; }; } // namespace NEO diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 354503cdb3..fd0401ce0f 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -9,7 +9,7 @@ #include "core/helpers/aligned_memory.h" #include "core/helpers/ptr_math.h" -#include "core/memory_manager/residency_handler.h" +#include "core/memory_manager/memory_operations_handler.h" #include "runtime/command_stream/command_stream_receiver_hw.h" #include "runtime/device/device.h" #include "runtime/execution_environment/execution_environment.h" @@ -314,7 +314,7 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation residencyController.removeFromTrimCandidateListIfUsed(input, true); } - executionEnvironment.osInterface->getResidencyInterface()->evict(*input); + executionEnvironment.memoryOperationsInterface->evict(*input); auto defaultGmm = gfxAllocation->getDefaultGmm(); if (defaultGmm) { diff --git a/runtime/os_interface/windows/wddm_residency_handler.cpp b/runtime/os_interface/windows/wddm_memory_operations_handler.cpp similarity index 73% rename from runtime/os_interface/windows/wddm_residency_handler.cpp rename to runtime/os_interface/windows/wddm_memory_operations_handler.cpp index ae2dc045f3..0f92741714 100644 --- a/runtime/os_interface/windows/wddm_residency_handler.cpp +++ b/runtime/os_interface/windows/wddm_memory_operations_handler.cpp @@ -5,7 +5,7 @@ * */ -#include "runtime/os_interface/windows/wddm_residency_handler.h" +#include "runtime/os_interface/windows/wddm_memory_operations_handler.h" #include "runtime/os_interface/windows/wddm/wddm.h" #include "runtime/os_interface/windows/wddm_allocation.h" @@ -15,22 +15,22 @@ namespace NEO { -WddmResidencyHandler::WddmResidencyHandler(Wddm *wddm) : wddm(wddm) { +WddmMemoryOperationsHandler::WddmMemoryOperationsHandler(Wddm *wddm) : wddm(wddm) { residentAllocations = std::make_unique(wddm); } -bool WddmResidencyHandler::makeResident(GraphicsAllocation &gfxAllocation) { +bool WddmMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) { WddmAllocation &wddmAllocation = reinterpret_cast(gfxAllocation); return residentAllocations->makeResidentResources(wddmAllocation.getHandles().data(), wddmAllocation.getNumHandles()); } -bool WddmResidencyHandler::evict(GraphicsAllocation &gfxAllocation) { +bool WddmMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) { WddmAllocation &wddmAllocation = reinterpret_cast(gfxAllocation); auto result = residentAllocations->evictResources(wddmAllocation.getHandles().data(), wddmAllocation.getNumHandles()); return result == EvictionStatus::SUCCESS; } -bool WddmResidencyHandler::isResident(GraphicsAllocation &gfxAllocation) { +bool WddmMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) { WddmAllocation &wddmAllocation = reinterpret_cast(gfxAllocation); return residentAllocations->isAllocationResident(wddmAllocation.getDefaultHandle()); } diff --git a/runtime/os_interface/windows/wddm_residency_handler.h b/runtime/os_interface/windows/wddm_memory_operations_handler.h similarity index 69% rename from runtime/os_interface/windows/wddm_residency_handler.h rename to runtime/os_interface/windows/wddm_memory_operations_handler.h index 55ef54be82..ffc5056455 100644 --- a/runtime/os_interface/windows/wddm_residency_handler.h +++ b/runtime/os_interface/windows/wddm_memory_operations_handler.h @@ -6,7 +6,7 @@ */ #pragma once -#include "core/memory_manager/residency_handler.h" +#include "core/memory_manager/memory_operations_handler.h" #include @@ -15,10 +15,10 @@ namespace NEO { class Wddm; class WddmResidentAllocationsContainer; -class WddmResidencyHandler : public ResidencyHandler { +class WddmMemoryOperationsHandler : public MemoryOperationsHandler { public: - WddmResidencyHandler(Wddm *wddm); - ~WddmResidencyHandler() override = default; + WddmMemoryOperationsHandler(Wddm *wddm); + ~WddmMemoryOperationsHandler() override = default; bool makeResident(GraphicsAllocation &gfxAllocation) override; bool evict(GraphicsAllocation &gfxAllocation) override; diff --git a/unit_tests/execution_environment/execution_environment_tests.cpp b/unit_tests/execution_environment/execution_environment_tests.cpp index 4a33efd93a..48a84bf876 100644 --- a/unit_tests/execution_environment/execution_environment_tests.cpp +++ b/unit_tests/execution_environment/execution_environment_tests.cpp @@ -25,6 +25,7 @@ #include "unit_tests/mocks/mock_device.h" #include "unit_tests/mocks/mock_execution_environment.h" #include "unit_tests/mocks/mock_memory_manager.h" +#include "unit_tests/mocks/mock_memory_operations_handler.h" #include "unit_tests/utilities/destructor_counted.h" using namespace NEO; @@ -193,7 +194,7 @@ static_assert(sizeof(ExecutionEnvironment) == sizeof(std::vector) + sizeof(std::mutex) + sizeof(std::unique_ptr) + - (is64bit ? 80 : 44), + (is64bit ? 88 : 48), "New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct"); TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDestroyedThenDeleteSequenceIsSpecified) { @@ -202,12 +203,15 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe struct MockExecutionEnvironment : ExecutionEnvironment { using ExecutionEnvironment::gmmHelper; }; - struct GmmHelperMock : public DestructorCounted { + struct GmmHelperMock : public DestructorCounted { GmmHelperMock(uint32_t &destructorId, const HardwareInfo *hwInfo) : DestructorCounted(destructorId, hwInfo) {} }; - struct OsInterfaceMock : public DestructorCounted { + struct OsInterfaceMock : public DestructorCounted { OsInterfaceMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} }; + struct MemoryOperationsHandlerMock : public DestructorCounted { + MemoryOperationsHandlerMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} + }; struct MemoryMangerMock : public DestructorCounted { MemoryMangerMock(uint32_t &destructorId, ExecutionEnvironment &executionEnvironment) : DestructorCounted(destructorId, executionEnvironment) {} }; @@ -235,6 +239,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe executionEnvironment->commandStreamReceivers.resize(1); executionEnvironment->gmmHelper = std::make_unique(destructorId, platformDevices[0]); executionEnvironment->osInterface = std::make_unique(destructorId); + executionEnvironment->memoryOperationsInterface = std::make_unique(destructorId); executionEnvironment->memoryManager = std::make_unique(destructorId, *executionEnvironment); executionEnvironment->aubCenter = std::make_unique(destructorId); executionEnvironment->commandStreamReceivers[0].push_back(std::make_unique(destructorId, *executionEnvironment)); @@ -244,7 +249,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe executionEnvironment->sourceLevelDebugger = std::make_unique(destructorId); executionEnvironment.reset(nullptr); - EXPECT_EQ(9u, destructorId); + EXPECT_EQ(10u, destructorId); } TEST(ExecutionEnvironment, givenMultipleDevicesWhenTheyAreCreatedTheyAllReuseTheSameMemoryManagerAndCommandStreamReceiver) { diff --git a/unit_tests/mocks/CMakeLists.txt b/unit_tests/mocks/CMakeLists.txt index 7e890f3e29..eb332b7ba8 100644 --- a/unit_tests/mocks/CMakeLists.txt +++ b/unit_tests/mocks/CMakeLists.txt @@ -56,6 +56,7 @@ set(IGDRCL_SRCS_tests_mocks ${CMAKE_CURRENT_SOURCE_DIR}/mock_lrca_helper.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_manager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_manager.h + ${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_operations_handler.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_os_context.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_ostime.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_physical_address_allocator.h diff --git a/unit_tests/mocks/mock_memory_operations_handler.h b/unit_tests/mocks/mock_memory_operations_handler.h new file mode 100644 index 0000000000..42d6017fcd --- /dev/null +++ b/unit_tests/mocks/mock_memory_operations_handler.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "core/memory_manager/memory_operations_handler.h" + +namespace NEO { + +class GraphicsAllocation; + +class MockMemoryOperationsHandler : public MemoryOperationsHandler { + public: + MockMemoryOperationsHandler() {} + virtual ~MockMemoryOperationsHandler() {} + bool makeResident(GraphicsAllocation &gfxAllocation) { return false; } + bool evict(GraphicsAllocation &gfxAllocation) { return false; } + bool isResident(GraphicsAllocation &gfxAllocation) { return false; } +}; +} // namespace NEO \ No newline at end of file diff --git a/unit_tests/os_interface/CMakeLists.txt b/unit_tests/os_interface/CMakeLists.txt index 2d11d01945..7bb2aa0b74 100644 --- a/unit_tests/os_interface/CMakeLists.txt +++ b/unit_tests/os_interface/CMakeLists.txt @@ -19,6 +19,10 @@ set(IGDRCL_SRCS_tests_os_interface_base ${CMAKE_CURRENT_SOURCE_DIR}/performance_counters_gen_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/performance_counters_tests.cpp ) + +get_property(NEO_CORE_OS_INTERFACE_AUB_TESTS GLOBAL PROPERTY NEO_CORE_OS_INTERFACE_AUB_TESTS) +list(APPEND IGDRCL_SRCS_tests_os_interface_base ${NEO_CORE_OS_INTERFACE_AUB_TESTS}) + target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_os_interface_base}) set_property(GLOBAL PROPERTY IGDRCL_SRCS_tests_os_interface_base ${IGDRCL_SRCS_tests_os_interface_base}) add_subdirectories() diff --git a/unit_tests/os_interface/device_factory_tests.cpp b/unit_tests/os_interface/device_factory_tests.cpp index 2615f45e07..f9aed554a7 100644 --- a/unit_tests/os_interface/device_factory_tests.cpp +++ b/unit_tests/os_interface/device_factory_tests.cpp @@ -11,6 +11,7 @@ #include "runtime/helpers/options.h" #include "runtime/memory_manager/memory_constants.h" #include "runtime/os_interface/device_factory.h" +#include "runtime/os_interface/os_interface.h" #include "runtime/os_interface/os_library.h" #include "runtime/platform/platform.h" @@ -169,4 +170,4 @@ TEST_F(DeviceFactoryTest, givenGetDevicesCallWhenItIsDoneThenOsInterfaceIsAlloca bool success = DeviceFactory::getDevices(numDevices, *executionEnvironment); EXPECT_TRUE(success); EXPECT_NE(nullptr, executionEnvironment->osInterface); -} +} \ No newline at end of file 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 190b4f3644..3e50a846ec 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 @@ -29,6 +29,7 @@ HWTEST_F(DrmCommandStreamMMTest, MMwithPinBB) { executionEnvironment.osInterface = std::make_unique(); executionEnvironment.osInterface->get()->setDrm(&mock); + executionEnvironment.memoryOperationsInterface = std::make_unique(); DrmCommandStreamReceiver csr(executionEnvironment, gemCloseWorkerMode::gemCloseWorkerInactive); 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 0257fa0d90..a331451c83 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -43,6 +43,7 @@ class DrmCommandStreamFixture { executionEnvironment.setHwInfo(*platformDevices); executionEnvironment.osInterface = std::make_unique(); executionEnvironment.osInterface->get()->setDrm(mock.get()); + executionEnvironment.memoryOperationsInterface = std::make_unique(); osContext = std::make_unique(*mock, 0u, 1, HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false); diff --git a/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp b/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp index 5d3efadae2..6250c061e5 100644 --- a/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp +++ b/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp @@ -71,6 +71,7 @@ class DrmGemCloseWorkerFixture { executionEnvironment.osInterface = std::make_unique(); executionEnvironment.osInterface->get()->setDrm(drmMock); + executionEnvironment.memoryOperationsInterface = std::make_unique(); this->mm = new DrmMemoryManager(gemCloseWorkerMode::gemCloseWorkerInactive, false, diff --git a/unit_tests/os_interface/linux/drm_memory_manager_tests.h b/unit_tests/os_interface/linux/drm_memory_manager_tests.h index 2b70f1bc83..0f9896e8c3 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.h +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.h @@ -25,6 +25,7 @@ class DrmMemoryManagerBasic : public ::testing::Test { void SetUp() override { executionEnvironment.osInterface = std::make_unique(); executionEnvironment.osInterface->get()->setDrm(Drm::get(0)); + executionEnvironment.memoryOperationsInterface = std::make_unique(); } MockExecutionEnvironment executionEnvironment; diff --git a/unit_tests/os_interface/linux/drm_residency_handler_tests.cpp b/unit_tests/os_interface/linux/drm_residency_handler_tests.cpp index e0ec6d306d..b9471249cc 100644 --- a/unit_tests/os_interface/linux/drm_residency_handler_tests.cpp +++ b/unit_tests/os_interface/linux/drm_residency_handler_tests.cpp @@ -5,7 +5,7 @@ * */ -#include "runtime/os_interface/linux/drm_residency_handler.h" +#include "runtime/os_interface/linux/drm_memory_operations_handler.h" #include "test.h" #include "unit_tests/mocks/mock_graphics_allocation.h" @@ -13,22 +13,22 @@ using namespace NEO; -struct DrmResidencyHandlerTest : public ::testing::Test { +struct DrmMemoryOperationsHandlerTest : public ::testing::Test { void SetUp() override { - drmResidencyHandler = std::make_unique(); + drmMemoryOperationsHandler = std::make_unique(); } MockGraphicsAllocation graphicsAllocation; - std::unique_ptr drmResidencyHandler; + std::unique_ptr drmMemoryOperationsHandler; }; -TEST_F(DrmResidencyHandlerTest, whenMakingResidentAllocaionExpectMakeResidentFail) { - EXPECT_FALSE(drmResidencyHandler->makeResident(graphicsAllocation)); - EXPECT_FALSE(drmResidencyHandler->isResident(graphicsAllocation)); +TEST_F(DrmMemoryOperationsHandlerTest, whenMakingResidentAllocaionExpectMakeResidentFail) { + EXPECT_FALSE(drmMemoryOperationsHandler->makeResident(graphicsAllocation)); + EXPECT_FALSE(drmMemoryOperationsHandler->isResident(graphicsAllocation)); } -TEST_F(DrmResidencyHandlerTest, whenEvictingResidentAllocationExpectEvictFalse) { - EXPECT_FALSE(drmResidencyHandler->makeResident(graphicsAllocation)); - EXPECT_FALSE(drmResidencyHandler->evict(graphicsAllocation)); - EXPECT_FALSE(drmResidencyHandler->isResident(graphicsAllocation)); +TEST_F(DrmMemoryOperationsHandlerTest, whenEvictingResidentAllocationExpectEvictFalse) { + EXPECT_FALSE(drmMemoryOperationsHandler->makeResident(graphicsAllocation)); + EXPECT_FALSE(drmMemoryOperationsHandler->evict(graphicsAllocation)); + EXPECT_FALSE(drmMemoryOperationsHandler->isResident(graphicsAllocation)); } diff --git a/unit_tests/os_interface/linux/os_interface_linux_tests.cpp b/unit_tests/os_interface/linux/os_interface_linux_tests.cpp index 56c5c7b906..4d8c48998a 100644 --- a/unit_tests/os_interface/linux/os_interface_linux_tests.cpp +++ b/unit_tests/os_interface/linux/os_interface_linux_tests.cpp @@ -23,10 +23,4 @@ TEST(OsInterfaceTest, GivenLinuxOsInterfaceWhenDeviceHandleQueriedthenZeroIsRetu OSInterface osInterface; EXPECT_EQ(0u, osInterface.getDeviceHandle()); } - -TEST(OsInterfaceTest, GivenLinuxOsInterfaceWhenResidencyInterfaceRetrievedThenCreatedObjectReturned) { - OSInterface osInterface; - EXPECT_NE(nullptr, osInterface.getResidencyInterface()); -} - } // namespace NEO diff --git a/unit_tests/os_interface/performance_counters_tests.cpp b/unit_tests/os_interface/performance_counters_tests.cpp index fbb4ecdcfa..57cf4e5c96 100644 --- a/unit_tests/os_interface/performance_counters_tests.cpp +++ b/unit_tests/os_interface/performance_counters_tests.cpp @@ -5,6 +5,7 @@ * */ +#include "core/unit_tests/helpers/debug_manager_state_restore.h" #include "runtime/helpers/options.h" #include "runtime/os_interface/os_interface.h" #include "runtime/os_interface/os_time.h" @@ -561,4 +562,4 @@ TEST_F(PerformanceCountersTest, givenRenderCoreFamilyThenMetricsLibraryGenIdenti const auto &hwInfo = device->getHardwareInfo(); const auto gen = hwInfo.platform.eRenderCoreFamily; EXPECT_NE(ClientGen::Unknown, static_cast(HwHelper::get(gen).getMetricsLibraryGenId())); -} \ No newline at end of file +} 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 fce93f1f62..98ac8e3d99 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -24,6 +24,7 @@ #include "runtime/os_interface/windows/os_interface.h" #include "runtime/os_interface/windows/wddm_device_command_stream.h" #include "runtime/os_interface/windows/wddm_memory_manager.h" +#include "runtime/os_interface/windows/wddm_memory_operations_handler.h" #include "runtime/os_interface/windows/wddm_residency_controller.h" #include "runtime/platform/platform.h" #include "test.h" @@ -63,7 +64,6 @@ class WddmCommandStreamFixture { memoryManager = new MockWddmMemoryManager(*executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); wddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); - csr = new WddmCommandStreamReceiver(*executionEnvironment); device.reset(MockDevice::create(executionEnvironment, 0u)); @@ -803,6 +803,7 @@ HWTEST_F(WddmSimpleTest, givenDefaultWddmCsrWhenItIsCreatedThenBatchingIsTurnedO auto wddm = Wddm::createWddm(); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); std::unique_ptr> mockCsr(new MockWddmCsr(*executionEnvironment)); EXPECT_EQ(DispatchMode::BatchedDispatch, mockCsr->dispatchMode); } @@ -811,6 +812,7 @@ HWTEST_F(WddmDefaultTest, givenFtrWddmHwQueuesFlagWhenCreatingCsrThenPickWddmVer auto wddm = Wddm::createWddm(); pDevice->executionEnvironment->osInterface = std::make_unique(); pDevice->executionEnvironment->osInterface->get()->setWddm(wddm); + pDevice->executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); WddmCommandStreamReceiver wddmCsr(*pDevice->executionEnvironment); auto wddmFromCsr = wddmCsr.peekWddm(); diff --git a/unit_tests/os_interface/windows/gl/gl_os_sharing_tests.cpp b/unit_tests/os_interface/windows/gl/gl_os_sharing_tests.cpp index 50af975826..7bcdafae82 100644 --- a/unit_tests/os_interface/windows/gl/gl_os_sharing_tests.cpp +++ b/unit_tests/os_interface/windows/gl/gl_os_sharing_tests.cpp @@ -11,7 +11,7 @@ #include "runtime/os_interface/windows/os_context_win.h" #include "runtime/os_interface/windows/os_interface.h" #include "runtime/os_interface/windows/wddm/wddm.h" -#include "runtime/os_interface/windows/wddm_residency_handler.h" +#include "runtime/os_interface/windows/wddm_memory_operations_handler.h" #include "runtime/sharings/gl/gl_arb_sync_event.h" #include "runtime/sharings/gl/gl_sharing.h" #include "unit_tests/mocks/gl/mock_gl_sharing.h" diff --git a/unit_tests/os_interface/windows/os_interface_win_tests.cpp b/unit_tests/os_interface/windows/os_interface_win_tests.cpp index 27fb766ef9..974f942925 100644 --- a/unit_tests/os_interface/windows/os_interface_win_tests.cpp +++ b/unit_tests/os_interface/windows/os_interface_win_tests.cpp @@ -21,7 +21,7 @@ TEST_F(OsInterfaceTest, GivenWindowsWhenCreateEentIsCalledThenValidEventHandleIs EXPECT_EQ(TRUE, ret); } -TEST(OsContextTest, givenWddmWhenCreateOsContextAfterInitWddmThenOsContextIsInitializedTrimCallbackIsRegisteredResidencyHandlerCreated) { +TEST(OsContextTest, givenWddmWhenCreateOsContextAfterInitWddmThenOsContextIsInitializedTrimCallbackIsRegisteredMemoryOperationsHandlerCreated) { auto wddm = new WddmMock; OSInterface osInterface; osInterface.get()->setWddm(wddm); @@ -33,5 +33,4 @@ TEST(OsContextTest, givenWddmWhenCreateOsContextAfterInitWddmThenOsContextIsInit EXPECT_TRUE(osContext->isInitialized()); EXPECT_EQ(osContext->getWddm(), wddm); EXPECT_EQ(1u, wddm->registerTrimCallbackResult.called); - EXPECT_NE(nullptr, osInterface.getResidencyInterface()); } diff --git a/unit_tests/os_interface/windows/wddm_fixture.h b/unit_tests/os_interface/windows/wddm_fixture.h index de01984ab7..0e5a7cc7fe 100644 --- a/unit_tests/os_interface/windows/wddm_fixture.h +++ b/unit_tests/os_interface/windows/wddm_fixture.h @@ -13,6 +13,7 @@ #include "runtime/os_interface/windows/gdi_interface.h" #include "runtime/os_interface/windows/os_context_win.h" #include "runtime/os_interface/windows/os_interface.h" +#include "runtime/os_interface/windows/wddm_memory_operations_handler.h" #include "runtime/platform/platform.h" #include "test.h" #include "unit_tests/mocks/mock_wddm.h" @@ -29,6 +30,7 @@ struct WddmFixture : ::testing::Test { wddm = static_cast(Wddm::createWddm()); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); osInterface = executionEnvironment->osInterface.get(); gdi = new MockGdi(); wddm->gdi.reset(gdi); @@ -55,6 +57,7 @@ struct WddmFixtureWithMockGdiDll : public GdiDllFixture { wddm = static_cast(Wddm::createWddm()); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); osInterface = executionEnvironment->osInterface.get(); } diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp index 0734e8a99e..fbef53ebd2 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -47,6 +47,7 @@ void WddmMemoryManagerFixture::SetUp() { executionEnvironment = platformImpl->peekExecutionEnvironment(); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); memoryManager = std::make_unique(*executionEnvironment); } @@ -1297,6 +1298,7 @@ TEST(WddmMemoryManagerDefaults, givenDefaultWddmMemoryManagerWhenItIsQueriedForI auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo); auto wddm = new WddmMock(); executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); auto hwInfoMock = *platformDevices[0]; wddm->init(hwInfoMock); MockWddmMemoryManager memoryManager(*executionEnvironment); @@ -1624,6 +1626,7 @@ TEST(WddmMemoryManagerCleanupTest, givenUsedTagAllocationInWddmMemoryManagerWhen executionEnvironment.osInterface = std::make_unique(); executionEnvironment.osInterface->get()->setWddm(wddm); + executionEnvironment.memoryOperationsInterface = std::make_unique(wddm); executionEnvironment.commandStreamReceivers.resize(1); executionEnvironment.commandStreamReceivers[0].push_back(std::unique_ptr(csr)); executionEnvironment.memoryManager = std::make_unique(executionEnvironment); diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h index 2af69a12ec..5291b7324c 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h @@ -8,6 +8,7 @@ #pragma once #include "runtime/os_interface/windows/os_interface.h" +#include "runtime/os_interface/windows/wddm_memory_operations_handler.h" #include "test.h" #include "unit_tests/helpers/execution_environment_helper.h" #include "unit_tests/mocks/mock_context.h" @@ -56,6 +57,7 @@ class MockWddmMemoryManagerFixture { executionEnvironment->osInterface.reset(new OSInterface()); executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); memoryManager = std::make_unique(*executionEnvironment); osContext = memoryManager->createAndRegisterOsContext(nullptr, HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0], @@ -101,6 +103,7 @@ class WddmMemoryManagerFixtureWithGmockWddm : public ExecutionEnvironmentFixture auto hwInfo = *platformDevices[0]; wddm->init(hwInfo); executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); osInterface = executionEnvironment->osInterface.get(); memoryManager = new (std::nothrow) MockWddmMemoryManager(*executionEnvironment); //assert we have memory manager @@ -162,6 +165,7 @@ class MockWddmMemoryManagerTest : public ::testing::Test { executionEnvironment = getExecutionEnvironmentImpl(hwInfo); wddm = new WddmMock(); executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); } HardwareInfo *hwInfo; diff --git a/unit_tests/os_interface/windows/wddm_preemption_tests.cpp b/unit_tests/os_interface/windows/wddm_preemption_tests.cpp index 67089b2b42..74721eb454 100644 --- a/unit_tests/os_interface/windows/wddm_preemption_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_preemption_tests.cpp @@ -32,6 +32,7 @@ class WddmPreemptionTests : public Test { wddm = static_cast(Wddm::createWddm()); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); osInterface = executionEnvironment->osInterface.get(); auto regReader = new RegistryReaderMock(); wddm->registryReader.reset(regReader); diff --git a/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp b/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp index b1dfadc5a4..0933df7aa6 100644 --- a/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp @@ -5,7 +5,7 @@ * */ -#include "core/memory_manager/residency_handler.h" +#include "core/memory_manager/memory_operations_handler.h" #include "runtime/command_stream/preemption.h" #include "runtime/execution_environment/execution_environment.h" #include "runtime/helpers/hw_helper.h" @@ -14,6 +14,7 @@ #include "runtime/os_interface/windows/os_context_win.h" #include "runtime/os_interface/windows/os_interface.h" #include "runtime/os_interface/windows/wddm/wddm_interface.h" +#include "runtime/os_interface/windows/wddm_memory_operations_handler.h" #include "runtime/os_interface/windows/wddm_residency_controller.h" #include "runtime/platform/platform.h" #include "test.h" @@ -94,6 +95,7 @@ struct WddmResidencyControllerWithMockWddmTest : public WddmResidencyControllerT executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); memoryManager = std::make_unique(*executionEnvironment); osContext = memoryManager->createAndRegisterOsContext(nullptr, HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0], 1, preemptionMode, false); @@ -126,6 +128,7 @@ struct WddmResidencyControllerWithGdiAndMemoryManagerTest : ::testing::Test { executionEnvironment = platform()->peekExecutionEnvironment(); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setWddm(wddm); + executionEnvironment->memoryOperationsInterface = std::make_unique(wddm); memoryManager = std::make_unique(*executionEnvironment); osContext = memoryManager->createAndRegisterOsContext(nullptr, HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0], diff --git a/unit_tests/os_interface/windows/wddm_residency_handler_tests.cpp b/unit_tests/os_interface/windows/wddm_residency_handler_tests.cpp index f3757a8e8e..979a15d72f 100644 --- a/unit_tests/os_interface/windows/wddm_residency_handler_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_residency_handler_tests.cpp @@ -5,7 +5,7 @@ * */ -#include "runtime/os_interface/windows/wddm_residency_handler.h" +#include "runtime/os_interface/windows/wddm_memory_operations_handler.h" #include "test.h" #include "unit_tests/mocks/mock_allocation_properties.h" #include "unit_tests/mocks/mock_wddm.h" @@ -14,24 +14,24 @@ using namespace NEO; -struct WddmResidencyHandlerTest : public WddmTest { +struct WddmMemoryOperationsHandlerTest : public WddmTest { void SetUp() override { WddmTest::SetUp(); - wddmResidencyHandler = std::make_unique(wddm); + wddmMemoryOperationsHandler = std::make_unique(wddm); wddmAllocation.handle = 0x2; } - std::unique_ptr wddmResidencyHandler; + std::unique_ptr wddmMemoryOperationsHandler; MockWddmAllocation wddmAllocation; }; -TEST_F(WddmResidencyHandlerTest, whenMakingResidentAllocaionExpectMakeResidentCalled) { - EXPECT_TRUE(wddmResidencyHandler->makeResident(wddmAllocation)); - EXPECT_TRUE(wddmResidencyHandler->isResident(wddmAllocation)); +TEST_F(WddmMemoryOperationsHandlerTest, whenMakingResidentAllocaionExpectMakeResidentCalled) { + EXPECT_TRUE(wddmMemoryOperationsHandler->makeResident(wddmAllocation)); + EXPECT_TRUE(wddmMemoryOperationsHandler->isResident(wddmAllocation)); } -TEST_F(WddmResidencyHandlerTest, whenEvictingResidentAllocationExpectEvictCalled) { - EXPECT_TRUE(wddmResidencyHandler->makeResident(wddmAllocation)); - EXPECT_TRUE(wddmResidencyHandler->evict(wddmAllocation)); - EXPECT_FALSE(wddmResidencyHandler->isResident(wddmAllocation)); +TEST_F(WddmMemoryOperationsHandlerTest, whenEvictingResidentAllocationExpectEvictCalled) { + EXPECT_TRUE(wddmMemoryOperationsHandler->makeResident(wddmAllocation)); + EXPECT_TRUE(wddmMemoryOperationsHandler->evict(wddmAllocation)); + EXPECT_FALSE(wddmMemoryOperationsHandler->isResident(wddmAllocation)); } diff --git a/unit_tests/tbx/CMakeLists.txt b/unit_tests/tbx/CMakeLists.txt index eced58bc52..3dea85aca0 100644 --- a/unit_tests/tbx/CMakeLists.txt +++ b/unit_tests/tbx/CMakeLists.txt @@ -7,9 +7,9 @@ add_executable(igdrcl_tbx_tests ${CMAKE_CURRENT_SOURCE_DIR}/main_tbx.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tbx_tests_configuration.cpp - ${IGDRCL_SOURCE_DIR}/runtime/aub/aub_stream_interface.cpp ${IGDRCL_SOURCE_DIR}/runtime/dll/create_command_stream.cpp ${IGDRCL_SOURCE_DIR}/runtime/dll${BRANCH_DIR_SUFFIX}/get_devices.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/options.cpp $