Library/ManagedCuda/CudaArray1D.cs
/// <summary>
/// Copy data from array to host memory
/// </summary>
/// <typeparam name="T">T must be of value type, i.e. a struct</typeparam>
/// <param name="dest">Destination pointer to host memory</param>
/// <param name="offsetInBytes">Offset in bytes of destination array</param>
Copy data from array to host memory
Copy data from array to host memory
public void CopyFromArray1DToHost<T>(ref T dest, SizeT offsetInBytes) where T : struct
        {
            SizeT sizeInBytes = Marshal.SizeOf(typeof(T));
            GCHandle handle = GCHandle.Alloc(dest, GCHandleType.Pinned);
            CUResult res;
            try
            {
                IntPtr ptr = handle.AddrOfPinnedObject();
                res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpyAtoH_v2(ptr, _cuArray, offsetInBytes, sizeInBytes);
                Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpyAtoH", res));
                dest = (T)Marshal.PtrToStructure(ptr, typeof(T)); 
            }
            finally
            {
                handle.Free();
            }
            if (res != CUResult.Success)
                throw new CudaException(res);
        }
public void CopyFromArray1DToHost < T > ( ref T dest , SizeT offsetInBytes ) where T : struct { SizeT sizeInBytes = Marshal . SizeOf ( typeof ( T ) ) ; GCHandle handle = GCHandle . Alloc ( dest , GCHandleType . Pinned ) ; CUResult res ; try { IntPtr ptr = handle . AddrOfPinnedObject ( ) ; res = DriverAPINativeMethods . SynchronousMemcpy_v2 . cuMemcpyAtoH_v2 ( ptr , _cuArray , offsetInBytes , sizeInBytes ) ; 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 array to host memory
Copy data from array 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
<not_specific>
offsetInBytes
SizeT
Offset in bytes of destination array
Offset in bytes of destination array
dest
<not_specific>
Destination pointer to host memory
Destination 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