Esempio n. 1
0
        public Event EnqueueTask(Kernel kernel, Event[] events)
        {
            ClHelper.ThrowNullException(Handle);

            if (kernel == Kernel.Null)
            {
                throw new ArgumentNullException("kernel");
            }

            unsafe
            {
                int     num_events_in_wait_list = events == null ? 0 : events.Length;
                IntPtr *wait_list = stackalloc IntPtr[num_events_in_wait_list];
                for (int i = 0; i < num_events_in_wait_list; ++i)
                {
                    wait_list[i] = events[i].Handle;
                }
                if (events == null)
                {
                    wait_list = null;
                }

                IntPtr event_ptr = IntPtr.Zero;

                ClHelper.GetError(Cl.EnqueueTask(Handle, kernel.Handle,
                                                 (uint)num_events_in_wait_list, wait_list, &event_ptr));

                return(new Event(event_ptr));
            }
        }
Esempio n. 2
0
        public void SetDestructorCallback(Action <Image, object> notify, object user_data)
        {
            ClHelper.ThrowNullException(Handle);

            if (notify == null)
            {
                throw new ArgumentNullException("notify");
            }

            unsafe
            {
                var function_ptr = IntPtr.Zero;
                var data         = Tuple.Create(notify, user_data);
                var data_handle  = GCHandle.Alloc(data);

                function_ptr = Marshal.GetFunctionPointerForDelegate(new CallbackDelegete(Callback));

                try
                {
                    ClHelper.GetError(Cl.SetMemObjectDestructorCallback(
                                          Handle, function_ptr, GCHandle.ToIntPtr(data_handle).ToPointer()));
                }
                catch (EntryPointNotFoundException)
                {
                    data_handle.Free();
                    throw ClHelper.VersionException(1, 1);
                }
                catch (Exception)
                {
                    data_handle.Free();
                    throw;
                }
            }
        }
