source: trunk/CrypPlugins/Libs/OpenCLNet/OpenCLAPI.cs @ 2040

Last change on this file since 2040 was 2040, checked in by Sven Rech, 11 years ago
  • added OpenCL.Net project
  • added OpenCL settings in KeySearcher
  • changed rereservation status message behavior
File size: 43.2 KB
Line 
1/*
2 * Copyright (c) 2009 Olav Kalgraf(olav.kalgraf@gmail.com)
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26// Toggles D3D10 extension support
27// NOTE: The C# API is not done yet, but enabling it will let you call something like the raw C API
28#define D3D10_Extension
29
30// Toggles Device fission support
31// NOTE: The C# API is not done yet, but enabling it will let you call something like the raw C API
32#define DEVICE_FISSION_Extension
33
34using System;
35using System.Collections.Generic;
36using System.Linq;
37using System.Text;
38using System.Runtime.InteropServices;
39using System.Diagnostics;
40using System.Security;
41
42namespace OpenCLNet
43{
44    #region Using statements
45
46    using cl_char=SByte;
47    using cl_uchar=Byte;
48    using cl_short=Byte;
49    using cl_ushort=Byte;
50    using cl_int=Int32;
51    using cl_uint=UInt32;
52    using cl_long=Int64;
53    using cl_ulong=UInt64;
54    using cl_half=UInt16;
55    using cl_float=Single;
56    using cl_double=Double;
57
58    using cl_platform_id=IntPtr;
59    using cl_device_id=IntPtr;
60    using cl_context=IntPtr;
61    using cl_command_queue=IntPtr;
62    using cl_mem=IntPtr;
63    using cl_program=IntPtr;
64    using cl_kernel=IntPtr;
65    using cl_event=IntPtr;
66    using cl_sampler=IntPtr;
67
68    using cl_bool=UInt32;
69    using cl_bitfield=UInt64;
70    using cl_device_type=UInt64;
71    using cl_platform_info=UInt32;
72    using cl_device_info=UInt32;
73    using cl_device_address_info=UInt64;
74    using cl_device_fp_config=UInt64;
75    using cl_device_mem_cache_type=UInt32;
76    using cl_device_local_mem_type=UInt32;
77    using cl_device_exec_capabilities=UInt64;
78    using cl_command_queue_properties=UInt64;
79
80    using cl_context_properties=IntPtr;
81    using cl_context_info=UInt32;
82    using cl_command_queue_info=UInt32;
83    using cl_channel_order=UInt32;
84    using cl_channel_type=UInt32;
85    using cl_mem_flags=UInt64;
86    using cl_mem_object_type=UInt32;
87    using cl_mem_info=UInt32;
88    using cl_image_info=UInt32;
89    using cl_addressing_mode=UInt32;
90    using cl_filter_mode=UInt32;
91    using cl_sampler_info=UInt32;
92    using cl_map_flags=UInt64;
93    using cl_program_info=UInt32;
94    using cl_program_build_info=UInt32;
95    using cl_build_status=Int32;
96    using cl_kernel_info=UInt32;
97    using cl_kernel_work_group_info=UInt32;
98    using cl_event_info=UInt32;
99    using cl_command_type=UInt32;
100    using cl_profiling_info=UInt32;
101
102    using cl_gl_object_type=UInt32;
103    using cl_gl_texture_info=UInt32;
104    using cl_gl_platform_info=UInt32;
105    using cl_gl_context_info=UInt32;
106    using GLuint=UInt32;
107    using GLint=Int32;
108    using GLenum=Int32;
109
110    using cl_device_partition_property_ext=UInt64;
111   
112    using cl_d3d10_device_source_khr = UInt32;
113    using cl_d3d10_device_set_khr = UInt32;
114    using UINT = UInt32;
115    using ID3D10Buffer = IntPtr;
116    using ID3D10Texture2D = IntPtr;
117    using ID3D10Texture3D = IntPtr;
118
119    #endregion
120
121
122#if D3D10_Extension
123    // D3D10 Delegates
124    public unsafe delegate ErrorCode clGetDeviceIDsFromD3D10KHRDelegate(cl_platform_id platform, cl_d3d10_device_source_khr d3d_device_source, void* d3d_object, cl_d3d10_device_set_khr d3d_device_set, cl_uint num_entries, cl_device_id* devices, cl_uint* num_devices);
125    public unsafe delegate cl_mem clCreateFromD3D10BufferKHRDelegate(cl_context context, cl_mem_flags flags, ID3D10Buffer* resource, out ErrorCode errcode_ret);
126    public unsafe delegate cl_mem clCreateFromD3D10Texture2DKHRDelegate(cl_context context, cl_mem_flags flags, ID3D10Texture2D* resource, UINT subresource, out ErrorCode errcode_ret);
127    public unsafe delegate cl_mem clCreateFromD3D10Texture3DKHRDelegate(cl_context context, cl_mem_flags flags, ID3D10Texture3D* resource, UINT subresource, out ErrorCode errcode_ret);
128    public unsafe delegate ErrorCode clEnqueueAcquireD3D10ObjectsKHRDelegate(cl_command_queue command_queue, cl_uint num_objects, cl_mem* mem_objects, cl_uint num_events_in_wait_list, cl_event* event_wait_list, cl_event* _event);
129    public unsafe delegate ErrorCode clEnqueueReleaseD3D10ObjectsKHRDelegate(cl_command_queue command_queue, cl_uint num_objects, cl_mem* mem_objects, cl_uint num_events_in_wait_list, cl_event* event_wait_list, cl_event* _event);
130#endif
131
132#if DEVICE_FISSION_Extension
133        public delegate ErrorCode clReleaseDeviceEXTDelegate(cl_device_id device);
134        public delegate ErrorCode clRetainDeviceEXTDelegate(cl_device_id device);
135        public unsafe delegate ErrorCode clCreateSubDevicesEXTDelegate(cl_device_id in_device,
136            [In] byte[] properties,
137            cl_uint num_entries,
138            [In] [Out] [MarshalAs(UnmanagedType.LPArray,SizeParamIndex=4)] cl_device_id[] out_devices,
139            [Out] cl_uint* num_devices );
140#endif
141
142    /// <summary>
143    /// OpenCLAPI - native bindings
144    /// </summary>
145    [SuppressUnmanagedCodeSecurity()]
146    unsafe public static class OpenCLAPI
147    {
148        internal static class Configuration
149        {
150            public const string Library = "opencl.dll";
151        }
152   
153        static OpenCLAPI()
154        {
155
156#if D3D10_Extension
157            {
158                // Get function pointers for D3D10 extension
159                IntPtr func;
160                func = OpenCLAPI.clGetExtensionFunctionAddress("clGetDeviceIDsFromD3D10KHR");
161                if (func != IntPtr.Zero)
162                    clGetDeviceIDsFromD3D10KHR = (clGetDeviceIDsFromD3D10KHRDelegate)Marshal.GetDelegateForFunctionPointer(func, typeof(clGetDeviceIDsFromD3D10KHRDelegate));
163                func = OpenCLAPI.clGetExtensionFunctionAddress("clCreateFromD3D10BufferKHR");
164                if (func != IntPtr.Zero)
165                    clCreateFromD3D10BufferKHR = (clCreateFromD3D10BufferKHRDelegate)Marshal.GetDelegateForFunctionPointer(func, typeof(clCreateFromD3D10BufferKHRDelegate));
166                func = OpenCLAPI.clGetExtensionFunctionAddress("clCreateFromD3D10Texture2DKHR");
167                if (func != IntPtr.Zero)
168                    clCreateFromD3D10Texture2DKHR = (clCreateFromD3D10Texture2DKHRDelegate)Marshal.GetDelegateForFunctionPointer(func, typeof(clCreateFromD3D10Texture2DKHRDelegate));
169                func = OpenCLAPI.clGetExtensionFunctionAddress("clCreateFromD3D10Texture3DKHR");
170                if (func != IntPtr.Zero)
171                    clCreateFromD3D10Texture3DKHR = (clCreateFromD3D10Texture3DKHRDelegate)Marshal.GetDelegateForFunctionPointer(func, typeof(clCreateFromD3D10Texture3DKHRDelegate));
172                func = OpenCLAPI.clGetExtensionFunctionAddress("clEnqueueAcquireD3D10ObjectsKHR");
173                if (func != IntPtr.Zero)
174                    clEnqueueAcquireD3D10ObjectsKHR = (clEnqueueAcquireD3D10ObjectsKHRDelegate)Marshal.GetDelegateForFunctionPointer(func, typeof(clEnqueueAcquireD3D10ObjectsKHRDelegate));
175                func = OpenCLAPI.clGetExtensionFunctionAddress("clEnqueueReleaseD3D10ObjectsKHR");
176                if (func != IntPtr.Zero)
177                    clEnqueueReleaseD3D10ObjectsKHR = (clEnqueueReleaseD3D10ObjectsKHRDelegate)Marshal.GetDelegateForFunctionPointer(func, typeof(clEnqueueReleaseD3D10ObjectsKHRDelegate));
178            }
179#endif
180
181#if DEVICE_FISSION_Extension
182            {
183                // Get function pointers for the device fission extension
184                IntPtr func;
185                func = OpenCLAPI.clGetExtensionFunctionAddress("clReleaseDeviceEXT");
186                if (func != IntPtr.Zero)
187                    clReleaseDeviceEXT = (clReleaseDeviceEXTDelegate)Marshal.GetDelegateForFunctionPointer(func, typeof(clReleaseDeviceEXTDelegate));
188                func = OpenCLAPI.clGetExtensionFunctionAddress("clRetainDeviceEXT");
189                if (func != IntPtr.Zero)
190                    clRetainDeviceEXT = (clRetainDeviceEXTDelegate)Marshal.GetDelegateForFunctionPointer(func, typeof(clRetainDeviceEXTDelegate));
191                func = OpenCLAPI.clGetExtensionFunctionAddress("clCreateSubDevicesEXT");
192                if (func != IntPtr.Zero)
193                    clCreateSubDevicesEXT = (clCreateSubDevicesEXTDelegate)Marshal.GetDelegateForFunctionPointer(func, typeof(clCreateSubDevicesEXTDelegate));
194            }
195#endif
196        }
197
198        #region Platform API
199
200        // Platform API
201        [DllImport(Configuration.Library)]
202        public extern static cl_int clGetPlatformIDs(cl_uint num_entries, [Out] [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] cl_platform_id[] platforms, out cl_uint num_platforms);
203
204        [DllImport(Configuration.Library)]
205        public extern static cl_int clGetPlatformInfo(cl_platform_id platform, cl_platform_info param_name, IntPtr param_value_size, void* param_value, out IntPtr param_value_size_ret);
206
207        #endregion
208
209        #region Device API
210
211        // Device APIs
212        [DllImport(Configuration.Library)]
213        public extern static cl_int clGetDeviceIDs(cl_platform_id platform, [MarshalAs(UnmanagedType.U8)]DeviceType device_type, cl_uint num_entries, [Out][MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]cl_device_id[] devices, out cl_uint num_devices);
214
215        [DllImport(Configuration.Library)]
216        public extern static cl_int clGetDeviceInfo(cl_device_id device, cl_device_info param_name, IntPtr param_value_size, void* param_value, out IntPtr param_value_size_ret);
217
218        #endregion
219
220        #region Context API
221
222        // Context APIs
223        [DllImport(Configuration.Library)]
224        public extern static cl_context clCreateContext([In] cl_context_properties[] properties, cl_uint num_devices, [In]cl_device_id[] devices, ContextNotify pfn_notify, IntPtr user_data, [MarshalAs(UnmanagedType.I4)] out ErrorCode errcode_ret);
225        [DllImport(Configuration.Library)]
226        public extern static cl_context clCreateContextFromType([In] cl_context_properties[] properties, [MarshalAs(UnmanagedType.U8)]DeviceType device_type, ContextNotify pfn_notify, IntPtr user_data, [MarshalAs(UnmanagedType.I4)] out ErrorCode errcode_ret);
227        [DllImport(Configuration.Library)]
228        public extern static cl_int clRetainContext(cl_context context);
229        [DllImport(Configuration.Library)]
230        public extern static cl_int clReleaseContext(cl_context context);
231        [DllImport(Configuration.Library)]
232        public extern static cl_int clGetContextInfo(cl_context context, cl_context_info param_name, IntPtr param_value_size, void* param_value, out IntPtr param_value_size_ret);
233
234        #endregion
235
236        #region Program Object API
237
238        // Program Object APIs
239        [DllImport(Configuration.Library)]
240        public extern static cl_program clCreateProgramWithSource(cl_context context,
241            cl_uint count,
242            [In] string[] strings,
243            [In] IntPtr[] lengths,
244            [MarshalAs(UnmanagedType.I4)] out ErrorCode errcode_ret);
245        [DllImport(Configuration.Library)]
246        public extern static cl_program clCreateProgramWithBinary(cl_context context,
247            cl_uint num_devices,
248            [In] cl_device_id[] device_list,
249            [In] IntPtr[] lengths,
250            [In] IntPtr[] pBinaries,
251            [Out][MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] cl_int[] binary_status,
252            [MarshalAs(UnmanagedType.I4)] out ErrorCode errcode_ret);
253        [DllImport(Configuration.Library)]
254        public extern static cl_int clRetainProgram(cl_program program);
255        [DllImport(Configuration.Library)]
256        public extern static cl_int clReleaseProgram(cl_program program);
257        [DllImport(Configuration.Library)]
258        public extern static cl_int clBuildProgram(cl_program program,
259            cl_uint num_devices,
260            [In] cl_device_id[] device_list,
261            string options,
262            ProgramNotify pfn_notify,
263            IntPtr user_data);
264        [DllImport(Configuration.Library)]
265        public extern static cl_int clUnloadCompiler();
266        [DllImport(Configuration.Library)]
267        public extern static cl_int clGetProgramInfo(cl_program program, cl_program_info param_name, IntPtr param_value_size, void* param_value, out IntPtr param_value_size_ret);
268        [DllImport(Configuration.Library)]
269        public extern static cl_int clGetProgramBuildInfo(cl_program program, cl_device_id device, cl_program_build_info param_name, IntPtr param_value_size, void* param_value, out IntPtr param_value_size_ret);
270
271        #endregion
272
273        #region Command Queue API
274
275        // Command Queue APIs
276        [DllImport(Configuration.Library)]
277        public extern static IntPtr clCreateCommandQueue(cl_context context, cl_device_id device, cl_command_queue_properties properties, [MarshalAs(UnmanagedType.I4)] out ErrorCode errcode_ret);
278        [DllImport(Configuration.Library)]
279        public extern static ErrorCode clRetainCommandQueue(cl_command_queue command_queue);
280        [DllImport(Configuration.Library)]
281        public extern static ErrorCode clReleaseCommandQueue(cl_command_queue command_queue);
282        [DllImport(Configuration.Library)]
283        public extern static ErrorCode clGetCommandQueueInfo(cl_command_queue command_queue, cl_command_queue_info param_name, IntPtr param_value_size, void* param_value, out IntPtr param_value_size_ret);
284        [DllImport(Configuration.Library)]
285        [Obsolete("Function deprecated in OpenCL 1.1 due to being inherently unsafe",false)]
286        public extern static ErrorCode clSetCommandQueueProperty(cl_command_queue command_queue, cl_command_queue_properties properties, [MarshalAs(UnmanagedType.I4)]bool enable, out cl_command_queue_properties old_properties);
287
288        #endregion
289
290        #region Memory Object API
291
292        // Memory Object APIs
293        [DllImport(Configuration.Library)]
294        public extern static cl_mem clCreateBuffer(cl_context context, cl_mem_flags flags, IntPtr size, void* host_ptr, out ErrorCode errcode_ret);
295        [DllImport(Configuration.Library)]
296        public extern static cl_mem clCreateImage2D(cl_context context, cl_mem_flags flags, ImageFormat* image_format, IntPtr image_width, IntPtr image_height, IntPtr image_row_pitch, void* host_ptr, out ErrorCode errcode_ret);
297        [DllImport(Configuration.Library)]
298        public extern static cl_mem clCreateImage3D(cl_context context, cl_mem_flags flags, ImageFormat* image_format, IntPtr image_width, IntPtr image_height, IntPtr image_depth, IntPtr image_row_pitch, IntPtr image_slice_pitch, void* host_ptr, out ErrorCode errcode_ret);
299        [DllImport(Configuration.Library)]
300        public extern static ErrorCode clRetainMemObject(cl_mem memobj);
301        [DllImport(Configuration.Library)]
302        public extern static ErrorCode clReleaseMemObject(cl_mem memobj);
303        [DllImport(Configuration.Library)]
304        public extern static ErrorCode clGetSupportedImageFormats(cl_context context,
305            cl_mem_flags flags,
306            cl_mem_object_type image_type,
307            cl_uint num_entries,
308            [Out][MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] ImageFormat[] image_formats,
309            out cl_uint num_image_formats);
310        [DllImport(Configuration.Library)]
311        public extern static ErrorCode clGetMemObjectInfo(cl_mem memobj, cl_mem_info param_name, IntPtr param_value_size, void* param_value, out IntPtr param_value_size_ret);
312        [DllImport(Configuration.Library)]
313        public extern static ErrorCode clGetImageInfo(cl_mem image, cl_image_info param_name, IntPtr param_value_size, void* param_value, out IntPtr param_value_size_ret);
314
315        // OpenCL 1.1
316        [DllImport(Configuration.Library)]
317        public extern static cl_mem clCreateSubBuffer(cl_mem buffer, cl_mem_flags flags, BufferCreateType buffer_create_type, void* buffer_create_info, out ErrorCode errcode_ret );
318        [DllImport(Configuration.Library)]
319        public extern static ErrorCode clSetMemObjectDestructorCallback(cl_mem memobj, void* pfn_notify, void* user_data);
320        #endregion
321
322        #region Kernel Object API
323
324        // Kernel Object APIs
325        [DllImport(Configuration.Library)]
326        public extern static cl_kernel clCreateKernel(cl_program program, string kernel_name, out ErrorCode errcode_ret);
327        [DllImport(Configuration.Library)]
328        public extern static ErrorCode clCreateKernelsInProgram(cl_program program,
329            cl_uint num_kernels,
330            [Out][MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)]cl_kernel[] kernels,
331            out cl_uint num_kernels_ret);
332        [DllImport(Configuration.Library)]
333        public extern static ErrorCode clRetainKernel(cl_kernel kernel);
334        [DllImport(Configuration.Library)]
335        public extern static ErrorCode clReleaseKernel(cl_kernel kernel);
336        [DllImport(Configuration.Library)]
337        public extern static ErrorCode clSetKernelArg(cl_kernel kernel, cl_uint arg_index, IntPtr arg_size, void* arg_value);
338        [DllImport(Configuration.Library)]
339        public extern static ErrorCode clGetKernelInfo(cl_kernel kernel, cl_kernel_info param_name, IntPtr param_value_size, void* param_value, out IntPtr param_value_size_ret);
340        [DllImport(Configuration.Library)]
341        public extern static ErrorCode clGetKernelWorkGroupInfo(cl_kernel kernel, cl_device_id device, cl_kernel_work_group_info param_name, IntPtr param_value_size, void* param_value, out IntPtr param_value_size_ret);
342
343        #endregion
344
345        #region Enqueued Commands API
346
347        // Enqueued Commands APIs
348        [DllImport(Configuration.Library)]
349        public extern static ErrorCode clEnqueueReadBuffer(cl_command_queue command_queue,
350            cl_mem buffer,
351            cl_bool blocking_read,
352            IntPtr offset,
353            IntPtr cb,
354            void* ptr,
355            cl_uint num_events_in_wait_list,
356            [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] event_wait_list,
357            cl_event* _event);
358        [DllImport(Configuration.Library)]
359        public extern static ErrorCode clEnqueueReadBuffer(cl_command_queue command_queue,
360            cl_mem buffer,
361            cl_bool blocking_read,
362            IntPtr offset,
363            IntPtr cb,
364            void* ptr,
365            cl_uint num_events_in_wait_list,
366            IntPtr* event_wait_list,
367            cl_event* _event);
368
369
370        [DllImport(Configuration.Library)]
371        public extern static ErrorCode clEnqueueWriteBuffer(cl_command_queue command_queue,
372            cl_mem buffer,
373            cl_bool blocking_write,
374            IntPtr offset,
375            IntPtr cb,
376            void* ptr,
377            cl_uint num_events_in_wait_list,
378            [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] event_wait_list,
379            cl_event* _event);
380        [DllImport(Configuration.Library)]
381        public extern static ErrorCode clEnqueueWriteBuffer(cl_command_queue command_queue,
382            cl_mem buffer,
383            cl_bool blocking_write,
384            IntPtr offset,
385            IntPtr cb,
386            void* ptr,
387            cl_uint num_events_in_wait_list,
388            IntPtr* event_wait_list,
389            cl_event* _event);
390
391        [DllImport(Configuration.Library)]
392        public extern static ErrorCode clEnqueueCopyBuffer(cl_command_queue command_queue,
393            cl_mem src_buffer,
394            cl_mem dst_buffer,
395            IntPtr src_offset,
396            IntPtr dst_offset,
397            IntPtr cb,
398            cl_uint num_events_in_wait_list,
399            [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] event_wait_list,
400            cl_event* _event);
401        [DllImport(Configuration.Library)]
402        public extern static ErrorCode clEnqueueCopyBuffer(cl_command_queue command_queue,
403            cl_mem src_buffer,
404            cl_mem dst_buffer,
405            IntPtr src_offset,
406            IntPtr dst_offset,
407            IntPtr cb,
408            cl_uint num_events_in_wait_list,
409            IntPtr* event_wait_list,
410            cl_event* _event);
411
412        [DllImport(Configuration.Library)]
413        public extern static ErrorCode clEnqueueReadImage(cl_command_queue command_queue,
414            cl_mem image,
415            cl_bool blocking_read,
416            [In] [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)]IntPtr[] origin,
417            [In] [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)]IntPtr[] region,
418            IntPtr row_pitch,
419            IntPtr slice_pitch,
420            void* ptr,
421            cl_uint num_events_in_wait_list,
422            [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] event_wait_list,
423            cl_event* _event);
424        [DllImport(Configuration.Library)]
425        public extern static ErrorCode clEnqueueReadImage(cl_command_queue command_queue,
426            cl_mem image,
427            cl_bool blocking_read,
428            IntPtr* origin,
429            IntPtr* region,
430            IntPtr row_pitch,
431            IntPtr slice_pitch,
432            void* ptr,
433            cl_uint num_events_in_wait_list,
434            IntPtr* event_wait_list,
435            cl_event* _event);
436
437        [DllImport(Configuration.Library)]
438        public extern static ErrorCode clEnqueueWriteImage(cl_command_queue command_queue,
439            cl_mem image,
440            cl_bool blocking_write,
441            [In] [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)]IntPtr[] origin,
442            [In] [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)]IntPtr[] region,
443            IntPtr input_row_pitch,
444            IntPtr input_slice_pitch,
445            void* ptr,
446            cl_uint num_events_in_wait_list,
447            [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] event_wait_list,
448            cl_event* _event);
449        [DllImport(Configuration.Library)]
450        public extern static ErrorCode clEnqueueWriteImage(cl_command_queue command_queue,
451            cl_mem image,
452            cl_bool blocking_write,
453            IntPtr* origin,
454            IntPtr* region,
455            IntPtr input_row_pitch,
456            IntPtr input_slice_pitch,
457            void* ptr,
458            cl_uint num_events_in_wait_list,
459            IntPtr* event_wait_list,
460            cl_event* _event);
461
462        [DllImport(Configuration.Library)]
463        public extern static ErrorCode clEnqueueCopyImage(cl_command_queue command_queue,
464            cl_mem src_image,
465            cl_mem dst_image,
466            [In] [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)]IntPtr[] src_origin,
467            [In] [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)]IntPtr[] dst_origin,
468            [In] [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)]IntPtr[] region,
469            cl_uint num_events_in_wait_list,
470            [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] event_wait_list,
471            cl_event* _event);
472        [DllImport(Configuration.Library)]
473        public extern static ErrorCode clEnqueueCopyImage(cl_command_queue command_queue,
474            cl_mem src_image,
475            cl_mem dst_image,
476            IntPtr* src_origin,
477            IntPtr* dst_origin,
478            IntPtr* region,
479            cl_uint num_events_in_wait_list,
480            IntPtr* event_wait_list,
481            cl_event* _event);
482
483
484        [DllImport(Configuration.Library)]
485        public extern static ErrorCode clEnqueueCopyImageToBuffer(cl_command_queue command_queue,
486            cl_mem src_image,
487            cl_mem dst_buffer,
488            [In] [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)]IntPtr[] src_origin,
489            [In] [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)]IntPtr[] region,
490            IntPtr dst_offset,
491            cl_uint num_events_in_wait_list,
492            [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] event_wait_list,
493            cl_event* _event);
494        [DllImport(Configuration.Library)]
495        public extern static ErrorCode clEnqueueCopyImageToBuffer(cl_command_queue command_queue,
496            cl_mem src_image,
497            cl_mem dst_buffer,
498            IntPtr* src_origin,
499            IntPtr* region,
500            IntPtr dst_offset,
501            cl_uint num_events_in_wait_list,
502            IntPtr* event_wait_list,
503            cl_event* _event);
504
505        [DllImport(Configuration.Library)]
506        public extern static ErrorCode clEnqueueCopyBufferToImage(cl_command_queue command_queue,
507            cl_mem src_buffer,
508            cl_mem dst_image,
509            IntPtr src_offset,
510            [In] [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)]IntPtr[] dst_origin,
511            [In] [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)]IntPtr[] region,
512            cl_uint num_events_in_wait_list,
513            [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] event_wait_list,
514            cl_event* _event);
515        [DllImport(Configuration.Library)]
516        public extern static ErrorCode clEnqueueCopyBufferToImage(cl_command_queue command_queue,
517            cl_mem src_buffer,
518            cl_mem dst_image,
519            IntPtr src_offset,
520            IntPtr* dst_origin,
521            IntPtr* region,
522            cl_uint num_events_in_wait_list,
523            IntPtr* event_wait_list,
524            cl_event* _event);
525
526
527        [DllImport(Configuration.Library)]
528        public extern static void* clEnqueueMapBuffer(cl_command_queue command_queue,
529            cl_mem buffer,
530            cl_bool blocking_map,
531            cl_map_flags map_flags,
532            IntPtr offset,
533            IntPtr cb,
534            cl_uint num_events_in_wait_list,
535            [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] event_wait_list,
536            cl_event* _event,
537            out ErrorCode errcode_ret);
538        [DllImport(Configuration.Library)]
539        public extern static void* clEnqueueMapBuffer(cl_command_queue command_queue,
540            cl_mem buffer,
541            cl_bool blocking_map,
542            cl_map_flags map_flags,
543            IntPtr offset,
544            IntPtr cb,
545            cl_uint num_events_in_wait_list,
546            IntPtr* event_wait_list,
547            cl_event* _event,
548            out ErrorCode errcode_ret);
549
550        [DllImport(Configuration.Library)]
551        public extern static void* clEnqueueMapImage(cl_command_queue command_queue,
552            cl_mem image,
553            cl_bool blocking_map,
554            cl_map_flags map_flags,
555            [In] [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)]IntPtr[] origin,
556            [In] [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)]IntPtr[] region,
557            out IntPtr image_row_pitch,
558            out IntPtr image_slice_pitch,
559            cl_uint num_events_in_wait_list,
560            [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] event_wait_list,
561            cl_event* _event,
562            out ErrorCode errcode_ret);
563        [DllImport(Configuration.Library)]
564        public extern static void* clEnqueueMapImage(cl_command_queue command_queue,
565            cl_mem image,
566            cl_bool blocking_map,
567            cl_map_flags map_flags,
568            IntPtr* origin,
569            IntPtr* region,
570            out IntPtr image_row_pitch,
571            out IntPtr image_slice_pitch,
572            cl_uint num_events_in_wait_list,
573            IntPtr* event_wait_list,
574            cl_event* _event,
575            out ErrorCode errcode_ret);
576
577        [DllImport(Configuration.Library)]
578        public extern static ErrorCode clEnqueueUnmapMemObject(cl_command_queue command_queue,
579            cl_mem memobj,
580            void* mapped_ptr,
581            cl_uint num_events_in_wait_list,
582            [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] event_wait_list,
583            cl_event* _event);
584        [DllImport(Configuration.Library)]
585        public extern static ErrorCode clEnqueueUnmapMemObject(cl_command_queue command_queue,
586            cl_mem memobj,
587            void* mapped_ptr,
588            cl_uint num_events_in_wait_list,
589            IntPtr* event_wait_list,
590            cl_event* _event);
591
592        [DllImport(Configuration.Library)]
593        public extern static ErrorCode clEnqueueNDRangeKernel(cl_command_queue command_queue,
594            cl_kernel kernel,
595            cl_uint work_dim,
596            [In] [MarshalAs(UnmanagedType.LPArray)] IntPtr[] global_work_offset,
597            [In] [MarshalAs(UnmanagedType.LPArray)] IntPtr[] global_work_size,
598            [In] [MarshalAs(UnmanagedType.LPArray)] IntPtr[] local_work_size,
599            cl_uint num_events_in_wait_list,
600            [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] event_wait_list,
601            cl_event* _event);
602        [DllImport(Configuration.Library)]
603        public extern static ErrorCode clEnqueueNDRangeKernel(cl_command_queue command_queue,
604            cl_kernel kernel,
605            cl_uint work_dim,
606            IntPtr* global_work_offset,
607            IntPtr* global_work_size,
608            IntPtr* local_work_size,
609            cl_uint num_events_in_wait_list,
610            IntPtr* event_wait_list,
611            cl_event* _event);
612
613        [DllImport(Configuration.Library)]
614        public extern static ErrorCode clEnqueueTask(cl_command_queue command_queue,
615            cl_kernel kernel,
616            cl_uint num_events_in_wait_list,
617            [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] event_wait_list,
618            cl_event* _event);
619        [DllImport(Configuration.Library)]
620        public extern static ErrorCode clEnqueueTask(cl_command_queue command_queue,
621            cl_kernel kernel,
622            cl_uint num_events_in_wait_list,
623            IntPtr* event_wait_list,
624            cl_event* _event);
625
626        [DllImport(Configuration.Library)]
627        public extern static ErrorCode clEnqueueNativeKernel(cl_command_queue command_queue,
628            NativeKernelInternal user_func,
629            void* args,
630            IntPtr cb_args,
631            cl_uint num_mem_objects,
632            [In] cl_mem[] mem_list,
633            [In] [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] IntPtr[] args_mem_loc,
634            cl_uint num_events_in_wait_list,
635            [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] event_wait_list,
636            cl_event* _event);
637
638        [DllImport(Configuration.Library)]
639        public extern static ErrorCode clEnqueueMarker(cl_command_queue command_queue, cl_event* _event);
640
641        [DllImport(Configuration.Library)]
642        public extern static ErrorCode clEnqueueWaitForEvents(cl_command_queue command_queue,
643            cl_uint num_events,
644            [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] _event_list);
645        [DllImport(Configuration.Library)]
646        public extern static ErrorCode clEnqueueWaitForEvents(cl_command_queue command_queue,
647            cl_uint num_events,
648            IntPtr* _event_list);
649       
650        [DllImport(Configuration.Library)]
651        public extern static ErrorCode clEnqueueBarrier(cl_command_queue command_queue);
652
653        // OpenCL 1.1
654        [DllImport(Configuration.Library)]
655        public extern static ErrorCode clEnqueueReadBufferRect(cl_command_queue command_queue,
656                                cl_mem buffer,
657                                cl_bool blocking_read,
658                                [In] IntPtr[] buffer_offset,
659                                [In] IntPtr[] host_offset,
660                                [In] IntPtr[] region,
661                                IntPtr buffer_row_pitch,
662                                IntPtr buffer_slice_pitch,
663                                IntPtr host_row_pitch,
664                                IntPtr host_slice_pitch,
665                                void* ptr,
666                                cl_uint num_events_in_wait_list,
667                                [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] event_wait_list,
668                                cl_event* _event);
669        [DllImport(Configuration.Library)]
670        public extern static ErrorCode clEnqueueReadBufferRect(cl_command_queue command_queue,
671                                cl_mem buffer,
672                                cl_bool blocking_read,
673                                IntPtr* buffer_offset,
674                                IntPtr* host_offset,
675                                IntPtr* region,
676                                IntPtr buffer_row_pitch,
677                                IntPtr buffer_slice_pitch,
678                                IntPtr host_row_pitch,
679                                IntPtr host_slice_pitch,
680                                void* ptr,
681                                cl_uint num_events_in_wait_list,
682                                cl_event* event_wait_list,
683                                cl_event* _event);
684
685        [DllImport(Configuration.Library)]
686        public extern static ErrorCode clEnqueueWriteBufferRect(cl_command_queue command_queue,
687                                 cl_mem buffer,
688                                 cl_bool blocking_write,
689                                 [In] IntPtr[] buffer_offset,
690                                 [In] IntPtr[] host_offset,
691                                 [In] IntPtr[] region,
692                                 IntPtr buffer_row_pitch,
693                                 IntPtr buffer_slice_pitch,
694                                 IntPtr host_row_pitch,
695                                 IntPtr host_slice_pitch,
696                                 void* ptr,
697                                 cl_uint num_events_in_wait_list,
698                                 [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] _event_wait_list,
699                                 cl_event* _event);
700        [DllImport(Configuration.Library)]
701        public extern static ErrorCode clEnqueueWriteBufferRect(cl_command_queue command_queue,
702                                 cl_mem buffer,
703                                 cl_bool blocking_write,
704                                 IntPtr* buffer_offset,
705                                 IntPtr* host_offset,
706                                 IntPtr* region,
707                                 IntPtr buffer_row_pitch,
708                                 IntPtr buffer_slice_pitch,
709                                 IntPtr host_row_pitch,
710                                 IntPtr host_slice_pitch,
711                                 void* ptr,
712                                 cl_uint num_events_in_wait_list,
713                                 cl_event* _event_wait_list,
714                                 cl_event* _event);
715
716        [DllImport(Configuration.Library)]
717        public extern static ErrorCode clEnqueueCopyBufferRect(cl_command_queue command_queue,
718                                cl_mem src_buffer,
719                                cl_mem dst_buffer,
720                                [In] IntPtr[] src_origin,
721                                [In] IntPtr[] dst_origin,
722                                [In] IntPtr[] region,
723                                IntPtr src_row_pitch,
724                                IntPtr src_slice_pitch,
725                                IntPtr dst_row_pitch,
726                                IntPtr dst_slice_pitch,
727                                cl_uint num_events_in_wait_list,
728                                [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] _event_wait_list,
729                                cl_event* _event);
730        [DllImport(Configuration.Library)]
731        public extern static ErrorCode clEnqueueCopyBufferRect(cl_command_queue command_queue,
732                                cl_mem src_buffer,
733                                cl_mem dst_buffer,
734                                IntPtr* src_origin,
735                                IntPtr* dst_origin,
736                                IntPtr* region,
737                                IntPtr src_row_pitch,
738                                IntPtr src_slice_pitch,
739                                IntPtr dst_row_pitch,
740                                IntPtr dst_slice_pitch,
741                                cl_uint num_events_in_wait_list,
742                                cl_event* _event_wait_list,
743                                cl_event* _event);
744        #endregion
745
746        #region Flush and Finish API
747
748        [DllImport(Configuration.Library)]
749        public extern static ErrorCode clFlush(cl_command_queue command_queue);
750        [DllImport(Configuration.Library)]
751        public extern static ErrorCode clFinish(cl_command_queue command_queue);
752
753        #endregion
754
755        #region Event Object API
756
757        [DllImport(Configuration.Library)]
758        public extern static ErrorCode clWaitForEvents(cl_uint num_events,
759            [In] [MarshalAs(UnmanagedType.LPArray)] cl_event[] _event_list);
760        [DllImport(Configuration.Library)]
761        public extern static ErrorCode clGetEventInfo(cl_event _event,
762            cl_event_info param_name,
763            IntPtr param_value_size,
764            void* param_value,
765            out IntPtr param_value_size_ret);
766        [DllImport(Configuration.Library)]
767        public extern static ErrorCode clRetainEvent(cl_event _event);
768        [DllImport(Configuration.Library)]
769        public extern static ErrorCode clReleaseEvent(cl_event _event);
770
771        // OpenCL 1.1
772        [DllImport(Configuration.Library)]
773        public extern static cl_event clCreateUserEvent(cl_context context, out ErrorCode errcode_ret);
774        [DllImport(Configuration.Library)]
775        public extern static ErrorCode clSetUserEventStatus(cl_event _event, ExecutionStatus execution_status);
776        [DllImport(Configuration.Library)]
777        public extern static ErrorCode clSetEventCallback(cl_event _event, cl_int command_exec_callback_type, EventNotifyInternal pfn_notify, IntPtr user_data);
778        #endregion
779
780        #region Sampler API
781
782        // Sampler APIs
783        [DllImport(Configuration.Library)]
784        public extern static cl_sampler clCreateSampler(cl_context context, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode, out ErrorCode errcode_ret);
785        [DllImport(Configuration.Library)]
786        public extern static ErrorCode clRetainSampler(cl_sampler sampler);
787        [DllImport(Configuration.Library)]
788        public extern static ErrorCode clReleaseSampler(cl_sampler sampler);
789        [DllImport(Configuration.Library)]
790        public extern static ErrorCode clGetSamplerInfo(cl_sampler sampler, cl_sampler_info param_name, IntPtr param_value_size, void* param_value, out IntPtr param_value_size_ret);
791
792        #endregion
793
794        #region GLObject API
795
796        [DllImport(Configuration.Library)]
797        public extern static cl_mem clCreateFromGLBuffer(cl_context context,
798            cl_mem_flags flags,
799            GLuint bufobj,
800            out ErrorCode errcode_ret);
801        [DllImport(Configuration.Library)]
802        public extern static cl_mem clCreateFromGLTexture2D(cl_context context,
803            cl_mem_flags flags,
804            GLenum target,
805            GLint mipLevel,
806            GLuint texture,
807            out ErrorCode errcode_ret);
808        [DllImport(Configuration.Library)]
809        public extern static cl_mem clCreateFromGLTexture3D(cl_context context,
810            cl_mem_flags flags,
811            GLenum target,
812            GLint mipLevel,
813            GLuint texture,
814            out ErrorCode errcode_ret);
815        [DllImport(Configuration.Library)]
816        public extern static cl_mem clCreateFromGLRenderbuffer(cl_context context,
817            cl_mem_flags flags,
818            GLuint renderBuffer,
819            out ErrorCode errcode_ret);
820        [DllImport(Configuration.Library)]
821        public extern static ErrorCode clGetGLObjectInfo(cl_mem memobj,
822            out cl_gl_object_type gl_object_type,
823            out GLuint gl_object_name);
824        [DllImport(Configuration.Library)]
825        public extern static ErrorCode clGetGLTextureInfo(cl_mem memobj,
826            cl_gl_texture_info param_name,
827            IntPtr param_value_size,
828            void* param_value,
829            out IntPtr param_value_size_ret);
830        [DllImport(Configuration.Library)]
831        public extern static ErrorCode clEnqueueAcquireGLObjects(cl_command_queue command_queue,
832            cl_uint num_objects,
833            [In] cl_mem[] mem_objects,
834            cl_uint num_events_in_wait_list,
835            [In] cl_event[] event_wait_list,
836            cl_event* _event);
837        [DllImport(Configuration.Library)]
838        public extern static ErrorCode clEnqueueReleaseGLObjects(cl_command_queue command_queue,
839            cl_uint num_objects,
840            [In] cl_mem[] mem_objects,
841            cl_uint num_events_in_wait_list,
842            [In] cl_event[] event_wait_list,
843            cl_event* _event);
844
845        #endregion
846
847
848        // Extension function access
849        [DllImport(Configuration.Library)]
850        public extern static IntPtr clGetExtensionFunctionAddress(string func_name);
851
852        [DllImport(Configuration.Library)]
853        public extern static cl_int clGetEventProfilingInfo(cl_event _event, cl_profiling_info param_name, IntPtr param_value_size, void* param_value, out IntPtr param_value_size_ret);
854
855#if D3D10_Extension
856        // D3D10 extension
857        public static clGetDeviceIDsFromD3D10KHRDelegate clGetDeviceIDsFromD3D10KHR;
858        public static clCreateFromD3D10BufferKHRDelegate clCreateFromD3D10BufferKHR;
859        public static clCreateFromD3D10Texture2DKHRDelegate clCreateFromD3D10Texture2DKHR;
860        public static clCreateFromD3D10Texture3DKHRDelegate clCreateFromD3D10Texture3DKHR;
861        public static clEnqueueAcquireD3D10ObjectsKHRDelegate clEnqueueAcquireD3D10ObjectsKHR;
862        public static clEnqueueReleaseD3D10ObjectsKHRDelegate clEnqueueReleaseD3D10ObjectsKHR;
863#endif
864
865#if DEVICE_FISSION_Extension
866        // cl_ext_device_fission extension
867        public static clReleaseDeviceEXTDelegate clReleaseDeviceEXT;
868        public static clRetainDeviceEXTDelegate clRetainDeviceEXT;
869        public static clCreateSubDevicesEXTDelegate clCreateSubDevicesEXT;
870#endif
871    }
872
873#if false
874    unsafe public static class GLSharing
875    {
876        public delegate cl_int clGetGLContextInfoKHRDelegate(cl_context_properties* properties,
877        cl_gl_context_info param_name,
878        IntPtr param_value_size,
879        void* param_value,
880        IntPtr* param_value_size_ret);
881
882        public static readonly clGetGLContextInfoKHRDelegate clGetGLContextInfoKHR;
883        static GLSharing()
884        {
885            IntPtr func = OpenCLAPI.clGetExtensionFunctionAddress("clGetGLContextInfoKHR");
886            clGetGLContextInfoKHR = (clGetGLContextInfoKHRDelegate)Marshal.GetDelegateForFunctionPointer(func, typeof(clGetGLContextInfoKHRDelegate));
887        }
888    }
889
890    unsafe public static class GLEvent
891    {
892        static GLEvent()
893        {
894        }
895    }
896
897#endif
898}
Note: See TracBrowser for help on using the repository browser.