From 37ed03a15c8ba2382418e0507c0310745dc3e113 Mon Sep 17 00:00:00 2001 From: Jaime Arteaga Date: Tue, 23 May 2023 04:23:38 +0000 Subject: [PATCH] feature: Propagate error from makeResident to caller Have makeResident return error to the caller, instead of always SUCCESS. This will allow interfaces like zeContextMakeMemoryResident to fail properly. Additionally, change the parsing of MemoryOperationsStatus from ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY to ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, since when making resources resident, it is the device running out of memory, instead of the host. Related-To: LOCI-4443 Signed-off-by: Jaime Arteaga --- level_zero/core/source/memory/memory_operations_helper.h | 4 ++-- .../core/test/unit_tests/sources/memory/test_memory.cpp | 2 +- .../linux/drm_memory_operations_handler_bind.cpp | 8 ++++++-- .../linux/drm_residency_handler_prelim_tests.cpp | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/level_zero/core/source/memory/memory_operations_helper.h b/level_zero/core/source/memory/memory_operations_helper.h index 3ae8a43104..8372f8433b 100644 --- a/level_zero/core/source/memory/memory_operations_helper.h +++ b/level_zero/core/source/memory/memory_operations_helper.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -20,7 +20,7 @@ static ze_result_t changeMemoryOperationStatusToL0ResultType(NEO::MemoryOperatio return ZE_RESULT_ERROR_INVALID_ARGUMENT; case NEO::MemoryOperationsStatus::OUT_OF_MEMORY: - return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY; + return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; case NEO::MemoryOperationsStatus::FAILED: return ZE_RESULT_ERROR_DEVICE_LOST; diff --git a/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp b/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp index 771f21e766..eb0c83521f 100644 --- a/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp +++ b/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp @@ -4690,7 +4690,7 @@ TEST_F(ContextMemoryTest, givenCallTochangeMemoryOperationStatusToL0ResultTypeTh status = NEO::MemoryOperationsStatus::OUT_OF_MEMORY; res = changeMemoryOperationStatusToL0ResultType(status); - EXPECT_EQ(res, ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY); + EXPECT_EQ(res, ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY); status = NEO::MemoryOperationsStatus::UNSUPPORTED; res = changeMemoryOperationStatusToL0ResultType(status); 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 17de6a5a97..f8c52d64ec 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 @@ -28,11 +28,15 @@ DrmMemoryOperationsHandlerBind::~DrmMemoryOperationsHandlerBind() = default; MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResident(Device *device, ArrayRef gfxAllocations) { auto &engines = device->getAllEngines(); + MemoryOperationsStatus result = MemoryOperationsStatus::SUCCESS; for (const auto &engine : engines) { engine.commandStreamReceiver->initializeResources(); - this->makeResidentWithinOsContext(engine.osContext, gfxAllocations, false); + result = this->makeResidentWithinOsContext(engine.osContext, gfxAllocations, false); + if (result != MemoryOperationsStatus::SUCCESS) { + break; + } } - return MemoryOperationsStatus::SUCCESS; + return result; } MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResidentWithinOsContext(OsContext *osContext, ArrayRef gfxAllocations, bool evictable) { 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_residency_handler_prelim_tests.cpp index dbb99345d9..8250fc20a9 100644 --- a/shared/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp @@ -291,7 +291,8 @@ TEST_F(DrmMemoryOperationsHandlerBindMultiRootDeviceTest2, whenNoSpaceLeftOnDevi EXPECT_EQ(allocationDefault, registeredAllocations[1]); EXPECT_EQ(operationHandler->evictUnusedCalled, 0u); - operationHandler->makeResident(device, ArrayRef(&allocation, 1)); + auto res = operationHandler->makeResident(device, ArrayRef(&allocation, 1)); + EXPECT_EQ(MemoryOperationsStatus::OUT_OF_MEMORY, res); EXPECT_EQ(operationHandler->evictUnusedCalled, 1u); memoryManager->freeGraphicsMemory(allocation);