Exemplo n.º 1
0
        /// <summary>
        /// Creates a new buffered scan operation.
        /// </summary>
        /// <typeparam name="T">The underlying type of the scan operation.</typeparam>
        /// <typeparam name="TScanOperation">The type of the scan operation.</typeparam>
        /// <param name="kind">The scan kind.</param>
        /// <returns>The created scan handler.</returns>
        public BufferedScan <T> CreateScan <T, TScanOperation>(
            ScanKind kind)
            where T : unmanaged
            where TScanOperation : struct, IScanReduceOperation <T>
        {
            var scan = Accelerator.CreateScan <T, TScanOperation>(kind);

            return((stream, input, output) =>
                   scan(stream, input, output, tempBuffer.View));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new buffered scan operation.
        /// </summary>
        /// <typeparam name="T">The underlying type of the scan operation.</typeparam>
        /// <typeparam name="TScanOperation">The type of the scan operation.</typeparam>
        /// <param name="kind">The scan kind.</param>
        /// <returns>The created scan handler.</returns>
        public BufferedScan <T> CreateScan <T, TScanOperation>(
            ScanKind kind)
            where T : unmanaged
            where TScanOperation : struct, IScanReduceOperation <T>
        {
            var scan = Accelerator.CreateScan <T, TScanOperation>(kind);

            return((stream, input, output) =>
            {
                var tempView = AllocateTempScanView(input);
                scan(stream, input, output, tempView);
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new scan operation.
        /// </summary>
        /// <typeparam name="T">The underlying type of the scan operation.</typeparam>
        /// <typeparam name="TShuffleDown">The type of the shuffle logic.</typeparam>
        /// <typeparam name="TScanOperation">The type of the scan operation.</typeparam>
        /// <param name="accelerator">The accelerator.</param>
        /// <param name="kind">The scan kind.</param>
        /// <param name="shuffleDown">The shuffle logic.</param>
        /// <param name="scanOperation">The scan logic.</param>
        /// <returns>The created scan handler.</returns>
        public static Scan <T> CreateScan <T, TShuffleDown, TScanOperation>(
            this Accelerator accelerator,
            ScanKind kind,
            TShuffleDown shuffleDown,
            TScanOperation scanOperation)
            where T : struct
            where TShuffleDown : struct, IShuffleDown <T>
            where TScanOperation : struct, IScanOperation <T>
        {
            var scan = CreateScan <T, TShuffleDown, TScanOperation>(accelerator, kind);

            return((stream, input, output, temp) =>
                   scan(stream, input, output, temp, shuffleDown, scanOperation));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new buffered scan operation.
        /// </summary>
        /// <typeparam name="T">The underlying type of the scan operation.</typeparam>
        /// <typeparam name="TShuffleDown">The type of the shuffle logic.</typeparam>
        /// <typeparam name="TScanOperation">The type of the scan operation.</typeparam>
        /// <param name="kind">The scan kind.</param>
        /// <returns>The created scan handler.</returns>
        public BufferedScan <T, TShuffleDown, TScanOperation> CreateScan <T, TShuffleDown, TScanOperation>(
            ScanKind kind)
            where T : struct
            where TShuffleDown : struct, IShuffleDown <T>
            where TScanOperation : struct, IScanOperation <T>
        {
            var scan = Accelerator.CreateScan <T, TShuffleDown, TScanOperation>(kind);

            return((stream, input, output, shuffleDown, scanOperation) =>
            {
                var tempView = AllocateTempScanView(input);
                scan(stream, input, output, tempView, shuffleDown, scanOperation);
            });
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a new scan operation.
        /// </summary>
        /// <typeparam name="T">The underlying type of the scan operation.</typeparam>
        /// <typeparam name="TShuffleDown">The type of the shuffle logic.</typeparam>
        /// <typeparam name="TScanOperation">The type of the scan operation.</typeparam>
        /// <param name="accelerator">The accelerator.</param>
        /// <param name="kind">The scan kind.</param>
        /// <returns>The created scan handler.</returns>
        public static Scan <T, TShuffleDown, TScanOperation> CreateScan <T, TShuffleDown, TScanOperation>(
            this Accelerator accelerator,
            ScanKind kind)
            where T : struct
            where TShuffleDown : struct, IShuffleDown <T>
            where TScanOperation : struct, IScanOperation <T>
        {
            var inclusive = kind == ScanKind.Inclusive;

            if (accelerator.MaxNumThreadsPerGroup < 2)
            {
                var scan = accelerator.LoadAutoGroupedKernel <
                    Action <AcceleratorStream, Index, ArrayView <T>, ArrayView <T>, TScanOperation> >(
                    inclusive ?
                    SingleThreadedScanImpl <T, TScanOperation> .InclusiveKernelMethod :
                    SingleThreadedScanImpl <T, TScanOperation> .ExclusiveKernelMethod,
                    out int groupSize, out int minGridSize);
                var minDataSize = groupSize * minGridSize;
                return((stream, input, output, temp, shuffleDown, scanOperation) =>
                {
                    if (!input.IsValid)
                    {
                        throw new ArgumentNullException(nameof(input));
                    }
                    if (!output.IsValid)
                    {
                        throw new ArgumentNullException(nameof(output));
                    }
                    var dimension = Math.Min(minDataSize, input.Length);
                    scan(stream, dimension, input, output, scanOperation);
                });
            }
            else
            {
                // TODO: add final scan implementation
                throw new NotImplementedException();
            }
        }