Esempio n. 3
0
        public Event EnqueueWriteBuffer(Buffer buffer, bool blocking, ulong offset, ulong count, IntPtr destination, Event[] events)
        {
            ClHelper.ThrowNullException(Handle);

            if (buffer == Buffer.Null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (destination == IntPtr.Zero)
            {
                throw new ArgumentNullException("destination");
            }

            unsafe
            {
                int     num_events_in_wait_list = events == null ? 0 : events.Length;
                IntPtr *wait_list = stackalloc IntPtr[num_events_in_wait_list];
                for (int i = 0; i < num_events_in_wait_list; ++i)
                {
                    wait_list[i] = events[i].Handle;
                }
                if (events == null)
                {
                    wait_list = null;
                }

                IntPtr event_ptr = IntPtr.Zero;

                ClHelper.GetError(Cl.EnqueueWriteBuffer(Handle, buffer.Handle,
                                                        blocking ? 1u : 0u, new UIntPtr(offset), new UIntPtr(count), destination.ToPointer(),
                                                        (uint)num_events_in_wait_list, wait_list, &event_ptr));

                return(new Event(event_ptr));
            }
        }
Esempio n. 4
0
        public void SetCallback(
            Action <Event, CommandExecutionStatus, object> notify,
            object user_data)
        {
            ClHelper.ThrowNullException(Handle);

            if (notify == null)
            {
                throw new ArgumentNullException("notify");
            }

            unsafe
            {
                var function_ptr = IntPtr.Zero;
                var data_handle  = new GCHandle();
                var data         = Tuple.Create(notify, user_data);
                data_handle = GCHandle.Alloc(data);

                function_ptr = Marshal.GetFunctionPointerForDelegate(new CallbackDelegete(Callback));

                try
                {
                    ClHelper.GetError(Cl.SetEventCallback(
                                          Handle, (int)CommandExecutionStatus.Complete, function_ptr, GCHandle.ToIntPtr(data_handle).ToPointer()));
                }
                catch (Exception)
                {
                    data_handle.Free();
                    throw;
                }
            }
        }
Esempio n. 5
0
        public Event EnqueueBarrier(Event[] events)
        {
            ClHelper.ThrowNullException(Handle);

            try
            {
                unsafe
                {
                    int     num_events_in_wait_list = events == null ? 0 : events.Length;
                    IntPtr *wait_list = stackalloc IntPtr[num_events_in_wait_list];
                    for (int i = 0; i < num_events_in_wait_list; ++i)
                    {
                        wait_list[i] = events[i].Handle;
                    }
                    if (events == null)
                    {
                        wait_list = null;
                    }

                    IntPtr event_ptr = IntPtr.Zero;

                    ClHelper.GetError(Cl.EnqueueBarrierWithWaitList(
                                          Handle, (uint)num_events_in_wait_list, wait_list, &event_ptr));

                    return(new Event(event_ptr));
                }
            }
            catch (EntryPointNotFoundException)
            {
                throw ClHelper.VersionException(1, 2);
            }
        }
Esempio n. 6
0
        public Event EnqueueUnmapBuffer(
            Buffer buffer, IntPtr pointer, Event[] events)
        {
            ClHelper.ThrowNullException(Handle);

            if (buffer == Buffer.Null)
            {
                throw new ArgumentNullException("buffer");
            }

            unsafe
            {
                int     num_events_in_wait_list = events == null ? 0 : events.Length;
                IntPtr *wait_list = stackalloc IntPtr[num_events_in_wait_list];
                for (int i = 0; i < num_events_in_wait_list; ++i)
                {
                    wait_list[i] = events[i].Handle;
                }
                if (events == null)
                {
                    wait_list = null;
                }

                IntPtr event_ptr = IntPtr.Zero;

                ClHelper.GetError(Cl.EnqueueUnmapMemObject(Handle,
                                                           buffer.Handle, pointer.ToPointer(),
                                                           (uint)num_events_in_wait_list, wait_list, &event_ptr));

                return(new Event(event_ptr));
            }
        }
Esempio n. 7
0
        public void Release()
        {
            ClHelper.ThrowNullException(Handle);
            var error = Cl.ReleaseCommandQueue(Handle);

            Handle = IntPtr.Zero;
            ClHelper.GetError(error);
        }
Esempio n. 8
0
        public void ReleaseProgram()
        {
            ClHelper.ThrowNullException(Handle);
            int error = Cl.ReleaseProgram(Handle);

            Handle = IntPtr.Zero;
            ClHelper.GetError(error);
        }
Esempio n. 9
0
        public void ReleaseImage()
        {
            ClHelper.ThrowNullException(Handle);
            int error = Cl.ReleaseMemObject(Handle);

            Handle = IntPtr.Zero;
            ClHelper.GetError(error);
        }
Esempio n. 10
0
 public override bool Equals(object obj)
 {
     ClHelper.ThrowNullException(Handle);
     if (obj is Program)
     {
         return(Equals((Program)obj));
     }
     return(false);
 }
Esempio n. 11
0
 public override bool Equals(object obj)
 {
     ClHelper.ThrowNullException(Handle);
     if (obj is CommandQueue)
     {
         return(Equals((CommandQueue)obj));
     }
     return(false);
 }
Esempio n. 12
0
        public void EnqueueBarrier()
        {
            ClHelper.ThrowNullException(Handle);

            unsafe
            {
                ClHelper.GetError(Cl.EnqueueBarrier(Handle));
            }
        }
Esempio n. 13
0
        public Event EnqueueCopyImage(
            Image source, Ibasa.Numerics.Vector3ul sourceOrigin,
            Image destination, Ibasa.Numerics.Vector3ul destinationOrigin,
            Ibasa.Numerics.Vector3ul region,
            ulong rowPitch, ulong slicePitch,
            Event[] events)
        {
            ClHelper.ThrowNullException(Handle);

            if (source == Image.Null)
            {
                throw new ArgumentNullException("source");
            }
            if (destination == Image.Null)
            {
                throw new ArgumentNullException("destination");
            }

            unsafe
            {
                int     num_events_in_wait_list = events == null ? 0 : events.Length;
                IntPtr *wait_list = stackalloc IntPtr[num_events_in_wait_list];
                for (int i = 0; i < num_events_in_wait_list; ++i)
                {
                    wait_list[i] = events[i].Handle;
                }
                if (events == null)
                {
                    wait_list = null;
                }

                IntPtr event_ptr = IntPtr.Zero;

                UIntPtr *sourceOrigin_ptr = stackalloc UIntPtr[3];
                sourceOrigin_ptr[0] = new UIntPtr(sourceOrigin.X);
                sourceOrigin_ptr[1] = new UIntPtr(sourceOrigin.Y);
                sourceOrigin_ptr[2] = new UIntPtr(sourceOrigin.Z);

                UIntPtr *destinationOrigin_ptr = stackalloc UIntPtr[3];
                destinationOrigin_ptr[0] = new UIntPtr(destinationOrigin.X);
                destinationOrigin_ptr[1] = new UIntPtr(destinationOrigin.Y);
                destinationOrigin_ptr[2] = new UIntPtr(destinationOrigin.Z);

                UIntPtr *region_ptr = stackalloc UIntPtr[3];
                region_ptr[0] = new UIntPtr(region.X);
                region_ptr[1] = new UIntPtr(region.Y);
                region_ptr[2] = new UIntPtr(region.Z);

                ClHelper.GetError(Cl.EnqueueCopyImage(Handle,
                                                      source.Handle, destination.Handle,
                                                      sourceOrigin_ptr, destinationOrigin_ptr, region_ptr,
                                                      (uint)num_events_in_wait_list, wait_list, &event_ptr));

                return(new Event(event_ptr));
            }
        }
Esempio n. 14
0
        public WorkGroupInfo GetWorkGroupInfo(Device device)
        {
            ClHelper.ThrowNullException(Handle);
            if (device == Device.Null)
            {
                throw new ArgumentNullException("device");
            }

            return(new WorkGroupInfo(Handle, device.Handle));
        }
Esempio n. 15
0
        public void SetArgument(int index, int value)
        {
            ClHelper.ThrowNullException(Handle);

            unsafe
            {
                ClHelper.GetError(Cl.SetKernelArg(Handle,
                                                  (uint)index, (UIntPtr)sizeof(int), &value));
            }
        }
Esempio n. 16
0
        public Event EnqueueMarker()
        {
            ClHelper.ThrowNullException(Handle);

            unsafe
            {
                IntPtr event_ptr = IntPtr.Zero;

                ClHelper.GetError(Cl.EnqueueMarker(Handle, &event_ptr));

                return(new Event(event_ptr));
            }
        }
Esempio n. 17
0
        public Event EnqueueFillBuffer(Image image,
                                       IntPtr fillColor,
                                       Ibasa.Numerics.Vector3ul origin,
                                       Ibasa.Numerics.Vector3ul region,
                                       ulong offset, ulong size, Event[] events)
        {
            ClHelper.ThrowNullException(Handle);

            if (image == Image.Null)
            {
                throw new ArgumentNullException("image");
            }
            if (fillColor == IntPtr.Zero)
            {
                throw new ArgumentNullException("fillColor");
            }

            unsafe
            {
                int     num_events_in_wait_list = events == null ? 0 : events.Length;
                IntPtr *wait_list = stackalloc IntPtr[num_events_in_wait_list];
                for (int i = 0; i < num_events_in_wait_list; ++i)
                {
                    wait_list[i] = events[i].Handle;
                }
                if (events == null)
                {
                    wait_list = null;
                }

                IntPtr event_ptr = IntPtr.Zero;

                UIntPtr *origin_ptr = stackalloc UIntPtr[3];
                origin_ptr[0] = new UIntPtr(origin.X);
                origin_ptr[1] = new UIntPtr(origin.Y);
                origin_ptr[2] = new UIntPtr(origin.Z);

                UIntPtr *region_ptr = stackalloc UIntPtr[3];
                region_ptr[0] = new UIntPtr(region.X);
                region_ptr[1] = new UIntPtr(region.Y);
                region_ptr[2] = new UIntPtr(region.Z);

                ClHelper.GetError(Cl.EnqueueFillImage(Handle, image.Handle,
                                                      fillColor.ToPointer(), origin_ptr, region_ptr,
                                                      (uint)num_events_in_wait_list, wait_list, &event_ptr));

                return(new Event(event_ptr));
            }
        }
Esempio n. 18
0
        public Event EnqueueWriteImage(Image image, bool blocking,
                                       Ibasa.Numerics.Vector3ul origin,
                                       Ibasa.Numerics.Vector3ul region,
                                       ulong rowPitch, ulong slicePitch,
                                       IntPtr source, Event[] events)
        {
            ClHelper.ThrowNullException(Handle);

            if (image == Image.Null)
            {
                throw new ArgumentNullException("image");
            }
            if (source == IntPtr.Zero)
            {
                throw new ArgumentNullException("source");
            }

            unsafe
            {
                int     num_events_in_wait_list = events == null ? 0 : events.Length;
                IntPtr *wait_list = stackalloc IntPtr[num_events_in_wait_list];
                for (int i = 0; i < num_events_in_wait_list; ++i)
                {
                    wait_list[i] = events[i].Handle;
                }
                if (events == null)
                {
                    wait_list = null;
                }

                IntPtr event_ptr = IntPtr.Zero;

                UIntPtr *origin_ptr = stackalloc UIntPtr[3];
                origin_ptr[0] = new UIntPtr(origin.X);
                origin_ptr[1] = new UIntPtr(origin.Y);
                origin_ptr[2] = new UIntPtr(origin.Z);

                UIntPtr *region_ptr = stackalloc UIntPtr[3];
                region_ptr[0] = new UIntPtr(region.X);
                region_ptr[1] = new UIntPtr(region.Y);
                region_ptr[2] = new UIntPtr(region.Z);

                ClHelper.GetError(Cl.EnqueueReadImage(Handle, image.Handle,
                                                      blocking ? 1u : 0u, origin_ptr, region_ptr, new UIntPtr(rowPitch), new UIntPtr(slicePitch),
                                                      source.ToPointer(), (uint)num_events_in_wait_list, wait_list, &event_ptr));

                return(new Event(event_ptr));
            }
        }
Esempio n. 19
0
        public void SetArgument(int index, Buffer buffer)
        {
            ClHelper.ThrowNullException(Handle);
            if (buffer == Buffer.Null)
            {
                throw new ArgumentNullException("buffer");
            }

            unsafe
            {
                IntPtr value = buffer.Handle;
                ClHelper.GetError(Cl.SetKernelArg(Handle,
                                                  (uint)index, (UIntPtr)IntPtr.Size, &value));
            }
        }
Esempio n. 20
0
        public void SetUserEventStatus(int status)
        {
            ClHelper.ThrowNullException(Handle);

            if (status > 0)
            {
                throw new ArgumentException("status must be zero or negative.");
            }

            try
            {
                ClHelper.GetError(Cl.SetUserEventStatus(Handle, status));
            }
            catch (EntryPointNotFoundException)
            {
                throw ClHelper.VersionException(1, 1);
            }
        }
Esempio n. 21
0
        public                          Device[] GetDevices(DeviceType deviceType)
        {
            ClHelper.ThrowNullException(Handle);
            unsafe
            {
                uint num_devices = 0;
                ClHelper.GetError(Cl.GetDeviceIDs(Handle, (uint)deviceType, 0, null, &num_devices));

                IntPtr *device_ptrs = stackalloc IntPtr[(int)num_devices];

                ClHelper.GetError(Cl.GetDeviceIDs(Handle, (uint)deviceType, num_devices, device_ptrs, null));

                Device[] devices = new Device[num_devices];

                for (uint i = 0; i < num_devices; ++i)
                {
                    devices[i] = new Device(device_ptrs[i]);
                }

                return(devices);
            }
        }
Esempio n. 22
0
        public Event EnqueueMigrateBuffer(
            Buffer[] buffers, MemoryMigrationFlags flags, Event[] events)
        {
            ClHelper.ThrowNullException(Handle);

            if (buffers == null)
            {
                throw new ArgumentNullException("buffers");
            }

            unsafe
            {
                var buffer_list = stackalloc IntPtr[buffers.Length];

                for (int i = 0; i < buffers.Length; ++i)
                {
                    buffer_list[i] = buffers[i].Handle;
                }

                int     num_events_in_wait_list = events == null ? 0 : events.Length;
                IntPtr *wait_list = stackalloc IntPtr[num_events_in_wait_list];
                for (int i = 0; i < num_events_in_wait_list; ++i)
                {
                    wait_list[i] = events[i].Handle;
                }
                if (events == null)
                {
                    wait_list = null;
                }

                IntPtr event_ptr = IntPtr.Zero;

                ClHelper.GetError(Cl.EnqueueMigrateMemObjects(Handle,
                                                              (uint)buffers.Length, buffer_list, (ulong)flags,
                                                              (uint)num_events_in_wait_list, wait_list, &event_ptr));

                return(new Event(event_ptr));
            }
        }
Esempio n. 23
0
        public Event EnqueueCopyBuffer(
            Buffer source, ulong sourceOffset,
            Buffer destination, ulong destinationOffset, ulong count, Event[] events)
        {
            ClHelper.ThrowNullException(Handle);

            if (source == Buffer.Null)
            {
                throw new ArgumentNullException("source");
            }
            if (destination == Buffer.Null)
            {
                throw new ArgumentNullException("destination");
            }

            unsafe
            {
                int     num_events_in_wait_list = events == null ? 0 : events.Length;
                IntPtr *wait_list = stackalloc IntPtr[num_events_in_wait_list];
                for (int i = 0; i < num_events_in_wait_list; ++i)
                {
                    wait_list[i] = events[i].Handle;
                }
                if (events == null)
                {
                    wait_list = null;
                }

                IntPtr event_ptr = IntPtr.Zero;

                ClHelper.GetError(Cl.EnqueueCopyBuffer(Handle,
                                                       source.Handle, destination.Handle,
                                                       new UIntPtr(sourceOffset), new UIntPtr(sourceOffset), new UIntPtr(count),
                                                       (uint)num_events_in_wait_list, wait_list, &event_ptr));

                return(new Event(event_ptr));
            }
        }
Esempio n. 24
0
        public Event EnqueueMapBuffer(
            Buffer buffer, bool blocking, MapFlags flags,
            ulong offset, ulong size, Event[] events, out IntPtr pointer)
        {
            ClHelper.ThrowNullException(Handle);

            if (buffer == Buffer.Null)
            {
                throw new ArgumentNullException("buffer");
            }

            unsafe
            {
                int     num_events_in_wait_list = events == null ? 0 : events.Length;
                IntPtr *wait_list = stackalloc IntPtr[num_events_in_wait_list];
                for (int i = 0; i < num_events_in_wait_list; ++i)
                {
                    wait_list[i] = events[i].Handle;
                }
                if (events == null)
                {
                    wait_list = null;
                }

                IntPtr event_ptr = IntPtr.Zero;

                int   error;
                void *result = Cl.EnqueueMapBuffer(Handle,
                                                   buffer.Handle, blocking ? 1u : 0u, (ulong)flags,
                                                   new UIntPtr(offset), new UIntPtr(size),
                                                   (uint)num_events_in_wait_list, wait_list, &event_ptr, &error);
                ClHelper.GetError(error);

                pointer = new IntPtr(result);

                return(new Event(event_ptr));
            }
        }
Esempio n. 25
0
        public Event EnqueueCopyBuffer(
            Buffer source, long sourceOffset,
            Buffer destination, long destinationOffset, long count, Event[] events)
        {
            ClHelper.ThrowNullException(Handle);

            if (sourceOffset < 0)
            {
                throw new ArgumentOutOfRangeException("sourceOffset", sourceOffset, "sourceOffset is less than zero.");
            }
            if (destinationOffset < 0)
            {
                throw new ArgumentOutOfRangeException("destinationOffset", destinationOffset, "destinationOffset is less than zero.");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", count, "count is less than zero.");
            }

            return(EnqueueCopyBuffer(
                       source, (ulong)sourceOffset,
                       destination, (ulong)destinationOffset, (ulong)count, events));
        }
Esempio n. 26
0
        public Event EnqueueFillBuffer(Buffer buffer,
                                       IntPtr pattern, ulong patternSize,
                                       ulong offset, ulong size, Event[] events)
        {
            ClHelper.ThrowNullException(Handle);

            if (buffer == Buffer.Null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (pattern == IntPtr.Zero)
            {
                throw new ArgumentNullException("pattern");
            }

            unsafe
            {
                int     num_events_in_wait_list = events == null ? 0 : events.Length;
                IntPtr *wait_list = stackalloc IntPtr[num_events_in_wait_list];
                for (int i = 0; i < num_events_in_wait_list; ++i)
                {
                    wait_list[i] = events[i].Handle;
                }
                if (events == null)
                {
                    wait_list = null;
                }

                IntPtr event_ptr = IntPtr.Zero;

                ClHelper.GetError(Cl.EnqueueFillBuffer(Handle, buffer.Handle,
                                                       pattern.ToPointer(), new UIntPtr(patternSize), new UIntPtr(offset), new UIntPtr(size),
                                                       (uint)num_events_in_wait_list, wait_list, &event_ptr));

                return(new Event(event_ptr));
            }
        }
Esempio n. 27
0
        public void Release()
        {
            ClHelper.ThrowNullException(Handle);
            int error = Cl.ReleaseContext(Handle);

            try
            {
                // try to get the ref count
                var test = ReferenceCount;
            }
            catch (OpenCLException)
            {
                // if the context is released ReferenceCount will throw
                var data = CallbackPointers[Handle];
                data.Free();
                CallbackPointers.Remove(Handle);
            }
            finally
            {
                Handle = IntPtr.Zero;
            }

            ClHelper.GetError(error);
        }
Esempio n. 28
0
        public void EnqueueWaitForEvents(Event[] events)
        {
            ClHelper.ThrowNullException(Handle);
            if (events == null)
            {
                throw new ArgumentNullException("events");
            }
            if (events.Length == 0)
            {
                throw new ArgumentException("events is empty.");
            }

            unsafe
            {
                int     num_events = events == null ? 0 : events.Length;
                IntPtr *wait_list  = stackalloc IntPtr[num_events];
                for (int i = 0; i < num_events; ++i)
                {
                    wait_list[i] = events[i].Handle;
                }

                ClHelper.GetError(Cl.EnqueueWaitForEvents(Handle, (uint)num_events, wait_list));
            }
        }
Esempio n. 29
0
 public override string ToString()
 {
     ClHelper.ThrowNullException(Handle);
     return(string.Format("Program: {0}", Handle.ToString()));
 }
Esempio n. 30
0
 public bool Equals(Program other)
 {
     ClHelper.ThrowNullException(Handle);
     return(Handle == other.Handle);
 }