Example #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);
        }
Example #2
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);
        }