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