Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
        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;
            }
        }
Exemplo n.º 4
0
        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();
                }
            }
        }