Beispiel #1
0
        public static HostBuffer1D <T> Alloc(int length)
        {
            HostBuffer1D <T> result   = new HostBuffer1D <T>();
            uint             elemSize = (uint)Marshal.SizeOf(typeof(T));

            CudaUtil.Call(CudaMem.cuMemAllocHost(out result.ptr, elemSize * (uint)length));
            result.length = length;
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Copies data from device memory to host memory asynchronously.
        /// </summary>
        /// <param name="src">The source pointer</param>
        /// <param name="dest">The destination buffer</param>
        /// <param name="stream">The stream in which to queue the copy operation</param>
        public static void CopyAsync <T>(DeviceBuffer src, HostBuffer1D <T> dest, Stream stream) where T : struct
        {
            if (src.ptr == DevicePtr.Zero || dest.IsNull())
            {
                throw new NullPointerException();
            }
            if (src.sizeInBytes != (uint)dest.SizeInBytes)
            {
                throw new ArgumentException("The source and destination sizes do not match.");
            }

            CudaUtil.Call(cuMemcpyDtoHAsync(dest.ptr, src.ptr.ptr, (uint)dest.SizeInBytes, stream.Handle));
        }
Beispiel #3
0
        /// <summary>
        /// Copies data from host memory to device memory.
        /// </summary>
        /// <param name="src">The source buffer</param>
        /// <param name="dest">The destination pointer</param>
        public static void Copy <T>(HostBuffer1D <T> src, DeviceBuffer dest) where T : struct
        {
            if (src.IsNull() || dest.ptr == DevicePtr.Zero)
            {
                throw new NullPointerException();
            }
            if (src.SizeInBytes != dest.SizeInBytes)
            {
                throw new ArgumentException("The source and destination sizes do not match.");
            }

            CudaUtil.Call(cuMemcpyHtoD(dest.ptr.ptr, src.ptr, (uint)src.SizeInBytes));
        }