Skip to content

Commit a240129

Browse files
JemaleCompute-Runtime-Automation
authored andcommitted
Fix zero size allocation look up
Signed-off-by: Jemale Lockett <[email protected]> Related-To: LOCI-2537
1 parent f0cb1cc commit a240129

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

level_zero/core/source/driver/driver_handle_imp.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,16 @@ ze_result_t DriverHandleImp::getDevice(uint32_t *pCount, ze_device_handle_t *phD
257257
bool DriverHandleImp::findAllocationDataForRange(const void *buffer,
258258
size_t size,
259259
NEO::SvmAllocationData **allocData) {
260+
261+
size_t offset = 0;
262+
if (size > 0) {
263+
offset = size - 1;
264+
}
265+
260266
// Make sure the host buffer does not overlap any existing allocation
261267
const char *baseAddress = reinterpret_cast<const char *>(buffer);
262268
NEO::SvmAllocationData *beginAllocData = svmAllocsManager->getSVMAlloc(baseAddress);
263-
NEO::SvmAllocationData *endAllocData = svmAllocsManager->getSVMAlloc(baseAddress + size - 1);
269+
NEO::SvmAllocationData *endAllocData = svmAllocsManager->getSVMAlloc(baseAddress + offset);
264270

265271
if (allocData) {
266272
if (beginAllocData) {

level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_3.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,38 @@ HWTEST2_F(CommandListCreate, givenCommandListWhenMemoryCopyRegionWithSignalAndIn
735735
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result);
736736
}
737737

738+
HWTEST2_F(CommandListCreate, givenCommandListWhenMemoryCopyRegionHasEmptyRegionWithSignalAndWaitEventsUsingCopyEngineThenSuccessIsReturned, Platforms) {
739+
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
740+
741+
ze_result_t result = ZE_RESULT_SUCCESS;
742+
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Copy, 0u, result));
743+
744+
void *srcBuffer = reinterpret_cast<void *>(0x1234);
745+
void *dstBuffer = reinterpret_cast<void *>(0x2345);
746+
747+
ze_event_pool_desc_t eventPoolDesc = {};
748+
eventPoolDesc.count = 2;
749+
auto eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
750+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
751+
std::vector<ze_event_handle_t> events;
752+
753+
ze_event_desc_t eventDesc = {};
754+
eventDesc.index = 0;
755+
eventDesc.wait = ZE_EVENT_SCOPE_FLAG_HOST;
756+
auto event = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
757+
events.push_back(event.get());
758+
eventDesc.index = 1;
759+
auto event1 = std::unique_ptr<L0::Event>(L0::Event::create<uint32_t>(eventPool.get(), &eventDesc, device));
760+
events.push_back(event1.get());
761+
762+
// set regions to 0
763+
ze_copy_region_t sr = {0U, 0U, 0U, 0U, 0U, 0U};
764+
ze_copy_region_t dr = {0U, 0U, 0U, 0U, 0U, 0U};
765+
result = commandList->appendMemoryCopyRegion(dstBuffer, &dr, 0, 0,
766+
srcBuffer, &sr, 0, 0, events[0], 1u, &events[1]);
767+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
768+
}
769+
738770
HWTEST2_F(CommandListCreate, givenImmediateCommandListWhenMemoryCopyRegionWithSignalAndWaitEventsUsingRenderEngineThenSuccessIsReturned, Platforms) {
739771
const ze_command_queue_desc_t desc = {};
740772
bool internalEngine = true;

0 commit comments

Comments
 (0)