Exemplo n.º 1
0
        public static Context Create(Device[] devices, params ContextParam[] ctxParams)
        {
            Context   result    = null;
            IntPtr    ctxHandle = IntPtr.Zero;
            ErrorCode errorCode = ErrorCode.Success;

            IntPtr[] devHandles = CLObject.GetHandles(devices);

            IntPtr[] properties = new IntPtr[2 * ctxParams.Length + 1];
            int      i          = 0;

            foreach (ContextParam cp in ctxParams)
            {
                properties[i] = (IntPtr)cp.Name;
                i++;
                properties[i] = cp.Value;
                i++;
            }
            properties[i] = (IntPtr)0;

            unsafe {
                ctxHandle = Native.CreateContext(properties, (uint)devices.Length, devHandles, IntPtr.Zero, IntPtr.Zero, &errorCode);
            }

            if (errorCode != ErrorCode.Success)
            {
                throw new OpenCLCallFailedException(errorCode);
            }

            result = new Context(ctxHandle);

            return(result);
        }
Exemplo n.º 2
0
        public unsafe void EnqueueUnmap(CommandQueue queue, ref IntPtr mappedPtr, Event[] waitList, out Event evt)
        {
            uint waitCount = (waitList == null ? 0 : (uint)waitList.Length);

            IntPtr[] wlh       = CLObject.GetHandles(waitList);
            IntPtr   evtHandle = IntPtr.Zero;

            Native.Call(Native.EnqueueUnmapMemObject(queue.Handle, this.Handle, mappedPtr, waitCount, wlh, &evtHandle));
            mappedPtr = IntPtr.Zero;
            evt       = new Event(evtHandle);
        }
Exemplo n.º 3
0
 public static void EnqueueReleaseGLObjects(CommandQueue queue, CLObject[] objects, Event[] waitList, out Event evt)
 {
     unsafe {
         uint     waitCount  = (waitList == null ? 0 : (uint)waitList.Length);
         IntPtr[] wlh        = CLObject.GetHandles(waitList);
         IntPtr   evtHandle  = IntPtr.Zero;
         IntPtr[] objHandles = CLObject.GetHandles(objects);
         Native.Call(Native.GL.EnqueueReleaseGLObjects(queue.Handle, (uint)objHandles.Length, objHandles, waitCount, wlh, &evtHandle));
         evt = new Event(evtHandle);
     }
 }
Exemplo n.º 4
0
 public void EnqueueAcquireGL(CommandQueue queue, Event[] waitList, out Event evt)
 {
     unsafe {
         uint     waitCount     = (waitList == null ? 0 : (uint)waitList.Length);
         IntPtr[] wlh           = CLObject.GetHandles(waitList);
         IntPtr   evtHandle     = IntPtr.Zero;
         IntPtr[] memobjHandles = new IntPtr[] { this.Handle };
         Native.Call(Native.GL.EnqueueAcquireGLObjects(queue.Handle, 1, memobjHandles, waitCount, wlh, &evtHandle));
         evt = new Event(evtHandle);
     }
 }
Exemplo n.º 5
0
 public void EnqueueWaitForEvents(Event[] waitList)
 {
     unsafe {
         uint     waitCount = (waitList == null ? 0 : (uint)waitList.Length);
         IntPtr[] wlh       = CLObject.GetHandles(waitList);
         fixed(IntPtr *p_wlh = wlh)
         {
             Native.Call(Native.EnqueueWaitForEvents(this.Handle, waitCount, p_wlh));
         }
     }
 }
Exemplo n.º 6
0
        public void Build(Device[] devices, string options)
        {
            ErrorCode errorCode;

            unsafe {
                IntPtr[] devHandles = CLObject.GetHandles(devices);
                errorCode = Native.BuildProgram(this.Handle, (uint)devices.Length, devHandles, options, IntPtr.Zero, IntPtr.Zero);
            }
            if (errorCode != ErrorCode.Success)
            {
                throw new OpenCLCallFailedException(errorCode);
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Enqueue a one dimensional kernel for launch.
 /// </summary>
 public void EnqueueLaunch(CommandQueue queue, IntPtr globalWorkSize, IntPtr localWorkSize, Event[] waitList, out Event evt)
 {
     unsafe {
         uint     waitCount = (waitList == null ? 0 : (uint)waitList.Length);
         IntPtr[] wlh       = CLObject.GetHandles(waitList);
         IntPtr   evtHandle = IntPtr.Zero;
         Native.Call(Native.EnqueueNDRangeKernel(
                         queue.Handle, this.Handle, 1, null,
                         (IntPtr *)(&globalWorkSize), (IntPtr *)(&localWorkSize),
                         waitCount, wlh, &evtHandle)
                     );
         evt = new Event(evtHandle);
     }
 }
Exemplo n.º 8
0
        public IntPtr EnqueueMap(CommandQueue queue, MapFlags flags, Offset2D origin, Dim2D region, out IntPtr pitch, Event[] waitList, out Event evt)
        {
            Offset3D origin_buf = new Offset3D(origin.X, origin.Y, (IntPtr)0);
            Dim3D    region_buf = new Dim3D(region.X, region.Y, (IntPtr)1);
            IntPtr   tempPitch  = IntPtr.Zero;
            uint     waitCount  = (waitList == null ? 0 : (uint)waitList.Length);

            IntPtr[]  wlh       = CLObject.GetHandles(waitList);
            IntPtr    evtHandle = IntPtr.Zero;
            ErrorCode errorCode;
            IntPtr    result = IntPtr.Zero;

            unsafe {
                result = Native.EnqueueMapImage(queue.Handle, this.Handle, true, flags, &origin_buf, &region_buf, &tempPitch, null, waitCount, wlh, &evtHandle, &errorCode);
            }
            if (errorCode != ErrorCode.Success)
            {
                throw new OpenCLCallFailedException(errorCode);
            }
            pitch = tempPitch;
            evt   = new Event(evtHandle);
            return(result);
        }