示例#1
0
        /// <summary>
        /// A simple 1D kernel using basic atomic functions.
        /// The second parameter (<paramref name="dataView"/>) represents the target
        /// view for all atomic operations.
        /// </summary>
        /// <param name="index">The current thread index.</param>
        /// <param name="dataView">The view pointing to our memory buffer.</param>
        /// <param name="constant">A uniform constant.</param>
        static void AtomicOperationKernel(
            Index index,               // The global thread index (1D in this case)
            ArrayView <int> dataView,  // A view to a chunk of memory (1D in this case)
            int constant)              // A sample uniform constant
        {
            // dataView[0] += constant
            Atomic.Add(dataView.GetVariableView(0), constant);

            // dataView[1] -= constant
            Atomic.Sub(dataView.GetVariableView(1), constant);

            // dataView[2] = Max(dataView[2], constant)
            Atomic.Max(dataView.GetVariableView(2), constant);

            // dataView[3] = Min(dataView[3], constant)
            Atomic.Min(dataView.GetVariableView(3), constant);

            // dataView[4] = Min(dataView[4], constant)
            Atomic.And(dataView.GetVariableView(4), constant);

            // dataView[5] = Min(dataView[5], constant)
            Atomic.Or(dataView.GetVariableView(5), constant);

            // dataView[6] = Min(dataView[6], constant)
            Atomic.Xor(dataView.GetVariableView(6), constant);
        }
示例#2
0
 /// <summary>
 /// The actual histogram kernel implementation.
 /// </summary>
 /// <typeparam name="T">The element type.</typeparam>
 /// <typeparam name="TBinType">The histogram bin type.</typeparam>
 /// <typeparam name="TIncrementor">
 /// The operation to increment the value of the bin.
 /// </typeparam>
 /// <typeparam name="TLocator">
 /// The operation to compute the bin location.
 /// </typeparam>
 /// <param name="view">The input view.</param>
 /// <param name="histogram">The histogram view to update.</param>
 /// <param name="histogramOverflow">
 /// Single-element view that indicates 4 the histogram has overflowed.
 /// </param>
 /// <param name="paddedLength">The padded length of the input view.</param>
 internal static void HistogramKernel <
     T,
     TBinType,
     TIncrementor,
     TLocator>(
     ArrayView <T> view,
     ArrayView <TBinType> histogram,
     ArrayView <int> histogramOverflow,
     int paddedLength)
     where T : unmanaged
     where TBinType : unmanaged
     where TIncrementor : struct, IIncrementOperation <TBinType>
     where TLocator : struct, IComputeMultiBinOperation <T, TBinType, TIncrementor>
 {
     HistogramWorkKernel <T, TBinType, TIncrementor, TLocator>(
         view,
         histogram,
         out var histogramDidOverflow,
         paddedLength);
     Atomic.Or(ref histogramOverflow[0], histogramDidOverflow ? 1 : 0);
 }
示例#3
0
        /// <summary>
        /// A simple 1D kernel using basic atomic functions.
        /// The second parameter (<paramref name="dataView"/>) represents the target
        /// view for all atomic operations.
        /// </summary>
        /// <param name="index">The current thread index.</param>
        /// <param name="dataView">The view pointing to our memory buffer.</param>
        /// <param name="constant">A uniform constant.</param>
        static void AtomicOperationKernel(
            Index1D index,             // The global thread index (1D in this case)
            ArrayView <int> dataView,  // A view to a chunk of memory (1D in this case)
            int constant)              // A sample uniform constant
        {
            // dataView[0] += constant
            Atomic.Add(ref dataView[0], constant);

            // dataView[1] = Max(dataView[1], constant)
            Atomic.Max(ref dataView[1], constant);

            // dataView[2] = Min(dataView[2], constant)
            Atomic.Min(ref dataView[2], constant);

            // dataView[3] = Min(dataView[3], constant)
            Atomic.And(ref dataView[3], constant);

            // dataView[4] = Min(dataView[4], constant)
            Atomic.Or(ref dataView[4], constant);

            // dataView[6] = Min(dataView[5], constant)
            Atomic.Xor(ref dataView[5], constant);
        }