Ejemplo n.º 1
0
        /// <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();
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        public void SetArgument(int argumentIndex, CLBuffer buffer)
        {
            IntPtr bufferPointer = buffer.InternalPointer;

            CLfunc.clSetKernelArg(InternalPointer, argumentIndex, Marshal.SizeOf(typeof(IntPtr)), ref bufferPointer);
        }