From 41a90e67d7fa46f381e9e12f5225a371b7537a02 Mon Sep 17 00:00:00 2001 From: Maciej Dziuban Date: Wed, 25 Nov 2020 17:36:10 +0000 Subject: [PATCH] OpenCL Queue Families extension 5/n Check queue capabilities in enqueue calls for kernels, barriers and markers Signed-off-by: Maciej Dziuban Related-To: NEO-5120 --- opencl/source/api/api.cpp | 36 +++++++++++++++++++ .../api/cl_enqueue_barrier_tests.inl | 9 ++++- ...l_enqueue_barrier_with_wait_list_tests.inl | 10 ++++++ .../unit_test/api/cl_enqueue_marker_tests.inl | 8 +++++ ...cl_enqueue_marker_with_wait_list_tests.inl | 10 ++++++ .../api/cl_enqueue_nd_range_kernel_tests.inl | 24 +++++++++++++ .../command_queue/enqueue_kernel_1_tests.cpp | 29 +++++++++++++++ 7 files changed, 125 insertions(+), 1 deletion(-) diff --git a/opencl/source/api/api.cpp b/opencl/source/api/api.cpp index 8353fd0f79..55c6658e34 100644 --- a/opencl/source/api/api.cpp +++ b/opencl/source/api/api.cpp @@ -3398,6 +3398,12 @@ cl_int CL_API_CALL clEnqueueNDRangeKernel(cl_command_queue commandQueue, return retVal; } + if (!pCommandQueue->validateCapabilityForOperation(CL_QUEUE_CAPABILITY_KERNEL_INTEL, eventWaitList, event)) { + retVal = CL_INVALID_OPERATION; + TRACING_EXIT(clEnqueueNDRangeKernel, &retVal); + return retVal; + } + TakeOwnershipWrapper kernelOwnership(*pKernel, gtpinIsGTPinInitialized()); if (gtpinIsGTPinInitialized()) { gtpinNotifyKernelSubmit(kernel, pCommandQueue); @@ -3481,6 +3487,12 @@ cl_int CL_API_CALL clEnqueueMarker(cl_command_queue commandQueue, auto pCommandQueue = castToObject(commandQueue); if (pCommandQueue) { + if (!pCommandQueue->validateCapability(CL_QUEUE_CAPABILITY_MARKER_INTEL)) { + retVal = CL_INVALID_OPERATION; + TRACING_EXIT(clEnqueueMarker, &retVal); + return retVal; + } + retVal = pCommandQueue->enqueueMarkerWithWaitList( 0, nullptr, @@ -3531,6 +3543,12 @@ cl_int CL_API_CALL clEnqueueBarrier(cl_command_queue commandQueue) { DBG_LOG_INPUTS("commandQueue", commandQueue); auto pCommandQueue = castToObject(commandQueue); if (pCommandQueue) { + if (!pCommandQueue->validateCapability(CL_QUEUE_CAPABILITY_BARRIER_INTEL)) { + retVal = CL_INVALID_OPERATION; + TRACING_EXIT(clEnqueueBarrier, &retVal); + return retVal; + } + retVal = pCommandQueue->enqueueBarrierWithWaitList( 0, nullptr, @@ -3565,6 +3583,12 @@ cl_int CL_API_CALL clEnqueueMarkerWithWaitList(cl_command_queue commandQueue, return retVal; } + if (!pCommandQueue->validateCapabilityForOperation(CL_QUEUE_CAPABILITY_MARKER_INTEL, eventWaitList, event)) { + retVal = CL_INVALID_OPERATION; + TRACING_EXIT(clEnqueueMarkerWithWaitList, &retVal); + return retVal; + } + retVal = pCommandQueue->enqueueMarkerWithWaitList( numEventsInWaitList, eventWaitList, @@ -3595,6 +3619,13 @@ cl_int CL_API_CALL clEnqueueBarrierWithWaitList(cl_command_queue commandQueue, TRACING_EXIT(clEnqueueBarrierWithWaitList, &retVal); return retVal; } + + if (!pCommandQueue->validateCapabilityForOperation(CL_QUEUE_CAPABILITY_BARRIER_INTEL, eventWaitList, event)) { + retVal = CL_INVALID_OPERATION; + TRACING_EXIT(clEnqueueBarrierWithWaitList, &retVal); + return retVal; + } + retVal = pCommandQueue->enqueueBarrierWithWaitList( numEventsInWaitList, eventWaitList, @@ -5800,6 +5831,11 @@ cl_int CL_API_CALL clEnqueueNDCountKernelINTEL(cl_command_queue commandQueue, pCommandQueue->getDevice().getSpecializedDevice()->allocateSyncBufferHandler(); } + if (!pCommandQueue->validateCapabilityForOperation(CL_QUEUE_CAPABILITY_KERNEL_INTEL, eventWaitList, event)) { + retVal = CL_INVALID_OPERATION; + return retVal; + } + TakeOwnershipWrapper kernelOwnership(*pKernel, gtpinIsGTPinInitialized()); if (gtpinIsGTPinInitialized()) { gtpinNotifyKernelSubmit(kernel, pCommandQueue); diff --git a/opencl/test/unit_test/api/cl_enqueue_barrier_tests.inl b/opencl/test/unit_test/api/cl_enqueue_barrier_tests.inl index d7caa7c93a..1a7c4a457d 100644 --- a/opencl/test/unit_test/api/cl_enqueue_barrier_tests.inl +++ b/opencl/test/unit_test/api/cl_enqueue_barrier_tests.inl @@ -19,8 +19,15 @@ TEST_F(clEnqueueBarrierTests, GivenNullCommandQueueWhenEnqueuingThenInvalidComma EXPECT_EQ(CL_INVALID_COMMAND_QUEUE, retVal); } -TEST_F(clEnqueueBarrierTests, GivenValidCommandQueueWhenEnqueuingThenSuccessIsReturned) { +TEST_F(clEnqueueBarrierTests, GivenValidCommandQueueWhenEnqueuingBarrierThenSuccessIsReturned) { auto retVal = clEnqueueBarrier( pCommandQueue); EXPECT_EQ(CL_SUCCESS, retVal); } + +TEST_F(clEnqueueBarrierTests, GivenQueueIncapableWhenEnqueuingBarrierThenInvalidOperationIsReturned) { + this->disableQueueCapabilities(CL_QUEUE_CAPABILITY_BARRIER_INTEL); + auto retVal = clEnqueueBarrier( + pCommandQueue); + EXPECT_EQ(CL_INVALID_OPERATION, retVal); +} diff --git a/opencl/test/unit_test/api/cl_enqueue_barrier_with_wait_list_tests.inl b/opencl/test/unit_test/api/cl_enqueue_barrier_with_wait_list_tests.inl index 279d1f0667..a22000cd67 100644 --- a/opencl/test/unit_test/api/cl_enqueue_barrier_with_wait_list_tests.inl +++ b/opencl/test/unit_test/api/cl_enqueue_barrier_with_wait_list_tests.inl @@ -30,3 +30,13 @@ TEST_F(clEnqueueBarrierWithWaitListTests, GivenValidCommandQueueWhenEnqueuingBar nullptr); EXPECT_EQ(CL_SUCCESS, retVal); } + +TEST_F(clEnqueueBarrierWithWaitListTests, GivenQueueIncapableWhenEnqueuingBarrierWithWaitListThenInvalidOperationIsReturned) { + this->disableQueueCapabilities(CL_QUEUE_CAPABILITY_BARRIER_INTEL); + auto retVal = clEnqueueBarrierWithWaitList( + pCommandQueue, + 0, + nullptr, + nullptr); + EXPECT_EQ(CL_INVALID_OPERATION, retVal); +} diff --git a/opencl/test/unit_test/api/cl_enqueue_marker_tests.inl b/opencl/test/unit_test/api/cl_enqueue_marker_tests.inl index 9afd0b2e69..d304808eb7 100644 --- a/opencl/test/unit_test/api/cl_enqueue_marker_tests.inl +++ b/opencl/test/unit_test/api/cl_enqueue_marker_tests.inl @@ -28,6 +28,14 @@ TEST_F(clEnqueueMarkerTests, GivenValidCommandQueueWhenEnqueingMarkerThenSuccess EXPECT_EQ(CL_SUCCESS, retVal); } +TEST_F(clEnqueueMarkerTests, GivenQueueIncapableWhenEnqueingMarkerThenInvalidOperationReturned) { + this->disableQueueCapabilities(CL_QUEUE_CAPABILITY_MARKER_INTEL); + auto retVal = clEnqueueMarker( + pCommandQueue, + nullptr); + EXPECT_EQ(CL_INVALID_OPERATION, retVal); +} + class CommandWithoutKernelTypesTests : public testing::TestWithParam { }; diff --git a/opencl/test/unit_test/api/cl_enqueue_marker_with_wait_list_tests.inl b/opencl/test/unit_test/api/cl_enqueue_marker_with_wait_list_tests.inl index 9232ed15e9..752b35e8dc 100644 --- a/opencl/test/unit_test/api/cl_enqueue_marker_with_wait_list_tests.inl +++ b/opencl/test/unit_test/api/cl_enqueue_marker_with_wait_list_tests.inl @@ -30,3 +30,13 @@ TEST_F(clEnqueueMarkerWithWaitListTests, GivenValidCommandQueueWhenEnqueingMarke nullptr); EXPECT_EQ(CL_SUCCESS, retVal); } + +TEST_F(clEnqueueMarkerWithWaitListTests, GivenQueueIncapableWhenEnqueingMarkerWithWaitListThenInvalidOperationIsReturned) { + this->disableQueueCapabilities(CL_QUEUE_CAPABILITY_MARKER_INTEL); + auto retVal = clEnqueueMarkerWithWaitList( + pCommandQueue, + 0, + nullptr, + nullptr); + EXPECT_EQ(CL_INVALID_OPERATION, retVal); +} diff --git a/opencl/test/unit_test/api/cl_enqueue_nd_range_kernel_tests.inl b/opencl/test/unit_test/api/cl_enqueue_nd_range_kernel_tests.inl index 98a0b98617..d7b2c93864 100644 --- a/opencl/test/unit_test/api/cl_enqueue_nd_range_kernel_tests.inl +++ b/opencl/test/unit_test/api/cl_enqueue_nd_range_kernel_tests.inl @@ -39,6 +39,30 @@ TEST_F(clEnqueueNDRangeKernelTests, GivenValidParametersWhenExecutingKernelThenS EXPECT_EQ(CL_SUCCESS, retVal); } +TEST_F(clEnqueueNDRangeKernelTests, GivenQueueIncapableWhenExecutingKernelThenInvalidOperationIsReturned) { + cl_uint workDim = 1; + size_t globalWorkOffset[3] = {0, 0, 0}; + size_t globalWorkSize[3] = {1, 1, 1}; + size_t localWorkSize[3] = {1, 1, 1}; + cl_uint numEventsInWaitList = 0; + cl_event *eventWaitList = nullptr; + cl_event *event = nullptr; + + this->disableQueueCapabilities(CL_QUEUE_CAPABILITY_KERNEL_INTEL); + retVal = clEnqueueNDRangeKernel( + pCommandQueue, + pKernel, + workDim, + globalWorkOffset, + globalWorkSize, + localWorkSize, + numEventsInWaitList, + eventWaitList, + event); + + EXPECT_EQ(CL_INVALID_OPERATION, retVal); +} + TEST_F(clEnqueueNDRangeKernelTests, GivenNullCommandQueueWhenExecutingKernelThenInvalidCommandQueueErrorIsReturned) { size_t globalWorkSize[3] = {1, 1, 1}; diff --git a/opencl/test/unit_test/command_queue/enqueue_kernel_1_tests.cpp b/opencl/test/unit_test/command_queue/enqueue_kernel_1_tests.cpp index b2621933e6..3a86288ae2 100644 --- a/opencl/test/unit_test/command_queue/enqueue_kernel_1_tests.cpp +++ b/opencl/test/unit_test/command_queue/enqueue_kernel_1_tests.cpp @@ -12,6 +12,7 @@ #include "opencl/source/api/api.h" #include "opencl/source/built_ins/builtins_dispatch_builder.h" +#include "opencl/test/unit_test/api/cl_api_tests.h" #include "opencl/test/unit_test/command_queue/enqueue_fixture.h" #include "opencl/test/unit_test/fixtures/hello_world_fixture.h" #include "opencl/test/unit_test/helpers/unit_test_helper.h" @@ -207,6 +208,34 @@ TEST_F(EnqueueKernelTest, GivenNullKernelWhenEnqueuingNDCountKernelINTELThenInva EXPECT_EQ(CL_INVALID_KERNEL, retVal); } +using clEnqueueNDCountKernelTests = api_tests; + +TEST_F(clEnqueueNDCountKernelTests, GivenQueueIncapableWhenEnqueuingNDCountKernelINTELThenInvalidOperationIsReturned) { + auto &hwHelper = HwHelper::get(::defaultHwInfo->platform.eRenderCoreFamily); + if (!hwHelper.isCooperativeDispatchSupported(pCommandQueue->getGpgpuEngine().getEngineType(), ::defaultHwInfo->platform.eProductFamily)) { + GTEST_SKIP(); + } + + cl_uint workDim = 1; + size_t globalWorkOffset[3] = {0, 0, 0}; + size_t workgroupCount[3] = {1, 1, 1}; + size_t localWorkSize[3] = {1, 1, 1}; + + this->disableQueueCapabilities(CL_QUEUE_CAPABILITY_KERNEL_INTEL); + retVal = clEnqueueNDCountKernelINTEL( + pCommandQueue, + pKernel, + workDim, + globalWorkOffset, + workgroupCount, + localWorkSize, + 0, + nullptr, + nullptr); + + EXPECT_EQ(CL_INVALID_OPERATION, retVal); +} + TEST_F(EnqueueKernelTest, givenKernelWhenAllArgsAreSetThenClEnqueueNDCountKernelINTELReturnsSuccess) { const size_t n = 512; size_t workgroupCount[3] = {2, 1, 1};