diff --git a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_function_types.h b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_function_types.h new file mode 100644 index 000000000..124f53ba7 --- /dev/null +++ b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_function_types.h @@ -0,0 +1,1184 @@ +/* + * Copyright (c) 2023 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * OpenCL is a trademark of Apple Inc. used under license by Khronos. + */ + +#ifndef OPENCL_CL_FUNCTION_TYPES_H_ +#define OPENCL_CL_FUNCTION_TYPES_H_ + +#include + +typedef cl_int CL_API_CALL clGetPlatformIDs_t( + cl_uint num_entries, + cl_platform_id* platforms, + cl_uint* num_platforms); + +typedef clGetPlatformIDs_t * +clGetPlatformIDs_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clGetPlatformInfo_t( + cl_platform_id platform, + cl_platform_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetPlatformInfo_t * +clGetPlatformInfo_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clGetDeviceIDs_t( + cl_platform_id platform, + cl_device_type device_type, + cl_uint num_entries, + cl_device_id* devices, + cl_uint* num_devices); + +typedef clGetDeviceIDs_t * +clGetDeviceIDs_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clGetDeviceInfo_t( + cl_device_id device, + cl_device_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetDeviceInfo_t * +clGetDeviceInfo_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_context CL_API_CALL clCreateContext_t( + const cl_context_properties* properties, + cl_uint num_devices, + const cl_device_id* devices, + void (CL_CALLBACK* pfn_notify)(const char* errinfo, const void* private_info, size_t cb, void* user_data), + void* user_data, + cl_int* errcode_ret); + +typedef clCreateContext_t * +clCreateContext_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_context CL_API_CALL clCreateContextFromType_t( + const cl_context_properties* properties, + cl_device_type device_type, + void (CL_CALLBACK* pfn_notify)(const char* errinfo, const void* private_info, size_t cb, void* user_data), + void* user_data, + cl_int* errcode_ret); + +typedef clCreateContextFromType_t * +clCreateContextFromType_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clRetainContext_t( + cl_context context); + +typedef clRetainContext_t * +clRetainContext_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clReleaseContext_t( + cl_context context); + +typedef clReleaseContext_t * +clReleaseContext_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clGetContextInfo_t( + cl_context context, + cl_context_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetContextInfo_t * +clGetContextInfo_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clRetainCommandQueue_t( + cl_command_queue command_queue); + +typedef clRetainCommandQueue_t * +clRetainCommandQueue_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clReleaseCommandQueue_t( + cl_command_queue command_queue); + +typedef clReleaseCommandQueue_t * +clReleaseCommandQueue_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clGetCommandQueueInfo_t( + cl_command_queue command_queue, + cl_command_queue_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetCommandQueueInfo_t * +clGetCommandQueueInfo_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_mem CL_API_CALL clCreateBuffer_t( + cl_context context, + cl_mem_flags flags, + size_t size, + void* host_ptr, + cl_int* errcode_ret); + +typedef clCreateBuffer_t * +clCreateBuffer_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clRetainMemObject_t( + cl_mem memobj); + +typedef clRetainMemObject_t * +clRetainMemObject_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clReleaseMemObject_t( + cl_mem memobj); + +typedef clReleaseMemObject_t * +clReleaseMemObject_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clGetSupportedImageFormats_t( + cl_context context, + cl_mem_flags flags, + cl_mem_object_type image_type, + cl_uint num_entries, + cl_image_format* image_formats, + cl_uint* num_image_formats); + +typedef clGetSupportedImageFormats_t * +clGetSupportedImageFormats_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clGetMemObjectInfo_t( + cl_mem memobj, + cl_mem_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetMemObjectInfo_t * +clGetMemObjectInfo_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clGetImageInfo_t( + cl_mem image, + cl_image_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetImageInfo_t * +clGetImageInfo_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clRetainSampler_t( + cl_sampler sampler); + +typedef clRetainSampler_t * +clRetainSampler_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clReleaseSampler_t( + cl_sampler sampler); + +typedef clReleaseSampler_t * +clReleaseSampler_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clGetSamplerInfo_t( + cl_sampler sampler, + cl_sampler_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetSamplerInfo_t * +clGetSamplerInfo_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_program CL_API_CALL clCreateProgramWithSource_t( + cl_context context, + cl_uint count, + const char** strings, + const size_t* lengths, + cl_int* errcode_ret); + +typedef clCreateProgramWithSource_t * +clCreateProgramWithSource_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_program CL_API_CALL clCreateProgramWithBinary_t( + cl_context context, + cl_uint num_devices, + const cl_device_id* device_list, + const size_t* lengths, + const unsigned char** binaries, + cl_int* binary_status, + cl_int* errcode_ret); + +typedef clCreateProgramWithBinary_t * +clCreateProgramWithBinary_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clRetainProgram_t( + cl_program program); + +typedef clRetainProgram_t * +clRetainProgram_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clReleaseProgram_t( + cl_program program); + +typedef clReleaseProgram_t * +clReleaseProgram_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clBuildProgram_t( + cl_program program, + cl_uint num_devices, + const cl_device_id* device_list, + const char* options, + void (CL_CALLBACK* pfn_notify)(cl_program program, void* user_data), + void* user_data); + +typedef clBuildProgram_t * +clBuildProgram_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clGetProgramInfo_t( + cl_program program, + cl_program_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetProgramInfo_t * +clGetProgramInfo_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clGetProgramBuildInfo_t( + cl_program program, + cl_device_id device, + cl_program_build_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetProgramBuildInfo_t * +clGetProgramBuildInfo_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_kernel CL_API_CALL clCreateKernel_t( + cl_program program, + const char* kernel_name, + cl_int* errcode_ret); + +typedef clCreateKernel_t * +clCreateKernel_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clCreateKernelsInProgram_t( + cl_program program, + cl_uint num_kernels, + cl_kernel* kernels, + cl_uint* num_kernels_ret); + +typedef clCreateKernelsInProgram_t * +clCreateKernelsInProgram_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clRetainKernel_t( + cl_kernel kernel); + +typedef clRetainKernel_t * +clRetainKernel_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clReleaseKernel_t( + cl_kernel kernel); + +typedef clReleaseKernel_t * +clReleaseKernel_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clSetKernelArg_t( + cl_kernel kernel, + cl_uint arg_index, + size_t arg_size, + const void* arg_value); + +typedef clSetKernelArg_t * +clSetKernelArg_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clGetKernelInfo_t( + cl_kernel kernel, + cl_kernel_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetKernelInfo_t * +clGetKernelInfo_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clGetKernelWorkGroupInfo_t( + cl_kernel kernel, + cl_device_id device, + cl_kernel_work_group_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetKernelWorkGroupInfo_t * +clGetKernelWorkGroupInfo_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clWaitForEvents_t( + cl_uint num_events, + const cl_event* event_list); + +typedef clWaitForEvents_t * +clWaitForEvents_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clGetEventInfo_t( + cl_event event, + cl_event_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetEventInfo_t * +clGetEventInfo_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clRetainEvent_t( + cl_event event); + +typedef clRetainEvent_t * +clRetainEvent_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clReleaseEvent_t( + cl_event event); + +typedef clReleaseEvent_t * +clReleaseEvent_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clGetEventProfilingInfo_t( + cl_event event, + cl_profiling_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetEventProfilingInfo_t * +clGetEventProfilingInfo_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clFlush_t( + cl_command_queue command_queue); + +typedef clFlush_t * +clFlush_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clFinish_t( + cl_command_queue command_queue); + +typedef clFinish_t * +clFinish_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clEnqueueReadBuffer_t( + cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_read, + size_t offset, + size_t size, + void* ptr, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueReadBuffer_t * +clEnqueueReadBuffer_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clEnqueueWriteBuffer_t( + cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_write, + size_t offset, + size_t size, + const void* ptr, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueWriteBuffer_t * +clEnqueueWriteBuffer_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clEnqueueCopyBuffer_t( + 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_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueCopyBuffer_t * +clEnqueueCopyBuffer_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clEnqueueReadImage_t( + cl_command_queue command_queue, + cl_mem image, + cl_bool blocking_read, + const size_t* origin, + const size_t* region, + size_t row_pitch, + size_t slice_pitch, + void* ptr, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueReadImage_t * +clEnqueueReadImage_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clEnqueueWriteImage_t( + cl_command_queue command_queue, + cl_mem image, + cl_bool blocking_write, + const size_t* origin, + const size_t* region, + size_t input_row_pitch, + size_t input_slice_pitch, + const void* ptr, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueWriteImage_t * +clEnqueueWriteImage_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clEnqueueCopyImage_t( + 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_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueCopyImage_t * +clEnqueueCopyImage_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clEnqueueCopyImageToBuffer_t( + 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_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueCopyImageToBuffer_t * +clEnqueueCopyImageToBuffer_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clEnqueueCopyBufferToImage_t( + 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_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueCopyBufferToImage_t * +clEnqueueCopyBufferToImage_fn CL_API_SUFFIX__VERSION_1_0; + +typedef void* CL_API_CALL clEnqueueMapBuffer_t( + cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_map, + cl_map_flags map_flags, + size_t offset, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event, + cl_int* errcode_ret); + +typedef clEnqueueMapBuffer_t * +clEnqueueMapBuffer_fn CL_API_SUFFIX__VERSION_1_0; + +typedef void* CL_API_CALL clEnqueueMapImage_t( + cl_command_queue command_queue, + cl_mem image, + cl_bool blocking_map, + cl_map_flags map_flags, + const size_t* origin, + const size_t* region, + size_t* image_row_pitch, + size_t* image_slice_pitch, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event, + cl_int* errcode_ret); + +typedef clEnqueueMapImage_t * +clEnqueueMapImage_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clEnqueueUnmapMemObject_t( + cl_command_queue command_queue, + cl_mem memobj, + void* mapped_ptr, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueUnmapMemObject_t * +clEnqueueUnmapMemObject_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clEnqueueNDRangeKernel_t( + cl_command_queue command_queue, + 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_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueNDRangeKernel_t * +clEnqueueNDRangeKernel_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clEnqueueNativeKernel_t( + cl_command_queue command_queue, + void (CL_CALLBACK* user_func)(void*), + void* args, + size_t cb_args, + cl_uint num_mem_objects, + const cl_mem* mem_list, + const void** args_mem_loc, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueNativeKernel_t * +clEnqueueNativeKernel_fn CL_API_SUFFIX__VERSION_1_0; + +typedef cl_int CL_API_CALL clSetCommandQueueProperty_t( + cl_command_queue command_queue, + cl_command_queue_properties properties, + cl_bool enable, + cl_command_queue_properties* old_properties); + +typedef clSetCommandQueueProperty_t * +clSetCommandQueueProperty_fn CL_API_SUFFIX__VERSION_1_0_DEPRECATED; + +typedef cl_mem CL_API_CALL clCreateImage2D_t( + cl_context context, + cl_mem_flags flags, + const cl_image_format* image_format, + size_t image_width, + size_t image_height, + size_t image_row_pitch, + void* host_ptr, + cl_int* errcode_ret); + +typedef clCreateImage2D_t * +clCreateImage2D_fn CL_API_SUFFIX__VERSION_1_1_DEPRECATED; + +typedef cl_mem CL_API_CALL clCreateImage3D_t( + cl_context context, + cl_mem_flags flags, + const cl_image_format* image_format, + size_t image_width, + size_t image_height, + size_t image_depth, + size_t image_row_pitch, + size_t image_slice_pitch, + void* host_ptr, + cl_int* errcode_ret); + +typedef clCreateImage3D_t * +clCreateImage3D_fn CL_API_SUFFIX__VERSION_1_1_DEPRECATED; + +typedef cl_int CL_API_CALL clEnqueueMarker_t( + cl_command_queue command_queue, + cl_event* event); + +typedef clEnqueueMarker_t * +clEnqueueMarker_fn CL_API_SUFFIX__VERSION_1_1_DEPRECATED; + +typedef cl_int CL_API_CALL clEnqueueWaitForEvents_t( + cl_command_queue command_queue, + cl_uint num_events, + const cl_event* event_list); + +typedef clEnqueueWaitForEvents_t * +clEnqueueWaitForEvents_fn CL_API_SUFFIX__VERSION_1_1_DEPRECATED; + +typedef cl_int CL_API_CALL clEnqueueBarrier_t( + cl_command_queue command_queue); + +typedef clEnqueueBarrier_t * +clEnqueueBarrier_fn CL_API_SUFFIX__VERSION_1_1_DEPRECATED; + +typedef cl_int CL_API_CALL clUnloadCompiler_t( + void ); + +typedef clUnloadCompiler_t * +clUnloadCompiler_fn CL_API_SUFFIX__VERSION_1_1_DEPRECATED; + +typedef void* CL_API_CALL clGetExtensionFunctionAddress_t( + const char* func_name); + +typedef clGetExtensionFunctionAddress_t * +clGetExtensionFunctionAddress_fn CL_API_SUFFIX__VERSION_1_1_DEPRECATED; + +typedef cl_command_queue CL_API_CALL clCreateCommandQueue_t( + cl_context context, + cl_device_id device, + cl_command_queue_properties properties, + cl_int* errcode_ret); + +typedef clCreateCommandQueue_t * +clCreateCommandQueue_fn CL_API_SUFFIX__VERSION_1_2_DEPRECATED; + +typedef cl_sampler CL_API_CALL clCreateSampler_t( + cl_context context, + cl_bool normalized_coords, + cl_addressing_mode addressing_mode, + cl_filter_mode filter_mode, + cl_int* errcode_ret); + +typedef clCreateSampler_t * +clCreateSampler_fn CL_API_SUFFIX__VERSION_1_2_DEPRECATED; + +typedef cl_int CL_API_CALL clEnqueueTask_t( + cl_command_queue command_queue, + cl_kernel kernel, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueTask_t * +clEnqueueTask_fn CL_API_SUFFIX__VERSION_1_2_DEPRECATED; + +#ifdef CL_VERSION_1_1 + +typedef cl_mem CL_API_CALL clCreateSubBuffer_t( + cl_mem buffer, + cl_mem_flags flags, + cl_buffer_create_type buffer_create_type, + const void* buffer_create_info, + cl_int* errcode_ret); + +typedef clCreateSubBuffer_t * +clCreateSubBuffer_fn CL_API_SUFFIX__VERSION_1_1; + +typedef cl_int CL_API_CALL clSetMemObjectDestructorCallback_t( + cl_mem memobj, + void (CL_CALLBACK* pfn_notify)(cl_mem memobj, void* user_data), + void* user_data); + +typedef clSetMemObjectDestructorCallback_t * +clSetMemObjectDestructorCallback_fn CL_API_SUFFIX__VERSION_1_1; + +typedef cl_event CL_API_CALL clCreateUserEvent_t( + cl_context context, + cl_int* errcode_ret); + +typedef clCreateUserEvent_t * +clCreateUserEvent_fn CL_API_SUFFIX__VERSION_1_1; + +typedef cl_int CL_API_CALL clSetUserEventStatus_t( + cl_event event, + cl_int execution_status); + +typedef clSetUserEventStatus_t * +clSetUserEventStatus_fn CL_API_SUFFIX__VERSION_1_1; + +typedef cl_int CL_API_CALL clSetEventCallback_t( + cl_event event, + cl_int command_exec_callback_type, + void (CL_CALLBACK* pfn_notify)(cl_event event, cl_int event_command_status, void *user_data), + void* user_data); + +typedef clSetEventCallback_t * +clSetEventCallback_fn CL_API_SUFFIX__VERSION_1_1; + +typedef cl_int CL_API_CALL clEnqueueReadBufferRect_t( + cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_read, + const size_t* buffer_origin, + const size_t* host_origin, + const size_t* region, + size_t buffer_row_pitch, + size_t buffer_slice_pitch, + size_t host_row_pitch, + size_t host_slice_pitch, + void* ptr, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueReadBufferRect_t * +clEnqueueReadBufferRect_fn CL_API_SUFFIX__VERSION_1_1; + +typedef cl_int CL_API_CALL clEnqueueWriteBufferRect_t( + cl_command_queue command_queue, + cl_mem buffer, + cl_bool blocking_write, + const size_t* buffer_origin, + const size_t* host_origin, + const size_t* region, + size_t buffer_row_pitch, + size_t buffer_slice_pitch, + size_t host_row_pitch, + size_t host_slice_pitch, + const void* ptr, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueWriteBufferRect_t * +clEnqueueWriteBufferRect_fn CL_API_SUFFIX__VERSION_1_1; + +typedef cl_int CL_API_CALL clEnqueueCopyBufferRect_t( + 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, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueCopyBufferRect_t * +clEnqueueCopyBufferRect_fn CL_API_SUFFIX__VERSION_1_1; + +#endif /* CL_VERSION_1_1 */ + +#ifdef CL_VERSION_1_2 + +typedef cl_int CL_API_CALL clCreateSubDevices_t( + cl_device_id in_device, + const cl_device_partition_property* properties, + cl_uint num_devices, + cl_device_id* out_devices, + cl_uint* num_devices_ret); + +typedef clCreateSubDevices_t * +clCreateSubDevices_fn CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int CL_API_CALL clRetainDevice_t( + cl_device_id device); + +typedef clRetainDevice_t * +clRetainDevice_fn CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int CL_API_CALL clReleaseDevice_t( + cl_device_id device); + +typedef clReleaseDevice_t * +clReleaseDevice_fn CL_API_SUFFIX__VERSION_1_2; + +typedef cl_mem CL_API_CALL clCreateImage_t( + cl_context context, + cl_mem_flags flags, + const cl_image_format* image_format, + const cl_image_desc* image_desc, + void* host_ptr, + cl_int* errcode_ret); + +typedef clCreateImage_t * +clCreateImage_fn CL_API_SUFFIX__VERSION_1_2; + +typedef cl_program CL_API_CALL clCreateProgramWithBuiltInKernels_t( + cl_context context, + cl_uint num_devices, + const cl_device_id* device_list, + const char* kernel_names, + cl_int* errcode_ret); + +typedef clCreateProgramWithBuiltInKernels_t * +clCreateProgramWithBuiltInKernels_fn CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int CL_API_CALL clCompileProgram_t( + cl_program program, + cl_uint num_devices, + const cl_device_id* device_list, + const char* options, + cl_uint num_input_headers, + const cl_program* input_headers, + const char** header_include_names, + void (CL_CALLBACK* pfn_notify)(cl_program program, void* user_data), + void* user_data); + +typedef clCompileProgram_t * +clCompileProgram_fn CL_API_SUFFIX__VERSION_1_2; + +typedef cl_program CL_API_CALL clLinkProgram_t( + cl_context context, + cl_uint num_devices, + const cl_device_id* device_list, + const char* options, + cl_uint num_input_programs, + const cl_program* input_programs, + void (CL_CALLBACK* pfn_notify)(cl_program program, void* user_data), + void* user_data, + cl_int* errcode_ret); + +typedef clLinkProgram_t * +clLinkProgram_fn CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int CL_API_CALL clUnloadPlatformCompiler_t( + cl_platform_id platform); + +typedef clUnloadPlatformCompiler_t * +clUnloadPlatformCompiler_fn CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int CL_API_CALL clGetKernelArgInfo_t( + cl_kernel kernel, + cl_uint arg_index, + cl_kernel_arg_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetKernelArgInfo_t * +clGetKernelArgInfo_fn CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int CL_API_CALL clEnqueueFillBuffer_t( + cl_command_queue command_queue, + cl_mem buffer, + const void* pattern, + size_t pattern_size, + size_t offset, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueFillBuffer_t * +clEnqueueFillBuffer_fn CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int CL_API_CALL clEnqueueFillImage_t( + cl_command_queue command_queue, + cl_mem image, + const void* fill_color, + const size_t* origin, + const size_t* region, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueFillImage_t * +clEnqueueFillImage_fn CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int CL_API_CALL clEnqueueMigrateMemObjects_t( + cl_command_queue command_queue, + cl_uint num_mem_objects, + const cl_mem* mem_objects, + cl_mem_migration_flags flags, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueMigrateMemObjects_t * +clEnqueueMigrateMemObjects_fn CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int CL_API_CALL clEnqueueMarkerWithWaitList_t( + cl_command_queue command_queue, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueMarkerWithWaitList_t * +clEnqueueMarkerWithWaitList_fn CL_API_SUFFIX__VERSION_1_2; + +typedef cl_int CL_API_CALL clEnqueueBarrierWithWaitList_t( + cl_command_queue command_queue, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueBarrierWithWaitList_t * +clEnqueueBarrierWithWaitList_fn CL_API_SUFFIX__VERSION_1_2; + +typedef void* CL_API_CALL clGetExtensionFunctionAddressForPlatform_t( + cl_platform_id platform, + const char* func_name); + +typedef clGetExtensionFunctionAddressForPlatform_t * +clGetExtensionFunctionAddressForPlatform_fn CL_API_SUFFIX__VERSION_1_2; + +#endif /* CL_VERSION_1_2 */ + +#ifdef CL_VERSION_2_0 + +typedef cl_command_queue CL_API_CALL clCreateCommandQueueWithProperties_t( + cl_context context, + cl_device_id device, + const cl_queue_properties* properties, + cl_int* errcode_ret); + +typedef clCreateCommandQueueWithProperties_t * +clCreateCommandQueueWithProperties_fn CL_API_SUFFIX__VERSION_2_0; + +typedef cl_mem CL_API_CALL clCreatePipe_t( + cl_context context, + cl_mem_flags flags, + cl_uint pipe_packet_size, + cl_uint pipe_max_packets, + const cl_pipe_properties* properties, + cl_int* errcode_ret); + +typedef clCreatePipe_t * +clCreatePipe_fn CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int CL_API_CALL clGetPipeInfo_t( + cl_mem pipe, + cl_pipe_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetPipeInfo_t * +clGetPipeInfo_fn CL_API_SUFFIX__VERSION_2_0; + +typedef void* CL_API_CALL clSVMAlloc_t( + cl_context context, + cl_svm_mem_flags flags, + size_t size, + cl_uint alignment); + +typedef clSVMAlloc_t * +clSVMAlloc_fn CL_API_SUFFIX__VERSION_2_0; + +typedef void CL_API_CALL clSVMFree_t( + cl_context context, + void* svm_pointer); + +typedef clSVMFree_t * +clSVMFree_fn CL_API_SUFFIX__VERSION_2_0; + +typedef cl_sampler CL_API_CALL clCreateSamplerWithProperties_t( + cl_context context, + const cl_sampler_properties* sampler_properties, + cl_int* errcode_ret); + +typedef clCreateSamplerWithProperties_t * +clCreateSamplerWithProperties_fn CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int CL_API_CALL clSetKernelArgSVMPointer_t( + cl_kernel kernel, + cl_uint arg_index, + const void* arg_value); + +typedef clSetKernelArgSVMPointer_t * +clSetKernelArgSVMPointer_fn CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int CL_API_CALL clSetKernelExecInfo_t( + cl_kernel kernel, + cl_kernel_exec_info param_name, + size_t param_value_size, + const void* param_value); + +typedef clSetKernelExecInfo_t * +clSetKernelExecInfo_fn CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int CL_API_CALL clEnqueueSVMFree_t( + cl_command_queue command_queue, + cl_uint num_svm_pointers, + void* svm_pointers[], + void (CL_CALLBACK* pfn_free_func)(cl_command_queue queue, cl_uint num_svm_pointers, void* svm_pointers[], void* user_data), + void* user_data, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueSVMFree_t * +clEnqueueSVMFree_fn CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int CL_API_CALL clEnqueueSVMMemcpy_t( + cl_command_queue command_queue, + cl_bool blocking_copy, + void* dst_ptr, + const void* src_ptr, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueSVMMemcpy_t * +clEnqueueSVMMemcpy_fn CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int CL_API_CALL clEnqueueSVMMemFill_t( + cl_command_queue command_queue, + void* svm_ptr, + const void* pattern, + size_t pattern_size, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueSVMMemFill_t * +clEnqueueSVMMemFill_fn CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int CL_API_CALL clEnqueueSVMMap_t( + cl_command_queue command_queue, + cl_bool blocking_map, + cl_map_flags flags, + void* svm_ptr, + size_t size, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueSVMMap_t * +clEnqueueSVMMap_fn CL_API_SUFFIX__VERSION_2_0; + +typedef cl_int CL_API_CALL clEnqueueSVMUnmap_t( + cl_command_queue command_queue, + void* svm_ptr, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueSVMUnmap_t * +clEnqueueSVMUnmap_fn CL_API_SUFFIX__VERSION_2_0; + +#endif /* CL_VERSION_2_0 */ + +#ifdef CL_VERSION_2_1 + +typedef cl_int CL_API_CALL clSetDefaultDeviceCommandQueue_t( + cl_context context, + cl_device_id device, + cl_command_queue command_queue); + +typedef clSetDefaultDeviceCommandQueue_t * +clSetDefaultDeviceCommandQueue_fn CL_API_SUFFIX__VERSION_2_1; + +typedef cl_int CL_API_CALL clGetDeviceAndHostTimer_t( + cl_device_id device, + cl_ulong* device_timestamp, + cl_ulong* host_timestamp); + +typedef clGetDeviceAndHostTimer_t * +clGetDeviceAndHostTimer_fn CL_API_SUFFIX__VERSION_2_1; + +typedef cl_int CL_API_CALL clGetHostTimer_t( + cl_device_id device, + cl_ulong* host_timestamp); + +typedef clGetHostTimer_t * +clGetHostTimer_fn CL_API_SUFFIX__VERSION_2_1; + +typedef cl_program CL_API_CALL clCreateProgramWithIL_t( + cl_context context, + const void* il, + size_t length, + cl_int* errcode_ret); + +typedef clCreateProgramWithIL_t * +clCreateProgramWithIL_fn CL_API_SUFFIX__VERSION_2_1; + +typedef cl_kernel CL_API_CALL clCloneKernel_t( + cl_kernel source_kernel, + cl_int* errcode_ret); + +typedef clCloneKernel_t * +clCloneKernel_fn CL_API_SUFFIX__VERSION_2_1; + +typedef cl_int CL_API_CALL clGetKernelSubGroupInfo_t( + cl_kernel kernel, + cl_device_id device, + cl_kernel_sub_group_info param_name, + size_t input_value_size, + const void* input_value, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetKernelSubGroupInfo_t * +clGetKernelSubGroupInfo_fn CL_API_SUFFIX__VERSION_2_1; + +typedef cl_int CL_API_CALL clEnqueueSVMMigrateMem_t( + cl_command_queue command_queue, + cl_uint num_svm_pointers, + const void** svm_pointers, + const size_t* sizes, + cl_mem_migration_flags flags, + cl_uint num_events_in_wait_list, + const cl_event* event_wait_list, + cl_event* event); + +typedef clEnqueueSVMMigrateMem_t * +clEnqueueSVMMigrateMem_fn CL_API_SUFFIX__VERSION_2_1; + +#endif /* CL_VERSION_2_1 */ + +#ifdef CL_VERSION_2_2 + +typedef cl_int CL_API_CALL clSetProgramSpecializationConstant_t( + cl_program program, + cl_uint spec_id, + size_t spec_size, + const void* spec_value); + +typedef clSetProgramSpecializationConstant_t * +clSetProgramSpecializationConstant_fn CL_API_SUFFIX__VERSION_2_2; + +typedef cl_int CL_API_CALL clSetProgramReleaseCallback_t( + cl_program program, + void (CL_CALLBACK* pfn_notify)(cl_program program, void* user_data), + void* user_data); + +typedef clSetProgramReleaseCallback_t * +clSetProgramReleaseCallback_fn CL_API_SUFFIX__VERSION_2_2_DEPRECATED; + +#endif /* CL_VERSION_2_2 */ + +#ifdef CL_VERSION_3_0 + +typedef cl_int CL_API_CALL clSetContextDestructorCallback_t( + cl_context context, + void (CL_CALLBACK* pfn_notify)(cl_context context, void* user_data), + void* user_data); + +typedef clSetContextDestructorCallback_t * +clSetContextDestructorCallback_fn CL_API_SUFFIX__VERSION_3_0; + +typedef cl_mem CL_API_CALL clCreateBufferWithProperties_t( + cl_context context, + const cl_mem_properties* properties, + cl_mem_flags flags, + size_t size, + void* host_ptr, + cl_int* errcode_ret); + +typedef clCreateBufferWithProperties_t * +clCreateBufferWithProperties_fn CL_API_SUFFIX__VERSION_3_0; + +typedef cl_mem CL_API_CALL clCreateImageWithProperties_t( + cl_context context, + const cl_mem_properties* properties, + cl_mem_flags flags, + const cl_image_format* image_format, + const cl_image_desc* image_desc, + void* host_ptr, + cl_int* errcode_ret); + +typedef clCreateImageWithProperties_t * +clCreateImageWithProperties_fn CL_API_SUFFIX__VERSION_3_0; + +#endif /* CL_VERSION_3_0 */ + +#endif /* OPENCL_CL_FUNCTION_TYPES_H_ */ diff --git a/tools/hitag2crack/common/OpenCL-Headers/CL/cl_layer.h b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_layer.h new file mode 100644 index 000000000..a43b89783 --- /dev/null +++ b/tools/hitag2crack/common/OpenCL-Headers/CL/cl_layer.h @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2008-2023 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +#ifndef OPENCL_CL_LAYER_H_ +#define OPENCL_CL_LAYER_H_ + +/* +** This header is generated from the Khronos OpenCL XML API Registry. +*/ + +#include + +#include + +/* CL_NO_PROTOTYPES implies CL_NO_EXTENSION_PROTOTYPES: */ +#if defined(CL_NO_PROTOTYPES) && !defined(CL_NO_EXTENSION_PROTOTYPES) +#define CL_NO_EXTENSION_PROTOTYPES +#endif + +/* CL_NO_EXTENSION_PROTOTYPES implies + CL_NO_ICD_DISPATCH_EXTENSION_PROTOTYPES and + CL_NO_NON_ICD_DISPATCH_EXTENSION_PROTOTYPES: */ +#if defined(CL_NO_EXTENSION_PROTOTYPES) && \ + !defined(CL_NO_ICD_DISPATCH_EXTENSION_PROTOTYPES) +#define CL_NO_ICD_DISPATCH_EXTENSION_PROTOTYPES +#endif +#if defined(CL_NO_EXTENSION_PROTOTYPES) && \ + !defined(CL_NO_NON_ICD_DISPATCH_EXTENSION_PROTOTYPES) +#define CL_NO_NON_ICD_DISPATCH_EXTENSION_PROTOTYPES +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/*************************************************************** +* cl_loader_layers +***************************************************************/ +#define cl_loader_layers 1 +#define CL_LOADER_LAYERS_EXTENSION_NAME \ + "cl_loader_layers" + +typedef cl_uint cl_layer_info; +typedef cl_uint cl_layer_api_version; + +/* cl_layer_info */ +#define CL_LAYER_API_VERSION 0x4240 +#define CL_LAYER_NAME 0x4241 + +/* Misc API enums */ +#define CL_LAYER_API_VERSION_100 100 + + +typedef cl_int CL_API_CALL +clGetLayerInfo_t( + cl_layer_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +typedef clGetLayerInfo_t * +clGetLayerInfo_fn ; + +typedef cl_int CL_API_CALL +clInitLayer_t( + cl_uint num_entries, + const cl_icd_dispatch* target_dispatch, + cl_uint* num_entries_ret, + const cl_icd_dispatch** layer_dispatch_ret); + +typedef clInitLayer_t * +clInitLayer_fn ; + +/* +** The function pointer typedefs prefixed with "pfn_" are provided for +** compatibility with earlier versions of the headers. New code is +** encouraged to use the function pointer typedefs that are suffixed with +** "_fn" instead, for consistency. +*/ + +typedef clGetLayerInfo_t * +pfn_clGetLayerInfo ; + +typedef clInitLayer_t * +pfn_clInitLayer ; + +#if !defined(CL_NO_NON_ICD_DISPATCH_EXTENSION_PROTOTYPES) + +extern CL_API_ENTRY cl_int CL_API_CALL +clGetLayerInfo( + cl_layer_info param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret) ; + +extern CL_API_ENTRY cl_int CL_API_CALL +clInitLayer( + cl_uint num_entries, + const cl_icd_dispatch* target_dispatch, + cl_uint* num_entries_ret, + const cl_icd_dispatch** layer_dispatch_ret) ; + +#endif /* !defined(CL_NO_NON_ICD_DISPATCH_EXTENSION_PROTOTYPES) */ + +#ifdef __cplusplus +} +#endif + +#endif /* OPENCL_CL_LAYER_H_ */ diff --git a/tools/hitag2crack/crack5opencl/ht2crack5opencl.c b/tools/hitag2crack/crack5opencl/ht2crack5opencl.c index 51e26edab..21829adf5 100644 --- a/tools/hitag2crack/crack5opencl/ht2crack5opencl.c +++ b/tools/hitag2crack/crack5opencl/ht2crack5opencl.c @@ -830,9 +830,13 @@ int main(int argc, char **argv) { continue; } - if (len == 0) continue; + if (len == 0) { + continue; + } - if (len > 0xdeadbe) len = 0xdeadbe; // limit build_log size + if (len > 0xdeadbe) { + len = 0xdeadbe; // limit build_log size + } char *buffer = (char *) calloc(len, sizeof(char)); if (!buffer) { @@ -908,27 +912,40 @@ int main(int argc, char **argv) { z = 0; for (w = 0; w < ocl_platform_cnt; w++) { - if (!cd_ctx[w].selected) continue; + + if (!cd_ctx[w].selected) { + continue; + } for (q = 0; q < cd_ctx[w].device_cnt; q++) { - if (!cd_ctx[w].device[q].selected) continue; + + if (!cd_ctx[w].device[q].selected) { + continue; + } ctx.global_ws[z] = (1 << profiles[profile][1]); // the following happens with cpu devices or Apple GPU if (ctx.local_ws[z] > 256) { - if (cd_ctx[w].is_apple) ctx.local_ws[z] = 256; - else if (!cd_ctx[w].device[q].is_gpu) ctx.local_ws[z] = 256; + + if (cd_ctx[w].is_apple) { + ctx.local_ws[z] = 256; + } else if (!cd_ctx[w].device[q].is_gpu) { + ctx.local_ws[z] = 256; + } } // dow't allow gws < lws - if (ctx.global_ws[z] < ctx.local_ws[z]) ctx.local_ws[z] = ctx.global_ws[z]; + if (ctx.global_ws[z] < ctx.local_ws[z]) { + ctx.local_ws[z] = ctx.global_ws[z]; + } if (opencl_profiling) { printf("[%zu] global_ws %zu, local_ws %zu\n", g, ctx.global_ws[z], ctx.local_ws[z]); } if (!ctx.force_hitag2_opencl) { + if (!(matches[z] = (uint64_t *) calloc((uint32_t)(ctx.global_ws[z] * WGS_MATCHES_FACTOR), sizeof(uint64_t)))) { printf("[%zu] Error: calloc (matches) failed (%d): %s\n", g, errno, strerror(errno)); MEMORY_FREE_OPENCL(ctx, z) @@ -937,7 +954,9 @@ int main(int argc, char **argv) { MEMORY_FREE_ALL exit(2); } + } else { // one + if (!(matches[z] = (uint64_t *) calloc(1, sizeof(uint64_t)))) { printf("[%zu] Error: calloc (matches) failed (%d): %s\n", z, errno, strerror(errno)); MEMORY_FREE_OPENCL(ctx, z) @@ -1093,7 +1112,9 @@ int main(int argc, char **argv) { printf("[queue] Fill queue with pre-calculated offset using profile (%d): ", profile); #endif - for (size_t step = 0; step < max_step; step++) wu_queue_push(&ctx.queue_ctx, step, step << chunk, max_step); + for (size_t step = 0; step < max_step; step++) { + wu_queue_push(&ctx.queue_ctx, step, step << chunk, max_step); + } #if DEBUGME > 0 printf("done\n"); diff --git a/tools/hitag2crack/crack5opencl/opencl.c b/tools/hitag2crack/crack5opencl/opencl.c index 04daa8b90..5b262ab84 100644 --- a/tools/hitag2crack/crack5opencl/opencl.c +++ b/tools/hitag2crack/crack5opencl/opencl.c @@ -29,13 +29,18 @@ bool plat_dev_enabled(unsigned int id, const unsigned int *sel, unsigned int cnt, unsigned int cur_type, unsigned int allow_type) { // usefulonly with devices if (allow_type != CL_DEVICE_TYPE_ALL) { - if (cur_type != allow_type) return false; + if (cur_type != allow_type) { + return false; + } } - if (sel[0] == 0xff) return true; // all - else { + if (sel[0] == 0xff) { + return true; // all + } else { for (unsigned int i = 0; i < cnt; i++) { - if (sel[i] == (id + 1)) return true; + if (sel[i] == (id + 1)) { + return true; + } } } @@ -43,15 +48,18 @@ bool plat_dev_enabled(unsigned int id, const unsigned int *sel, } unsigned int get_smallest_profile(compute_platform_ctx_t *cd_ctx, size_t ocl_platform_cnt) { - unsigned int profile = 0xff; - size_t x = 0, y = 0; + unsigned int profile = 0xFF; - for (x = 0; x < ocl_platform_cnt; x++) { - if (!cd_ctx[x].selected) continue; + for (int x = 0; x < ocl_platform_cnt; x++) { + if (!cd_ctx[x].selected) { + continue; + } - for (y = 0; y < cd_ctx[x].device_cnt; y++) { - if (!cd_ctx[x].device[y].selected) continue; + for (int y = 0; y < cd_ctx[x].device_cnt; y++) { + if (!cd_ctx[x].device[y].selected) { + continue; + } #if DEBUGME > 1 printf("[debug] Initial profile for device %zu: %d\n", y, cd_ctx[x].device[y].profile); @@ -59,12 +67,16 @@ unsigned int get_smallest_profile(compute_platform_ctx_t *cd_ctx, size_t ocl_pla // with same devices will be selected the best // but for different devices in the same platform we need the worst for now (todo) - if (cd_ctx[x].device[y].profile < profile) profile = cd_ctx[x].device[y].profile; + if (cd_ctx[x].device[y].profile < profile) { + profile = cd_ctx[x].device[y].profile; + } } } // at worst, set profile to 0 - if (profile > 10) profile = 0; + if (profile > 10) { + profile = 0; + } return profile; } @@ -118,17 +130,26 @@ int discoverDevices(unsigned int profile_selected, uint32_t device_types_selecte unsigned int global_device_id = 0; - if (verbose) printf("- Found %u OpenCL Platform(s)\n", ocl_platform_cnt); + if (verbose) { + printf("- Found %u OpenCL Platform(s)\n", ocl_platform_cnt); + } for (cl_uint platform_idx = 0; platform_idx < ocl_platform_cnt; platform_idx++) { + (*cd_ctx)[platform_idx].platform_id = ocl_platforms[platform_idx]; + (*cd_ctx)[platform_idx].selected = plat_dev_enabled(platform_idx, plat_sel, plat_cnt, 0, 0); - if ((*cd_ctx)[platform_idx].selected)(*selected_platforms_cnt)++; + if ((*cd_ctx)[platform_idx].selected) { + (*selected_platforms_cnt)++; + } - if (verbose) printf("\n-- Platform ID: %u\n", platform_idx + 1); + if (verbose) { + printf("\n-- Platform ID: %u\n", platform_idx + 1); + } for (info_idx = 0; info_idx < ocl_platforms_info_cnt; info_idx++) { + cl_platform_info ocl_info = ocl_platforms_info[info_idx]; err = clGetPlatformInfo((*cd_ctx)[platform_idx].platform_id, ocl_info, 0, NULL, &tmp_len); @@ -169,7 +190,6 @@ int discoverDevices(unsigned int profile_selected, uint32_t device_types_selecte if (verbose) { const char *tmp_info_desc = (info_idx == 0) ? "Name" : (info_idx == 1) ? "Vendor" : "Version"; - printf("%14s: %s\n", tmp_info_desc, tmp_buf); } @@ -186,18 +206,31 @@ int discoverDevices(unsigned int profile_selected, uint32_t device_types_selecte } if (info_idx == 1) { - if (!strncmp(tmp_buf, "NVIDIA", 6))(*cd_ctx)[platform_idx].is_nv = true; - else if (!strncmp(tmp_buf, "Apple", 5)) { (*cd_ctx)[platform_idx].is_apple = true; (*cd_ctx)[platform_idx].warning = true; } - else if (!strncmp(tmp_buf, "Intel", 5))(*cd_ctx)[platform_idx].is_intel = true; - else if (!strncmp(tmp_buf, "The pocl project", 16))(*cd_ctx)[platform_idx].is_pocl = true; - } + if (!strncmp(tmp_buf, "NVIDIA", 6)) { + (*cd_ctx)[platform_idx].is_nv = true; + + } else if (!strncmp(tmp_buf, "Apple", 5)) { + (*cd_ctx)[platform_idx].is_apple = true; + (*cd_ctx)[platform_idx].warning = true; + + } else if (!strncmp(tmp_buf, "Intel", 5)) { + (*cd_ctx)[platform_idx].is_intel = true; + + } else if (!strncmp(tmp_buf, "The pocl project", 16)) { + (*cd_ctx)[platform_idx].is_pocl = true; + } + } free(tmp_buf); } if (!show && verbose) { + printf("%14s: %s\n", "Selected", ((*cd_ctx)[platform_idx].selected) ? "yes" : "no"); - if ((*cd_ctx)[platform_idx].warning) printf("\n%14s: performance will not be optimal using this platform\n\n", "=====> Warning"); + + if ((*cd_ctx)[platform_idx].warning) { + printf("\n%14s: performance will not be optimal using this platform\n\n", "=====> Warning"); + } } // enum devices with this platform @@ -214,7 +247,9 @@ int discoverDevices(unsigned int profile_selected, uint32_t device_types_selecte err = clGetDeviceIDs((*cd_ctx)[platform_idx].platform_id, CL_DEVICE_TYPE_ALL, ocl_device_max, ocl_devices, &ocl_device_cnt); if (ocl_device_cnt == 0) { - if (device_types_selected == CL_DEVICE_TYPE_ALL) printf("No device(s) available with platform id %u\n", platform_idx); + if (device_types_selected == CL_DEVICE_TYPE_ALL) { + printf("No device(s) available with platform id %u\n", platform_idx); + } (*cd_ctx)[platform_idx].device_cnt = 0; continue; } @@ -227,16 +262,23 @@ int discoverDevices(unsigned int profile_selected, uint32_t device_types_selecte return -9; } - if (verbose) printf("%14s: %u\n", "Device(s)", ocl_device_cnt); + if (verbose) { + printf("%14s: %u\n", "Device(s)", ocl_device_cnt); + } (*cd_ctx)[platform_idx].device_cnt = ocl_device_cnt; for (unsigned int device_idx = 0; device_idx < ocl_device_cnt; device_idx++) { + memset(&(*cd_ctx)[platform_idx].device[device_idx], 0, sizeof(compute_device_ctx_t)); + cl_device_id ocl_device = ocl_devices[device_idx]; + (*cd_ctx)[platform_idx].device[device_idx].platform_id = (*cd_ctx)[platform_idx].platform_id; - if (verbose) printf("---- * ID: %u\n", global_device_id + 1); + if (verbose) { + printf("---- * ID: %u\n", global_device_id + 1); + } for (info_idx = 0; info_idx < ocl_devices_info_cnt; info_idx++) { cl_device_info ocl_dev_info = ocl_devices_info[info_idx]; @@ -253,19 +295,31 @@ int discoverDevices(unsigned int profile_selected, uint32_t device_types_selecte return -10; } - if (device_type & CL_DEVICE_TYPE_GPU)(*cd_ctx)[platform_idx].device[device_idx].is_gpu = 1; - else if ((device_type & CL_DEVICE_TYPE_CPU) && (*cd_ctx)[platform_idx].is_pocl) { + if (device_type & CL_DEVICE_TYPE_GPU) { + (*cd_ctx)[platform_idx].device[device_idx].is_gpu = 1; + } else if ((device_type & CL_DEVICE_TYPE_CPU) && (*cd_ctx)[platform_idx].is_pocl) { (*cd_ctx)[platform_idx].device[device_idx].profile = (profile_selected > 1) ? 0 : profile_selected; } - if (verbose) printf("%14s: %s\n", "Device Type", (device_type & CL_DEVICE_TYPE_GPU) ? "GPU" : (device_type & CL_DEVICE_TYPE_CPU) ? "CPU" : "Other"); + if (verbose) { + printf("%14s: %s\n", "Device Type", (device_type & CL_DEVICE_TYPE_GPU) ? "GPU" : (device_type & CL_DEVICE_TYPE_CPU) ? "CPU" : "Other"); + } - if ((*cd_ctx)[platform_idx].selected == false)(*cd_ctx)[platform_idx].device[device_idx].selected = false; - else (*cd_ctx)[platform_idx].device[device_idx].selected = plat_dev_enabled(global_device_id, dev_sel, dev_cnt, (unsigned int) device_type, device_types_selected); + if ((*cd_ctx)[platform_idx].selected == false) { + (*cd_ctx)[platform_idx].device[device_idx].selected = false; + } else { + (*cd_ctx)[platform_idx].device[device_idx].selected = plat_dev_enabled(global_device_id, dev_sel, dev_cnt, (unsigned int) device_type, device_types_selected); + } + global_device_id++; - if ((*cd_ctx)[platform_idx].device[device_idx].selected)(*selected_devices_cnt)++; + + if ((*cd_ctx)[platform_idx].device[device_idx].selected) { + (*selected_devices_cnt)++; + } + continue; } else if (info_idx == 5) { + cl_device_local_mem_type local_mem_type; err = clGetDeviceInfo(ocl_device, ocl_dev_info, sizeof(cl_device_local_mem_type), &local_mem_type, 0); @@ -278,29 +332,47 @@ int discoverDevices(unsigned int profile_selected, uint32_t device_types_selecte } if (local_mem_type == CL_LOCAL || local_mem_type == CL_GLOBAL) { - if (verbose) printf("%14s: %s\n", "Local Mem Type", (local_mem_type == CL_LOCAL) ? "Local" : "Global"); + + if (verbose) { + printf("%14s: %s\n", "Local Mem Type", (local_mem_type == CL_LOCAL) ? "Local" : "Global"); + } + if ((*cd_ctx)[platform_idx].is_apple) { + if (strncmp((*cd_ctx)[platform_idx].device[device_idx].vendor, "Intel", 5) != 0) { + (*cd_ctx)[platform_idx].device[device_idx].have_local_memory = true; if ((*cd_ctx)[platform_idx].device[device_idx].is_gpu) { - if (profile_selected > 2)(*cd_ctx)[platform_idx].device[device_idx].profile = PROFILE_DEFAULT; // Apple-Intel GPU's + if (profile_selected > 2) { + (*cd_ctx)[platform_idx].device[device_idx].profile = PROFILE_DEFAULT; // Apple-Intel GPU's + } } else { - if (profile_selected > 3)(*cd_ctx)[platform_idx].device[device_idx].profile = PROFILE_DEFAULT; // Apple-Intel CPU's + if (profile_selected > 3) { + (*cd_ctx)[platform_idx].device[device_idx].profile = PROFILE_DEFAULT; // Apple-Intel CPU's + } } } + } else if ((*cd_ctx)[platform_idx].is_nv) { (*cd_ctx)[platform_idx].device[device_idx].have_local_memory = true; } + } else { - if (verbose) printf("%14s: None\n", "Local Mem Type"); + if (verbose) { + printf("%14s: None\n", "Local Mem Type"); + } } - if (verbose) printf("%14s: %s\n", "Local Mem Opt", ((*cd_ctx)[platform_idx].device[device_idx].have_local_memory) ? "yes" : "no"); + if (verbose) { + printf("%14s: %s\n", "Local Mem Opt", ((*cd_ctx)[platform_idx].device[device_idx].have_local_memory) ? "yes" : "no"); + } continue; } else if (info_idx == 6) { + size_t wis[3] = { 0 }; + err = clGetDeviceInfo(ocl_device, ocl_dev_info, sizeof(size_t) * 3, wis, 0); if (err != CL_SUCCESS) { printf("Error: clGetDeviceInfo(work_items_size) failed (%d)\n", err); @@ -310,7 +382,9 @@ int discoverDevices(unsigned int profile_selected, uint32_t device_types_selecte return -10; } - if (verbose) printf("%14s: (%zu,%zu,%zu)\n", "Max Work-Items", wis[0], wis[1], wis[2]); + if (verbose) { + printf("%14s: (%zu,%zu,%zu)\n", "Max Work-Items", wis[0], wis[1], wis[2]); + } #if APPLE_GPU_BROKEN == 1 if (wis[1] < GLOBAL_WS_1 && (*cd_ctx)[platform_idx].device[device_idx].is_apple_gpu) { @@ -318,8 +392,11 @@ int discoverDevices(unsigned int profile_selected, uint32_t device_types_selecte } #endif continue; + } else if (info_idx == 7) { + cl_uint cores = 0; + err = clGetDeviceInfo(ocl_device, ocl_dev_info, sizeof(cl_uint), &cores, 0); if (err != CL_SUCCESS) { printf("Error: clGetDeviceInfo(compute_units) failed (%d)\n", err); @@ -329,7 +406,9 @@ int discoverDevices(unsigned int profile_selected, uint32_t device_types_selecte return -10; } - if (verbose) printf("%14s: %u\n", "Compute Units", cores); + if (verbose) { + printf("%14s: %u\n", "Compute Units", cores); + } (*cd_ctx)[platform_idx].device[device_idx].compute_units = cores; continue; @@ -404,8 +483,11 @@ int discoverDevices(unsigned int profile_selected, uint32_t device_types_selecte if (strstr(tmp_buf, "Tegra") && (*cd_ctx)[platform_idx].is_pocl) { (*cd_ctx)[platform_idx].device[device_idx].profile = (profile_selected > 1) ? 0 : profile_selected; } + } else if (info_idx == 4) { + if (!strncmp(tmp_buf, "Intel", 5)) { + if ((*cd_ctx)[platform_idx].is_apple) { (*cd_ctx)[platform_idx].device[device_idx].is_apple_gpu = (*cd_ctx)[platform_idx].device[device_idx].is_gpu; } @@ -438,7 +520,9 @@ int discoverDevices(unsigned int profile_selected, uint32_t device_types_selecte (*cd_ctx)[platform_idx].device[device_idx].sm_maj = sm_maj; (*cd_ctx)[platform_idx].device[device_idx].sm_min = sm_min; - if (verbose) printf("%14s: %u%u\n", "SM", sm_maj, sm_min); + if (verbose) { + printf("%14s: %u%u\n", "SM", sm_maj, sm_min); + } if (sm_maj >= 5) { // >= Maxwell // https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#logic-and-shift-instructions-lop3 @@ -464,7 +548,9 @@ int discoverDevices(unsigned int profile_selected, uint32_t device_types_selecte free(tmp_buf); } - if (!show && verbose) printf("%14s: %s\n", "Selected", ((*cd_ctx)[platform_idx].device[device_idx].selected) ? "yes" : "no"); + if (!show && verbose) { + printf("%14s: %s\n", "Selected", ((*cd_ctx)[platform_idx].device[device_idx].selected) ? "yes" : "no"); + } if ((*cd_ctx)[platform_idx].device[device_idx].unsupported) { printf("\n%14s: this device was not supported, because of missing resources\n\n", "=====> Warning"); @@ -472,7 +558,9 @@ int discoverDevices(unsigned int profile_selected, uint32_t device_types_selecte } if ((*cd_ctx)[platform_idx].device[device_idx].warning) { - if (!show && verbose) printf("\n%14s: performance will not be optimal using this device\n\n", "=====> Warning"); + if (!show && verbose) { + printf("\n%14s: performance will not be optimal using this device\n\n", "=====> Warning"); + } } (*cd_ctx)[platform_idx].device[device_idx].device_id = ocl_device; @@ -486,7 +574,9 @@ int discoverDevices(unsigned int profile_selected, uint32_t device_types_selecte *platform_detected_cnt = ocl_platform_cnt; - if (show) free(*cd_ctx); + if (show) { + free(*cd_ctx); + } return 0; } @@ -582,7 +672,7 @@ int runKernel(opencl_ctx_t *ctx, uint32_t cand_base, uint64_t *matches, uint32_t if (ctx->force_hitag2_opencl) { if (matches_found[0] != 1) printf("[%zu] BUG: if match the counter must be 1. Here %u are founds\n", id, matches_found[0]); } else { - if (matches_found[0] > (uint32_t)(ctx->global_ws[id]*WGS_MATCHES_FACTOR)) { + if (matches_found[0] > (uint32_t)(ctx->global_ws[id] * WGS_MATCHES_FACTOR)) { printf("[%zu] BUG: the next clEnqueueReadBuffer will crash. 'matches' buffer (%u) is lower than requested (%u)\n", id, (uint32_t)(ctx->global_ws[id]*WGS_MATCHES_FACTOR), matches_found[0]); } }