Ejemplo n.º 1
0
        /// <summary>
        /// Constructs the base class for all exchange buffer implementations.
        /// </summary>
        /// <param name="buffer">The memory buffer to use.</param>
        /// <param name="mode">The exchange buffer mode to use.</param>
        internal ExchangeBufferBase(MemoryBuffer <T, TIndex> buffer,
                                    ExchangeBufferMode mode)
            : base(buffer.Accelerator, buffer.Extent.Size)
        {
            cpuMemory = buffer.Accelerator is CudaAccelerator &&
                        mode == ExchangeBufferMode.PreferPagedLockedMemory
                ? CudaViewSource.Create(buffer.LengthInBytes)
                : (ViewPointerWrapper)UnmanagedMemoryViewSource.Create(
                buffer.LengthInBytes);

            cpuMemoryPointer = cpuMemory.NativePtr.ToPointer();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs the base class for all exchange buffer implementations.
        /// </summary>
        /// <param name="accelerator">The associated accelerator.</param>
        /// <param name="extent">The extent (number of elements).</param>
        /// <param name="mode">The exchange buffer mode to use.</param>
        protected ExchangeBufferBase(
            Accelerator accelerator,
            TIndex extent,
            ExchangeBufferMode mode)
            : base(accelerator, extent)
        {
            CPUMemory = Accelerator is CudaAccelerator &&
                        mode == ExchangeBufferMode.PreferPageLockedMemory
                ? CudaViewSource.Create(LengthInBytes)
                : (ViewPointerWrapper)UnmanagedMemoryViewSource.Create(LengthInBytes);

            var baseView = new ArrayView <T>(CPUMemory, 0, Length);

            CPUView = new ArrayView <T, TIndex>(baseView, extent);
        }