Exemplo n.º 1
0
            public void Finish()
            {
                // Perform group wide reduction
                ReducedValue = GroupExtensions.Reduce <T, TReduction>(ReducedValue);

                if (Group.IsFirstThread)
                {
                    GetReduction().AtomicApply(ref Output[0], ReducedValue);
                }
            }
Exemplo n.º 2
0
        /// <summary>
        /// The actual reduction implementation.
        /// </summary>
        /// <typeparam name="T">The underlying type of the reduction.</typeparam>
        /// <typeparam name="TReduction">The type of the reduction logic.</typeparam>
        /// <param name="input">The input view.</param>
        /// <param name="output">The output view.</param>
        internal static void ReductionKernel <T, TReduction>(
            ArrayView <T> input,
            ArrayView <T> output)
            where T : unmanaged
            where TReduction : struct, IScanReduceOperation <T>
        {
            var stride = GridExtensions.GridStrideLoopStride;

            TReduction reduction = default;

            var reduced = reduction.Identity;

            for (var idx = Grid.GlobalIndex.X; idx < input.Length; idx += stride)
            {
                reduced = reduction.Apply(reduced, input[idx]);
            }

            reduced = GroupExtensions.Reduce <T, TReduction>(reduced);

            if (Group.IsFirstThread)
            {
                reduction.AtomicApply(ref output[0], reduced);
            }
        }