Skip to content

Commit

Permalink
Merge pull request #2095 from Bensuo/ewan/update_opencl_headers
Browse files Browse the repository at this point in the history
Reflect upstream OpenCL command-buffer API changes
  • Loading branch information
aarongreig authored Sep 24, 2024
2 parents f5c907a + 762eb9f commit 1d1808a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion source/adapters/opencl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if(UR_OPENCL_INCLUDE_DIR)
else()
FetchContent_Declare(OpenCL-Headers
GIT_REPOSITORY "https://github.com/KhronosGroup/OpenCL-Headers.git"
GIT_TAG 1e193332d02e27e15812d24ff2a3a7a908eb92a3
GIT_TAG 542d7a8f65ecfd88b38de35d8b10aa67b36b33b2
)
FetchContent_MakeAvailable(OpenCL-Headers)
FetchContent_GetProperties(OpenCL-Headers
Expand Down
32 changes: 16 additions & 16 deletions source/adapters/opencl/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
cl_mutable_command_khr *OutCommandHandle =
hCommandBuffer->IsUpdatable ? &CommandHandle : nullptr;

cl_ndrange_kernel_command_properties_khr UpdateProperties[] = {
cl_command_properties_khr UpdateProperties[] = {
CL_MUTABLE_DISPATCH_UPDATABLE_FIELDS_KHR,
CL_MUTABLE_DISPATCH_GLOBAL_OFFSET_KHR |
CL_MUTABLE_DISPATCH_GLOBAL_SIZE_KHR |
CL_MUTABLE_DISPATCH_LOCAL_SIZE_KHR |
CL_MUTABLE_DISPATCH_ARGUMENTS_KHR | CL_MUTABLE_DISPATCH_EXEC_INFO_KHR,
0};

cl_ndrange_kernel_command_properties_khr *Properties =
cl_command_properties_khr *Properties =
hCommandBuffer->IsUpdatable ? UpdateProperties : nullptr;
CL_RETURN_ON_FAILURE(clCommandNDRangeKernelKHR(
hCommandBuffer->CLCommandBuffer, nullptr, Properties,
Expand All @@ -176,8 +176,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
auto URCommandHandle =
std::make_unique<ur_exp_command_buffer_command_handle_t_>(
hCommandBuffer, CommandHandle, workDim, pLocalWorkSize != nullptr);
*phCommandHandle = URCommandHandle.release();
hCommandBuffer->CommandHandles.push_back(*phCommandHandle);
ur_exp_command_buffer_command_handle_t Handle = URCommandHandle.release();
hCommandBuffer->CommandHandles.push_back(Handle);
if (phCommandHandle) {
*phCommandHandle = Handle;
}
} catch (...) {
return UR_RESULT_ERROR_OUT_OF_RESOURCES;
}
Expand Down Expand Up @@ -222,7 +225,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferCopyExp(
cl_ext::CommandCopyBufferName, &clCommandCopyBufferKHR));

CL_RETURN_ON_FAILURE(clCommandCopyBufferKHR(
hCommandBuffer->CLCommandBuffer, nullptr,
hCommandBuffer->CLCommandBuffer, nullptr, nullptr,
cl_adapter::cast<cl_mem>(hSrcMem), cl_adapter::cast<cl_mem>(hDstMem),
srcOffset, dstOffset, size, numSyncPointsInWaitList, pSyncPointWaitList,
pSyncPoint, nullptr));
Expand Down Expand Up @@ -256,7 +259,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferCopyRectExp(
cl_ext::CommandCopyBufferRectName, &clCommandCopyBufferRectKHR));

CL_RETURN_ON_FAILURE(clCommandCopyBufferRectKHR(
hCommandBuffer->CLCommandBuffer, nullptr,
hCommandBuffer->CLCommandBuffer, nullptr, nullptr,
cl_adapter::cast<cl_mem>(hSrcMem), cl_adapter::cast<cl_mem>(hDstMem),
OpenCLOriginRect, OpenCLDstRect, OpenCLRegion, srcRowPitch, srcSlicePitch,
dstRowPitch, dstSlicePitch, numSyncPointsInWaitList, pSyncPointWaitList,
Expand All @@ -274,9 +277,6 @@ ur_result_t UR_APICALL urCommandBufferAppendMemBufferWriteExp(
[[maybe_unused]] const ur_exp_command_buffer_sync_point_t
*pSyncPointWaitList,
[[maybe_unused]] ur_exp_command_buffer_sync_point_t *pSyncPoint) {

cl_adapter::die("Experimental Command-buffer feature is not "
"implemented for OpenCL adapter.");
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

Expand Down Expand Up @@ -343,7 +343,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferFillExp(
cl_ext::CommandFillBufferName, &clCommandFillBufferKHR));

CL_RETURN_ON_FAILURE(clCommandFillBufferKHR(
hCommandBuffer->CLCommandBuffer, nullptr,
hCommandBuffer->CLCommandBuffer, nullptr, nullptr,
cl_adapter::cast<cl_mem>(hBuffer), pPattern, patternSize, offset, size,
numSyncPointsInWaitList, pSyncPointWaitList, pSyncPoint, nullptr));

Expand Down Expand Up @@ -556,8 +556,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferUpdateKernelLaunchExp(
cl_mutable_command_khr command =
cl_adapter::cast<cl_mutable_command_khr>(hCommand->CLMutableCommand);
cl_mutable_dispatch_config_khr dispatch_config = {
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR,
nullptr,
command,
static_cast<cl_uint>(CLArgs.size()), // num_args
static_cast<cl_uint>(CLUSMArgs.size()), // num_svm_args
Expand All @@ -570,10 +568,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferUpdateKernelLaunchExp(
CLGlobalWorkSize.data(), // global_work_size
CLLocalWorkSize.data(), // local_work_size
};
cl_mutable_base_config_khr config = {
CL_STRUCTURE_TYPE_MUTABLE_BASE_CONFIG_KHR, nullptr, 1, &dispatch_config};
CL_RETURN_ON_FAILURE(
clUpdateMutableCommandsKHR(hCommandBuffer->CLCommandBuffer, &config));
cl_uint num_configs = 1;
cl_command_buffer_update_type_khr config_types[1] = {
CL_STRUCTURE_TYPE_MUTABLE_DISPATCH_CONFIG_KHR};
const void *configs[1] = {&dispatch_config};
CL_RETURN_ON_FAILURE(clUpdateMutableCommandsKHR(
hCommandBuffer->CLCommandBuffer, num_configs, config_types, configs));

return UR_RESULT_SUCCESS;
}
Expand Down
26 changes: 15 additions & 11 deletions source/adapters/opencl/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,33 +272,36 @@ cl_int(CL_API_CALL *)(cl_command_buffer_khr command_buffer);

using clCommandNDRangeKernelKHR_fn = CL_API_ENTRY cl_int(CL_API_CALL *)(
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,
cl_sync_point_khr *sync_point, cl_mutable_command_khr *mutable_handle);

using clCommandCopyBufferKHR_fn = CL_API_ENTRY cl_int(CL_API_CALL *)(
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);

using clCommandCopyBufferRectKHR_fn = CL_API_ENTRY cl_int(CL_API_CALL *)(
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);

using clCommandFillBufferKHR_fn = CL_API_ENTRY cl_int(CL_API_CALL *)(
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);

Expand All @@ -313,8 +316,9 @@ using clGetCommandBufferInfoKHR_fn = CL_API_ENTRY cl_int(CL_API_CALL *)(
size_t param_value_size, void *param_value, size_t *param_value_size_ret);

using clUpdateMutableCommandsKHR_fn = CL_API_ENTRY
cl_int(CL_API_CALL *)(cl_command_buffer_khr command_buffer,
const cl_mutable_base_config_khr *mutable_config);
cl_int(CL_API_CALL *)(cl_command_buffer_khr command_buffer, cl_uint num_configs,
const cl_command_buffer_update_type_khr *config_types,
const void **configs);

template <typename T> struct FuncPtrCache {
std::map<cl_context, T> Map;
Expand Down

0 comments on commit 1d1808a

Please sign in to comment.