Library/ManagedCuda/CudaDeviceVariable.cs
/// <summary>
/// Copy data from device to host memory
/// </summary>
/// <param name="dest">Destination data in host memory</param>
/// <param name="offsetSrc">Offset to source pointer in bytes</param>
Copy data from device to host memory
Copy data from device to host memory
public void CopyToHost(ref T dest, SizeT offsetSrc)
		{
			if (disposed) throw new ObjectDisposedException(this.ToString());
			SizeT aSizeInBytes = _typeSize;
			GCHandle handle = GCHandle.Alloc(dest, GCHandleType.Pinned);
			CUResult res;
			try
			{
				IntPtr ptr = handle.AddrOfPinnedObject();
				res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpyDtoH_v2(ptr, _devPtr + offsetSrc, aSizeInBytes);
				Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpyDtoH", res));
				dest = (T)Marshal.PtrToStructure(ptr, typeof(T));
			}
			finally
			{
				handle.Free();
			}
			if (res != CUResult.Success)
				throw new CudaException(res);
		}
public void CopyToHost ( ref T dest , SizeT offsetSrc ) { if ( disposed ) throw new ObjectDisposedException ( this . ToString ( ) ) ; SizeT aSizeInBytes = _typeSize ; GCHandle handle = GCHandle . Alloc ( dest , GCHandleType . Pinned ) ; CUResult res ; try { IntPtr ptr = handle . AddrOfPinnedObject ( ) ; res = DriverAPINativeMethods . SynchronousMemcpy_v2 . cuMemcpyDtoH_v2 ( ptr , _devPtr + offsetSrc , aSizeInBytes ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; dest = ( T ) Marshal . PtrToStructure ( ptr , typeof ( T ) ) ; } finally { handle . Free ( ) ; } if ( res != CUResult . Success ) throw new CudaException ( res ) ; }
Copy data from device to host memory
Copy data from device to host memory
// T is a struct and therefor a value type. GCHandle will pin a copy of dest, not dest itself //Copy Data from pinned copy to original dest
T
ref
offsetSrc
SizeT
Offset to source pointer in bytes
Offset to source pointer in bytes
dest
Destination data in host memory
Destination data in host memory