Skip to content

Commit

Permalink
update to latest command buffer APIs (KhronosGroup#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbaug authored Sep 6, 2024
1 parent 1bee20e commit 979eb30
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 68 deletions.
2 changes: 1 addition & 1 deletion include/CL/opencl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@ CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_PROPE
CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_COMMAND_QUEUE_KHR, CommandQueue)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_COMMAND_BUFFER_KHR, CommandBufferKhr)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_COMMAND_TYPE_KHR, cl_command_type)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_PROPERTIES_ARRAY_KHR, cl::vector<cl_ndrange_kernel_command_properties_khr>)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_PROPERTIES_ARRAY_KHR, cl::vector<cl_command_properties_khr>)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_KERNEL_KHR, cl_kernel)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_DIMENSIONS_KHR, cl_uint)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_GLOBAL_WORK_OFFSET_KHR, cl::vector<size_type>)
Expand Down
130 changes: 85 additions & 45 deletions layers/10_cmdbufemu/emulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include "emulate.h"

static constexpr cl_version version_cl_khr_command_buffer =
CL_MAKE_VERSION(0, 9, 4);
CL_MAKE_VERSION(0, 9, 5);
static constexpr cl_version version_cl_khr_command_buffer_mutable_dispatch =
CL_MAKE_VERSION(0, 9, 1);
CL_MAKE_VERSION(0, 9, 3);

