/// <summary> /// Creates a new <see cref="ComputeBuffer{T}"/>. /// </summary> /// <param name="context"> A <see cref="ComputeContext"/> used to create the <see cref="ComputeBuffer{T}"/>. </param> /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeBuffer{T}"/>. </param> /// <param name="count"> The number of elements of the <see cref="ComputeBuffer{T}"/>. </param> /// <param name="dataPtr"> A pointer to the data for the <see cref="ComputeBuffer{T}"/>. </param> public ComputeBuffer(ComputeContext context, ComputeMemoryFlags flags, long count, IntPtr dataPtr) : base(context, flags) { var size = ComputeTools.SizeOf <T>() * count; Handle = CL12.CreateBuffer(context.Handle, flags, new IntPtr(size), dataPtr, out var error); ComputeException.ThrowOnError(error); Init(size, count); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Creates a new <see cref="ComputeBuffer{T}"/>. </summary> /// /// <param name="context"> A <see cref="ComputeContext"/> used to create the /// <see cref="ComputeBuffer{T}"/>. </param> /// <param name="flags"> A bit-field that is used to specify allocation and usage information /// about the <see cref="ComputeBuffer{T}"/>. </param> /// <param name="count"> The number of elements of the <see cref="ComputeBuffer{T}"/>. </param> /// <param name="dataPtr"> A pointer to the data for the <see cref="ComputeBuffer{T}"/>. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// public ComputeBuffer(ComputeContext context, ComputeMemoryFlags flags, long count, IntPtr dataPtr) : base(context, flags) { ComputeErrorCode error = ComputeErrorCode.Success; Handle = CL12.CreateBuffer(context.Handle, flags, new IntPtr(Marshal.SizeOf(typeof(T)) * count), dataPtr, out error); ComputeException.ThrowOnError(error); Init(); }
public XArrayMemory(ComputeContext context, ComputeMemoryFlags flags, XArray obj) : base(context, flags) { var hostPtr = IntPtr.Zero; if ((flags & (ComputeMemoryFlags.CopyHostPointer | ComputeMemoryFlags.UseHostPointer)) != ComputeMemoryFlags.None) { hostPtr = obj.NativePtr; } ComputeErrorCode error = ComputeErrorCode.Success; var handle = CL12.CreateBuffer(context.Handle, flags, new IntPtr(obj.Count), hostPtr, out error); this.Size = obj.Count; this.Handle = handle; }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Creates a new <see cref="ComputeBuffer{T}"/>. </summary> /// /// <remarks> /// Note, that <paramref name="data"/> cannot be an "immediate" parameter, i.e.: <c>new /// T[100]</c>, because it could be quickly collected by the GC causing Cloo to send and invalid /// reference to OpenCL. /// </remarks> /// /// <param name="context"> A <see cref="ComputeContext"/> used to create the /// <see cref="ComputeBuffer{T}"/>. </param> /// <param name="flags"> A bit-field that is used to specify allocation and usage information /// about the <see cref="ComputeBuffer{T}"/>. </param> /// <param name="data"> The data for the <see cref="ComputeBuffer{T}"/>. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// public ComputeBuffer(ComputeContext context, ComputeMemoryFlags flags, T[] data) : base(context, flags) { GCHandle dataPtr = GCHandle.Alloc(data, GCHandleType.Pinned); try { ComputeErrorCode error = ComputeErrorCode.Success; Handle = CL12.CreateBuffer(context.Handle, flags, new IntPtr(Marshal.SizeOf(typeof(T)) * data.Length), dataPtr.AddrOfPinnedObject(), out error); ComputeException.ThrowOnError(error); } finally { dataPtr.Free(); } Init(); }
public GenericArrayMemory(ComputeContext context, ComputeMemoryFlags flags, object obj) : base(context, flags) { Array array = (Array)obj; if (array.Length == 0) { return; } int size = Marshal.SizeOf(array.GetValue(0).GetType()) * array.Length; var datagch = GCHandle.Alloc(obj, GCHandleType.Pinned); ComputeErrorCode error = ComputeErrorCode.Success; var handle = CL12.CreateBuffer(context.Handle, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, new IntPtr(size), datagch.AddrOfPinnedObject(), out error); this.Size = size; this.Handle = handle; }
/// <summary> /// Creates a new <see cref="ComputeBuffer{T}"/>. /// </summary> /// <param name="context"> A <see cref="ComputeContext"/> used to create the <see cref="ComputeBuffer{T}"/>. </param> /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeBuffer{T}"/>. </param> /// <param name="data"> The data for the <see cref="ComputeBuffer{T}"/>. </param> /// <remarks> Note, that <paramref name="data"/> cannot be an "immediate" parameter, i.e.: <c>new T[100]</c>, because it could be quickly collected by the GC causing Amplifier.OpenCL.Cloo to send and invalid reference to OpenCL. </remarks> public ComputeBuffer(ComputeContext context, ComputeMemoryFlags flags, T[] data) : base(context, flags) { var size = ComputeTools.SizeOf <T>() * data.Length; GCHandle dataPtr = GCHandle.Alloc(data, GCHandleType.Pinned); try { Handle = CL12.CreateBuffer(context.Handle, flags, new IntPtr(size), dataPtr.AddrOfPinnedObject(), out var error); ComputeException.ThrowOnError(error); } finally { dataPtr.Free(); } Init(size, data.Length); }
public GenericArrayMemory(ComputeContext context, ComputeMemoryFlags flags, Array array) : base(context, flags) { if (array.Length == 0) { return; } int size = Marshal.SizeOf(array.GetValue(0).GetType()) * array.Length; var hostPtr = IntPtr.Zero; if ((flags & (ComputeMemoryFlags.CopyHostPointer | ComputeMemoryFlags.UseHostPointer)) != ComputeMemoryFlags.None) { var datagch = GCHandle.Alloc(array, GCHandleType.Pinned); hostPtr = datagch.AddrOfPinnedObject(); } ComputeErrorCode error = ComputeErrorCode.Success; var handle = CL12.CreateBuffer(context.Handle, flags, new IntPtr(size), hostPtr, out error); this.Size = size; this.Handle = handle; }