/// <summary>
        /// Performs a reduction using a reduction logic.
        /// </summary>
        /// <typeparam name="T">The underlying type of the reduction.</typeparam>
        /// <typeparam name="TShuffleDown">The type of the shuffle logic.</typeparam>
        /// <typeparam name="TReduction">The type of the reduction logic.</typeparam>
        /// <param name="accelerator">The accelerator.</param>
        /// <param name="stream">The accelerator stream.</param>
        /// <param name="input">The input elements to reduce.</param>
        /// <param name="output">The output view to store the reduced value.</param>
        /// <param name="shuffleDown">The shuffle logic.</param>
        /// <param name="reduction">The reduction logic.</param>
        /// <remarks>Uses the internal cache to realize a temporary output buffer.</remarks>
        public static void Reduce <T, TShuffleDown, TReduction>(
            this Accelerator accelerator,
            AcceleratorStream stream,
            ArrayView <T> input,
            ArrayView <T> output,
            TShuffleDown shuffleDown,
            TReduction reduction)
            where T : struct
            where TShuffleDown : struct, IShuffleDown <T>
            where TReduction : struct, IReduction <T>
        {
            if (!input.IsValid)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (input.Length < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(input));
            }
            var tempStorageSize = accelerator.ComputeReductionTempStorageSize(input.Length);
            var temp            = accelerator.MemoryCache.Allocate <T>(tempStorageSize);

            accelerator.CreateReduction <T, TShuffleDown, TReduction>()(
                stream,
                input,
                output,
                temp,
                shuffleDown,
                reduction);
        }
예제 #2
0
 /// <summary>
 /// Performs a reduction using a reduction logic.
 /// </summary>
 /// <typeparam name="T">The underlying type of the reduction.</typeparam>
 /// <typeparam name="TReduction">The type of the reduction logic.</typeparam>
 /// <param name="accelerator">The accelerator.</param>
 /// <param name="stream">The accelerator stream.</param>
 /// <param name="input">The input elements to reduce.</param>
 /// <param name="output">The output view to store the reduced value.</param>
 public static void Reduce <T, TReduction>(
     this Accelerator accelerator,
     AcceleratorStream stream,
     ArrayView <T> input,
     ArrayView <T> output)
     where T : unmanaged
     where TReduction : struct, IScanReduceOperation <T> =>
 accelerator.CreateReduction <T, Stride1D.Dense, TReduction>()(
     stream,
     input,
     output);
        /// <summary>
        /// Creates a new instance of a atomic reduction handler.
        /// </summary>
        /// <typeparam name="T">The underlying type of the reduction.</typeparam>
        /// <typeparam name="TShuffleDown">The type of the shuffle logic.</typeparam>
        /// <typeparam name="TReduction">The type of the reduction logic.</typeparam>
        /// <param name="accelerator">The accelerator.</param>
        /// <param name="shuffleDown">The shuffle logic.</param>
        /// <param name="reduction">The reduction logic.</param>
        /// <returns>The created reduction handler.</returns>
        public static Reduction <T> CreateReduction <T, TShuffleDown, TReduction>(
            this Accelerator accelerator,
            TShuffleDown shuffleDown,
            TReduction reduction)
            where T : struct
            where TShuffleDown : struct, IShuffleDown <T>
            where TReduction : struct, IReduction <T>
        {
            var reductionDel = accelerator.CreateReduction <T, TShuffleDown, TReduction>();

            return((stream, input, output, temp) =>
            {
                reductionDel(stream, input, output, temp, shuffleDown, reduction);
            });
        }
 /// <summary>
 /// Performs a reduction using a reduction logic.
 /// </summary>
 /// <typeparam name="T">The underlying type of the reduction.</typeparam>
 /// <typeparam name="TShuffleDown">The type of the shuffle logic.</typeparam>
 /// <typeparam name="TReduction">The type of the reduction logic.</typeparam>
 /// <param name="accelerator">The accelerator.</param>
 /// <param name="stream">The accelerator stream.</param>
 /// <param name="input">The input elements to reduce.</param>
 /// <param name="output">The output view to store the reduced value.</param>
 /// <param name="temp">The temporary view to store the temporary values.</param>
 /// <param name="shuffleDown">The shuffle logic.</param>
 /// <param name="reduction">The reduction logic.</param>
 public static void Reduce <T, TShuffleDown, TReduction>(
     this Accelerator accelerator,
     AcceleratorStream stream,
     ArrayView <T> input,
     ArrayView <T> output,
     ArrayView <T> temp,
     TShuffleDown shuffleDown,
     TReduction reduction)
     where T : struct
     where TShuffleDown : struct, IShuffleDown <T>
     where TReduction : struct, IReduction <T>
 {
     accelerator.CreateReduction <T, TShuffleDown, TReduction>()(
         stream,
         input,
         output,
         temp,
         shuffleDown,
         reduction);
 }