From a2401299a02e1b9ed8b73e0f1e13dd4cb4cee5dd Mon Sep 17 00:00:00 2001 From: Jemale Lockett Date: Wed, 17 Nov 2021 13:06:21 -0500 Subject: [PATCH] Fix zero size allocation look up Signed-off-by: Jemale Lockett Related-To: LOCI-2537 --- .../core/source/driver/driver_handle_imp.cpp | 8 ++++- .../sources/cmdlist/test_cmdlist_3.cpp | 32 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/level_zero/core/source/driver/driver_handle_imp.cpp b/level_zero/core/source/driver/driver_handle_imp.cpp index c023e46238..1168aa2cc3 100644 --- a/level_zero/core/source/driver/driver_handle_imp.cpp +++ b/level_zero/core/source/driver/driver_handle_imp.cpp @@ -257,10 +257,16 @@ ze_result_t DriverHandleImp::getDevice(uint32_t *pCount, ze_device_handle_t *phD bool DriverHandleImp::findAllocationDataForRange(const void *buffer, size_t size, NEO::SvmAllocationData **allocData) { + + size_t offset = 0; + if (size > 0) { + offset = size - 1; + } + // Make sure the host buffer does not overlap any existing allocation const char *baseAddress = reinterpret_cast(buffer); NEO::SvmAllocationData *beginAllocData = svmAllocsManager->getSVMAlloc(baseAddress); - NEO::SvmAllocationData *endAllocData = svmAllocsManager->getSVMAlloc(baseAddress + size - 1); + NEO::SvmAllocationData *endAllocData = svmAllocsManager->getSVMAlloc(baseAddress + offset); if (allocData) { if (beginAllocData) { diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_3.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_3.cpp index 65496164ec..f30045903f 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_3.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_3.cpp @@ -735,6 +735,38 @@ HWTEST2_F(CommandListCreate, givenCommandListWhenMemoryCopyRegionWithSignalAndIn EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result); } +HWTEST2_F(CommandListCreate, givenCommandListWhenMemoryCopyRegionHasEmptyRegionWithSignalAndWaitEventsUsingCopyEngineThenSuccessIsReturned, Platforms) { + using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; + + ze_result_t result = ZE_RESULT_SUCCESS; + std::unique_ptr commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Copy, 0u, result)); + + void *srcBuffer = reinterpret_cast(0x1234); + void *dstBuffer = reinterpret_cast(0x2345); + + ze_event_pool_desc_t eventPoolDesc = {}; + eventPoolDesc.count = 2; + auto eventPool = std::unique_ptr(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result)); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + std::vector events; + + ze_event_desc_t eventDesc = {}; + eventDesc.index = 0; + eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST; + auto event = std::unique_ptr(L0::Event::create(eventPool.get(), &eventDesc, device)); + events.push_back(event.get()); + eventDesc.index = 1; + auto event1 = std::unique_ptr(L0::Event::create(eventPool.get(), &eventDesc, device)); + events.push_back(event1.get()); + + // set regions to 0 + ze_copy_region_t sr = {0U, 0U, 0U, 0U, 0U, 0U}; + ze_copy_region_t dr = {0U, 0U, 0U, 0U, 0U, 0U}; + result = commandList->appendMemoryCopyRegion(dstBuffer, &dr, 0, 0, + srcBuffer, &sr, 0, 0, events[0], 1u, &events[1]); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); +} + HWTEST2_F(CommandListCreate, givenImmediateCommandListWhenMemoryCopyRegionWithSignalAndWaitEventsUsingRenderEngineThenSuccessIsReturned, Platforms) { const ze_command_queue_desc_t desc = {}; bool internalEngine = true;