/// <summary> /// バッファからデータを読み出します /// </summary> /// <typeparam name="T"></typeparam> /// <param name="buffer"></param> /// <param name="systemBuffer"></param> public void ReadBuffer <T>(CLBuffer buffer, T[] systemBuffer) where T : struct { GCHandle handle = GCHandle.Alloc(systemBuffer, GCHandleType.Pinned); CLfunc.clEnqueueReadBuffer( InternalPointer, buffer.InternalPointer, true, 0, Math.Min(buffer.SizeInBytes, Marshal.SizeOf(typeof(T)) * systemBuffer.Length), handle.AddrOfPinnedObject(), 0, IntPtr.Zero, IntPtr.Zero); handle.Free(); }
/// <summary> /// バッファにデータを書き込みます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context"></param> /// <param name="initialData"></param> /// <returns></returns> public static CLBuffer FromCopiedHostMemory <T>(CLContext context, T[] initialData) where T : struct { CLBuffer result = new CLBuffer(); result.SizeInBytes = Marshal.SizeOf(typeof(T)) * initialData.Length; int errorCode; GCHandle handle = GCHandle.Alloc(initialData, GCHandleType.Pinned); result.InternalPointer = CLfunc.clCreateBuffer( context.InternalPointer, MemoryFlags.CopyHostMemory, result.SizeInBytes, handle.AddrOfPinnedObject(), out errorCode); handle.Free(); return(result); }
public void SetArgument(int argumentIndex, CLBuffer buffer) { IntPtr bufferPointer = buffer.InternalPointer; CLfunc.clSetKernelArg(InternalPointer, argumentIndex, Marshal.SizeOf(typeof(IntPtr)), ref bufferPointer); }