Skip to content

Commit

Permalink
CMD-Buf supported queue properties
Browse files Browse the repository at this point in the history
Updates to the command-buffer emulation layer to support
changes from KhronosGroup/OpenCL-Docs#850

Requires using KhronosGroup#265
in `external/OpenCL-Headers` and can be used to test CTS changes from
KhronosGroup/OpenCL-CTS#2101
  • Loading branch information
EwanC committed Oct 4, 2024
1 parent 979eb30 commit d0b62a4
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 22 deletions.
1 change: 1 addition & 0 deletions include/CL/opencl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandQueue>)
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)
Expand Down
34 changes: 30 additions & 4 deletions layers/10_cmdbufemu/emulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2732,22 +2732,47 @@ 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 cbProps = CL_QUEUE_PROFILING_ENABLE;

cl_command_queue_properties cqProps = 0;
g_pNextDispatch->clGetDeviceInfo(
device,
CL_DEVICE_QUEUE_PROPERTIES,
sizeof(cqProps),
&cqProps,
nullptr );
if( cqProps & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE )

// Profiling is the minimum required property
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 );

Expand All @@ -2756,6 +2781,7 @@ bool clGetDeviceInfo_override(
errcode_ret[0] = errorCode;
}
return true;

}
break;
case CL_DEVICE_COMMAND_BUFFER_REQUIRED_QUEUE_PROPERTIES_KHR:
Expand Down
18 changes: 13 additions & 5 deletions samples/12_commandbuffers/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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]};
Expand Down
12 changes: 7 additions & 5 deletions samples/12_commandbufferspp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -119,9 +117,13 @@ int main(
devices[deviceIndex].getInfo<CL_DEVICE_COMMAND_BUFFER_CAPABILITIES_KHR>());

printf("\tCommand Buffer Required Queue Properties:\n");
PrintCommandBufferRequiredQueueProperties(
PrintCommandBufferQueueProperties(
devices[deviceIndex].getInfo<CL_DEVICE_COMMAND_BUFFER_REQUIRED_QUEUE_PROPERTIES_KHR>());

printf("\tCommand Buffer Supported Queue Properties:\n");
PrintCommandBufferQueueProperties(
devices[deviceIndex].getInfo<CL_DEVICE_COMMAND_BUFFER_SUPPORTED_QUEUE_PROPERTIES_KHR>());

cl::Context context{devices[deviceIndex]};
cl::CommandQueue commandQueue{context, devices[deviceIndex]};

Expand Down
18 changes: 13 additions & 5 deletions samples/13_mutablecommandbuffers/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions samples/14_ooqcommandbuffers/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ int main(
return -1;
}

cl_device_command_buffer_capabilities_khr cmdbufcaps =
devices[deviceIndex].getInfo<CL_DEVICE_COMMAND_BUFFER_CAPABILITIES_KHR>();
if (cmdbufcaps & CL_COMMAND_BUFFER_CAPABILITY_OUT_OF_ORDER_KHR) {
cl_command_queue_properties cmdbufqueueprops =
devices[deviceIndex].getInfo<CL_DEVICE_COMMAND_BUFFER_SUPPORTED_QUEUE_PROPERTIES_KHR>();
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");
Expand Down

0 comments on commit d0b62a4

Please sign in to comment.