From 35bc4329bcdaed907260356c6c82d1974051dd36 Mon Sep 17 00:00:00 2001 From: Ewan Crawford Date: Fri, 4 Oct 2024 09:06:34 +0100 Subject: [PATCH] CMD-Buf supported queue properties Updates to the command-buffer emulation layer to support changes from https://github.com/KhronosGroup/OpenCL-Docs/pull/850 Requires using https://github.com/KhronosGroup/OpenCL-Headers/pull/265 in `external/OpenCL-Headers` and can be used to test CTS changes from https://github.com/KhronosGroup/OpenCL-CTS/pull/2101 --- include/CL/opencl.hpp | 1 + layers/10_cmdbufemu/emulate.cpp | 31 ++++++++++++++++++++--- samples/12_commandbuffers/main.cpp | 18 +++++++++---- samples/12_commandbufferspp/main.cpp | 12 +++++---- samples/13_mutablecommandbuffers/main.cpp | 18 +++++++++---- samples/14_ooqcommandbuffers/main.cpp | 6 ++--- 6 files changed, 64 insertions(+), 22 deletions(-) diff --git a/include/CL/opencl.hpp b/include/CL/opencl.hpp index 88351de..87d74d3 100644 --- a/include/CL/opencl.hpp +++ b/include/CL/opencl.hpp @@ -1776,6 +1776,7 @@ CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_ #if defined(cl_khr_command_buffer) CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMMAND_BUFFER_CAPABILITIES_KHR, cl_device_command_buffer_capabilities_khr) CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMMAND_BUFFER_REQUIRED_QUEUE_PROPERTIES_KHR, cl_command_queue_properties) +CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMMAND_BUFFER_SUPPORTED_QUEUE_PROPERTIES_KHR, cl_command_queue_properties) CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_QUEUES_KHR, cl::vector) CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_NUM_QUEUES_KHR, cl_uint) CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_REFERENCE_COUNT_KHR, cl_uint) diff --git a/layers/10_cmdbufemu/emulate.cpp b/layers/10_cmdbufemu/emulate.cpp index 532ecae..929769c 100644 --- a/layers/10_cmdbufemu/emulate.cpp +++ b/layers/10_cmdbufemu/emulate.cpp @@ -2732,6 +2732,22 @@ bool clGetDeviceInfo_override( caps |= CL_COMMAND_BUFFER_CAPABILITY_DEVICE_SIDE_ENQUEUE_KHR; } + auto ptr = (cl_device_command_buffer_capabilities_khr*)param_value; + cl_int errorCode = writeParamToMemory( + param_value_size, + caps, + param_value_size_ret, + ptr ); + + if( errcode_ret ) + { + errcode_ret[0] = errorCode; + } + return true; + } + break; + case CL_DEVICE_COMMAND_BUFFER_SUPPORTED_QUEUE_PROPERTIES_KHR: + { cl_command_queue_properties cqProps = 0; g_pNextDispatch->clGetDeviceInfo( device, @@ -2739,15 +2755,22 @@ bool clGetDeviceInfo_override( sizeof(cqProps), &cqProps, nullptr ); - if( cqProps & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE ) + + cl_command_queue_properties cbProps = 0; + if(cqProps & CL_QUEUE_PROFILING_ENABLE) { - caps |= CL_COMMAND_BUFFER_CAPABILITY_OUT_OF_ORDER_KHR; + cbProps |= CL_QUEUE_PROFILING_ENABLE; } - auto ptr = (cl_device_command_buffer_capabilities_khr*)param_value; + if(cqProps & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) + { + cbProps |= CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE; + } + + auto ptr = (cl_command_queue_properties*)param_value; cl_int errorCode = writeParamToMemory( param_value_size, - caps, + cbProps, param_value_size_ret, ptr ); diff --git a/samples/12_commandbuffers/main.cpp b/samples/12_commandbuffers/main.cpp index bcffeb3..d5a241b 100644 --- a/samples/12_commandbuffers/main.cpp +++ b/samples/12_commandbuffers/main.cpp @@ -33,19 +33,17 @@ static void PrintCommandBufferCapabilities( if (caps & CL_COMMAND_BUFFER_CAPABILITY_KERNEL_PRINTF_KHR ) printf("\t\tCL_COMMAND_BUFFER_CAPABILITY_KERNEL_PRINTF_KHR\n"); if (caps & CL_COMMAND_BUFFER_CAPABILITY_DEVICE_SIDE_ENQUEUE_KHR ) printf("\t\tCL_COMMAND_BUFFER_CAPABILITY_DEVICE_SIDE_ENQUEUE_KHR\n"); if (caps & CL_COMMAND_BUFFER_CAPABILITY_SIMULTANEOUS_USE_KHR ) printf("\t\tCL_COMMAND_BUFFER_CAPABILITY_SIMULTANEOUS_USE_KHR\n"); - if (caps & CL_COMMAND_BUFFER_CAPABILITY_OUT_OF_ORDER_KHR ) printf("\t\tCL_COMMAND_BUFFER_CAPABILITY_OUT_OF_ORDER_KHR\n"); cl_device_command_buffer_capabilities_khr extra = caps & ~( CL_COMMAND_BUFFER_CAPABILITY_KERNEL_PRINTF_KHR | CL_COMMAND_BUFFER_CAPABILITY_DEVICE_SIDE_ENQUEUE_KHR | - CL_COMMAND_BUFFER_CAPABILITY_SIMULTANEOUS_USE_KHR | - CL_COMMAND_BUFFER_CAPABILITY_OUT_OF_ORDER_KHR ); + CL_COMMAND_BUFFER_CAPABILITY_SIMULTANEOUS_USE_KHR ); if (extra) { printf("\t\t(Unknown capability: %016" PRIx64 ")\n", extra); } } -static void PrintCommandBufferRequiredQueueProperties( +static void PrintCommandBufferQueueProperties( cl_command_queue_properties props ) { if (props & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE ) printf("\t\tCL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE\n"); @@ -137,7 +135,17 @@ int main( &requiredProps, NULL ); printf("\tCommand Buffer Required Queue Properties:\n"); - PrintCommandBufferRequiredQueueProperties(requiredProps); + PrintCommandBufferQueueProperties(requiredProps); + + cl_command_queue_properties supportedProps = 0; + clGetDeviceInfo( + devices[deviceIndex](), + CL_DEVICE_COMMAND_BUFFER_SUPPORTED_QUEUE_PROPERTIES_KHR, + sizeof(supportedProps), + &supportedProps, + NULL ); + printf("\tCommand Buffer Supported Queue Properties:\n"); + PrintCommandBufferQueueProperties(supportedProps); cl::Context context{devices[deviceIndex]}; cl::CommandQueue commandQueue{context, devices[deviceIndex]}; diff --git a/samples/12_commandbufferspp/main.cpp b/samples/12_commandbufferspp/main.cpp index 254a461..df7252d 100644 --- a/samples/12_commandbufferspp/main.cpp +++ b/samples/12_commandbufferspp/main.cpp @@ -28,19 +28,17 @@ static void PrintCommandBufferCapabilities( if (caps & CL_COMMAND_BUFFER_CAPABILITY_KERNEL_PRINTF_KHR ) printf("\t\tCL_COMMAND_BUFFER_CAPABILITY_KERNEL_PRINTF_KHR\n"); if (caps & CL_COMMAND_BUFFER_CAPABILITY_DEVICE_SIDE_ENQUEUE_KHR ) printf("\t\tCL_COMMAND_BUFFER_CAPABILITY_DEVICE_SIDE_ENQUEUE_KHR\n"); if (caps & CL_COMMAND_BUFFER_CAPABILITY_SIMULTANEOUS_USE_KHR ) printf("\t\tCL_COMMAND_BUFFER_CAPABILITY_SIMULTANEOUS_USE_KHR\n"); - if (caps & CL_COMMAND_BUFFER_CAPABILITY_OUT_OF_ORDER_KHR ) printf("\t\tCL_COMMAND_BUFFER_CAPABILITY_OUT_OF_ORDER_KHR\n"); cl_device_command_buffer_capabilities_khr extra = caps & ~( CL_COMMAND_BUFFER_CAPABILITY_KERNEL_PRINTF_KHR | CL_COMMAND_BUFFER_CAPABILITY_DEVICE_SIDE_ENQUEUE_KHR | - CL_COMMAND_BUFFER_CAPABILITY_SIMULTANEOUS_USE_KHR | - CL_COMMAND_BUFFER_CAPABILITY_OUT_OF_ORDER_KHR ); + CL_COMMAND_BUFFER_CAPABILITY_SIMULTANEOUS_USE_KHR ); if (extra) { printf("\t\t(Unknown capability: %016" PRIx64 ")\n", extra); } } -static void PrintCommandBufferRequiredQueueProperties( +static void PrintCommandBufferQueueProperties( cl_command_queue_properties props ) { if (props & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE ) printf("\t\tCL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE\n"); @@ -119,9 +117,13 @@ int main( devices[deviceIndex].getInfo()); printf("\tCommand Buffer Required Queue Properties:\n"); - PrintCommandBufferRequiredQueueProperties( + PrintCommandBufferQueueProperties( devices[deviceIndex].getInfo()); + printf("\tCommand Buffer Supported Queue Properties:\n"); + PrintCommandBufferQueueProperties( + devices[deviceIndex].getInfo()); + cl::Context context{devices[deviceIndex]}; cl::CommandQueue commandQueue{context, devices[deviceIndex]}; diff --git a/samples/13_mutablecommandbuffers/main.cpp b/samples/13_mutablecommandbuffers/main.cpp index 0429f64..26aeccf 100644 --- a/samples/13_mutablecommandbuffers/main.cpp +++ b/samples/13_mutablecommandbuffers/main.cpp @@ -30,19 +30,17 @@ static void PrintCommandBufferCapabilities( if (caps & CL_COMMAND_BUFFER_CAPABILITY_KERNEL_PRINTF_KHR ) printf("\t\tCL_COMMAND_BUFFER_CAPABILITY_KERNEL_PRINTF_KHR\n"); if (caps & CL_COMMAND_BUFFER_CAPABILITY_DEVICE_SIDE_ENQUEUE_KHR ) printf("\t\tCL_COMMAND_BUFFER_CAPABILITY_DEVICE_SIDE_ENQUEUE_KHR\n"); if (caps & CL_COMMAND_BUFFER_CAPABILITY_SIMULTANEOUS_USE_KHR ) printf("\t\tCL_COMMAND_BUFFER_CAPABILITY_SIMULTANEOUS_USE_KHR\n"); - if (caps & CL_COMMAND_BUFFER_CAPABILITY_OUT_OF_ORDER_KHR ) printf("\t\tCL_COMMAND_BUFFER_CAPABILITY_OUT_OF_ORDER_KHR\n"); cl_device_command_buffer_capabilities_khr extra = caps & ~( CL_COMMAND_BUFFER_CAPABILITY_KERNEL_PRINTF_KHR | CL_COMMAND_BUFFER_CAPABILITY_DEVICE_SIDE_ENQUEUE_KHR | - CL_COMMAND_BUFFER_CAPABILITY_SIMULTANEOUS_USE_KHR | - CL_COMMAND_BUFFER_CAPABILITY_OUT_OF_ORDER_KHR ); + CL_COMMAND_BUFFER_CAPABILITY_SIMULTANEOUS_USE_KHR ); if (extra) { printf("\t\t(Unknown capability: %016" PRIx64 ")\n", extra); } } -static void PrintCommandBufferRequiredQueueProperties( +static void PrintCommandBufferQueueProperties( cl_command_queue_properties props ) { if (props & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE ) printf("\t\tCL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE\n"); @@ -162,7 +160,17 @@ int main( &requiredProps, NULL ); printf("\tCommand Buffer Required Queue Properties:\n"); - PrintCommandBufferRequiredQueueProperties(requiredProps); + PrintCommandBufferQueueProperties(requiredProps); + + cl_command_queue_properties supportedProps = 0; + clGetDeviceInfo( + devices[deviceIndex](), + CL_DEVICE_COMMAND_BUFFER_SUPPORTED_QUEUE_PROPERTIES_KHR, + sizeof(supportedProps), + &supportedProps, + NULL ); + printf("\tCommand Buffer Supported Queue Properties:\n"); + PrintCommandBufferQueueProperties(supportedProps); cl_mutable_dispatch_fields_khr mutableCaps = 0; clGetDeviceInfo( diff --git a/samples/14_ooqcommandbuffers/main.cpp b/samples/14_ooqcommandbuffers/main.cpp index c608431..d70e7ec 100644 --- a/samples/14_ooqcommandbuffers/main.cpp +++ b/samples/14_ooqcommandbuffers/main.cpp @@ -95,9 +95,9 @@ int main( return -1; } - cl_device_command_buffer_capabilities_khr cmdbufcaps = - devices[deviceIndex].getInfo(); - if (cmdbufcaps & CL_COMMAND_BUFFER_CAPABILITY_OUT_OF_ORDER_KHR) { + cl_command_queue_properties cmdbufqueueprops = + devices[deviceIndex].getInfo(); + if (cmdbufqueueprops & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) { printf("Device supports out-of-order command buffers.\n"); } else { printf("Device does not support out-of-order command buffers, exiting.\n");