Library/ManagedCuda/CudaContext.cs
/// <summary>
/// Copy data from host to device memory
/// </summary>
/// <typeparam name="T">T must be of value type, i.e. a struct</typeparam>
/// <param name="aDest">Destination CUdeviceptr (Pointer to device memory)</param>
/// <param name="aSource">Source pointer to host memory</param>
Copy data from host to device memory
Copy data from host to device memory
public void CopyToDevice<T>(CUdeviceptr aDest, T aSource) where T : struct
		{
			if (disposed) throw new ObjectDisposedException(this.ToString());
			SizeT aSizeInBytes = (uint)Marshal.SizeOf(typeof(T));
			GCHandle handle = GCHandle.Alloc(aSource, GCHandleType.Pinned);
			CUResult res;
			try
			{
				IntPtr ptr = handle.AddrOfPinnedObject();
				res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpyHtoD_v2(aDest, ptr, aSizeInBytes);
				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 > ( CUdeviceptr aDest , T aSource ) where T : struct { if ( disposed ) throw new ObjectDisposedException ( this . ToString ( ) ) ; SizeT aSizeInBytes = ( uint ) Marshal . SizeOf ( typeof ( T ) ) ; GCHandle handle = GCHandle . Alloc ( aSource , GCHandleType . Pinned ) ; CUResult res ; try { IntPtr ptr = handle . AddrOfPinnedObject ( ) ; res = DriverAPINativeMethods . SynchronousMemcpy_v2 . cuMemcpyHtoD_v2 ( aDest , ptr , aSizeInBytes ) ; 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
aDest
CUdeviceptr
Destination CUdeviceptr (Pointer to device memory)
Destination CUdeviceptr ( Pointer to device memory )
aSource
T
Source pointer to host memory
Source pointer to host memory
typeparam
T must be of value type, i.e. a struct
T must be of value type i . e . a struct