Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Update command-buffer API to 0.9.5 #519

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ set(CMAKE_CXX_EXTENSIONS ON)
# them available here rather here rather than in source/cl/external.
FetchContent_Declare(
OpenCLHeaders
GIT_REPOSITORY https://github.com/KhronosGroup/OpenCL-Headers.git
GIT_TAG v2024.05.08
GIT_REPOSITORY git@github.com:EwanC/OpenCL-Headers.git
GIT_TAG ewan/command_properties
)
FetchContent_MakeAvailable(OpenCLHeaders)

Expand Down
18 changes: 9 additions & 9 deletions source/cl/examples/CommandBufferKHR/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,20 @@ int main(const int argc, const char **argv) {
CL_CHECK(error);

for (size_t tile_index = 0; tile_index < tile_count; tile_index++) {
CL_CHECK(clCommandCopyBufferKHR(command_buffer, nullptr, buffer_src1,
buffer_tile1, tile_index * tile_size, 0,
tile_size, 0, nullptr, nullptr, nullptr));
CL_CHECK(clCommandCopyBufferKHR(command_buffer, nullptr, buffer_src2,
buffer_tile2, tile_index * tile_size, 0,
tile_size, 0, nullptr, nullptr, nullptr));
CL_CHECK(clCommandCopyBufferKHR(
command_buffer, nullptr, nullptr, buffer_src1, buffer_tile1,
tile_index * tile_size, 0, tile_size, 0, nullptr, nullptr, nullptr));
CL_CHECK(clCommandCopyBufferKHR(
command_buffer, nullptr, nullptr, buffer_src2, buffer_tile2,
tile_index * tile_size, 0, tile_size, 0, nullptr, nullptr, nullptr));

CL_CHECK(clCommandNDRangeKernelKHR(command_buffer, nullptr, nullptr, kernel,
1, nullptr, &tile_elements, nullptr, 0,
nullptr, nullptr, nullptr));

CL_CHECK(clCommandCopyBufferKHR(command_buffer, nullptr, buffer_res,
buffer_dst, 0, tile_index * tile_size,
tile_size, 0, nullptr, nullptr, nullptr));
CL_CHECK(clCommandCopyBufferKHR(
command_buffer, nullptr, nullptr, buffer_res, buffer_dst, 0,
tile_index * tile_size, tile_size, 0, nullptr, nullptr, nullptr));
}

CL_CHECK(clFinalizeCommandBufferKHR(command_buffer));
Expand Down
2 changes: 1 addition & 1 deletion source/cl/examples/MutableDispatchKHR/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ int main(const int argc, const char **argv) {
CL_CHECK(clSetKernelArg(kernel, 2, sizeof(cl_mem), &output_buffers[0]));

// Instruct the nd-range command to allow for mutable kernel arguments
cl_ndrange_kernel_command_properties_khr mutable_properties[] = {
cl_command_properties_khr mutable_properties[] = {
CL_MUTABLE_DISPATCH_UPDATABLE_FIELDS_KHR,
CL_MUTABLE_DISPATCH_ARGUMENTS_KHR, 0};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ struct _cl_mutable_command_khr final {
/// @brief Command-buffer used to create mutable command
cl_command_buffer_khr command_buffer;
/// @brief List of properties passed on creation
cargo::small_vector<cl_ndrange_kernel_command_properties_khr, 3>
properties_list;
cargo::small_vector<cl_command_properties_khr, 3> properties_list;
/// @brief Fields of mutable kernel command that can be modified
cl_mutable_dispatch_fields_khr updatable_fields = 0;
/// @brief Work dimensions used on mutable-dispatch creation
Expand Down
86 changes: 62 additions & 24 deletions source/cl/source/extension/source/khr_command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension::khr_command_buffer::khr_command_buffer()
#else
usage_category::DISABLED
#endif
CA_CL_EXT_VERSION(0, 1, 0)) {
CA_CL_EXT_VERSION(0, 9, 5)) {
}

void *extension::khr_command_buffer::GetExtensionFunctionAddressForPlatform(
Expand Down Expand Up @@ -1285,6 +1285,7 @@ CL_API_ENTRY cl_int CL_API_CALL clEnqueueCommandBufferKHR(

CL_API_ENTRY cl_int CL_API_CALL clCommandBarrierWithWaitListKHR(
cl_command_buffer_khr command_buffer, 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, cl_mutable_command_khr *mutable_handle) {
Expand All @@ -1300,6 +1301,11 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandBarrierWithWaitListKHR(
OCL_CHECK(!sync_point_wait_list && num_sync_points_in_wait_list,
return CL_INVALID_SYNC_POINT_WAIT_LIST_KHR);

// No properties defined for entry-point
if (properties && properties[0] != 0) {
return CL_INVALID_VALUE;
}

cargo::array_view<const cl_sync_point_khr> wait_list(
sync_point_wait_list, num_sync_points_in_wait_list);

Expand All @@ -1311,8 +1317,9 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandBarrierWithWaitListKHR(

CL_API_ENTRY cl_int CL_API_CALL clCommandCopyBufferKHR(
cl_command_buffer_khr command_buffer, cl_command_queue command_queue,
cl_mem src_buffer, cl_mem dst_buffer, size_t src_offset, size_t dst_offset,
size_t size, cl_uint num_sync_points_in_wait_list,
const cl_command_properties_khr *properties, cl_mem src_buffer,
cl_mem dst_buffer, size_t src_offset, size_t dst_offset, size_t size,
cl_uint num_sync_points_in_wait_list,
const cl_sync_point_khr *sync_point_wait_list,
cl_sync_point_khr *sync_point, cl_mutable_command_khr *mutable_handle) {
const tracer::TraceGuard<tracer::OpenCL> guard("clCommandCopyBufferKHR");
Expand All @@ -1326,6 +1333,11 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandCopyBufferKHR(
OCL_CHECK(!sync_point_wait_list && num_sync_points_in_wait_list,
return CL_INVALID_SYNC_POINT_WAIT_LIST_KHR);

// No properties defined for entry-point
if (properties && properties[0] != 0) {
return CL_INVALID_VALUE;
}

const cl_int error = cl::validate::CopyBufferArguments(
command_buffer->command_queue, src_buffer, dst_buffer, src_offset,
dst_offset, size);
Expand All @@ -1344,9 +1356,10 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandCopyBufferKHR(

CL_API_ENTRY cl_int CL_API_CALL clCommandCopyBufferRectKHR(
cl_command_buffer_khr command_buffer, cl_command_queue command_queue,
cl_mem src_buffer, cl_mem dst_buffer, const size_t *src_origin,
const size_t *dst_origin, const size_t *region, size_t src_row_pitch,
size_t src_slice_pitch, size_t dst_row_pitch, size_t dst_slice_pitch,
const cl_command_properties_khr *properties, cl_mem src_buffer,
cl_mem dst_buffer, const size_t *src_origin, const size_t *dst_origin,
const size_t *region, size_t src_row_pitch, size_t src_slice_pitch,
size_t dst_row_pitch, size_t dst_slice_pitch,
cl_uint num_sync_points_in_wait_list,
const cl_sync_point_khr *sync_point_wait_list,
cl_sync_point_khr *sync_point, cl_mutable_command_khr *mutable_handle) {
Expand All @@ -1360,6 +1373,10 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandCopyBufferRectKHR(
return CL_INVALID_SYNC_POINT_WAIT_LIST_KHR);
OCL_CHECK(!sync_point_wait_list && num_sync_points_in_wait_list,
return CL_INVALID_SYNC_POINT_WAIT_LIST_KHR);
// No properties defined for entry-point
if (properties && properties[0] != 0) {
return CL_INVALID_VALUE;
}

// The OpenCL spec has the following special cases for the pitches.
if (src_row_pitch == 0) {
Expand Down Expand Up @@ -1394,9 +1411,9 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandCopyBufferRectKHR(

CL_API_ENTRY cl_int CL_API_CALL clCommandCopyBufferToImageKHR(
cl_command_buffer_khr command_buffer, cl_command_queue command_queue,
cl_mem src_buffer, cl_mem dst_image, size_t src_offset,
const size_t *dst_origin, const size_t *region,
cl_uint num_sync_points_in_wait_list,
const cl_command_properties_khr *properties, cl_mem src_buffer,
cl_mem dst_image, size_t src_offset, const size_t *dst_origin,
const size_t *region, cl_uint num_sync_points_in_wait_list,
const cl_sync_point_khr *sync_point_wait_list,
cl_sync_point_khr *sync_point, cl_mutable_command_khr *mutable_handle) {
const tracer::TraceGuard<tracer::OpenCL> guard(
Expand All @@ -1410,6 +1427,10 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandCopyBufferToImageKHR(
return CL_INVALID_SYNC_POINT_WAIT_LIST_KHR);
OCL_CHECK(!sync_point_wait_list && num_sync_points_in_wait_list,
return CL_INVALID_SYNC_POINT_WAIT_LIST_KHR);
// No properties defined for entry-point
if (properties && properties[0] != 0) {
return CL_INVALID_VALUE;
}

const cl_int error = cl::validate::CopyBufferToImageArguments(
command_buffer->command_queue, src_buffer, dst_image, src_offset,
Expand All @@ -1429,9 +1450,9 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandCopyBufferToImageKHR(

CL_API_ENTRY cl_int CL_API_CALL clCommandCopyImageKHR(
cl_command_buffer_khr command_buffer, cl_command_queue command_queue,
cl_mem src_image, cl_mem dst_image, const size_t *src_origin,
const size_t *dst_origin, const size_t *region,
cl_uint num_sync_points_in_wait_list,
const cl_command_properties_khr *properties, cl_mem src_image,
cl_mem dst_image, const size_t *src_origin, const size_t *dst_origin,
const size_t *region, cl_uint num_sync_points_in_wait_list,
const cl_sync_point_khr *sync_point_wait_list,
cl_sync_point_khr *sync_point, cl_mutable_command_khr *mutable_handle) {
const tracer::TraceGuard<tracer::OpenCL> guard("clCommandCopyImageKHR");
Expand All @@ -1444,6 +1465,10 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandCopyImageKHR(
return CL_INVALID_SYNC_POINT_WAIT_LIST_KHR);
OCL_CHECK(!sync_point_wait_list && num_sync_points_in_wait_list,
return CL_INVALID_SYNC_POINT_WAIT_LIST_KHR);
// No properties defined for entry-point
if (properties && properties[0] != 0) {
return CL_INVALID_VALUE;
}

const cl_int error = cl::validate::CopyImageArguments(
command_buffer->command_queue, src_image, dst_image, src_origin,
Expand All @@ -1463,9 +1488,9 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandCopyImageKHR(

CL_API_ENTRY cl_int CL_API_CALL clCommandCopyImageToBufferKHR(
cl_command_buffer_khr command_buffer, cl_command_queue command_queue,
cl_mem src_image, cl_mem dst_buffer, const size_t *src_origin,
const size_t *region, size_t dst_offset,
cl_uint num_sync_points_in_wait_list,
const cl_command_properties_khr *properties, cl_mem src_image,
cl_mem dst_buffer, const size_t *src_origin, const size_t *region,
size_t dst_offset, cl_uint num_sync_points_in_wait_list,
const cl_sync_point_khr *sync_point_wait_list,
cl_sync_point_khr *sync_point, cl_mutable_command_khr *mutable_handle) {
const tracer::TraceGuard<tracer::OpenCL> guard(
Expand All @@ -1479,6 +1504,10 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandCopyImageToBufferKHR(
return CL_INVALID_SYNC_POINT_WAIT_LIST_KHR);
OCL_CHECK(!sync_point_wait_list && num_sync_points_in_wait_list,
return CL_INVALID_SYNC_POINT_WAIT_LIST_KHR);
// No properties defined for entry-point
if (properties && properties[0] != 0) {
return CL_INVALID_VALUE;
}

const cl_int error = cl::validate::CopyImageToBufferArguments(
command_buffer->command_queue, src_image, dst_buffer, src_origin, region,
Expand All @@ -1498,8 +1527,9 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandCopyImageToBufferKHR(

CL_API_ENTRY cl_int CL_API_CALL clCommandFillBufferKHR(
cl_command_buffer_khr command_buffer, cl_command_queue command_queue,
cl_mem buffer, const void *pattern, size_t pattern_size, size_t offset,
size_t size, cl_uint num_sync_points_in_wait_list,
const cl_command_properties_khr *properties, cl_mem buffer,
const void *pattern, size_t pattern_size, size_t offset, size_t size,
cl_uint num_sync_points_in_wait_list,
const cl_sync_point_khr *sync_point_wait_list,
cl_sync_point_khr *sync_point, cl_mutable_command_khr *mutable_handle) {
const tracer::TraceGuard<tracer::OpenCL> guard("clCommandFillBufferKHR");
Expand All @@ -1512,6 +1542,10 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandFillBufferKHR(
return CL_INVALID_SYNC_POINT_WAIT_LIST_KHR);
OCL_CHECK(!sync_point_wait_list && num_sync_points_in_wait_list,
return CL_INVALID_SYNC_POINT_WAIT_LIST_KHR);
// No properties defined for entry-point
if (properties && properties[0] != 0) {
return CL_INVALID_VALUE;
}

const cl_int error =
cl::validate::FillBufferArguments(command_buffer->command_queue, buffer,
Expand All @@ -1530,8 +1564,9 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandFillBufferKHR(

CL_API_ENTRY cl_int CL_API_CALL clCommandFillImageKHR(
cl_command_buffer_khr command_buffer, cl_command_queue command_queue,
cl_mem image, const void *fill_color, const size_t *origin,
const size_t *region, cl_uint num_sync_points_in_wait_list,
const cl_command_properties_khr *properties, cl_mem image,
const void *fill_color, const size_t *origin, const size_t *region,
cl_uint num_sync_points_in_wait_list,
const cl_sync_point_khr *sync_point_wait_list,
cl_sync_point_khr *sync_point, cl_mutable_command_khr *mutable_handle) {
const tracer::TraceGuard<tracer::OpenCL> guard("clCommandFillImageKHR");
Expand All @@ -1544,6 +1579,10 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandFillImageKHR(
return CL_INVALID_SYNC_POINT_WAIT_LIST_KHR);
OCL_CHECK(!sync_point_wait_list && num_sync_points_in_wait_list,
return CL_INVALID_SYNC_POINT_WAIT_LIST_KHR);
// No properties defined for entry-point
if (properties && properties[0] != 0) {
return CL_INVALID_VALUE;
}

const cl_int error = cl::validate::FillImageArguments(
command_buffer->command_queue, image, fill_color, origin, region);
Expand All @@ -1561,8 +1600,8 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandFillImageKHR(

CL_API_ENTRY cl_int CL_API_CALL clCommandNDRangeKernelKHR(
cl_command_buffer_khr command_buffer, cl_command_queue command_queue,
const cl_ndrange_kernel_command_properties_khr *properties,
cl_kernel kernel, cl_uint work_dim, const size_t *global_work_offset,
const cl_command_properties_khr *properties, cl_kernel kernel,
cl_uint work_dim, const size_t *global_work_offset,
const size_t *global_work_size, const size_t *local_work_size,
cl_uint num_sync_points_in_wait_list,
const cl_sync_point_khr *sync_point_wait_list,
Expand All @@ -1580,8 +1619,7 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandNDRangeKernelKHR(
OCL_CHECK(!sync_point_wait_list && num_sync_points_in_wait_list,
return CL_INVALID_SYNC_POINT_WAIT_LIST_KHR);

cargo::small_vector<cl_ndrange_kernel_command_properties_khr, 3>
properties_list;
cargo::small_vector<cl_command_properties_khr, 3> properties_list;

// CL_MUTABLE_DISPATCH_UPDATABLE_FIELDS_KHR defaults to values supported by
// the device in CL_DEVICE_MUTABLE_DISPATCH_CAPABILITIES_KHR
Expand All @@ -1595,7 +1633,7 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandNDRangeKernelKHR(
return CL_INVALID_VALUE;
#endif

cl_ndrange_kernel_command_properties_khr seen = 0;
cl_command_properties_khr seen = 0;
auto current = properties;
do {
const cl_command_buffer_properties_khr property = current[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension::khr_command_buffer_mutable_dispatch::
#else
usage_category::DISABLED
#endif
CA_CL_EXT_VERSION(0, 1, 0)) {
CA_CL_EXT_VERSION(0, 9, 3)) {
}

void *extension::khr_command_buffer_mutable_dispatch::
Expand Down Expand Up @@ -60,7 +60,7 @@ cl_int extension::khr_command_buffer_mutable_dispatch::GetDeviceInfo(
return CL_INVALID_DEVICE;
}

cl_ndrange_kernel_command_properties_khr result = 0;
cl_command_properties_khr result = 0;
if (CL_DEVICE_MUTABLE_DISPATCH_CAPABILITIES_KHR == param_name) {
result = CL_MUTABLE_DISPATCH_ARGUMENTS_KHR;
} else {
Expand All @@ -73,8 +73,7 @@ cl_int extension::khr_command_buffer_mutable_dispatch::GetDeviceInfo(
constexpr size_t type_size = sizeof(result);
if (nullptr != param_value) {
OCL_CHECK(param_value_size < type_size, return CL_INVALID_VALUE);
*static_cast<cl_ndrange_kernel_command_properties_khr *>(param_value) =
result;
*static_cast<cl_command_properties_khr *>(param_value) = result;
}
OCL_SET_IF_NOT_NULL(param_value_size_ret, type_size);
return CL_SUCCESS;
Expand Down Expand Up @@ -172,15 +171,14 @@ CL_API_ENTRY cl_int CL_API_CALL clGetMutableCommandInfoKHR(
MUTABLE_COMMAND_ARRAY_INFO_CASE(CL_MUTABLE_DISPATCH_LOCAL_WORK_SIZE_KHR,
command->local_size);

case CL_MUTABLE_DISPATCH_PROPERTIES_ARRAY_KHR: {
case CL_MUTABLE_COMMAND_PROPERTIES_ARRAY_KHR: {
const auto &properties_list = command->properties_list;
OCL_SET_IF_NOT_NULL(param_value_size_ret,
sizeof(cl_ndrange_kernel_command_properties_khr) *
properties_list.size());
OCL_SET_IF_NOT_NULL(
param_value_size_ret,
sizeof(cl_command_properties_khr) * properties_list.size());
OCL_CHECK(
param_value && param_value_size <
sizeof(cl_ndrange_kernel_command_properties_khr) *
properties_list.size(),
param_value && param_value_size < sizeof(cl_command_properties_khr) *
properties_list.size(),
return CL_INVALID_VALUE);
if (param_value) {
std::copy(std::begin(properties_list), std::end(properties_list),
Expand Down
Loading
Loading