Library/ManagedCuda/CudaContext.cs
/// <summary>
/// Copy data from device to host memory
/// </summary>
/// <typeparam name="T">T must be of value type, i.e. a struct</typeparam>
/// <param name="aDest">Destination data in host memory</param>
/// <param name="aSource">Source CUdeviceptr (Pointer to device memory)</param>
Copy data from device to host memory
Copy data from device to host memory
public void CopyToHost<T>(T[] aDest, CUdeviceptr aSource) where T : struct
		{
			if (disposed) throw new ObjectDisposedException(this.ToString());
			SizeT aSizeInBytes = (aDest.LongLength * Marshal.SizeOf(typeof(T)));
			CUResult res;
			GCHandle handle = GCHandle.Alloc(aDest, GCHandleType.Pinned);
			try
			{
				IntPtr ptr = handle.AddrOfPinnedObject();
				res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpyDtoH_v2(ptr, aSource, aSizeInBytes);
				Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpyDtoH_v2", res));
			}
			finally
			{
				handle.Free();
			}
			if (res != CUResult.Success)
				throw new CudaException(res);
		}
public void CopyToHost < T > ( T [ ] aDest , CUdeviceptr aSource ) where T : struct { if ( disposed ) throw new ObjectDisposedException ( this . ToString ( ) ) ; SizeT aSizeInBytes = ( aDest . LongLength * Marshal . SizeOf ( typeof ( T ) ) ) ; CUResult res ; GCHandle handle = GCHandle . Alloc ( aDest , GCHandleType . Pinned ) ; try { IntPtr ptr = handle . AddrOfPinnedObject ( ) ; res = DriverAPINativeMethods . SynchronousMemcpy_v2 . cuMemcpyDtoH_v2 ( ptr , aSource , aSizeInBytes ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; } 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
aDest
T[]
Destination data in host memory
Destination data in host memory
aSource
CUdeviceptr
Source CUdeviceptr (Pointer to device memory)
Source CUdeviceptr ( Pointer to device memory )
typeparam
T must be of value type, i.e. a struct
T must be of value type i . e . a struct