From 27a3307bb093e1060090d8e4e055019cf9551d22 Mon Sep 17 00:00:00 2001 From: Young Jin Yoon Date: Fri, 22 Mar 2024 06:51:12 +0000 Subject: [PATCH] feature: support explicit memory locking Added lockMemory in context to explicitly locking memory, Added a boolean flag in graphics_allocation to indicate the allocation is locked, and modified memory_operations_handler to add lock(). Change the logic to work correctly with makeResident() when lock() is called previously for the same memory region Related-To: NEO-8277 Signed-off-by: Young Jin Yoon --- level_zero/core/source/context/CMakeLists.txt | 3 +- level_zero/core/source/context/context.h | 2 +- .../core/source/context/context_imp.cpp | 3 + level_zero/core/source/context/context_imp.h | 1 + ..._helper.cpp => context_imp_drm_helper.cpp} | 2 +- ...cpp => context_imp_drm_or_wddm_helper.cpp} | 2 +- .../source/context/context_imp_helper.cpp | 18 ++ ...helper.cpp => context_imp_wddm_helper.cpp} | 3 +- .../unit_tests/sources/context/CMakeLists.txt | 3 +- .../sources/context/linux/CMakeLists.txt | 4 +- ...lper.cpp => test_context_helper_linux.cpp} | 5 +- .../sources/context/test_context.cpp | 25 +++ .../sources/context/test_context_helper.cpp | 48 ++++++ .../sources/context/windows/CMakeLists.txt | 4 +- ...er.cpp => test_context_helper_windows.cpp} | 4 +- .../memory_manager/graphics_allocation.h | 6 +- .../memory_operations_handler.h | 3 +- .../aub_memory_operations_handler.cpp | 6 +- .../aub_memory_operations_handler.h | 3 +- .../os_interface/linux/drm_buffer_object.h | 4 + .../drm_memory_operations_handler_bind.cpp | 17 +- .../drm_memory_operations_handler_bind.h | 3 +- .../drm_memory_operations_handler_default.cpp | 26 ++- .../drm_memory_operations_handler_default.h | 3 +- ..._memory_operations_handler_with_aub_dump.h | 7 +- shared/source/os_interface/linux/drm_neo.cpp | 3 +- .../source/os_interface/linux/ioctl_helper.h | 6 +- .../linux/ioctl_helper_prelim.cpp | 4 +- .../linux/ioctl_helper_upstream.cpp | 2 +- .../os_interface/linux/xe/CMakeLists.txt | 1 + .../os_interface/linux/xe/ioctl_helper_xe.cpp | 16 +- .../os_interface/linux/xe/ioctl_helper_xe.h | 5 +- .../linux/xe/ioctl_helper_xe_vm_bind_flag.cpp | 29 ++++ .../windows/wddm_memory_operations_handler.h | 5 +- .../mocks/mock_memory_operations_handler.h | 11 +- .../aub_memory_operations_handler_tests.cpp | 25 ++- .../os_interface/linux/CMakeLists.txt | 4 +- ..._memory_operations_handler_bind_tests.cpp} | 85 +++++++++ ...emory_operations_handler_default_tests.cpp | 163 ++++++++++++++++++ ...operations_handler_with_aub_dump_tests.cpp | 52 +++++- .../linux/drm_residency_handler_tests.cpp | 48 ------ .../linux/ioctl_helper_tests_prelim.cpp | 31 ++-- .../linux/ioctl_helper_tests_upstream.cpp | 6 +- .../os_interface/linux/xe/CMakeLists.txt | 1 + .../linux/xe/ioctl_helper_xe_tests.cpp | 7 +- .../xe/ioctl_helper_xe_vm_bind_flag_tests.cpp | 41 +++++ .../windows/wddm_memory_manager_tests.cpp | 17 ++ ...operations_handler_with_aub_dump_tests.cpp | 6 +- 48 files changed, 644 insertions(+), 129 deletions(-) rename level_zero/core/source/context/context_imp_drm/{context_imp_helper.cpp => context_imp_drm_helper.cpp} (92%) rename level_zero/core/source/context/context_imp_drm_or_wddm/{context_imp_helper.cpp => context_imp_drm_or_wddm_helper.cpp} (92%) create mode 100644 level_zero/core/source/context/context_imp_helper.cpp rename level_zero/core/source/context/context_imp_wddm/{context_imp_helper.cpp => context_imp_wddm_helper.cpp} (92%) rename level_zero/core/test/unit_tests/sources/context/linux/{test_context_helper.cpp => test_context_helper_linux.cpp} (90%) create mode 100644 level_zero/core/test/unit_tests/sources/context/test_context_helper.cpp rename level_zero/core/test/unit_tests/sources/context/windows/{test_context_helper.cpp => test_context_helper_windows.cpp} (93%) create mode 100644 shared/source/os_interface/linux/xe/ioctl_helper_xe_vm_bind_flag.cpp rename shared/test/unit_test/os_interface/linux/{drm_residency_handler_prelim_tests.cpp => drm_memory_operations_handler_bind_tests.cpp} (94%) create mode 100644 shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_default_tests.cpp delete mode 100644 shared/test/unit_test/os_interface/linux/drm_residency_handler_tests.cpp create mode 100644 shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_vm_bind_flag_tests.cpp diff --git a/level_zero/core/source/context/CMakeLists.txt b/level_zero/core/source/context/CMakeLists.txt index 5090a786a7..ffc4bceae1 100644 --- a/level_zero/core/source/context/CMakeLists.txt +++ b/level_zero/core/source/context/CMakeLists.txt @@ -7,8 +7,9 @@ target_sources(${L0_STATIC_LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/${BRANCH_DIR_SUFFIX}context_imp_helper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/context_imp_${DRIVER_MODEL}/context_imp_${DRIVER_MODEL}.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/context_imp_${DRIVER_MODEL}${BRANCH_DIR_SUFFIX}context_imp_helper.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/context_imp_${DRIVER_MODEL}${BRANCH_DIR_SUFFIX}context_imp_${DRIVER_MODEL}_helper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/context_imp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/context_imp.h ${CMAKE_CURRENT_SOURCE_DIR}/context.h diff --git a/level_zero/core/source/context/context.h b/level_zero/core/source/context/context.h index c64ba5e0c2..aed34492ee 100644 --- a/level_zero/core/source/context/context.h +++ b/level_zero/core/source/context/context.h @@ -162,7 +162,7 @@ struct Context : _ze_context_handle_t { virtual ze_result_t getVirtualAddressSpaceIpcHandle(ze_device_handle_t hDevice, ze_ipc_mem_handle_t *pIpcHandle) = 0; virtual ze_result_t putVirtualAddressSpaceIpcHandle(ze_ipc_mem_handle_t ipcHandle) = 0; - + virtual ze_result_t lockMemory(ze_device_handle_t hDevice, void *ptr, size_t size) = 0; virtual bool isShareableMemory(const void *exportDesc, bool exportableMemory, NEO::Device *neoDevice) = 0; virtual void *getMemHandlePtr(ze_device_handle_t hDevice, uint64_t handle, NEO::AllocationType allocationType, ze_ipc_memory_flags_t flags) = 0; diff --git a/level_zero/core/source/context/context_imp.cpp b/level_zero/core/source/context/context_imp.cpp index ade634443a..abd5c2aa5a 100644 --- a/level_zero/core/source/context/context_imp.cpp +++ b/level_zero/core/source/context/context_imp.cpp @@ -471,6 +471,9 @@ ze_result_t ContextImp::makeMemoryResident(ze_device_handle_t hDevice, void *ptr return ZE_RESULT_ERROR_INVALID_ARGUMENT; } } + if (allocation->isLockedMemory()) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } NEO::MemoryOperationsHandler *memoryOperationsIface = neoDevice->getRootDeviceEnvironment().memoryOperationsInterface.get(); auto success = memoryOperationsIface->makeResident(neoDevice, ArrayRef(&allocation, 1)); diff --git a/level_zero/core/source/context/context_imp.h b/level_zero/core/source/context/context_imp.h index 16f38d98b2..80958c0d19 100644 --- a/level_zero/core/source/context/context_imp.h +++ b/level_zero/core/source/context/context_imp.h @@ -66,6 +66,7 @@ struct ContextImp : Context { void **ptr) override; ze_result_t getIpcHandleFromFd(uint64_t handle, ze_ipc_mem_handle_t *pIpcHandle) override; ze_result_t getFdFromIpcHandle(ze_ipc_mem_handle_t ipcHandle, uint64_t *pHandle) override; + ze_result_t lockMemory(ze_device_handle_t hDevice, void *ptr, size_t size) override; ze_result_t getIpcMemHandles( diff --git a/level_zero/core/source/context/context_imp_drm/context_imp_helper.cpp b/level_zero/core/source/context/context_imp_drm/context_imp_drm_helper.cpp similarity index 92% rename from level_zero/core/source/context/context_imp_drm/context_imp_helper.cpp rename to level_zero/core/source/context/context_imp_drm/context_imp_drm_helper.cpp index 08585fe140..2665e601cb 100644 --- a/level_zero/core/source/context/context_imp_drm/context_imp_helper.cpp +++ b/level_zero/core/source/context/context_imp_drm/context_imp_drm_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * diff --git a/level_zero/core/source/context/context_imp_drm_or_wddm/context_imp_helper.cpp b/level_zero/core/source/context/context_imp_drm_or_wddm/context_imp_drm_or_wddm_helper.cpp similarity index 92% rename from level_zero/core/source/context/context_imp_drm_or_wddm/context_imp_helper.cpp rename to level_zero/core/source/context/context_imp_drm_or_wddm/context_imp_drm_or_wddm_helper.cpp index 08585fe140..2665e601cb 100644 --- a/level_zero/core/source/context/context_imp_drm_or_wddm/context_imp_helper.cpp +++ b/level_zero/core/source/context/context_imp_drm_or_wddm/context_imp_drm_or_wddm_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * diff --git a/level_zero/core/source/context/context_imp_helper.cpp b/level_zero/core/source/context/context_imp_helper.cpp new file mode 100644 index 0000000000..602900c98c --- /dev/null +++ b/level_zero/core/source/context/context_imp_helper.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/source/context/context_imp.h" +#include "level_zero/core/source/device/device.h" +#include "level_zero/core/source/driver/driver_handle_imp.h" + +namespace L0 { + +ze_result_t ContextImp::lockMemory(ze_device_handle_t device, void *ptr, size_t size) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + +} // namespace L0 diff --git a/level_zero/core/source/context/context_imp_wddm/context_imp_helper.cpp b/level_zero/core/source/context/context_imp_wddm/context_imp_wddm_helper.cpp similarity index 92% rename from level_zero/core/source/context/context_imp_wddm/context_imp_helper.cpp rename to level_zero/core/source/context/context_imp_wddm/context_imp_wddm_helper.cpp index 7cd84abacb..2665e601cb 100644 --- a/level_zero/core/source/context/context_imp_wddm/context_imp_helper.cpp +++ b/level_zero/core/source/context/context_imp_wddm/context_imp_wddm_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,4 +18,5 @@ ze_result_t ContextImp::getVirtualAddressSpaceIpcHandle(ze_device_handle_t hDevi ze_result_t ContextImp::putVirtualAddressSpaceIpcHandle(ze_ipc_mem_handle_t ipcHandle) { return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } + } // namespace L0 diff --git a/level_zero/core/test/unit_tests/sources/context/CMakeLists.txt b/level_zero/core/test/unit_tests/sources/context/CMakeLists.txt index e7dfd94d3c..4138c808ce 100644 --- a/level_zero/core/test/unit_tests/sources/context/CMakeLists.txt +++ b/level_zero/core/test/unit_tests/sources/context/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2020-2023 Intel Corporation +# Copyright (C) 2020-2024 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -8,6 +8,7 @@ target_sources(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/test_context.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_context_${DRIVER_MODEL}.cpp + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}test_context_helper.cpp ) add_subdirectories() diff --git a/level_zero/core/test/unit_tests/sources/context/linux/CMakeLists.txt b/level_zero/core/test/unit_tests/sources/context/linux/CMakeLists.txt index 028f1a7170..6a5e0b2776 100644 --- a/level_zero/core/test/unit_tests/sources/context/linux/CMakeLists.txt +++ b/level_zero/core/test/unit_tests/sources/context/linux/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2023 Intel Corporation +# Copyright (C) 2023-2024 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -7,7 +7,7 @@ if(UNIX) target_sources(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt - ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}test_context_helper.cpp + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}test_context_helper_linux.cpp ) endif() diff --git a/level_zero/core/test/unit_tests/sources/context/linux/test_context_helper.cpp b/level_zero/core/test/unit_tests/sources/context/linux/test_context_helper_linux.cpp similarity index 90% rename from level_zero/core/test/unit_tests/sources/context/linux/test_context_helper.cpp rename to level_zero/core/test/unit_tests/sources/context/linux/test_context_helper_linux.cpp index b3c24281ae..87f7b9d197 100644 --- a/level_zero/core/test/unit_tests/sources/context/linux/test_context_helper.cpp +++ b/level_zero/core/test/unit_tests/sources/context/linux/test_context_helper_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -10,12 +10,14 @@ #include "shared/test/common/mocks/mock_builtins.h" #include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_driver_model.h" +#include "shared/test/common/mocks/mock_memory_operations_handler.h" #include "shared/test/common/test_macros/test.h" #include "level_zero/core/source/context/context_imp.h" #include "level_zero/core/source/driver/driver_handle_imp.h" #include "level_zero/core/source/driver/driver_imp.h" #include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" +#include "level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h" #include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" #include "gtest/gtest.h" @@ -41,5 +43,6 @@ TEST_F(ContextGetVirtualAddressSpaceTests, givenDrmDriverModelWhenCallingGetVirt res = contextImp->destroy(); EXPECT_EQ(ZE_RESULT_SUCCESS, res); } + } // namespace ult } // namespace L0 diff --git a/level_zero/core/test/unit_tests/sources/context/test_context.cpp b/level_zero/core/test/unit_tests/sources/context/test_context.cpp index 8aa10749f5..42c68997d6 100644 --- a/level_zero/core/test/unit_tests/sources/context/test_context.cpp +++ b/level_zero/core/test/unit_tests/sources/context/test_context.cpp @@ -580,6 +580,31 @@ TEST_F(ContextMakeMemoryResidentTests, context->freeMem(ptr); } +TEST_F(ContextMakeMemoryResidentTests, + givenValidAllocationwithLockedWhenCallingMakeMemoryResidentThenInvalidArgumentIsReturned) { + const size_t size = 4096; + void *ptr = nullptr; + ze_host_mem_alloc_desc_t hostDesc = {}; + ze_device_mem_alloc_desc_t deviceDesc = {}; + ze_result_t res = context->allocSharedMem(device->toHandle(), + &deviceDesc, + &hostDesc, + size, + 0, + &ptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + DriverHandleImp *driverHandleImp = static_cast(hostDriverHandle.get()); + auto allocation = driverHandleImp->getDriverSystemMemoryAllocation(ptr, size, neoDevice->getRootDeviceIndex(), nullptr); + allocation->setLockedMemory(true); + + mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::success; + res = context->makeMemoryResident(device, ptr, size); + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, res); + + context->freeMem(ptr); +} + TEST_F(ContextMakeMemoryResidentTests, whenMakingASharedMemoryResidentThenIsAddedToVectorOfResidentAllocations) { const size_t size = 4096; diff --git a/level_zero/core/test/unit_tests/sources/context/test_context_helper.cpp b/level_zero/core/test/unit_tests/sources/context/test_context_helper.cpp new file mode 100644 index 0000000000..fbcb5311bf --- /dev/null +++ b/level_zero/core/test/unit_tests/sources/context/test_context_helper.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2023-2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/os_interface/os_interface.h" +#include "shared/test/common/mocks/mock_builtins.h" +#include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_driver_model.h" +#include "shared/test/common/mocks/mock_memory_operations_handler.h" +#include "shared/test/common/test_macros/test.h" + +#include "level_zero/core/source/context/context_imp.h" +#include "level_zero/core/source/driver/driver_handle_imp.h" +#include "level_zero/core/source/driver/driver_imp.h" +#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" +#include "level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h" +#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" + +#include "gtest/gtest.h" +namespace L0 { +namespace ult { + +using ContextLockMemoryTests = Test; + +TEST_F(ContextLockMemoryTests, givenValidPointerWhenCallingLockMemoryThenUnsupportedErrorIsReturned) { + const size_t size = 4096; + void *ptr = nullptr; + ze_device_mem_alloc_desc_t deviceDesc = {}; + ze_result_t res = context->allocDeviceMem(device->toHandle(), + &deviceDesc, + size, + 0, + &ptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + mockMemoryInterface->lockResult = NEO::MemoryOperationsStatus::success; + res = context->lockMemory(device, ptr, size); + EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, res); + + context->freeMem(ptr); +} + +} // namespace ult +} // namespace L0 diff --git a/level_zero/core/test/unit_tests/sources/context/windows/CMakeLists.txt b/level_zero/core/test/unit_tests/sources/context/windows/CMakeLists.txt index 3243baad55..c0750f1f30 100644 --- a/level_zero/core/test/unit_tests/sources/context/windows/CMakeLists.txt +++ b/level_zero/core/test/unit_tests/sources/context/windows/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2023 Intel Corporation +# Copyright (C) 2023-2024 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -7,6 +7,6 @@ if(WIN32) target_sources(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt - ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}test_context_helper.cpp + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}test_context_helper_windows.cpp ) endif() diff --git a/level_zero/core/test/unit_tests/sources/context/windows/test_context_helper.cpp b/level_zero/core/test/unit_tests/sources/context/windows/test_context_helper_windows.cpp similarity index 93% rename from level_zero/core/test/unit_tests/sources/context/windows/test_context_helper.cpp rename to level_zero/core/test/unit_tests/sources/context/windows/test_context_helper_windows.cpp index bd853e52e9..7a0ffae58f 100644 --- a/level_zero/core/test/unit_tests/sources/context/windows/test_context_helper.cpp +++ b/level_zero/core/test/unit_tests/sources/context/windows/test_context_helper_windows.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -10,12 +10,14 @@ #include "shared/test/common/mocks/mock_builtins.h" #include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_driver_model.h" +#include "shared/test/common/mocks/mock_memory_operations_handler.h" #include "shared/test/common/test_macros/test.h" #include "level_zero/core/source/context/context_imp.h" #include "level_zero/core/source/driver/driver_handle_imp.h" #include "level_zero/core/source/driver/driver_imp.h" #include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" +#include "level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h" #include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" #include "gtest/gtest.h" diff --git a/shared/source/memory_manager/graphics_allocation.h b/shared/source/memory_manager/graphics_allocation.h index 16954b9da3..a053791810 100644 --- a/shared/source/memory_manager/graphics_allocation.h +++ b/shared/source/memory_manager/graphics_allocation.h @@ -124,6 +124,8 @@ class GraphicsAllocation : public IDNode { bool peekEvictable() const { return allocationInfo.flags.evictable; } bool isFlushL3Required() const { return allocationInfo.flags.flushL3Required; } void setFlushL3Required(bool flushL3Required) { allocationInfo.flags.flushL3Required = flushL3Required; } + bool isLockedMemory() const { return allocationInfo.flags.lockedMemory; } + void setLockedMemory(bool locked) { allocationInfo.flags.lockedMemory = locked; } bool isUncacheable() const { return allocationInfo.flags.uncacheable; } void setUncacheable(bool uncacheable) { allocationInfo.flags.uncacheable = uncacheable; } @@ -345,7 +347,8 @@ class GraphicsAllocation : public IDNode { uint32_t flushL3Required : 1; uint32_t uncacheable : 1; uint32_t is32BitAllocation : 1; - uint32_t reserved : 27; + uint32_t lockedMemory : 1; + uint32_t reserved : 26; } flags; uint32_t allFlags = 0u; }; @@ -355,6 +358,7 @@ class GraphicsAllocation : public IDNode { flags.evictable = true; flags.flushL3Required = true; flags.is32BitAllocation = false; + flags.lockedMemory = false; } }; diff --git a/shared/source/memory_manager/memory_operations_handler.h b/shared/source/memory_manager/memory_operations_handler.h index ac41926d1b..e12b67f2e5 100644 --- a/shared/source/memory_manager/memory_operations_handler.h +++ b/shared/source/memory_manager/memory_operations_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2023 Intel Corporation + * Copyright (C) 2019-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -20,6 +20,7 @@ class MemoryOperationsHandler { virtual ~MemoryOperationsHandler() = default; virtual MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations) = 0; + virtual MemoryOperationsStatus lock(Device *device, ArrayRef gfxAllocations) = 0; virtual MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) = 0; virtual MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) = 0; diff --git a/shared/source/os_interface/aub_memory_operations_handler.cpp b/shared/source/os_interface/aub_memory_operations_handler.cpp index 41399a9133..c74a87e2b2 100644 --- a/shared/source/os_interface/aub_memory_operations_handler.cpp +++ b/shared/source/os_interface/aub_memory_operations_handler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2023 Intel Corporation + * Copyright (C) 2019-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -69,6 +69,10 @@ MemoryOperationsStatus AubMemoryOperationsHandler::makeResident(Device *device, return MemoryOperationsStatus::success; } +MemoryOperationsStatus AubMemoryOperationsHandler::lock(Device *device, ArrayRef gfxAllocations) { + return makeResident(device, gfxAllocations); +} + MemoryOperationsStatus AubMemoryOperationsHandler::evict(Device *device, GraphicsAllocation &gfxAllocation) { auto lock = acquireLock(resourcesLock); auto itor = std::find(residentAllocations.begin(), residentAllocations.end(), &gfxAllocation); diff --git a/shared/source/os_interface/aub_memory_operations_handler.h b/shared/source/os_interface/aub_memory_operations_handler.h index eaf6ea6931..4de09dc14f 100644 --- a/shared/source/os_interface/aub_memory_operations_handler.h +++ b/shared/source/os_interface/aub_memory_operations_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2023 Intel Corporation + * Copyright (C) 2019-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -23,6 +23,7 @@ class AubMemoryOperationsHandler : public MemoryOperationsHandler { ~AubMemoryOperationsHandler() override = default; MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations) override; + MemoryOperationsStatus lock(Device *device, ArrayRef gfxAllocations) override; MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override; MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override; diff --git a/shared/source/os_interface/linux/drm_buffer_object.h b/shared/source/os_interface/linux/drm_buffer_object.h index a111e0c9cd..b4d0df6d49 100644 --- a/shared/source/os_interface/linux/drm_buffer_object.h +++ b/shared/source/os_interface/linux/drm_buffer_object.h @@ -209,6 +209,9 @@ class BufferObject { std::vector &getColourAddresses() { return this->bindAddresses; } + void requireExplicitLockedMemory(bool locked) { requiresLocked = locked; } + bool isExplicitLockedMemoryRequired() { return requiresLocked; } + uint64_t peekPatIndex() const { return patIndex; } void setPatIndex(uint64_t newPatIndex) { this->patIndex = newPatIndex; } BOType peekBOType() const { return boType; } @@ -243,6 +246,7 @@ class BufferObject { bool requiresImmediateBinding = false; bool requiresExplicitResidency = false; void *lockedAddress = nullptr; // CPU side virtual address + bool requiresLocked = false; BOType boType = BOType::legacy; uint64_t size; diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp index 63db235488..6844ea078c 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -39,6 +39,13 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResident(Device *devi return result; } +MemoryOperationsStatus DrmMemoryOperationsHandlerBind::lock(Device *device, ArrayRef gfxAllocations) { + for (auto gfxAllocation = gfxAllocations.begin(); gfxAllocation != gfxAllocations.end(); gfxAllocation++) { + (*gfxAllocation)->setLockedMemory(true); + } + return makeResident(device, gfxAllocations); +} + MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResidentWithinOsContext(OsContext *osContext, ArrayRef gfxAllocations, bool evictable) { auto deviceBitfield = osContext->getDeviceBitfield(); @@ -59,12 +66,12 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResidentWithinOsConte } if (!bo->bindInfo[bo->getOsContextId(osContext)][drmIterator]) { + bo->requireExplicitLockedMemory(drmAllocation->isLockedMemory()); int result = drmAllocation->makeBOsResident(osContext, drmIterator, nullptr, true); if (result) { return MemoryOperationsStatus::outOfMemory; } } - if (!evictable) { drmAllocation->updateResidencyTaskCount(GraphicsAllocation::objectAlwaysResident, osContext->getContextId()); } @@ -77,6 +84,7 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResidentWithinOsConte MemoryOperationsStatus DrmMemoryOperationsHandlerBind::evict(Device *device, GraphicsAllocation &gfxAllocation) { auto &engines = device->getAllEngines(); auto retVal = MemoryOperationsStatus::success; + gfxAllocation.setLockedMemory(false); for (const auto &engine : engines) { retVal = this->evictWithinOsContext(engine.osContext, gfxAllocation); if (retVal != MemoryOperationsStatus::success) { @@ -185,7 +193,10 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::evictUnusedAllocationsImp evict = false; break; } - + if (allocation->isLockedMemory()) { + evict = false; + break; + } if (waitForCompletion) { const auto waitStatus = engine.commandStreamReceiver->waitForCompletionWithTimeout(WaitParams{false, false, 0}, engine.commandStreamReceiver->peekLatestFlushedTaskCount()); if (waitStatus == WaitStatus::gpuHang) { diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.h b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.h index e5d6aeb89a..018f67bc7b 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.h +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,6 +18,7 @@ class DrmMemoryOperationsHandlerBind : public DrmMemoryOperationsHandler { MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef gfxAllocations, bool evictable) override; MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations) override; + MemoryOperationsStatus lock(Device *device, ArrayRef gfxAllocations) override; MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override; MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) override; MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override; diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_default.cpp b/shared/source/os_interface/linux/drm_memory_operations_handler_default.cpp index be9c7eabef..e0e15fb607 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_default.cpp +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_default.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,6 +8,8 @@ #include "shared/source/os_interface/linux/drm_memory_operations_handler_default.h" #include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/source/os_interface/linux/drm_allocation.h" +#include "shared/source/os_interface/linux/drm_buffer_object.h" #include @@ -29,6 +31,18 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::makeResident(Device *d return this->makeResidentWithinOsContext(osContext, gfxAllocations, false); } +MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::lock(Device *device, ArrayRef gfxAllocations) { + OsContext *osContext = nullptr; + for (auto gfxAllocation = gfxAllocations.begin(); gfxAllocation != gfxAllocations.end(); gfxAllocation++) { + auto drmAllocation = static_cast(*gfxAllocation); + drmAllocation->setLockedMemory(true); + for (auto bo : drmAllocation->getBOs()) { + bo->requireExplicitLockedMemory(true); + } + } + return this->makeResidentWithinOsContext(osContext, gfxAllocations, false); +} + MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) { std::lock_guard lock(mutex); this->residency.erase(&gfxAllocation); @@ -37,6 +51,16 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::evictWithinOsContext(O MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::evict(Device *device, GraphicsAllocation &gfxAllocation) { OsContext *osContext = nullptr; + auto drmAllocation = static_cast(&gfxAllocation); + drmAllocation->setLockedMemory(false); + if (drmAllocation->storageInfo.isChunked || drmAllocation->storageInfo.getNumBanks() == 1) { + auto bo = drmAllocation->getBO(); + bo->requireExplicitLockedMemory(false); + } else { + for (auto bo : drmAllocation->getBOs()) { + bo->requireExplicitLockedMemory(false); + } + } return this->evictWithinOsContext(osContext, gfxAllocation); } diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_default.h b/shared/source/os_interface/linux/drm_memory_operations_handler_default.h index 8bff152b28..fc1c2b027d 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_default.h +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_default.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -21,6 +21,7 @@ class DrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandler { MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef gfxAllocations, bool evictable) override; MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations) override; + MemoryOperationsStatus lock(Device *device, ArrayRef gfxAllocations) override; MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override; MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) override; MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override; diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_with_aub_dump.h b/shared/source/os_interface/linux/drm_memory_operations_handler_with_aub_dump.h index a3266be406..294e26e88c 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_with_aub_dump.h +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_with_aub_dump.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -41,6 +41,11 @@ class DrmMemoryOperationsHandlerWithAubDump : public BaseOperationsHandler { return BaseOperationsHandler::makeResident(device, gfxAllocations); } + MemoryOperationsStatus lock(Device *device, ArrayRef gfxAllocations) override { + aubMemoryOperationsHandler->makeResident(device, gfxAllocations); + return BaseOperationsHandler::lock(device, gfxAllocations); + } + MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override { aubMemoryOperationsHandler->evict(device, gfxAllocation); return BaseOperationsHandler::evict(device, gfxAllocation); diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index 91a9fbca71..b493738f4d 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -1313,7 +1313,8 @@ int changeBufferObjectBinding(Drm *drm, OsContext *osContext, uint32_t vmHandleI bindMakeResident = bo->isExplicitResidencyRequired(); bindImmediate = true; } - flags |= ioctlHelper->getFlagsForVmBind(bindCapture, bindImmediate, bindMakeResident); + bool bindLock = bo->isExplicitLockedMemoryRequired(); + flags |= ioctlHelper->getFlagsForVmBind(bindCapture, bindImmediate, bindMakeResident, bindLock); } auto &bindAddresses = bo->getColourAddresses(); diff --git a/shared/source/os_interface/linux/ioctl_helper.h b/shared/source/os_interface/linux/ioctl_helper.h index c6c05b04f6..887130dbc4 100644 --- a/shared/source/os_interface/linux/ioctl_helper.h +++ b/shared/source/os_interface/linux/ioctl_helper.h @@ -115,7 +115,7 @@ class IoctlHelper { virtual bool getGemTiling(void *setTiling) = 0; virtual uint32_t getDirectSubmissionFlag() = 0; virtual std::unique_ptr prepareVmBindExt(const StackVec &bindExtHandles) = 0; - virtual uint64_t getFlagsForVmBind(bool bindCapture, bool bindImmediate, bool bindMakeResident) = 0; + virtual uint64_t getFlagsForVmBind(bool bindCapture, bool bindImmediate, bool bindMakeResident, bool bindLockedMemory) = 0; virtual int queryDistances(std::vector &queryItems, std::vector &distanceInfos) = 0; virtual uint16_t getWaitUserFenceSoftFlag() = 0; virtual int execBuffer(ExecBuffer *execBuffer, uint64_t completionGpuAddress, TaskCountType counterValue) = 0; @@ -257,7 +257,7 @@ class IoctlHelperUpstream : public IoctlHelperI915 { bool setVmPrefetch(uint64_t start, uint64_t length, uint32_t region, uint32_t vmId) override; uint32_t getDirectSubmissionFlag() override; std::unique_ptr prepareVmBindExt(const StackVec &bindExtHandles) override; - uint64_t getFlagsForVmBind(bool bindCapture, bool bindImmediate, bool bindMakeResident) override; + uint64_t getFlagsForVmBind(bool bindCapture, bool bindImmediate, bool bindMakeResident, bool bindLockedMemory) override; int queryDistances(std::vector &queryItems, std::vector &distanceInfos) override; uint16_t getWaitUserFenceSoftFlag() override; int execBuffer(ExecBuffer *execBuffer, uint64_t completionGpuAddress, TaskCountType counterValue) override; @@ -334,7 +334,7 @@ class IoctlHelperPrelim20 : public IoctlHelperI915 { bool setVmPrefetch(uint64_t start, uint64_t length, uint32_t region, uint32_t vmId) override; uint32_t getDirectSubmissionFlag() override; std::unique_ptr prepareVmBindExt(const StackVec &bindExtHandles) override; - uint64_t getFlagsForVmBind(bool bindCapture, bool bindImmediate, bool bindMakeResident) override; + uint64_t getFlagsForVmBind(bool bindCapture, bool bindImmediate, bool bindMakeResident, bool bindLockedMemory) override; int queryDistances(std::vector &queryItems, std::vector &distanceInfos) override; uint16_t getWaitUserFenceSoftFlag() override; int execBuffer(ExecBuffer *execBuffer, uint64_t completionGpuAddress, TaskCountType counterValue) override; diff --git a/shared/source/os_interface/linux/ioctl_helper_prelim.cpp b/shared/source/os_interface/linux/ioctl_helper_prelim.cpp index be37d0e1cd..b9cd9e39b8 100644 --- a/shared/source/os_interface/linux/ioctl_helper_prelim.cpp +++ b/shared/source/os_interface/linux/ioctl_helper_prelim.cpp @@ -503,7 +503,7 @@ std::unique_ptr IoctlHelperPrelim20::prepareVmBindExt(const StackVec< return extensionsBuffer; } -uint64_t IoctlHelperPrelim20::getFlagsForVmBind(bool bindCapture, bool bindImmediate, bool bindMakeResident) { +uint64_t IoctlHelperPrelim20::getFlagsForVmBind(bool bindCapture, bool bindImmediate, bool bindMakeResident, bool bindLockedMemory) { uint64_t flags = 0u; if (bindCapture) { flags |= PRELIM_I915_GEM_VM_BIND_CAPTURE; @@ -511,7 +511,7 @@ uint64_t IoctlHelperPrelim20::getFlagsForVmBind(bool bindCapture, bool bindImmed if (bindImmediate) { flags |= PRELIM_I915_GEM_VM_BIND_IMMEDIATE; } - if (bindMakeResident) { + if (bindMakeResident || bindLockedMemory) { // lockedMemory is equal to residency in i915_prelim flags |= PRELIM_I915_GEM_VM_BIND_MAKE_RESIDENT; } return flags; diff --git a/shared/source/os_interface/linux/ioctl_helper_upstream.cpp b/shared/source/os_interface/linux/ioctl_helper_upstream.cpp index 839d483526..22761658a2 100644 --- a/shared/source/os_interface/linux/ioctl_helper_upstream.cpp +++ b/shared/source/os_interface/linux/ioctl_helper_upstream.cpp @@ -168,7 +168,7 @@ std::unique_ptr IoctlHelperUpstream::prepareVmBindExt(const StackVec< return {}; } -uint64_t IoctlHelperUpstream::getFlagsForVmBind(bool bindCapture, bool bindImmediate, bool bindMakeResident) { +uint64_t IoctlHelperUpstream::getFlagsForVmBind(bool bindCapture, bool bindImmediate, bool bindMakeResident, bool bindLockedMemory) { return 0u; } diff --git a/shared/source/os_interface/linux/xe/CMakeLists.txt b/shared/source/os_interface/linux/xe/CMakeLists.txt index b5144a600d..63190a74c7 100644 --- a/shared/source/os_interface/linux/xe/CMakeLists.txt +++ b/shared/source/os_interface/linux/xe/CMakeLists.txt @@ -9,6 +9,7 @@ set(NEO_CORE_OS_INTERFACE_LINUX_XE ${CMAKE_CURRENT_SOURCE_DIR}/drm_version_xe.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe.cpp ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}ioctl_helper_xe_string_value_getter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}ioctl_helper_xe_vm_bind_flag.cpp ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}ioctl_helper_xe_vm_export.cpp ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}ioctl_helper_xe_perf.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe.h diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp index cc37fb9e8f..a6e81ffff5 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp @@ -743,21 +743,6 @@ bool IoctlHelperXe::completionFenceExtensionSupported(const bool isVmBindAvailab return isVmBindAvailable; } -uint64_t IoctlHelperXe::getFlagsForVmBind(bool bindCapture, bool bindImmediate, bool bindMakeResident) { - uint64_t ret = 0; - xeLog(" -> IoctlHelperXe::%s %d %d %d\n", __FUNCTION__, bindCapture, bindImmediate, bindMakeResident); - if (bindCapture) { - ret |= XE_NEO_BIND_CAPTURE_FLAG; - } - if (bindImmediate) { - ret |= XE_NEO_BIND_IMMEDIATE_FLAG; - } - if (bindMakeResident) { - ret |= XE_NEO_BIND_MAKERESIDENT_FLAG; - } - return ret; -} - int IoctlHelperXe::queryDistances(std::vector &queryItems, std::vector &distanceInfos) { xeLog(" -> IoctlHelperXe::%s\n", __FUNCTION__); return 0; @@ -1236,6 +1221,7 @@ int IoctlHelperXe::xeVmBind(const VmBindParams &vmBindParams, bool isBind) { if (isBind) { bind.bind.op = DRM_XE_VM_BIND_OP_MAP; + bind.bind.flags = static_cast(vmBindParams.flags); bind.bind.obj = vmBindParams.handle; if (bindInfo[index].userptr) { bind.bind.op = DRM_XE_VM_BIND_OP_MAP_USERPTR; diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h index 6067f229ab..536e4f7c0e 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h @@ -20,7 +20,8 @@ struct drm_xe_engine_class_instance; // Arbitratry value for easier identification in the logs for now #define XE_NEO_BIND_CAPTURE_FLAG 0x1 #define XE_NEO_BIND_IMMEDIATE_FLAG 0x20 -#define XE_NEO_BIND_MAKERESIDENT_FLAG 0x300 +#define XE_NEO_BIND_PIN_FLAG (1 << 3) // value for DRM_XE_VM_BIND_FLAG_PIN +#define XE_NEO_BIND_MAKERESIDENT_FLAG XE_NEO_BIND_PIN_FLAG #define XE_NEO_VMCREATE_DISABLESCRATCH_FLAG 0x100000 #define XE_NEO_VMCREATE_ENABLEPAGEFAULT_FLAG 0x20000 @@ -76,7 +77,7 @@ class IoctlHelperXe : public IoctlHelper { bool getGemTiling(void *setTiling) override; uint32_t getDirectSubmissionFlag() override; std::unique_ptr prepareVmBindExt(const StackVec &bindExtHandles) override; - uint64_t getFlagsForVmBind(bool bindCapture, bool bindImmediate, bool bindMakeResident) override; + uint64_t getFlagsForVmBind(bool bindCapture, bool bindImmediate, bool bindMakeResident, bool bindLock) override; int queryDistances(std::vector &queryItems, std::vector &distanceInfos) override; uint16_t getWaitUserFenceSoftFlag() override; int execBuffer(ExecBuffer *execBuffer, uint64_t completionGpuAddress, TaskCountType counterValue) override; diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe_vm_bind_flag.cpp b/shared/source/os_interface/linux/xe/ioctl_helper_xe_vm_bind_flag.cpp new file mode 100644 index 0000000000..9dc12e47ec --- /dev/null +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe_vm_bind_flag.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/linux/xe/ioctl_helper_xe.h" + +#include "drm/xe_drm.h" + +namespace NEO { + +uint64_t IoctlHelperXe::getFlagsForVmBind(bool bindCapture, bool bindImmediate, bool bindMakeResident, bool bindLock) { + uint64_t ret = 0; + xeLog(" -> IoctlHelperXe::%s %d %d %d %d\n", __FUNCTION__, bindCapture, bindImmediate, bindMakeResident, bindLock); + if (bindCapture) { + ret |= XE_NEO_BIND_CAPTURE_FLAG; + } + if (bindImmediate) { + ret |= DRM_XE_VM_BIND_FLAG_IMMEDIATE; + } + if (bindMakeResident) { + ret |= XE_NEO_BIND_MAKERESIDENT_FLAG; + } + return ret; +} + +} // namespace NEO diff --git a/shared/source/os_interface/windows/wddm_memory_operations_handler.h b/shared/source/os_interface/windows/wddm_memory_operations_handler.h index 98093a3f12..0065e21732 100644 --- a/shared/source/os_interface/windows/wddm_memory_operations_handler.h +++ b/shared/source/os_interface/windows/wddm_memory_operations_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2023 Intel Corporation + * Copyright (C) 2019-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -27,6 +27,9 @@ class WddmMemoryOperationsHandler : public MemoryOperationsHandler { MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override; MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override; + MemoryOperationsStatus lock(Device *device, ArrayRef gfxAllocations) override { + return MemoryOperationsStatus::unsupported; + } MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef gfxAllocations, bool evictable) override { return makeResident(nullptr, gfxAllocations); } diff --git a/shared/test/common/mocks/mock_memory_operations_handler.h b/shared/test/common/mocks/mock_memory_operations_handler.h index 9acb3a9c26..3ebd6aaaeb 100644 --- a/shared/test/common/mocks/mock_memory_operations_handler.h +++ b/shared/test/common/mocks/mock_memory_operations_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2023 Intel Corporation + * Copyright (C) 2019-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -21,6 +21,7 @@ class MockMemoryOperationsHandler : public MemoryOperationsHandler { public: MockMemoryOperationsHandler() {} MemoryOperationsStatus makeResident(Device *device, ArrayRef gfxAllocations) override { return MemoryOperationsStatus::unsupported; } + MemoryOperationsStatus lock(Device *device, ArrayRef gfxAllocations) override { return MemoryOperationsStatus::unsupported; } MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override { return MemoryOperationsStatus::unsupported; } MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override { return MemoryOperationsStatus::unsupported; } MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef gfxAllocations, bool evictable) override { return MemoryOperationsStatus::unsupported; } @@ -31,6 +32,7 @@ class MockMemoryOperationsHandlerTests : public MemoryOperationsHandler { public: MockMemoryOperationsHandlerTests() {} ADDMETHOD_NOBASE(makeResident, MemoryOperationsStatus, MemoryOperationsStatus::unsupported, (Device * device, ArrayRef gfxAllocations)); + ADDMETHOD_NOBASE(lock, MemoryOperationsStatus, MemoryOperationsStatus::unsupported, (Device * device, ArrayRef gfxAllocations)); ADDMETHOD_NOBASE(evict, MemoryOperationsStatus, MemoryOperationsStatus::unsupported, (Device * device, GraphicsAllocation &gfxAllocation)); ADDMETHOD_NOBASE(isResident, MemoryOperationsStatus, MemoryOperationsStatus::unsupported, (Device * device, GraphicsAllocation &gfxAllocation)); ADDMETHOD_NOBASE(makeResidentWithinOsContext, MemoryOperationsStatus, MemoryOperationsStatus::unsupported, (OsContext * osContext, ArrayRef gfxAllocations, bool evictable)); @@ -52,6 +54,12 @@ class MockMemoryOperations : public MemoryOperationsHandler { } return MemoryOperationsStatus::success; } + + MemoryOperationsStatus lock(Device *device, ArrayRef gfxAllocations) override { + lockCalledCount++; + return MemoryOperationsStatus::success; + } + MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override { evictCalledCount++; if (captureGfxAllocationsForMakeResident) { @@ -98,6 +106,7 @@ class MockMemoryOperations : public MemoryOperationsHandler { int makeResidentCalledCount = 0; int evictCalledCount = 0; uint32_t isResidentCalledCount = 0; + uint32_t lockCalledCount = 0; uint32_t makeResidentContextId = std::numeric_limits::max(); bool captureGfxAllocationsForMakeResident = false; }; diff --git a/shared/test/unit_test/os_interface/aub_memory_operations_handler_tests.cpp b/shared/test/unit_test/os_interface/aub_memory_operations_handler_tests.cpp index a0304a149a..be6f7cd14a 100644 --- a/shared/test/unit_test/os_interface/aub_memory_operations_handler_tests.cpp +++ b/shared/test/unit_test/os_interface/aub_memory_operations_handler_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2023 Intel Corporation + * Copyright (C) 2019-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -44,6 +44,29 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledThe EXPECT_EQ(2u, memoryOperationsInterface->residentAllocations.size()); } +TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenCallingLockThenTrueReturnedAndWriteCalled) { + MockAubManager aubManager; + getMemoryOperationsHandler()->setAubManager(&aubManager); + auto memoryOperationsInterface = getMemoryOperationsHandler(); + auto result = memoryOperationsInterface->lock(device.get(), ArrayRef(&allocPtr, 1)); + EXPECT_EQ(result, MemoryOperationsStatus::success); + EXPECT_TRUE(aubManager.writeMemory2Called); + + auto itor = std::find(memoryOperationsInterface->residentAllocations.begin(), memoryOperationsInterface->residentAllocations.end(), allocPtr); + EXPECT_NE(memoryOperationsInterface->residentAllocations.end(), itor); + EXPECT_EQ(1u, memoryOperationsInterface->residentAllocations.size()); + + aubManager.writeMemory2Called = false; + + result = memoryOperationsInterface->lock(device.get(), ArrayRef(&allocPtr, 1)); + EXPECT_EQ(result, MemoryOperationsStatus::success); + EXPECT_TRUE(aubManager.writeMemory2Called); + + itor = std::find(memoryOperationsInterface->residentAllocations.begin(), memoryOperationsInterface->residentAllocations.end(), allocPtr); + EXPECT_NE(memoryOperationsInterface->residentAllocations.end(), itor); + EXPECT_EQ(2u, memoryOperationsInterface->residentAllocations.size()); +} + TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerAndAllocationOfOneTimeAubWritableAllocationTypeWhenMakeResidentCalledTwoTimesThenWriteMemoryOnce) { ASSERT_TRUE(AubHelper::isOneTimeAubWritableAllocationType(AllocationType::buffer)); allocPtr->setAllocationType(AllocationType::buffer); diff --git a/shared/test/unit_test/os_interface/linux/CMakeLists.txt b/shared/test/unit_test/os_interface/linux/CMakeLists.txt index 259e936c54..97abbae2f6 100644 --- a/shared/test/unit_test/os_interface/linux/CMakeLists.txt +++ b/shared/test/unit_test/os_interface/linux/CMakeLists.txt @@ -22,12 +22,12 @@ set(NEO_CORE_OS_INTERFACE_TESTS_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/drm_mapper_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_bindless_heap_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_operations_handler_default_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_operations_handler_with_aub_dump_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_mock_impl.h ${CMAKE_CURRENT_SOURCE_DIR}/drm_os_memory_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_pci_speed_info_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_query_topology_upstream_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drm_residency_handler_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_special_heap_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_system_info_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_tests.cpp @@ -54,9 +54,9 @@ if(NEO_ENABLE_i915_PRELIM_DETECTION) ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_info_prelim_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_debug_surface_prelim_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_localmem_prelim_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_operations_handler_bind_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_query_prelim_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_query_topology_prelim_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drm_residency_handler_prelim_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_vm_bind_prelim_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_with_prelim_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_tests_prelim.cpp diff --git a/shared/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_bind_tests.cpp similarity index 94% rename from shared/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp rename to shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_bind_tests.cpp index 1351102df8..578cd84f5a 100644 --- a/shared/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_bind_tests.cpp @@ -1324,6 +1324,91 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenClosEnabledAndAllocationToBeCach memoryManager->freeGraphicsMemory(allocation); } +TEST_F(DrmMemoryOperationsHandlerBindTest, whenIoctlFailDuringLockingThenOutOfMemoryIsThrown) { + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize}); + + mock->context.vmBindReturn = -1; + EXPECT_EQ(operationHandler->isResident(device, *allocation), MemoryOperationsStatus::memoryNotFound); + EXPECT_EQ(operationHandler->lock(device, ArrayRef(&allocation, 1)), MemoryOperationsStatus::outOfMemory); + memoryManager->freeGraphicsMemory(allocation); +} + +TEST_F(DrmMemoryOperationsHandlerBindTest, whenLockingDrmAllocationThenBosRequireExplicitLockedMemory) { + + BufferObjects bos; + MockBufferObject mockBo1(0, mock, 3, 0, 0, 1), mockBo2(0, mock, 3, 0, 0, 1); + mockBo1.setSize(1024); + mockBo2.setSize(1024); + bos.push_back(&mockBo1); + bos.push_back(&mockBo2); + GraphicsAllocation *mockDrmAllocation = new MockDrmAllocation(AllocationType::unknown, MemoryPool::localMemory, bos); + mockDrmAllocation->storageInfo.memoryBanks = 3; + EXPECT_EQ(2u, mockDrmAllocation->storageInfo.getNumBanks()); + + mock->context.vmBindReturn = 0; + EXPECT_EQ(operationHandler->isResident(device, *mockDrmAllocation), MemoryOperationsStatus::memoryNotFound); + + EXPECT_EQ(operationHandler->lock(device, ArrayRef(&mockDrmAllocation, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(operationHandler->isResident(device, *mockDrmAllocation), MemoryOperationsStatus::success); + EXPECT_TRUE(mockDrmAllocation->isLockedMemory()); + EXPECT_TRUE(mockBo1.isExplicitLockedMemoryRequired()); + EXPECT_TRUE(mockBo2.isExplicitLockedMemoryRequired()); + + delete mockDrmAllocation; +} + +TEST_F(DrmMemoryOperationsHandlerBindTest, givenPreviouslyLockedMemoryWhenCallingResidentMemoryThenBosDoNotRequireExplicitLockedMemory) { + + BufferObjects bos; + MockBufferObject mockBo(0, mock, 3, 0, 0, 1); + mockBo.setSize(1024); + bos.push_back(&mockBo); + GraphicsAllocation *mockDrmAllocation = new MockDrmAllocation(AllocationType::unknown, MemoryPool::localMemory, bos); + + mock->context.vmBindReturn = 0; + mock->context.vmUnbindReturn = 0; + EXPECT_EQ(operationHandler->isResident(device, *mockDrmAllocation), MemoryOperationsStatus::memoryNotFound); + + EXPECT_EQ(operationHandler->lock(device, ArrayRef(&mockDrmAllocation, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(operationHandler->isResident(device, *mockDrmAllocation), MemoryOperationsStatus::success); + + EXPECT_EQ(operationHandler->evict(device, *mockDrmAllocation), MemoryOperationsStatus::success); + EXPECT_EQ(operationHandler->isResident(device, *mockDrmAllocation), MemoryOperationsStatus::memoryNotFound); + EXPECT_FALSE(mockDrmAllocation->isLockedMemory()); + + EXPECT_EQ(operationHandler->makeResident(device, ArrayRef(&mockDrmAllocation, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(operationHandler->isResident(device, *mockDrmAllocation), MemoryOperationsStatus::success); + EXPECT_FALSE(mockDrmAllocation->isLockedMemory()); + EXPECT_FALSE(mockBo.isExplicitLockedMemoryRequired()); + + delete mockDrmAllocation; +} + +TEST_F(DrmMemoryOperationsHandlerBindTest, givenLockedAndResidentAllocationsWhenCallingEvictUnusedMemoryThenBothAllocationsAreNotEvicted) { + auto allocation1 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize}); + auto allocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize}); + + EXPECT_EQ(operationHandler->isResident(device, *allocation1), MemoryOperationsStatus::memoryNotFound); + EXPECT_EQ(operationHandler->isResident(device, *allocation2), MemoryOperationsStatus::memoryNotFound); + + EXPECT_EQ(operationHandler->lock(device, ArrayRef(&allocation1, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(operationHandler->isResident(device, *allocation1), MemoryOperationsStatus::success); + + EXPECT_EQ(operationHandler->makeResident(device, ArrayRef(&allocation2, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(operationHandler->isResident(device, *allocation2), MemoryOperationsStatus::success); + + operationHandler->useBaseEvictUnused = true; + EXPECT_EQ(operationHandler->evictUnusedCalled, 0u); + EXPECT_EQ(operationHandler->evictUnusedAllocations(false, true), MemoryOperationsStatus::success); + EXPECT_EQ(operationHandler->evictUnusedCalled, 1u); + + EXPECT_EQ(operationHandler->isResident(device, *allocation1), MemoryOperationsStatus::success); + EXPECT_EQ(operationHandler->isResident(device, *allocation2), MemoryOperationsStatus::success); + + memoryManager->freeGraphicsMemory(allocation2); + memoryManager->freeGraphicsMemory(allocation1); +} + using DrmResidencyHandlerTests = ::testing::Test; HWTEST2_F(DrmResidencyHandlerTests, givenClosIndexAndMemoryTypeWhenAskingForPatIndexThenReturnCorrectValue, IsWithinXeGfxFamily) { diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_default_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_default_tests.cpp new file mode 100644 index 0000000000..772b281983 --- /dev/null +++ b/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_default_tests.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2019-2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/linux/drm_memory_operations_handler_default.h" +#include "shared/test/common/libult/linux/drm_query_mock.h" +#include "shared/test/common/mocks/linux/mock_drm_allocation.h" +#include "shared/test/common/mocks/mock_execution_environment.h" +#include "shared/test/common/mocks/mock_graphics_allocation.h" +#include "shared/test/common/test_macros/test.h" + +#include + +using namespace NEO; + +struct MockDrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandlerDefault { + using DrmMemoryOperationsHandlerDefault::DrmMemoryOperationsHandlerDefault; + using DrmMemoryOperationsHandlerDefault::residency; +}; +struct DrmMemoryOperationsHandlerBaseTest : public ::testing::Test { + void SetUp() override { + executionEnvironment = new ExecutionEnvironment; + executionEnvironment->prepareRootDeviceEnvironments(1); + executionEnvironment->rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(defaultHwInfo.get()); + executionEnvironment->rootDeviceEnvironments[0]->initGmm(); + executionEnvironment->calculateMaxOsContextCount(); + mock = new DrmQueryMock(*executionEnvironment->rootDeviceEnvironments[0]); + mock->setBindAvailable(); + + drmMemoryOperationsHandler = std::make_unique(0); + } + void initializeAllocation(int numBos) { + if (!drmAllocation) { + for (auto i = 0; i < numBos; i++) { + mockBos.push_back(new MockBufferObject(0, mock, 3, 0, 0, 1)); + } + drmAllocation = new MockDrmAllocation(AllocationType::unknown, MemoryPool::localMemory, mockBos); + for (auto i = 0; i < numBos; i++) { + drmAllocation->storageInfo.memoryBanks[i] = 1; + } + allocationPtr = drmAllocation; + } + } + void TearDown() override { + for (auto i = 0u; i < mockBos.size(); i++) { + delete mockBos[i]; + } + mockBos.clear(); + delete drmAllocation; + delete mock; + delete executionEnvironment; + } + + ExecutionEnvironment *executionEnvironment; + DrmQueryMock *mock; + BufferObjects mockBos; + MockDrmAllocation *drmAllocation = nullptr; + GraphicsAllocation *allocationPtr = nullptr; + std::unique_ptr drmMemoryOperationsHandler; +}; + +TEST_F(DrmMemoryOperationsHandlerBaseTest, whenMakingAllocationResidentThenAllocationIsResident) { + initializeAllocation(1); + EXPECT_EQ(1u, drmAllocation->storageInfo.getNumBanks()); + + EXPECT_EQ(drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u); + EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(allocationPtr) != drmMemoryOperationsHandler->residency.end()); + EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, *allocationPtr), MemoryOperationsStatus::success); +} + +TEST_F(DrmMemoryOperationsHandlerBaseTest, whenEvictingResidentAllocationThenAllocationIsNotResident) { + initializeAllocation(1); + EXPECT_EQ(1u, drmAllocation->storageInfo.getNumBanks()); + + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u); + EXPECT_EQ(drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, *allocationPtr), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u); + EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(allocationPtr) != drmMemoryOperationsHandler->residency.end()); + EXPECT_EQ(drmMemoryOperationsHandler->evict(nullptr, *allocationPtr), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, *allocationPtr), MemoryOperationsStatus::memoryNotFound); + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u); +} + +TEST_F(DrmMemoryOperationsHandlerBaseTest, whenLockingAllocationThenAllocationIsResident) { + initializeAllocation(2); + EXPECT_EQ(2u, drmAllocation->storageInfo.getNumBanks()); + + EXPECT_EQ(drmMemoryOperationsHandler->lock(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u); + EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(drmAllocation) != drmMemoryOperationsHandler->residency.end()); + EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, *drmAllocation), MemoryOperationsStatus::success); + EXPECT_TRUE(drmAllocation->isLockedMemory()); + EXPECT_TRUE(mockBos[0]->isExplicitLockedMemoryRequired()); + EXPECT_TRUE(mockBos[1]->isExplicitLockedMemoryRequired()); +} + +TEST_F(DrmMemoryOperationsHandlerBaseTest, whenEvictingLockedAllocationThenAllocationIsNotResident) { + initializeAllocation(1); + EXPECT_EQ(1u, drmAllocation->storageInfo.getNumBanks()); + + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u); + + EXPECT_EQ(drmMemoryOperationsHandler->lock(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, *drmAllocation), MemoryOperationsStatus::success); + EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(drmAllocation) != drmMemoryOperationsHandler->residency.end()); + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u); + EXPECT_TRUE(drmAllocation->isLockedMemory()); + EXPECT_TRUE(mockBos[0]->isExplicitLockedMemoryRequired()); + + EXPECT_EQ(drmMemoryOperationsHandler->evict(nullptr, *drmAllocation), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, *drmAllocation), MemoryOperationsStatus::memoryNotFound); + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u); + EXPECT_FALSE(drmAllocation->isLockedMemory()); + EXPECT_FALSE(mockBos[0]->isExplicitLockedMemoryRequired()); +} + +TEST_F(DrmMemoryOperationsHandlerBaseTest, whenEvictingLockedAllocationWithMultipleBOsThenAllocationIsNotResident) { + initializeAllocation(2); + EXPECT_EQ(2u, drmAllocation->storageInfo.getNumBanks()); + + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u); + + EXPECT_EQ(drmMemoryOperationsHandler->lock(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, *drmAllocation), MemoryOperationsStatus::success); + EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(drmAllocation) != drmMemoryOperationsHandler->residency.end()); + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u); + EXPECT_TRUE(drmAllocation->isLockedMemory()); + EXPECT_TRUE(mockBos[0]->isExplicitLockedMemoryRequired()); + EXPECT_TRUE(mockBos[1]->isExplicitLockedMemoryRequired()); + + EXPECT_EQ(drmMemoryOperationsHandler->evict(nullptr, *drmAllocation), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, *drmAllocation), MemoryOperationsStatus::memoryNotFound); + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u); + EXPECT_FALSE(drmAllocation->isLockedMemory()); + EXPECT_FALSE(mockBos[0]->isExplicitLockedMemoryRequired()); + EXPECT_FALSE(mockBos[1]->isExplicitLockedMemoryRequired()); +} + +TEST_F(DrmMemoryOperationsHandlerBaseTest, whenEvictingLockedAllocationWithChunkedThenAllocationIsNotResident) { + initializeAllocation(1); + EXPECT_EQ(1u, drmAllocation->storageInfo.getNumBanks()); + drmAllocation->storageInfo.isChunked = true; + + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u); + + EXPECT_EQ(drmMemoryOperationsHandler->lock(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, *drmAllocation), MemoryOperationsStatus::success); + EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(drmAllocation) != drmMemoryOperationsHandler->residency.end()); + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u); + EXPECT_TRUE(drmAllocation->isLockedMemory()); + EXPECT_TRUE(mockBos[0]->isExplicitLockedMemoryRequired()); + + EXPECT_EQ(drmMemoryOperationsHandler->evict(nullptr, *drmAllocation), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, *drmAllocation), MemoryOperationsStatus::memoryNotFound); + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u); + EXPECT_FALSE(drmAllocation->isLockedMemory()); + EXPECT_FALSE(mockBos[0]->isExplicitLockedMemoryRequired()); +} diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_with_aub_dump_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_with_aub_dump_tests.cpp index 7aecacbb21..69458f865d 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_with_aub_dump_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_with_aub_dump_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -9,6 +9,8 @@ #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/os_interface/linux/drm_memory_operations_handler_default.h" #include "shared/source/os_interface/linux/drm_memory_operations_handler_with_aub_dump.h" +#include "shared/test/common/libult/linux/drm_query_mock.h" +#include "shared/test/common/mocks/linux/mock_drm_allocation.h" #include "shared/test/common/mocks/mock_aub_memory_operations_handler.h" #include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" @@ -59,17 +61,55 @@ TEST_F(DrmMemoryOperationsHandlerWithAubDumpTest, whenMakingAllocationResidentTh } TEST_F(DrmMemoryOperationsHandlerWithAubDumpTest, whenEvictingResidentAllocationThenAllocationIsNotResident) { + auto mock = new DrmQueryMock(*device->executionEnvironment->rootDeviceEnvironments[0]); + mock->setBindAvailable(); + + BufferObjects bos; + MockBufferObject mockBo(0, mock, 3, 0, 0, 1); + mockBo.setSize(1024); + bos.push_back(&mockBo); + GraphicsAllocation *mockDrmAllocation = new MockDrmAllocation(AllocationType::unknown, MemoryPool::localMemory, bos); + EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->residency.size(), 0u); - EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); - EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->isResident(nullptr, graphicsAllocation), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->makeResident(nullptr, ArrayRef(&mockDrmAllocation, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->isResident(nullptr, *mockDrmAllocation), MemoryOperationsStatus::success); EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->residency.size(), 1u); - EXPECT_TRUE(drmMemoryOperationsHandlerWithAubDumpMock->residency.find(allocationPtr) != drmMemoryOperationsHandlerWithAubDumpMock->residency.end()); - EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->evict(nullptr, graphicsAllocation), MemoryOperationsStatus::success); - EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->isResident(nullptr, graphicsAllocation), MemoryOperationsStatus::memoryNotFound); + EXPECT_TRUE(drmMemoryOperationsHandlerWithAubDumpMock->residency.find(mockDrmAllocation) != drmMemoryOperationsHandlerWithAubDumpMock->residency.end()); + EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->evict(nullptr, *mockDrmAllocation), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->isResident(nullptr, *mockDrmAllocation), MemoryOperationsStatus::memoryNotFound); EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->residency.size(), 0u); EXPECT_TRUE(mockAubMemoryOperationsHandler->makeResidentCalled); EXPECT_TRUE(mockAubMemoryOperationsHandler->isResidentCalled); EXPECT_TRUE(mockAubMemoryOperationsHandler->evictCalled); + + delete mockDrmAllocation; + delete mock; +} + +TEST_F(DrmMemoryOperationsHandlerWithAubDumpTest, whenEvictingLockedAllocationThenAllocationIsNotResident) { + auto mock = new DrmQueryMock(*device->executionEnvironment->rootDeviceEnvironments[0]); + mock->setBindAvailable(); + + BufferObjects bos; + MockBufferObject mockBo(0, mock, 3, 0, 0, 1); + mockBo.setSize(1024); + bos.push_back(&mockBo); + GraphicsAllocation *mockDrmAllocation = new MockDrmAllocation(AllocationType::unknown, MemoryPool::localMemory, bos); + + EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->residency.size(), 0u); + EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->lock(nullptr, ArrayRef(&mockDrmAllocation, 1)), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->isResident(nullptr, *mockDrmAllocation), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->residency.size(), 1u); + EXPECT_TRUE(drmMemoryOperationsHandlerWithAubDumpMock->residency.find(mockDrmAllocation) != drmMemoryOperationsHandlerWithAubDumpMock->residency.end()); + EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->evict(nullptr, *mockDrmAllocation), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->isResident(nullptr, *mockDrmAllocation), MemoryOperationsStatus::memoryNotFound); + EXPECT_EQ(drmMemoryOperationsHandlerWithAubDumpMock->residency.size(), 0u); + EXPECT_TRUE(mockAubMemoryOperationsHandler->makeResidentCalled); + EXPECT_TRUE(mockAubMemoryOperationsHandler->isResidentCalled); + EXPECT_TRUE(mockAubMemoryOperationsHandler->evictCalled); + + delete mockDrmAllocation; + delete mock; } TEST_F(DrmMemoryOperationsHandlerWithAubDumpTest, whenConstructingDrmMemoryOperationsHandlerWithAubDumpWithoutAubCenterThenAubCenterIsInitialized) { diff --git a/shared/test/unit_test/os_interface/linux/drm_residency_handler_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_residency_handler_tests.cpp deleted file mode 100644 index f4f435b903..0000000000 --- a/shared/test/unit_test/os_interface/linux/drm_residency_handler_tests.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2019-2023 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "shared/source/os_interface/linux/drm_memory_operations_handler_default.h" -#include "shared/test/common/mocks/mock_graphics_allocation.h" -#include "shared/test/common/test_macros/test.h" - -#include - -using namespace NEO; - -struct MockDrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandlerDefault { - using DrmMemoryOperationsHandlerDefault::DrmMemoryOperationsHandlerDefault; - using DrmMemoryOperationsHandlerDefault::residency; -}; - -struct DrmMemoryOperationsHandlerBaseTest : public ::testing::Test { - void SetUp() override { - drmMemoryOperationsHandler = std::make_unique(0); - allocationPtr = &graphicsAllocation; - } - - MockGraphicsAllocation graphicsAllocation; - GraphicsAllocation *allocationPtr; - std::unique_ptr drmMemoryOperationsHandler; -}; - -TEST_F(DrmMemoryOperationsHandlerBaseTest, whenMakingAllocationResidentThenAllocationIsResident) { - EXPECT_EQ(drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); - EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u); - EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(allocationPtr) != drmMemoryOperationsHandler->residency.end()); - EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, graphicsAllocation), MemoryOperationsStatus::success); -} - -TEST_F(DrmMemoryOperationsHandlerBaseTest, whenEvictingResidentAllocationThenAllocationIsNotResident) { - EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u); - EXPECT_EQ(drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::success); - EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, graphicsAllocation), MemoryOperationsStatus::success); - EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u); - EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(allocationPtr) != drmMemoryOperationsHandler->residency.end()); - EXPECT_EQ(drmMemoryOperationsHandler->evict(nullptr, graphicsAllocation), MemoryOperationsStatus::success); - EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, graphicsAllocation), MemoryOperationsStatus::memoryNotFound); - EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u); -} diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp index 0b494985f9..4cf54b8c36 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp @@ -266,20 +266,23 @@ TEST_F(IoctlPrelimHelperTests, whenGettingFlagsForVmBindThenProperValuesAreRetur for (auto &bindCapture : ::testing::Bool()) { for (auto &bindImmediate : ::testing::Bool()) { for (auto &bindMakeResident : ::testing::Bool()) { - auto flags = ioctlHelper.getFlagsForVmBind(bindCapture, bindImmediate, bindMakeResident); - if (bindCapture) { - EXPECT_EQ(PRELIM_I915_GEM_VM_BIND_CAPTURE, (flags & PRELIM_I915_GEM_VM_BIND_CAPTURE)); - } - if (bindImmediate) { - EXPECT_EQ(PRELIM_I915_GEM_VM_BIND_IMMEDIATE, (flags & PRELIM_I915_GEM_VM_BIND_IMMEDIATE)); - } - if (bindMakeResident) { - EXPECT_EQ(PRELIM_I915_GEM_VM_BIND_MAKE_RESIDENT, (flags & PRELIM_I915_GEM_VM_BIND_MAKE_RESIDENT)); - } - if (flags == 0) { - EXPECT_FALSE(bindCapture); - EXPECT_FALSE(bindImmediate); - EXPECT_FALSE(bindMakeResident); + for (auto &bindLockedMemory : ::testing::Bool()) { + auto flags = ioctlHelper.getFlagsForVmBind(bindCapture, bindImmediate, bindMakeResident, bindLockedMemory); + if (bindCapture) { + EXPECT_EQ(PRELIM_I915_GEM_VM_BIND_CAPTURE, (flags & PRELIM_I915_GEM_VM_BIND_CAPTURE)); + } + if (bindImmediate) { + EXPECT_EQ(PRELIM_I915_GEM_VM_BIND_IMMEDIATE, (flags & PRELIM_I915_GEM_VM_BIND_IMMEDIATE)); + } + if (bindMakeResident || bindLockedMemory) { + EXPECT_EQ(PRELIM_I915_GEM_VM_BIND_MAKE_RESIDENT, (flags & PRELIM_I915_GEM_VM_BIND_MAKE_RESIDENT)); + } + if (flags == 0) { + EXPECT_FALSE(bindCapture); + EXPECT_FALSE(bindImmediate); + EXPECT_FALSE(bindMakeResident); + EXPECT_FALSE(bindLockedMemory); + } } } } diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp index 8f3a079c32..0d851c3c95 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp @@ -318,8 +318,10 @@ TEST(IoctlHelperUpstreamTest, whenGettingFlagsForVmBindThenZeroIsReturned) { for (auto &bindCapture : ::testing::Bool()) { for (auto &bindImmediate : ::testing::Bool()) { for (auto &bindMakeResident : ::testing::Bool()) { - auto flags = ioctlHelper.getFlagsForVmBind(bindCapture, bindImmediate, bindMakeResident); - EXPECT_EQ(0u, flags); + for (auto &bindLock : ::testing::Bool()) { + auto flags = ioctlHelper.getFlagsForVmBind(bindCapture, bindImmediate, bindMakeResident, bindLock); + EXPECT_EQ(0u, flags); + } } } } diff --git a/shared/test/unit_test/os_interface/linux/xe/CMakeLists.txt b/shared/test/unit_test/os_interface/linux/xe/CMakeLists.txt index 7ad1985195..a408fa18ee 100644 --- a/shared/test/unit_test/os_interface/linux/xe/CMakeLists.txt +++ b/shared/test/unit_test/os_interface/linux/xe/CMakeLists.txt @@ -7,6 +7,7 @@ set(NEO_CORE_OS_INTERFACE_TESTS_LINUX_XE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/${BRANCH_TYPE}/ioctl_helper_xe_vm_bind_flag_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe_vm_export_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe_perf_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe_tests.h diff --git a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp index 7f07101280..0989c1e934 100644 --- a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp @@ -260,7 +260,7 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingAnyMethodThenDummyValueIsRe EXPECT_EQ(0u, xeIoctlHelper->getDirectSubmissionFlag()); - EXPECT_EQ(0u, xeIoctlHelper->getFlagsForVmBind(false, false, false)); + EXPECT_EQ(0u, xeIoctlHelper->getFlagsForVmBind(false, false, false, false)); std::vector queryItems; std::vector distanceInfos; @@ -401,11 +401,6 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingAnyMethodThenDummyValueIsRe XE_NEO_VMCREATE_USEVMBIND_FLAG), xeIoctlHelper->getFlagsForVmCreate(true, true, true)); - EXPECT_EQ(static_cast(XE_NEO_BIND_CAPTURE_FLAG | - XE_NEO_BIND_IMMEDIATE_FLAG | - XE_NEO_BIND_MAKERESIDENT_FLAG), - xeIoctlHelper->getFlagsForVmBind(true, true, true)); - uint32_t fabricId = 0, latency = 0, bandwidth = 0; EXPECT_FALSE(xeIoctlHelper->getFabricLatency(fabricId, latency, bandwidth)); } diff --git a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_vm_bind_flag_tests.cpp b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_vm_bind_flag_tests.cpp new file mode 100644 index 0000000000..db98ccdf8b --- /dev/null +++ b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_vm_bind_flag_tests.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.h" + +using namespace NEO; + +TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingGetFlagsForVmBindThenExpectedValueIsReturned) { + auto executionEnvironment = std::make_unique(); + DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; + auto xeIoctlHelper = std::make_unique(drm); + ASSERT_NE(nullptr, xeIoctlHelper); + + for (auto &bindCapture : ::testing::Bool()) { + for (auto &bindImmediate : ::testing::Bool()) { + for (auto &bindMakeResident : ::testing::Bool()) { + for (auto &bindLockedMemory : ::testing::Bool()) { + auto flags = xeIoctlHelper->getFlagsForVmBind(bindCapture, bindImmediate, bindMakeResident, bindLockedMemory); + if (bindCapture) { + EXPECT_EQ(static_cast(XE_NEO_BIND_CAPTURE_FLAG), (flags & XE_NEO_BIND_CAPTURE_FLAG)); + } + if (bindImmediate) { + EXPECT_EQ(static_cast(DRM_XE_VM_BIND_FLAG_IMMEDIATE), (flags & DRM_XE_VM_BIND_FLAG_IMMEDIATE)); + } + if (bindMakeResident) { + EXPECT_EQ(static_cast(XE_NEO_BIND_MAKERESIDENT_FLAG), (flags & XE_NEO_BIND_MAKERESIDENT_FLAG)); + } + if (flags == 0) { + EXPECT_FALSE(bindCapture); + EXPECT_FALSE(bindImmediate); + EXPECT_FALSE(bindMakeResident); + } + } + } + } + } +} diff --git a/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index 83dfbf175a..7a63927c5e 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -843,6 +843,23 @@ TEST_F(WddmMemoryManagerSimpleTest, givenAllocationDataWithFlagsWhenAllocateGrap memoryManager->freeGraphicsMemory(allocation); } +TEST_F(WddmMemoryManagerSimpleTest, givenAllocationWhenCallingSetLockedMemoryThenFlagIsSetCorrectly) { + class MockGraphicsAllocation : public GraphicsAllocation { + public: + using GraphicsAllocation::allocationInfo; + }; + memoryManager.reset(new MockWddmMemoryManager(false, false, executionEnvironment)); + AllocationData allocationData; + auto allocation = static_cast(memoryManager->allocateGraphicsMemory64kb(allocationData)); + EXPECT_NE(nullptr, allocation); + EXPECT_FALSE(allocation->allocationInfo.flags.lockedMemory); + allocation->setLockedMemory(true); + EXPECT_TRUE(allocation->allocationInfo.flags.lockedMemory); + EXPECT_TRUE(allocation->isLockedMemory()); + + memoryManager->freeGraphicsMemory(allocation); +} + TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPages) { memoryManager.reset(new MockWddmMemoryManager(false, false, executionEnvironment)); if (memoryManager->isLimitedGPU(0)) { diff --git a/shared/test/unit_test/os_interface/windows/wddm_memory_operations_handler_with_aub_dump_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_memory_operations_handler_with_aub_dump_tests.cpp index f4b7c5c8e9..34143bb59c 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_memory_operations_handler_with_aub_dump_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_memory_operations_handler_with_aub_dump_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -122,3 +122,7 @@ TEST_F(WddmMemoryOperationsHandlerWithAubDumpTest, whenConstructingWddmMemoryOpe auto wddmMemoryOperationsHandlerWithAubDump = std::make_unique>(wddm, *rootDeviceEnvironment); EXPECT_NE(nullptr, rootDeviceEnvironment->aubCenter.get()); } + +TEST_F(WddmMemoryOperationsHandlerWithAubDumpTest, givenRegularAllocationWhenLockingAllocationThenUnsupportIsReturned) { + EXPECT_EQ(wddmMemoryOperationsHandlerWithAubDumpMock->lock(nullptr, ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::unsupported); +}