SLayerContext& getLayerContext(void)
{
Expand Down Expand Up @@ -106,11 +106,9 @@ typedef struct _cl_mutable_command_khr
ptr );
}
break;
// These are only valid for clCommandNDRangeKernel, but the spec says
// they should return size = 0 rather than an error.
case CL_MUTABLE_DISPATCH_PROPERTIES_ARRAY_KHR:
case CL_MUTABLE_COMMAND_PROPERTIES_ARRAY_KHR:
{
auto ptr = (cl_ndrange_kernel_command_properties_khr*)param_value;
auto ptr = (cl_command_properties_khr*)param_value;
return writeVectorToMemory(
param_value_size,
{}, // No properties are currently supported.
Expand Down Expand Up @@ -811,7 +809,7 @@ struct SVMMemFill : Command
struct NDRangeKernel : Command
{
static std::unique_ptr<NDRangeKernel> create(
const cl_ndrange_kernel_command_properties_khr* properties,
const cl_command_properties_khr* properties,
cl_command_buffer_khr cmdbuf,
cl_command_queue queue,
cl_kernel kernel,
Expand All @@ -836,9 +834,10 @@ struct NDRangeKernel : Command
{
switch( param_name )
{
case CL_MUTABLE_DISPATCH_PROPERTIES_ARRAY_KHR:
// TODO: eventually this should move to the base Command class.
case CL_MUTABLE_COMMAND_PROPERTIES_ARRAY_KHR:
{
auto ptr = (cl_ndrange_kernel_command_properties_khr*)param_value;
auto ptr = (cl_command_properties_khr*)param_value;
return writeVectorToMemory(
param_value_size,
properties,
Expand Down Expand Up @@ -1101,7 +1100,7 @@ struct NDRangeKernel : Command
cl_mutable_dispatch_asserts_khr mutableAsserts = 0;
size_t numWorkGroups = 0;
#endif // defined(cl_khr_command_buffer_mutable_dispatch)
std::vector<cl_command_buffer_properties_khr> properties;
std::vector<cl_command_properties_khr> properties;
std::vector<size_t> global_work_offset;
std::vector<size_t> global_work_size;
std::vector<size_t> local_work_size;
Expand Down Expand Up @@ -1510,7 +1509,10 @@ typedef struct _cl_command_buffer_khr
}

#if defined(cl_khr_command_buffer_mutable_dispatch)
cl_int mutate( const cl_mutable_base_config_khr* mutable_config )
cl_int mutate(
cl_uint numUpdates,
const cl_command_buffer_update_type_khr* updateTypes,
const void** updateConfigs )
{
if( State != CL_COMMAND_BUFFER_STATE_EXECUTABLE_KHR )
{
Expand All @@ -1521,48 +1523,32 @@ typedef struct _cl_command_buffer_khr
return CL_INVALID_OPERATION;
}

if( mutable_config == nullptr )
{
return CL_INVALID_VALUE;
}
if( mutable_config->type != CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR )
{
return CL_INVALID_VALUE;
}
if( mutable_config->next == nullptr && mutable_config->mutable_dispatch_list == nullptr )
{
return CL_INVALID_VALUE;
}
if( ( mutable_config->num_mutable_dispatch > 0 && mutable_config->mutable_dispatch_list == nullptr ) ||
( mutable_config->num_mutable_dispatch == 0 && mutable_config->mutable_dispatch_list != nullptr ) )
if( ( numUpdates > 0 && updateTypes == nullptr ) ||
( numUpdates == 0 && updateTypes != nullptr ) )
{
return CL_INVALID_VALUE;
}
// No "next" extensions are currently supported.
if( mutable_config->next != nullptr )
if( ( numUpdates > 0 && updateConfigs == nullptr ) ||
( numUpdates == 0 && updateConfigs != nullptr ) )
{
return CL_INVALID_VALUE;
}

for( cl_uint i = 0; i < mutable_config->num_mutable_dispatch; i++ )
for( cl_uint i = 0; i < numUpdates; i++ )
{
const cl_mutable_dispatch_config_khr* dispatchConfig =
&mutable_config->mutable_dispatch_list[i];
if( !Command::isValid(dispatchConfig->command) ||
dispatchConfig->command->getCmdBuf() != this )
{
return CL_INVALID_MUTABLE_COMMAND_KHR;
}
if( dispatchConfig->type == CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR )
if( updateTypes[i] == CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR &&
updateConfigs[i] != nullptr )
{
if( dispatchConfig->command->getType() != CL_COMMAND_NDRANGE_KERNEL )
auto config = (const cl_mutable_dispatch_config_khr*)updateConfigs[i];
if( !Command::isValid(config->command) ||
config->command->getCmdBuf() != this ||
config->command->getType() != CL_COMMAND_NDRANGE_KERNEL )
{
return CL_INVALID_MUTABLE_COMMAND_KHR;
}

if( cl_int errorCode = ((NDRangeKernel*)dispatchConfig->command)->mutate(
if( cl_int errorCode = ((NDRangeKernel*)config->command)->mutate(
MutableDispatchAsserts,
dispatchConfig ) )
config ) )
{
return errorCode;
}
Expand Down Expand Up @@ -1624,7 +1610,7 @@ _cl_mutable_command_khr::_cl_mutable_command_khr(
Queue(queue ? queue : cmdbuf->getQueue()) {}

std::unique_ptr<NDRangeKernel> NDRangeKernel::create(
const cl_ndrange_kernel_command_properties_khr* properties,
const cl_command_properties_khr* properties,
cl_command_buffer_khr cmdbuf,
cl_command_queue queue,
cl_kernel kernel,
Expand All @@ -1644,7 +1630,7 @@ std::unique_ptr<NDRangeKernel> NDRangeKernel::create(

if( properties )
{
const cl_ndrange_kernel_command_properties_khr* check = properties;
const cl_command_properties_khr* check = properties;
bool found_CL_MUTABLE_DISPATCH_UPDATABLE_FIELDS_KHR = false;
bool found_CL_MUTABLE_DISPATCH_ASSERTS_KHR = false;
while( errorCode == CL_SUCCESS && check[0] != 0 )
Expand Down Expand Up @@ -1890,6 +1876,7 @@ cl_int CL_API_CALL clEnqueueCommandBufferKHR_EMU(
cl_int CL_API_CALL clCommandBarrierWithWaitListKHR_EMU(
cl_command_buffer_khr cmdbuf,
cl_command_queue command_queue,
const cl_command_properties_khr* properties,
cl_uint num_sync_points_in_wait_list,
const cl_sync_point_khr* sync_point_wait_list,
cl_sync_point_khr* sync_point,
Expand All @@ -1906,6 +1893,10 @@ cl_int CL_API_CALL clCommandBarrierWithWaitListKHR_EMU(
{
return errorCode;
}
if( properties != nullptr && properties[0] != 0 )
{
return CL_INVALID_PROPERTY;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
Expand All @@ -1926,6 +1917,7 @@ cl_int CL_API_CALL clCommandBarrierWithWaitListKHR_EMU(
cl_int CL_API_CALL clCommandCopyBufferKHR_EMU(
cl_command_buffer_khr cmdbuf,
cl_command_queue command_queue,
const cl_command_properties_khr* properties,
cl_mem src_buffer,
cl_mem dst_buffer,
size_t src_offset,
Expand All @@ -1947,6 +1939,10 @@ cl_int CL_API_CALL clCommandCopyBufferKHR_EMU(
{
return errorCode;
}
if( properties != nullptr && properties[0] != 0 )
{
return CL_INVALID_PROPERTY;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
Expand Down Expand Up @@ -1974,6 +1970,7 @@ cl_int CL_API_CALL clCommandCopyBufferKHR_EMU(
cl_int CL_API_CALL clCommandCopyBufferRectKHR_EMU(
cl_command_buffer_khr cmdbuf,
cl_command_queue command_queue,
const cl_command_properties_khr* properties,
cl_mem src_buffer,
cl_mem dst_buffer,
const size_t* src_origin,
Expand All @@ -1999,6 +1996,10 @@ cl_int CL_API_CALL clCommandCopyBufferRectKHR_EMU(
{
return errorCode;
}
if( properties != nullptr && properties[0] != 0 )
{
return CL_INVALID_PROPERTY;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
Expand Down Expand Up @@ -2030,6 +2031,7 @@ cl_int CL_API_CALL clCommandCopyBufferRectKHR_EMU(
cl_int CL_API_CALL clCommandCopyBufferToImageKHR_EMU(
cl_command_buffer_khr cmdbuf,
cl_command_queue command_queue,
const cl_command_properties_khr* properties,
cl_mem src_buffer,
cl_mem dst_image,
size_t src_offset,
Expand All @@ -2051,6 +2053,10 @@ cl_int CL_API_CALL clCommandCopyBufferToImageKHR_EMU(
{
return errorCode;
}
if( properties != nullptr && properties[0] != 0 )
{
return CL_INVALID_PROPERTY;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
Expand Down Expand Up @@ -2078,6 +2084,7 @@ cl_int CL_API_CALL clCommandCopyBufferToImageKHR_EMU(
cl_int CL_API_CALL clCommandCopyImageKHR_EMU(
cl_command_buffer_khr cmdbuf,
cl_command_queue command_queue,
const cl_command_properties_khr* properties,
cl_mem src_image,
cl_mem dst_image,
const size_t* src_origin,
Expand All @@ -2099,6 +2106,10 @@ cl_int CL_API_CALL clCommandCopyImageKHR_EMU(
{
return errorCode;
}
if( properties != nullptr && properties[0] != 0 )
{
return CL_INVALID_PROPERTY;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
Expand Down Expand Up @@ -2126,6 +2137,7 @@ cl_int CL_API_CALL clCommandCopyImageKHR_EMU(
cl_int CL_API_CALL clCommandCopyImageToBufferKHR_EMU(
cl_command_buffer_khr cmdbuf,
cl_command_queue command_queue,
const cl_command_properties_khr* properties,
cl_mem src_image,
cl_mem dst_buffer,
const size_t* src_origin,
Expand All @@ -2147,6 +2159,10 @@ cl_int CL_API_CALL clCommandCopyImageToBufferKHR_EMU(
{
return errorCode;
}
if( properties != nullptr && properties[0] != 0 )
{
return CL_INVALID_PROPERTY;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
Expand Down Expand Up @@ -2174,6 +2190,7 @@ cl_int CL_API_CALL clCommandCopyImageToBufferKHR_EMU(
cl_int CL_API_CALL clCommandFillBufferKHR_EMU(
cl_command_buffer_khr cmdbuf,
cl_command_queue command_queue,
const cl_command_properties_khr* properties,
cl_mem buffer,
const void* pattern,
size_t pattern_size,
Expand All @@ -2195,6 +2212,10 @@ cl_int CL_API_CALL clCommandFillBufferKHR_EMU(
{
return errorCode;
}
if( properties != nullptr && properties[0] != 0 )
{
return CL_INVALID_PROPERTY;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
Expand Down Expand Up @@ -2222,6 +2243,7 @@ cl_int CL_API_CALL clCommandFillBufferKHR_EMU(
cl_int CL_API_CALL clCommandFillImageKHR_EMU(
cl_command_buffer_khr cmdbuf,
cl_command_queue command_queue,
const cl_command_properties_khr* properties,
cl_mem image,
const void* fill_color,
const size_t* origin,
Expand All @@ -2242,6 +2264,10 @@ cl_int CL_API_CALL clCommandFillImageKHR_EMU(
{
return errorCode;
}
if( properties != nullptr && properties[0] != 0 )
{
return CL_INVALID_PROPERTY;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
Expand All @@ -2268,6 +2294,7 @@ cl_int CL_API_CALL clCommandFillImageKHR_EMU(
cl_int CL_API_CALL clCommandSVMMemcpyKHR_EMU(
cl_command_buffer_khr cmdbuf,
cl_command_queue command_queue,
const cl_command_properties_khr* properties,
void* dst_ptr,
const void* src_ptr,
size_t size,
Expand All @@ -2287,6 +2314,10 @@ cl_int CL_API_CALL clCommandSVMMemcpyKHR_EMU(
{
return errorCode;
}
if( properties != nullptr && properties[0] != 0 )
{
return CL_INVALID_PROPERTY;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
Expand All @@ -2312,6 +2343,7 @@ cl_int CL_API_CALL clCommandSVMMemcpyKHR_EMU(
cl_int CL_API_CALL clCommandSVMMemFillKHR_EMU(
cl_command_buffer_khr cmdbuf,
cl_command_queue command_queue,
const cl_command_properties_khr* properties,
void* dst_ptr,
const void* pattern,
size_t pattern_size,
Expand All @@ -2332,6 +2364,10 @@ cl_int CL_API_CALL clCommandSVMMemFillKHR_EMU(
{
return errorCode;
}
if( properties != nullptr && properties[0] != 0 )
{
return CL_INVALID_PROPERTY;
}
if( mutable_handle != nullptr )
{
return CL_INVALID_VALUE;
Expand All @@ -2358,7 +2394,7 @@ cl_int CL_API_CALL clCommandSVMMemFillKHR_EMU(
cl_int CL_API_CALL clCommandNDRangeKernelKHR_EMU(
cl_command_buffer_khr cmdbuf,
cl_command_queue command_queue,
const cl_ndrange_kernel_command_properties_khr* properties,
const cl_command_properties_khr* properties,
cl_kernel kernel,
cl_uint work_dim,
const size_t* global_work_offset,
Expand Down Expand Up @@ -2464,14 +2500,18 @@ cl_command_buffer_khr CL_API_CALL clRemapCommandBufferKHR_EMU(
// cl_khr_command_buffer_mutable_dispatch
cl_int CL_API_CALL clUpdateMutableCommandsKHR_EMU(
cl_command_buffer_khr cmdbuf,
const cl_mutable_base_config_khr* mutable_config)
cl_uint num_configs,
const cl_command_buffer_update_type_khr* config_types,
const void** configs )
{
if( !CommandBuffer::isValid(cmdbuf) )
{
return CL_INVALID_COMMAND_BUFFER_KHR;
}
if( cl_int errorCode = cmdbuf->mutate(
mutable_config ) )
num_configs,
config_types,
configs ) )
{
return errorCode;
}
Expand Down
Loading

0 comments on commit 979eb30

Please sign in to comment.