/// <summary> /// Copies data from host memory to a cuda array. 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> public static void Copy <T>(HostBuffer2D <T> src, CudaArray dest) where T : struct { if (src.IsNull() || dest.IsNull()) { throw new NullPointerException(); } CudaUtil.Call(CudaMem.memcpy2DHelper( MemoryType.Host, 0, 0, src.ptr, (uint)src.RowSizeBytes, MemoryType.Array, 0, 0, dest.handle, 0, (uint)src.RowSizeBytes, (uint)src.height) ); }
/// <summary> /// Copies data from host memory to device memory. 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="widthInBytes">The size of each row in bytes</param> /// <param name="height">The number of rows</param> public static void CopyRaw2D(IntPtr srcPtr, DevicePtr2D dest, IntPtr widthInBytes, IntPtr height) { if (srcPtr == IntPtr.Zero || dest == DevicePtr2D.Zero) { throw new NullPointerException(); } CudaUtil.Call(CudaMem.memcpy2DHelper( MemoryType.Host, 0, 0, srcPtr, (uint)widthInBytes, MemoryType.Device, 0, 0, (IntPtr)dest.ptr, (uint)dest.Pitch, (uint)widthInBytes, (uint)height) ); }
/// <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) ); }