|
| 1 | +#region License |
| 2 | + |
| 3 | +/* |
| 4 | +
|
| 5 | +Permission is hereby granted, free of charge, to any person |
| 6 | +obtaining a copy of this software and associated documentation |
| 7 | +files (the "Software"), to deal in the Software without |
| 8 | +restriction, including without limitation the rights to use, |
| 9 | +copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +copies of the Software, and to permit persons to whom the |
| 11 | +Software is furnished to do so, subject to the following |
| 12 | +conditions: |
| 13 | +
|
| 14 | +The above copyright notice and this permission notice shall be |
| 15 | +included in all copies or substantial portions of the Software. |
| 16 | +
|
| 17 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 19 | +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 21 | +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 22 | +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 23 | +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 24 | +OTHER DEALINGS IN THE SOFTWARE. |
| 25 | +
|
| 26 | +*/ |
| 27 | + |
| 28 | +#endregion |
| 29 | + |
| 30 | +using System; |
| 31 | +using System.Diagnostics; |
| 32 | +using System.Runtime.InteropServices; |
| 33 | +using System.Security; |
| 34 | + |
| 35 | +namespace Amplifier.OpenCL.Cloo.Bindings |
| 36 | +{ |
| 37 | + /// <summary> |
| 38 | + /// Contains bindings to the OpenCL 2.0 functions. |
| 39 | + /// </summary> |
| 40 | + /// <remarks> See the OpenCL specification for documentation regarding these functions. </remarks> |
| 41 | + [SuppressUnmanagedCodeSecurity] |
| 42 | + internal class CL20 : CL12 |
| 43 | + { |
| 44 | + #region Command Queue |
| 45 | + |
| 46 | + /// <summary> |
| 47 | + /// Creates a host or device command-queue on a specific device. |
| 48 | + /// </summary> |
| 49 | + [DllImport(libName, EntryPoint = "clCreateCommandQueueWithProperties")] |
| 50 | + public static extern CLCommandQueueHandle CreateCommandQueueWithProperties( |
| 51 | + CLContextHandle context, |
| 52 | + CLDeviceHandle device, |
| 53 | + [MarshalAs(UnmanagedType.LPArray)] IntPtr[] properties, |
| 54 | + out ComputeErrorCode errcode_ret); |
| 55 | + |
| 56 | + #endregion |
| 57 | + |
| 58 | + #region Pipes |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// Creates a pipe object. |
| 62 | + /// </summary> |
| 63 | + [DllImport(libName, EntryPoint = "clCreatePipe")] |
| 64 | + public static extern CLMemoryHandle CreatePipe( |
| 65 | + CLContextHandle context, |
| 66 | + ComputeMemoryFlags flags, |
| 67 | + Int32 pipe_packet_size, |
| 68 | + Int32 pipe_max_packets, |
| 69 | + [MarshalAs(UnmanagedType.LPArray)] IntPtr[] properties, |
| 70 | + out ComputeErrorCode errcode_ret); |
| 71 | + |
| 72 | + /// <summary> |
| 73 | + /// Gets information specific to a pipe object. |
| 74 | + /// </summary> |
| 75 | + [DllImport(libName, EntryPoint = "clGetPipeInfo")] |
| 76 | + public static extern ComputeErrorCode GetPipeInfo( |
| 77 | + CLMemoryHandle pipe, |
| 78 | + ComputePipeInfo param_name, |
| 79 | + IntPtr param_value_size, |
| 80 | + IntPtr param_value, |
| 81 | + out IntPtr param_value_size_ret); |
| 82 | + |
| 83 | + #endregion |
| 84 | + |
| 85 | + #region Sampler |
| 86 | + |
| 87 | + /// <summary> |
| 88 | + /// Creates a sampler object with properties. |
| 89 | + /// </summary> |
| 90 | + [DllImport(libName, EntryPoint = "clCreateSamplerWithProperties")] |
| 91 | + public static extern CLSamplerHandle CreateSamplerWithProperties( |
| 92 | + CLContextHandle context, |
| 93 | + [MarshalAs(UnmanagedType.LPArray)] IntPtr[] sampler_properties, |
| 94 | + out ComputeErrorCode errcode_ret); |
| 95 | + |
| 96 | + #endregion |
| 97 | + |
| 98 | + #region Shared Virtual Memory (SVM) |
| 99 | + |
| 100 | + /// <summary> |
| 101 | + /// Allocates a shared virtual memory buffer. |
| 102 | + /// </summary> |
| 103 | + [DllImport(libName, EntryPoint = "clSVMAlloc")] |
| 104 | + public static extern IntPtr SVMAlloc( |
| 105 | + CLContextHandle context, |
| 106 | + ComputeSVMMemFlags flags, |
| 107 | + IntPtr size, |
| 108 | + Int32 alignment); |
| 109 | + |
| 110 | + /// <summary> |
| 111 | + /// Frees a shared virtual memory buffer. |
| 112 | + /// </summary> |
| 113 | + [DllImport(libName, EntryPoint = "clSVMFree")] |
| 114 | + public static extern void SVMFree( |
| 115 | + CLContextHandle context, |
| 116 | + IntPtr svm_pointer); |
| 117 | + |
| 118 | + /// <summary> |
| 119 | + /// Enqueues a command to free shared virtual memory buffers. |
| 120 | + /// </summary> |
| 121 | + [DllImport(libName, EntryPoint = "clEnqueueSVMFree")] |
| 122 | + public static extern ComputeErrorCode EnqueueSVMFree( |
| 123 | + CLCommandQueueHandle command_queue, |
| 124 | + Int32 num_svm_pointers, |
| 125 | + [MarshalAs(UnmanagedType.LPArray)] IntPtr[] svm_pointers, |
| 126 | + IntPtr pfn_free_func, |
| 127 | + IntPtr user_data, |
| 128 | + Int32 num_events_in_wait_list, |
| 129 | + [MarshalAs(UnmanagedType.LPArray)] CLEventHandle[] event_wait_list, |
| 130 | + [Out, MarshalAs(UnmanagedType.LPArray, SizeConst = 1)] CLEventHandle[] new_event); |
| 131 | + |
| 132 | + /// <summary> |
| 133 | + /// Enqueues a command to do a memcpy operation on shared virtual memory. |
| 134 | + /// </summary> |
| 135 | + [DllImport(libName, EntryPoint = "clEnqueueSVMMemcpy")] |
| 136 | + public static extern ComputeErrorCode EnqueueSVMMemcpy( |
| 137 | + CLCommandQueueHandle command_queue, |
| 138 | + ComputeBoolean blocking_copy, |
| 139 | + IntPtr dst_ptr, |
| 140 | + IntPtr src_ptr, |
| 141 | + IntPtr size, |
| 142 | + Int32 num_events_in_wait_list, |
| 143 | + [MarshalAs(UnmanagedType.LPArray)] CLEventHandle[] event_wait_list, |
| 144 | + [Out, MarshalAs(UnmanagedType.LPArray, SizeConst = 1)] CLEventHandle[] new_event); |
| 145 | + |
| 146 | + /// <summary> |
| 147 | + /// Enqueues a command to fill a region in memory with a pattern. |
| 148 | + /// </summary> |
| 149 | + [DllImport(libName, EntryPoint = "clEnqueueSVMMemFill")] |
| 150 | + public static extern ComputeErrorCode EnqueueSVMMemFill( |
| 151 | + CLCommandQueueHandle command_queue, |
| 152 | + IntPtr svm_ptr, |
| 153 | + IntPtr pattern, |
| 154 | + IntPtr pattern_size, |
| 155 | + IntPtr size, |
| 156 | + Int32 num_events_in_wait_list, |
| 157 | + [MarshalAs(UnmanagedType.LPArray)] CLEventHandle[] event_wait_list, |
| 158 | + [Out, MarshalAs(UnmanagedType.LPArray, SizeConst = 1)] CLEventHandle[] new_event); |
| 159 | + |
| 160 | + /// <summary> |
| 161 | + /// Enqueues a command that will allow the host to update a region of a SVM buffer. |
| 162 | + /// </summary> |
| 163 | + [DllImport(libName, EntryPoint = "clEnqueueSVMMap")] |
| 164 | + public static extern ComputeErrorCode EnqueueSVMMap( |
| 165 | + CLCommandQueueHandle command_queue, |
| 166 | + ComputeBoolean blocking_map, |
| 167 | + ComputeMemoryMappingFlags flags, |
| 168 | + IntPtr svm_ptr, |
| 169 | + IntPtr size, |
| 170 | + Int32 num_events_in_wait_list, |
| 171 | + [MarshalAs(UnmanagedType.LPArray)] CLEventHandle[] event_wait_list, |
| 172 | + [Out, MarshalAs(UnmanagedType.LPArray, SizeConst = 1)] CLEventHandle[] new_event); |
| 173 | + |
| 174 | + /// <summary> |
| 175 | + /// Enqueues a command to indicate that the host has completed updating a region. |
| 176 | + /// </summary> |
| 177 | + [DllImport(libName, EntryPoint = "clEnqueueSVMUnmap")] |
| 178 | + public static extern ComputeErrorCode EnqueueSVMUnmap( |
| 179 | + CLCommandQueueHandle command_queue, |
| 180 | + IntPtr svm_ptr, |
| 181 | + Int32 num_events_in_wait_list, |
| 182 | + [MarshalAs(UnmanagedType.LPArray)] CLEventHandle[] event_wait_list, |
| 183 | + [Out, MarshalAs(UnmanagedType.LPArray, SizeConst = 1)] CLEventHandle[] new_event); |
| 184 | + |
| 185 | + /// <summary> |
| 186 | + /// Sets the argument value for a specific argument of a kernel to a SVM pointer. |
| 187 | + /// </summary> |
| 188 | + [DllImport(libName, EntryPoint = "clSetKernelArgSVMPointer")] |
| 189 | + public static extern ComputeErrorCode SetKernelArgSVMPointer( |
| 190 | + CLKernelHandle kernel, |
| 191 | + Int32 arg_index, |
| 192 | + IntPtr arg_value); |
| 193 | + |
| 194 | + /// <summary> |
| 195 | + /// Used to pass additional information other than argument values to a kernel. |
| 196 | + /// </summary> |
| 197 | + [DllImport(libName, EntryPoint = "clSetKernelExecInfo")] |
| 198 | + public static extern ComputeErrorCode SetKernelExecInfo( |
| 199 | + CLKernelHandle kernel, |
| 200 | + ComputeKernelExecInfo param_name, |
| 201 | + IntPtr param_value_size, |
| 202 | + IntPtr param_value); |
| 203 | + |
| 204 | + #endregion |
| 205 | + |
| 206 | + #region Deprecated functions |
| 207 | + |
| 208 | + /// <summary> |
| 209 | + /// See the OpenCL specification. |
| 210 | + /// </summary> |
| 211 | + [Obsolete("Deprecated in OpenCL 2.0. Use CreateCommandQueueWithProperties instead.")] |
| 212 | + public new static CLCommandQueueHandle CreateCommandQueue( |
| 213 | + CLContextHandle context, |
| 214 | + CLDeviceHandle device, |
| 215 | + ComputeCommandQueueFlags properties, |
| 216 | + out ComputeErrorCode errcode_ret) |
| 217 | + { |
| 218 | + Debug.WriteLine("WARNING! clCreateCommandQueue has been deprecated in OpenCL 2.0."); |
| 219 | + return CL12.CreateCommandQueue(context, device, properties, out errcode_ret); |
| 220 | + } |
| 221 | + |
| 222 | + /// <summary> |
| 223 | + /// See the OpenCL specification. |
| 224 | + /// </summary> |
| 225 | + [Obsolete("Deprecated in OpenCL 2.0. Use CreateSamplerWithProperties instead.")] |
| 226 | + public new static CLSamplerHandle CreateSampler( |
| 227 | + CLContextHandle context, |
| 228 | + [MarshalAs(UnmanagedType.Bool)] bool normalized_coords, |
| 229 | + ComputeImageAddressing addressing_mode, |
| 230 | + ComputeImageFiltering filter_mode, |
| 231 | + out ComputeErrorCode errcode_ret) |
| 232 | + { |
| 233 | + Debug.WriteLine("WARNING! clCreateSampler has been deprecated in OpenCL 2.0."); |
| 234 | + return CL12.CreateSampler(context, normalized_coords, addressing_mode, filter_mode, out errcode_ret); |
| 235 | + } |
| 236 | + |
| 237 | + /// <summary> |
| 238 | + /// See the OpenCL specification. |
| 239 | + /// </summary> |
| 240 | + [Obsolete("Deprecated in OpenCL 2.0.")] |
| 241 | + public new static ComputeErrorCode EnqueueTask( |
| 242 | + CLCommandQueueHandle command_queue, |
| 243 | + CLKernelHandle kernel, |
| 244 | + Int32 num_events_in_wait_list, |
| 245 | + [MarshalAs(UnmanagedType.LPArray)] CLEventHandle[] event_wait_list, |
| 246 | + [Out, MarshalAs(UnmanagedType.LPArray, SizeConst = 1)] CLEventHandle[] new_event) |
| 247 | + { |
| 248 | + Debug.WriteLine("WARNING! clEnqueueTask has been deprecated in OpenCL 2.0."); |
| 249 | + return CL12.EnqueueTask(command_queue, kernel, num_events_in_wait_list, event_wait_list, new_event); |
| 250 | + } |
| 251 | + |
| 252 | + #endregion |
| 253 | + } |
| 254 | +} |
0 commit comments