From fe0c7f1004744fa3cff9a8ad73fb7ca76e5d7e7b Mon Sep 17 00:00:00 2001 From: "Baj, Tomasz" Date: Thu, 30 Nov 2023 15:39:10 +0000 Subject: [PATCH] fix: when size is 0 then don't copy Related-To: NEO-8381 Signed-off-by: Baj, Tomasz --- opencl/source/api/api.cpp | 21 +++++++++------- .../api/cl_enqueue_svm_memcpy_tests.inl | 24 +++++++++++++++++++ .../test/unit_test/mocks/mock_command_queue.h | 6 ++++- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/opencl/source/api/api.cpp b/opencl/source/api/api.cpp index 60262b9173..59eb82539f 100644 --- a/opencl/source/api/api.cpp +++ b/opencl/source/api/api.cpp @@ -4750,15 +4750,18 @@ cl_int CL_API_CALL clEnqueueSVMMemcpy(cl_command_queue commandQueue, return retVal; } - retVal = pCommandQueue->enqueueSVMMemcpy( - blockingCopy, - dstPtr, - srcPtr, - size, - numEventsInWaitList, - eventWaitList, - event); - + if (size != 0) { + retVal = pCommandQueue->enqueueSVMMemcpy( + blockingCopy, + dstPtr, + srcPtr, + size, + numEventsInWaitList, + eventWaitList, + event); + } else { + retVal = pCommandQueue->enqueueMarkerWithWaitList(numEventsInWaitList, eventWaitList, event); + } TRACING_EXIT(ClEnqueueSvmMemcpy, &retVal); return retVal; } diff --git a/opencl/test/unit_test/api/cl_enqueue_svm_memcpy_tests.inl b/opencl/test/unit_test/api/cl_enqueue_svm_memcpy_tests.inl index 0d1942faeb..ab1b912089 100644 --- a/opencl/test/unit_test/api/cl_enqueue_svm_memcpy_tests.inl +++ b/opencl/test/unit_test/api/cl_enqueue_svm_memcpy_tests.inl @@ -185,6 +185,30 @@ TEST_F(ClEnqueueSVMMemcpyTests, GivenZeroSizeWhenCopyingSVMMemoryThenSuccessIsRe } } +TEST_F(ClEnqueueSVMMemcpyTests, GivenInvalidPtrAndZeroSizeWhenCopyingSVMMemoryThenSuccessIsReturned) { + const ClDeviceInfo &devInfo = pDevice->getDeviceInfo(); + if (devInfo.svmCapabilities != 0) { + UserEvent uEvent(pContext); + cl_event eventWaitList[] = {&uEvent}; + void *pDstSvm = reinterpret_cast(0x100001); + void *pSrcSvm = reinterpret_cast(0x100001); + + auto retVal = clEnqueueSVMMemcpy( + pCommandQueue, // cl_command_queue command_queue + CL_FALSE, // cl_bool blocking_copy + pDstSvm, // void *dst_ptr + pSrcSvm, // const void *src_ptr + 0, // size_t size + 1, // cl_uint num_events_in_wait_list + eventWaitList, // const cl_event *event_wait_list + nullptr // cl_event *event + ); + EXPECT_EQ(CL_QUEUED, uEvent.peekExecutionStatus()); + EXPECT_TRUE(pCommandQueue->enqueueMarkerWithWaitListCalled); + EXPECT_EQ(CL_SUCCESS, retVal); + } +} + TEST_F(ClEnqueueSVMMemcpyTests, GivenDeviceNotSupportingSvmWhenEnqueuingSVMMemcpyThenInvalidOperationErrorIsReturned) { auto hwInfo = *defaultHwInfo; hwInfo.capabilityTable.ftrSvm = false; diff --git a/opencl/test/unit_test/mocks/mock_command_queue.h b/opencl/test/unit_test/mocks/mock_command_queue.h index dbd1e4f027..2d1e1d17d6 100644 --- a/opencl/test/unit_test/mocks/mock_command_queue.h +++ b/opencl/test/unit_test/mocks/mock_command_queue.h @@ -162,7 +162,10 @@ class MockCommandQueue : public CommandQueue { cl_int enqueueSVMMemFill(void *svmPtr, const void *pattern, size_t patternSize, size_t size, cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *event) override { return CL_SUCCESS; } - cl_int enqueueMarkerWithWaitList(cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *event) override { return CL_SUCCESS; } + cl_int enqueueMarkerWithWaitList(cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *event) override { + enqueueMarkerWithWaitListCalled = true; + return CL_SUCCESS; + } cl_int enqueueMigrateMemObjects(cl_uint numMemObjects, const cl_mem *memObjects, cl_mem_migration_flags flags, cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *event) override { return CL_SUCCESS; } @@ -235,6 +238,7 @@ class MockCommandQueue : public CommandQueue { return CommandQueue::isCompleted(gpgpuTaskCount, bcsStates); } + bool enqueueMarkerWithWaitListCalled = false; bool releaseIndirectHeapCalled = false; bool waitForTimestampsCalled = false; cl_int writeBufferRetValue = CL_SUCCESS;