diff --git a/opencl/extensions/public/cl_ext_private.h b/opencl/extensions/public/cl_ext_private.h index 3ecbbfc121..6308b7316f 100644 --- a/opencl/extensions/public/cl_ext_private.h +++ b/opencl/extensions/public/cl_ext_private.h @@ -257,3 +257,12 @@ typedef struct _cl_device_pci_bus_info_khr { // New query for clGetDeviceInfo: #define CL_MEM_COMPRESSED_INTEL 0x417D + +/* cl_queue_properties */ +#define CL_QUEUE_MDAPI_PROPERTIES_INTEL 0x425E +#define CL_QUEUE_MDAPI_CONFIGURATION_INTEL 0x425F + +typedef cl_bitfield cl_command_queue_mdapi_properties_intel; + +/* cl_command_queue_mdapi_properties_intel - bitfield */ +#define CL_QUEUE_MDAPI_ENABLE_INTEL (1 << 0) diff --git a/opencl/source/api/api.cpp b/opencl/source/api/api.cpp index 66153f1a3e..b875dba331 100644 --- a/opencl/source/api/api.cpp +++ b/opencl/source/api/api.cpp @@ -5199,13 +5199,18 @@ cl_command_queue CL_API_CALL clCreateCommandQueueWithProperties(cl_context conte auto propertiesAddress = properties; while (tokenValue != 0) { - if (tokenValue != CL_QUEUE_PROPERTIES && - tokenValue != CL_QUEUE_SIZE && - tokenValue != CL_QUEUE_PRIORITY_KHR && - tokenValue != CL_QUEUE_THROTTLE_KHR && - tokenValue != CL_QUEUE_SLICE_COUNT_INTEL && - tokenValue != CL_QUEUE_FAMILY_INTEL && - tokenValue != CL_QUEUE_INDEX_INTEL) { + switch (tokenValue) { + case CL_QUEUE_PROPERTIES: + case CL_QUEUE_SIZE: + case CL_QUEUE_PRIORITY_KHR: + case CL_QUEUE_THROTTLE_KHR: + case CL_QUEUE_SLICE_COUNT_INTEL: + case CL_QUEUE_FAMILY_INTEL: + case CL_QUEUE_INDEX_INTEL: + case CL_QUEUE_MDAPI_PROPERTIES_INTEL: + case CL_QUEUE_MDAPI_CONFIGURATION_INTEL: + break; + default: err.set(CL_INVALID_VALUE); TRACING_EXIT(clCreateCommandQueueWithProperties, &commandQueue); return commandQueue; @@ -5281,12 +5286,37 @@ cl_command_queue CL_API_CALL clCreateCommandQueueWithProperties(cl_context conte TRACING_EXIT(clCreateCommandQueueWithProperties, &commandQueue); return commandQueue; } + + bool mdapiPropertySet = false; + bool mdapiConfigurationSet = false; + cl_command_queue_mdapi_properties_intel mdapiProperties = getCmdQueueProperties(properties, CL_QUEUE_MDAPI_PROPERTIES_INTEL, &mdapiPropertySet); + cl_uint mdapiConfiguration = getCmdQueueProperties(properties, CL_QUEUE_MDAPI_CONFIGURATION_INTEL, &mdapiConfigurationSet); + + if (mdapiConfigurationSet && mdapiConfiguration != 0) { + err.set(CL_INVALID_OPERATION); + TRACING_EXIT(clCreateCommandQueueWithProperties, &commandQueue); + return commandQueue; + } + commandQueue = CommandQueue::create( pContext, pDevice, properties, false, retVal); + + if (mdapiPropertySet && (mdapiProperties & CL_QUEUE_MDAPI_ENABLE_INTEL)) { + auto commandQueueObj = castToObjectOrAbort(commandQueue); + + if (!commandQueueObj->setPerfCountersEnabled()) { + clReleaseCommandQueue(commandQueue); + TRACING_EXIT(clCreateCommandQueueWithProperties, &commandQueue); + + err.set(CL_OUT_OF_RESOURCES); + return nullptr; + } + } + if (pContext->isProvidingPerformanceHints()) { pContext->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_NEUTRAL_INTEL, DRIVER_CALLS_INTERNAL_CL_FLUSH); if (castToObjectOrAbort(commandQueue)->isProfilingEnabled()) { @@ -5297,8 +5327,9 @@ cl_command_queue CL_API_CALL clCreateCommandQueueWithProperties(cl_context conte } } - if (!commandQueue) + if (!commandQueue) { retVal = CL_OUT_OF_HOST_MEMORY; + } DBG_LOG_INPUTS("commandQueue", commandQueue, "properties", static_cast(getCmdQueueProperties(properties))); diff --git a/opencl/test/unit_test/api/cl_create_perf_counters_command_queue_tests.inl b/opencl/test/unit_test/api/cl_create_perf_counters_command_queue_tests.inl index 3949eaaf4f..cf297924b7 100644 --- a/opencl/test/unit_test/api/cl_create_perf_counters_command_queue_tests.inl +++ b/opencl/test/unit_test/api/cl_create_perf_counters_command_queue_tests.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -179,4 +179,57 @@ TEST_F(clCreatePerfCountersCommandQueueINTELTests, givenInvalidMetricsLibraryWhe EXPECT_EQ(CL_OUT_OF_RESOURCES, retVal); } +struct clCreateCommandQueueWithPropertiesMdapiTests : public clCreatePerfCountersCommandQueueINTELTests { + cl_queue_properties queueProperties[7] = {CL_QUEUE_PROPERTIES, CL_QUEUE_PROFILING_ENABLE, + CL_QUEUE_MDAPI_PROPERTIES_INTEL, CL_QUEUE_MDAPI_ENABLE_INTEL, + CL_QUEUE_MDAPI_CONFIGURATION_INTEL, 0, + 0}; +}; + +TEST_F(clCreateCommandQueueWithPropertiesMdapiTests, givenCorrectParamsWhenCreatingQueueWithPropertiesThenEnablePerfCounters) { + auto cmdQ = clCreateCommandQueueWithProperties(context.get(), deviceId, queueProperties, &retVal); + + ASSERT_NE(nullptr, cmdQ); + EXPECT_EQ(CL_SUCCESS, retVal); + + auto commandQueueObject = castToObject(cmdQ); + EXPECT_TRUE(commandQueueObject->isPerfCountersEnabled()); + + clReleaseCommandQueue(cmdQ); +} + +TEST_F(clCreateCommandQueueWithPropertiesMdapiTests, givenParamsWithDisabledPerfCounterWhenCreatingQueueWithPropertiesThenCreateRegularQueue) { + queueProperties[3] = 0; + auto cmdQ = clCreateCommandQueueWithProperties(context.get(), deviceId, queueProperties, &retVal); + + ASSERT_NE(nullptr, cmdQ); + EXPECT_EQ(CL_SUCCESS, retVal); + + auto commandQueueObject = castToObject(cmdQ); + EXPECT_FALSE(commandQueueObject->isPerfCountersEnabled()); + + clReleaseCommandQueue(cmdQ); +} + +TEST_F(clCreateCommandQueueWithPropertiesMdapiTests, givenIncorrectConfigurationWhenCreatingQueueWithPropertiesThenFail) { + queueProperties[5] = 1; + + auto cmdQ = clCreateCommandQueueWithProperties(context.get(), deviceId, queueProperties, &retVal); + + EXPECT_EQ(nullptr, cmdQ); + EXPECT_NE(CL_SUCCESS, retVal); +} + +TEST_F(clCreateCommandQueueWithPropertiesMdapiTests, givenInvalidMdapiOpenWhenCreatingQueueWithPropertiesThenFail) { + auto performanceCounters = device->getPerformanceCounters(); + + auto metricsLibary = static_cast(performanceCounters->getMetricsLibraryInterface()); + metricsLibary->validOpen = false; + + auto cmdQ = clCreateCommandQueueWithProperties(context.get(), deviceId, queueProperties, &retVal); + + EXPECT_EQ(nullptr, cmdQ); + EXPECT_NE(CL_SUCCESS, retVal); +} + } // namespace ULT