From f7b6dfff5230fb6a60c7068a805999bdc662728f Mon Sep 17 00:00:00 2001 From: Michal Mrozek Date: Fri, 10 May 2024 12:10:35 +0000 Subject: [PATCH] fix: allow nullptr addresses while creating cb event. Signed-off-by: Michal Mrozek --- .../driver_experimental/public/zex_event.cpp | 23 +++++++++++-------- .../sources/cmdlist/test_in_order_cmdlist.cpp | 19 ++++++++++++--- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/level_zero/api/driver_experimental/public/zex_event.cpp b/level_zero/api/driver_experimental/public/zex_event.cpp index b203707b0d..c355b952d0 100644 --- a/level_zero/api/driver_experimental/public/zex_event.cpp +++ b/level_zero/api/driver_experimental/public/zex_event.cpp @@ -49,23 +49,26 @@ zexCounterBasedEventCreate(ze_context_handle_t hContext, ze_device_handle_t hDev auto device = Device::fromHandle(hDevice); - if (!hDevice || !deviceAddress || !hostAddress || !desc || !phEvent) { + if (!hDevice || !desc || !phEvent) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } NEO::SvmAllocationData *externalHostAllocData = nullptr; - bool allocFound = device->getDriverHandle()->findAllocationDataForRange(hostAddress, sizeof(uint64_t), externalHostAllocData); - - if (!allocFound) { - return ZE_RESULT_ERROR_INVALID_ARGUMENT; + if (hostAddress) { + bool allocFound = device->getDriverHandle()->findAllocationDataForRange(hostAddress, sizeof(uint64_t), externalHostAllocData); + if (!allocFound) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } } - auto allocation = externalHostAllocData->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex()); - - auto inOrderExecInfo = NEO::InOrderExecInfo::createFromExternalAllocation(*device->getNEODevice(), castToUint64(deviceAddress), allocation, hostAddress, completionValue); - *phEvent = Event::create(eventDescriptor, desc, device); - Event::fromHandle(*phEvent)->updateInOrderExecState(inOrderExecInfo, completionValue, 0); + + if (hostAddress && deviceAddress) { + NEO::GraphicsAllocation *allocation = nullptr; + allocation = externalHostAllocData->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex()); + auto inOrderExecInfo = NEO::InOrderExecInfo::createFromExternalAllocation(*device->getNEODevice(), castToUint64(deviceAddress), allocation, hostAddress, completionValue); + Event::fromHandle(*phEvent)->updateInOrderExecState(inOrderExecInfo, completionValue, 0); + } return ZE_RESULT_SUCCESS; } diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist.cpp index b7f7df9ccf..b8892e290d 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist.cpp @@ -3977,14 +3977,27 @@ HWTEST2_F(InOrderCmdListTests, givenCorrectInputParamsWhenCreatingCbEventThenRet EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, zexCounterBasedEventCreate(context, device, gpuAddress, hostAddress, counterValue, &eventDesc, nullptr)); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, zexCounterBasedEventCreate(context, device, gpuAddress, hostAddress, counterValue, nullptr, &handle)); - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, zexCounterBasedEventCreate(context, device, gpuAddress, nullptr, counterValue, &eventDesc, &handle)); - EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, zexCounterBasedEventCreate(context, device, nullptr, hostAddress, counterValue, &eventDesc, &handle)); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, zexCounterBasedEventCreate(context, nullptr, gpuAddress, hostAddress, counterValue, &eventDesc, &handle)); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, zexCounterBasedEventCreate(context, device, gpuAddress, &counterValue, counterValue, &eventDesc, &handle)); + EXPECT_EQ(ZE_RESULT_SUCCESS, zexCounterBasedEventCreate(context, device, gpuAddress, nullptr, counterValue, &eventDesc, &handle)); + auto eventObj = Event::fromHandle(handle); + EXPECT_EQ(nullptr, eventObj->getInOrderExecInfo()); + zeEventDestroy(handle); + + EXPECT_EQ(ZE_RESULT_SUCCESS, zexCounterBasedEventCreate(context, device, nullptr, hostAddress, counterValue, &eventDesc, &handle)); + eventObj = Event::fromHandle(handle); + EXPECT_EQ(nullptr, eventObj->getInOrderExecInfo()); + zeEventDestroy(handle); + + EXPECT_EQ(ZE_RESULT_SUCCESS, zexCounterBasedEventCreate(context, device, nullptr, nullptr, counterValue, &eventDesc, &handle)); + eventObj = Event::fromHandle(handle); + EXPECT_EQ(nullptr, eventObj->getInOrderExecInfo()); + zeEventDestroy(handle); + EXPECT_EQ(ZE_RESULT_SUCCESS, zexCounterBasedEventCreate(context, device, gpuAddress, hostAddress, counterValue, &eventDesc, &handle)); - auto eventObj = Event::fromHandle(handle); + eventObj = Event::fromHandle(handle); ASSERT_NE(nullptr, eventObj); ASSERT_NE(nullptr, eventObj->getInOrderExecInfo().get());