Library/ManagedCuda/CudaDeviceVariable.cs
/// <summary>
/// Copy data from host to device memory
/// </summary>
/// <param name="source">Source pointer to host memory</param>
/// <param name="offsetSrc">Offset to source pointer in bytes</param>
/// <param name="offsetDest">Offset to destination pointer in bytes</param>
/// <param name="sizeInBytes">Size to copy in bytes</param>
Copy data from host to device memory
Copy data from host to device memory
public void CopyToDevice(T[] source, SizeT offsetSrc, SizeT offsetDest, SizeT sizeInBytes)
		{
			if (disposed) throw new ObjectDisposedException(this.ToString());
			GCHandle handle = GCHandle.Alloc(source, GCHandleType.Pinned);
			CUResult res;
			try
			{
				IntPtr ptr = new IntPtr(handle.AddrOfPinnedObject().ToInt64() + (long)offsetSrc);
				res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpyHtoD_v2(_devPtr + offsetDest, ptr, sizeInBytes);
				Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpyHtoD", res));
			}
			finally
			{
				handle.Free();
			}
			if (res != CUResult.Success)
				throw new CudaException(res);
		}
public void CopyToDevice ( T [ ] source , SizeT offsetSrc , SizeT offsetDest , SizeT sizeInBytes ) { if ( disposed ) throw new ObjectDisposedException ( this . ToString ( ) ) ; GCHandle handle = GCHandle . Alloc ( source , GCHandleType . Pinned ) ; CUResult res ; try { IntPtr ptr = new IntPtr ( handle . AddrOfPinnedObject ( ) . ToInt64 ( ) + ( long ) offsetSrc ) ; res = DriverAPINativeMethods . SynchronousMemcpy_v2 . cuMemcpyHtoD_v2 ( _devPtr + offsetDest , ptr , sizeInBytes ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; } finally { handle . Free ( ) ; } if ( res != CUResult . Success ) throw new CudaException ( res ) ; }
Copy data from host to device memory
Copy data from host to device memory
source
T[]
Source pointer to host memory
Source pointer to host memory
offsetSrc
SizeT
Offset to source pointer in bytes
Offset to source pointer in bytes
offsetDest
SizeT
Offset to destination pointer in bytes
Offset to destination pointer in bytes
sizeInBytes
SizeT
Size to copy in bytes
Size to copy in bytes