Exemple #1
0
        public static HostBuffer2D <T> Alloc(int width, int height)
        {
            HostBuffer2D <T> result = new HostBuffer2D <T>();

            result.ptr    = RawHostBuffer.Alloc((uint)result.ElemSize * (uint)width * (uint)height);
            result.width  = width;
            result.height = height;

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Copies data from host memory to a cuda array asynchronously. No size checks are performed, it is
        /// up to the programmer to ensure the destination is large enough to hold the data.
        /// </summary>
        /// <param name="src">The source buffer</param>
        /// <param name="dest">The destination pointer</param>
        /// <param name="stream">The stream in which to queue the copy operation</param>
        public static void CopyAsync <T>(HostBuffer2D <T> src, CudaArray dest, Stream stream) where T : struct
        {
            if (src.IsNull() || dest.IsNull())
            {
                throw new NullPointerException();
            }

            CudaUtil.Call(CudaMem.memcpy2DAsyncHelper(
                              MemoryType.Host, 0, 0, src.ptr, (uint)src.RowSizeBytes,
                              MemoryType.Array, 0, 0, dest.handle, 0,
                              (uint)src.RowSizeBytes, (uint)src.height, stream.Handle
                              ));
        }
Exemple #3
0
        /// <summary>
        /// Copies data from device memory to host memory asynchronously.
        /// </summary>
        /// <param name="src">The source pointer</param>
        /// <param name="dest">The destination buffer</param>
        /// <param name="stream">The stream in which to queue the copy operation</param>
        public static void CopyAsync <T>(DeviceBuffer2D src, HostBuffer2D <T> dest, Stream stream) where T : struct
        {
            if (src.ptr == DevicePtr2D.Zero || dest.IsNull())
            {
                throw new NullPointerException();
            }
            if (src.widthInBytes != (uint)dest.RowSizeBytes || src.height != (uint)dest.height)
            {
                throw new ArgumentException("The source and destination sizes do not match.");
            }

            CudaUtil.Call(memcpy2DAsyncHelper(
                              MemoryType.Device, 0, 0, (IntPtr)src.ptr.ptr, src.ptr.pitch,
                              MemoryType.Host, 0, 0, dest.Ptr, (uint)dest.RowSizeBytes,
                              (uint)dest.RowSizeBytes, (uint)dest.Height, stream.Handle)
                          );
        }
Exemple #4
0
        /// <summary>
        /// Copies data from host memory to device memory.
        /// </summary>
        /// <param name="src">The source buffer</param>
        /// <param name="dest">The destination buffer</param>
        public static void Copy <T>(HostBuffer2D <T> src, DeviceBuffer2D dest) where T : struct
        {
            if (src.IsNull() || dest.ptr == DevicePtr2D.Zero)
            {
                throw new NullPointerException();
            }
            if ((uint)src.RowSizeBytes != dest.WidthInBytes || (uint)src.Height != dest.Height)
            {
                throw new ArgumentException("The source and destination sizes do not match.");
            }

            CudaUtil.Call(CudaMem.memcpy2DHelper(
                              MemoryType.Host, 0, 0, src.ptr, (uint)src.RowSizeBytes,
                              MemoryType.Device, 0, 0, (IntPtr)dest.ptr.ptr, dest.ptr.pitch,
                              (uint)src.RowSizeBytes, (uint)src.height)
                          );
        }