1#![allow(non_camel_case_types)]
2
3use std::ffi::c_void;
4use std::os::raw::c_char;
5
6pub type size_t = usize;
7
8pub type cl_platform_id = *mut c_void;
9pub type cl_device_id = *mut c_void;
10pub type cl_context = *mut c_void;
11pub type cl_command_queue = *mut c_void;
12pub type cl_mem = *mut c_void;
13pub type cl_program = *mut c_void;
14pub type cl_kernel = *mut c_void;
15pub type cl_event = *mut c_void;
16
17pub type cl_int = i32;
18pub type cl_uint = u32;
19pub type cl_long = i64;
20pub type cl_ulong = u64;
21pub type cl_bool = cl_uint;
23pub type cl_bitfield = cl_ulong;
24pub type cl_device_type = cl_bitfield;
25pub type cl_platform_info = cl_uint;
26pub type cl_device_info = cl_uint;
27pub type cl_command_queue_properties = cl_bitfield;
28pub type cl_context_properties = isize;
29pub type cl_mem_flags = cl_bitfield;
30pub type cl_program_info = cl_uint;
31pub type cl_kernel_work_group_info = cl_uint;
32pub type cl_program_build_info = cl_uint;
33pub type cl_map_flags = cl_bitfield;
34
35pub const CL_KERNEL_WORK_GROUP_SIZE: cl_uint = 0x11B0;
37pub const CL_KERNEL_COMPILE_WORK_GROUP_SIZE: cl_uint = 0x11B1;
38pub const CL_KERNEL_LOCAL_MEM_SIZE: cl_uint = 0x11B2;
39pub const CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE: cl_uint = 0x11B3;
40pub const CL_KERNEL_PRIVATE_MEM_SIZE: cl_uint = 0x11B4;
41pub const CL_KERNEL_GLOBAL_WORK_SIZE: cl_uint = 0x11B5;
42
43#[cfg_attr(target_os = "macos", link(name = "OpenCL", kind = "framework"))]
44#[cfg_attr(target_os = "windows", link(name = "OpenCL"))]
45#[cfg_attr(not(target_os = "macos"), link(name = "OpenCL"))]
46extern "system" {
47 pub fn clGetPlatformIDs(
48 num_entries: cl_uint,
49 platforms: *mut cl_platform_id,
50 num_platforms: *mut cl_uint,
51 ) -> cl_int;
52
53 pub fn clGetPlatformInfo(
54 platform: cl_platform_id,
55 param_name: cl_platform_info,
56 param_value_size: size_t,
57 param_value: *mut c_void,
58 param_value_size_ret: *mut size_t,
59 ) -> cl_int;
60
61 pub fn clGetDeviceIDs(
62 platform: cl_platform_id,
63 device_type: cl_device_type,
64 num_entries: cl_uint,
65 devices: *mut cl_device_id,
66 num_devices: *mut cl_uint,
67 ) -> cl_int;
68
69 pub fn clGetDeviceInfo(
70 device: cl_device_id,
71 param_name: cl_device_info,
72 param_value_size: size_t,
73 param_value: *mut c_void,
74 param_value_size_ret: *mut size_t,
75 ) -> cl_int;
76
77 pub fn clCreateContext(
78 properties: *const cl_context_properties,
79 num_devices: cl_uint,
80 devices: *const cl_device_id,
81 pfn_notify: *mut c_void,
82 user_data: *mut c_void,
83 errcode_ret: *mut cl_int,
84 ) -> cl_context;
85
86 pub fn clReleaseContext(context: cl_context) -> cl_int;
87
88 pub fn clCreateCommandQueue(
89 context: cl_context,
90 device: cl_device_id,
91 properties: cl_command_queue_properties,
92 errcode_ret: *mut cl_int,
93 ) -> cl_command_queue;
94
95 pub fn clFinish(command_queue: cl_command_queue) -> cl_int;
96
97 pub fn clReleaseCommandQueue(command_queue: cl_command_queue) -> cl_int;
98
99 pub fn clWaitForEvents(num_events: cl_uint, event_list: *const cl_event) -> cl_int;
100
101 pub fn clReleaseEvent(event: cl_event) -> cl_int;
102
103 pub fn clCreateBuffer(
104 context: cl_context,
105 flags: cl_mem_flags,
106 size: size_t,
107 host_ptr: *mut c_void,
108 errcode_ret: *mut cl_int,
109 ) -> cl_mem;
110
111 pub fn clRetainMemObject(memobj: cl_mem) -> cl_int;
112
113 pub fn clReleaseMemObject(memobj: cl_mem) -> cl_int;
114
115 pub fn clEnqueueReadBuffer(
116 command_queue: cl_command_queue,
117 buffer: cl_mem,
118 blocking_read: cl_bool,
119 offset: size_t,
120 cb: size_t,
121 ptr: *mut c_void,
122 num_events_in_wait_list: cl_uint,
123 event_wait_list: *const cl_event,
124 event: *mut cl_event,
125 ) -> cl_int;
126
127 pub fn clEnqueueWriteBuffer(
128 command_queue: cl_command_queue,
129 buffer: cl_mem,
130 blocking_write: cl_bool,
131 offset: size_t,
132 cb: size_t,
133 ptr: *const c_void,
134 num_events_in_wait_list: cl_uint,
135 event_wait_list: *const cl_event,
136 event: *mut cl_event,
137 ) -> cl_int;
138
139 pub fn clEnqueueCopyBuffer(
140 command_queue: cl_command_queue,
141 src_buffer: cl_mem,
142 dst_buffer: cl_mem,
143 src_offset: size_t,
144 dst_offset: size_t,
145 cb: size_t,
146 num_events_in_wait_list: cl_uint,
147 event_wait_list: *const cl_event,
148 event: *mut cl_event,
149 ) -> cl_int;
150
151 pub fn clEnqueueMapBuffer(
152 command_queue: cl_command_queue,
153 buffer: cl_mem,
154 blocking_map: cl_bool,
155 map_flags: cl_map_flags,
156 offset: size_t,
157 size: size_t,
158 num_events_in_wait_list: cl_uint,
159 event_wait_list: *const cl_event,
160 event: *mut cl_event,
161 errorcode_ret: *mut cl_int,
162 ) -> *mut c_void;
163
164 pub fn clEnqueueFillBuffer(
165 command_queue: cl_command_queue,
166 buffer: cl_mem,
167 pattern: *const c_void,
168 pattern_size: size_t,
169 offset: size_t,
170 size: size_t,
171 num_events_in_wait_list: cl_uint,
172 event_wait_list: *const cl_event,
173 event: *mut cl_event,
174 ) -> cl_int;
175
176 pub fn clReleaseProgram(program: cl_program) -> cl_int;
177
178 pub fn clGetProgramInfo(
179 program: cl_program,
180 param_name: cl_program_info,
181 param_value_size: size_t,
182 param_value: *mut c_void,
183 param_value_size_ret: *mut size_t,
184 ) -> cl_int;
185
186 pub fn clCreateProgramWithSource(
187 context: cl_context,
188 count: cl_uint,
189 strings: *const *const c_char,
190 lengths: *const size_t,
191 errcode_ret: *mut cl_int,
192 ) -> cl_program;
193
194 pub fn clGetProgramBuildInfo(
195 program: cl_program,
196 device: cl_device_id,
197 param_name: cl_program_build_info,
198 param_value_size: size_t,
199 param_value: *mut c_void,
200 param_value_size_ret: *mut size_t,
201 ) -> cl_int;
202
203 pub fn clBuildProgram(
204 program: cl_program,
205 num_devices: cl_uint,
206 device_list: *const cl_device_id,
207 options: *const c_char,
208 pfn_notify: *mut c_void,
209 user_data: *mut c_void,
210 ) -> cl_int;
211
212 pub fn clCreateKernel(
213 program: cl_program,
214 kernel_name: *const c_char,
215 errcode_ret: *mut cl_int,
216 ) -> cl_kernel;
217
218 pub fn clCreateKernelsInProgram(
219 program: cl_program,
220 num_kernels: cl_uint,
221 kernels: *mut cl_kernel,
222 num_kernels_ret: *mut cl_uint,
223 ) -> cl_int;
224 pub fn clReleaseKernel(kernel: cl_kernel) -> cl_int;
225
226 pub fn clSetKernelArg(
227 kernel: cl_kernel,
228 arg_index: cl_uint,
229 arg_size: size_t,
230 arg_value: *const c_void,
231 ) -> cl_int;
232
233 pub fn clGetKernelWorkGroupInfo(
234 kernel: cl_kernel,
235 device: cl_device_id,
236 param_name: cl_kernel_work_group_info,
237 param_value_size: size_t,
238 param_value: *mut c_void,
239 param_value_size_ret: *mut size_t,
240 ) -> cl_int;
241
242 pub fn clEnqueueNDRangeKernel(
243 command_queue: cl_command_queue,
244 kernel: cl_kernel,
245 work_dim: cl_uint,
246 global_work_offset: *const size_t,
247 global_work_dims: *const size_t,
248 local_work_dims: *const size_t,
249 num_events_in_wait_list: cl_uint,
250 event_wait_list: *const cl_event,
251 event: *mut cl_event,
252 ) -> cl_int;
253
254 pub fn clCreateProgramWithBinary(
255 context: cl_context,
256 num_devices: cl_uint,
257 device_list: *const cl_device_id,
258 lenghts: *const usize,
259 binaries: *const *const u8,
260 binary_status: &mut cl_int,
261 errcode_ret: &mut cl_int,
262 ) -> cl_program;
263}