void ExecuteInternal(bool outputEventHandle, Kernel kernel, int[] global_work_offset, int[] global_work_size, int[] local_work_size, EventHandle[] wait_list, out EventHandle eventHandle) { if (global_work_size == null || local_work_size == null || global_work_size.Length != local_work_size.Length) { throw new ArgumentException(); } uint work_dim = (uint)global_work_size.Length; IntPtr[] goffsets = null; IntPtr[] gthreads = new IntPtr[work_dim]; IntPtr[] lthreads = new IntPtr[work_dim]; for (int i = 0; i < work_dim; i++) { gthreads[i] = new IntPtr(global_work_size[i]); lthreads[i] = new IntPtr(local_work_size[i]); } IntPtr[] waits = wait_list == null ? null : EventHandle.ToIntPtrArray(wait_list); uint num_waits = waits == null ? 0 : (uint)waits.Length; if (outputEventHandle) { IntPtr event_handle; OpenCLException.Check(Native.clEnqueueNDRangeKernel(_handle, kernel.Handle, work_dim, goffsets, gthreads, lthreads, num_waits, waits, out event_handle)); eventHandle = new EventHandle(event_handle); } else { OpenCLException.Check(Native.clEnqueueNDRangeKernel(_handle, kernel.Handle, work_dim, goffsets, gthreads, lthreads, num_waits, waits, IntPtr.Zero)); eventHandle = null; } }
public static void WaitAll (EventHandle[] waits) { IntPtr[] array = ToIntPtrArray (waits); if (array == null) return; OpenCLException.Check (Native.clWaitForEvents ((uint)array.Length, array)); }
internal static IntPtr[] ToIntPtrArray (EventHandle[] waits) { if (waits == null || waits.Length == 0) return null; IntPtr[] array = new IntPtr[waits.Length]; for (int i = 0; i < array.Length; i++) array[i] = waits[i]._handle; return array; }
void ExecuteInternal(bool outputEventHandle, Kernel kernel, EventHandle[] wait_list, out EventHandle eventHandle) { IntPtr[] waits = wait_list == null ? null : EventHandle.ToIntPtrArray(wait_list); uint num_waits = waits == null ? 0 : (uint)waits.Length; if (outputEventHandle) { IntPtr event_handle; OpenCLException.Check(Native.clEnqueueTask(_handle, kernel.Handle, num_waits, waits, out event_handle)); eventHandle = new EventHandle(event_handle); } else { OpenCLException.Check(Native.clEnqueueTask(_handle, kernel.Handle, num_waits, waits, IntPtr.Zero)); eventHandle = null; } }
void CopyBuferInternal(bool outputEventHandle, Memory src, int src_offset, Memory dst, int dst_offset, int size, EventHandle[] wait_list, out EventHandle eventHandle) { IntPtr[] waits = EventHandle.ToIntPtrArray(wait_list); uint num_waits = waits == null ? 0 : (uint)waits.Length; if (outputEventHandle) { IntPtr event_handle; OpenCLException.Check(Native.clEnqueueCopyBuffer(_handle, src.Handle, dst.Handle, new IntPtr(src_offset), new IntPtr(dst_offset), new IntPtr(size), num_waits, waits, out event_handle)); eventHandle = new EventHandle(event_handle); } else { OpenCLException.Check(Native.clEnqueueCopyBuffer(_handle, src.Handle, dst.Handle, new IntPtr(src_offset), new IntPtr(dst_offset), new IntPtr(size), num_waits, waits, IntPtr.Zero)); eventHandle = null; } }
void ReadBufferInternal(bool blocking, bool outputEventHandle, Memory buf, int buf_offset, object dst, int dst_offset, int size, EventHandle[] wait_list, out EventHandle eventHandle) { IntPtr dst_handle; GCHandle dst_gc_handle; if (dst is IntPtr) { dst_handle = (IntPtr)dst; dst_gc_handle = new GCHandle(); } else { dst_gc_handle = GCHandle.Alloc(dst, GCHandleType.Pinned); dst_handle = dst_gc_handle.AddrOfPinnedObject(); } try { IntPtr dst_ptr = new IntPtr(dst_handle.ToInt64() + dst_offset); IntPtr[] waits = EventHandle.ToIntPtrArray(wait_list); uint num_waits = waits == null ? 0 : (uint)waits.Length; CL_Bool is_blocking = (blocking ? CL_Bool.True : CL_Bool.False); if (outputEventHandle) { IntPtr event_handle; OpenCLException.Check(Native.clEnqueueReadBuffer(_handle, buf.Handle, is_blocking, new IntPtr(buf_offset), new IntPtr(size), dst_ptr, num_waits, waits, out event_handle)); eventHandle = new EventHandle(event_handle); } else { OpenCLException.Check(Native.clEnqueueReadBuffer(_handle, buf.Handle, is_blocking, new IntPtr(buf_offset), new IntPtr(size), dst_ptr, num_waits, waits, IntPtr.Zero)); eventHandle = null; } } finally { if (dst_gc_handle.IsAllocated) { dst_gc_handle.Free(); } } }
public void ReadBufferAsync(Memory buf, int buf_offset, object dst, int dst_offset, int size, EventHandle[] wait_list, out EventHandle eventHandle) { ReadBufferInternal(false, true, buf, buf_offset, dst, dst_offset, size, wait_list, out eventHandle); }
public void ExecuteAsync(Kernel kernel, int[] global_work_offset, int[] global_work_size, int[] local_work_size, EventHandle[] wait_list, out EventHandle eventHandle) { ExecuteInternal(true, kernel, global_work_offset, global_work_size, local_work_size, wait_list, out eventHandle); }
public void ExecuteAsync(Kernel kernel, int global_work_offset, int global_work_size, int local_work_size, EventHandle[] wait_list, out EventHandle eventHandle) { ExecuteAsync(kernel, new int[] { global_work_offset }, new int[] { global_work_size }, new int[] { local_work_size }, wait_list, out eventHandle); }
public void ExecuteAsync(Kernel kernel, EventHandle[] wait_list, out EventHandle eventHandle) { ExecuteInternal(true, kernel, wait_list, out eventHandle); }
public void CopyBuferAsync(Memory src, int src_offset, Memory dst, int dst_offset, int size, EventHandle[] wait_list, out EventHandle eventHandle) { CopyBuferInternal(true, src, src_offset, dst, dst_offset, size, wait_list, out eventHandle); }
public void WriteBufferAsync(Memory buf, int buf_offset, object src, int src_offset, int size, EventHandle[] wait_list, out EventHandle eventHandle) { WriteBufferInternal(false, true, buf, buf_offset, src, src_offset, size, null, out eventHandle); }