示例#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
 protected override void algorithm()
 {
     result = 0;
     Parallel.For(ExecuteOn, 0, sizeX, delegate(int x){
         Atomic.Add(ref result, a[x]);
     });
 }
示例#3
0
 public static void AtomicAdd(this VariableView <Vector4> target, Vector4 operand)
 {
     Atomic.Add(ref target.SubView <float>(Vector4XOffset).Value, operand.X);
     Atomic.Add(ref target.SubView <float>(Vector4YOffset).Value, operand.Y);
     Atomic.Add(ref target.SubView <float>(Vector4ZOffset).Value, operand.Z);
     Atomic.Add(ref target.SubView <float>(Vector4WOffset).Value, operand.W);
 }
示例#4
0
 public void Release()
 {
     if (Group.IsFirstThread)
     {
         Atomic.Add(ref address.Value, 1);
     }
 }
示例#5
0
        protected override void algorithm()
        {
            histo = new int[sizeZ];

            int[] temp = new int[sizeZ];

            Parallel.For(ExecuteOn, 0, sizeZ, delegate(int thread_id)
            {
                temp[thread_id] = 0;
            });


            Parallel.For(ExecuteOn, 0, sizeY, delegate(int thread_id)
            {
                int i = thread_id;

                while (i < sizeX)
                {
                    Atomic.Add(ref temp[buffer[i]], 1);
                    i += sizeY;
                }
            });

            Parallel.For(ExecuteOn, 0, sizeZ, delegate(int thread_id)
            {
                Atomic.Add(ref histo[thread_id], temp[thread_id]);
            });
        }
示例#6
0
        internal static void Kernel(
            Index index,
            ArrayView <T> input,
            ArrayView <T> output,
            TRadixSortMapper mapper,
            ArrayView <Index> offsetCounter,
            ArrayView <Index> counter,
            int bitIdx,
            int trueOrFalse)
        {
            var stride = GridExtensions.GridStrideLoopStride;
            var offset = offsetCounter[0];

            var expectTrue = trueOrFalse == 1;

            for (var idx = index; idx < input.Length; idx += stride)
            {
                var element      = input[idx];
                var extractedBit = mapper.ExtractRadixBits(element, bitIdx);
                if (extractedBit == expectTrue)
                {
                    // Append to the output buffer
                    var elementIdx = Atomic.Add(ref counter[0], Index.One);
                    output[elementIdx + offset] = element;
                }
            }
        }
示例#7
0
 public static void MyKernel(Index1D index, ArrayView <int> progress)
 {
     for (var i = 0; i < NumIterations; i++)
     {
         Atomic.Add(ref progress[0], 1);
         MemoryFence.SystemLevel();
     }
 }
示例#8
0
 /// <summary>
 /// A simple 1D kernel using a pre-defined implementation
 /// of atomic add for doubles.
 /// <param name="index">The current thread index.</param>
 /// <param name="dataView">The view pointing to our memory buffer.</param>
 /// <param name="value">The value to add.</param>
 static void AddDoubleBuiltInKernel(
     Index index,
     ArrayView <double> dataView,
     double value)
 {
     // atomic add: dataView[0] += value;
     Atomic.Add(dataView.GetVariableView(0), value);
 }
示例#9
0
 /// <summary>
 /// A simple 1D kernel using a pre-defined implementation
 /// of atomic add for doubles.
 /// <param name="index">The current thread index.</param>
 /// <param name="dataView">The view pointing to our memory buffer.</param>
 /// <param name="value">The value to add.</param>
 static void AddDoubleBuiltInKernel(
     Index1 index,
     ArrayView <double> dataView,
     double value)
 {
     // atomic add: dataView[0] += value;
     Atomic.Add(ref dataView[0], value);
 }
示例#10
0
        public static void CalculateHistogram(Index3 index, ArrayView <int> result, ArrayView3D <short> input)
        {
            var val = input[index];

            if (val < 0)
            {
                val = 0;
            }
            Atomic.Add(ref result[(int)val], 1);
        }
示例#11
0
        internal static void GroupDivergentControlFlowKernel(ArrayView <int> data)
        {
            var idx = Grid.IdxX * Group.DimX + Group.IdxX;

            Group.Barrier();
            for (var i = 0; i < Group.IdxX; i++)
            {
                Group.Barrier();
                Atomic.Add(ref data[idx], 1);
            }
        }
示例#12
0
        private static void ReadThreadFunc(object state)
        {
            int count = 0;

            while (value < Result && count < CheckCount)
            {
                int element;
                while (ypipe.Read(out element))
                {
                    Atomic.Add(ref value, element);
                }
                Soyo.Base.Thread.Sleep(1);
                count++;
            }
        }
示例#13
0
文件: Program.cs 项目: MoFtZ/ILGPU
        /// <summary>
        /// A simple kernel that uses a variable-sub-view access to compute
        /// the target memory location for an atomic operation.
        /// </summary>
        /// <param name="index">The thread index.</param>
        /// <param name="elements">The elements to check.</param>
        /// <param name="view">The target view.</param>
        /// <param name="comparisonValue">The comparison value to use.</param>
        static void MyKernel(
            Index1D index,
            ArrayView <int> elements,
            ArrayView <ComposedStructure> view,
            int comparisonValue)
        {
            var element = elements[index];

            if (element == comparisonValue)
            {
                var baseView    = view.VariableView(0);
                var counterView = baseView.SubView <int>(ComposedStructure.ElementCounterOffset);
                Atomic.Add(ref counterView.Value, 1);
            }
        }
示例#14
0
        private static void ReadThreadSafeFunc(object state)
        {
            int count = 0;

            while (value < Result && count < CheckCount)
            {
                int  element;
                bool ret = false;
                lock (ypipe.ReadRoot) {
                    ret = ypipe.Read(out element);
                }
                while (ret)
                {
                    Atomic.Add(ref value, element);
                    lock (ypipe.ReadRoot) {
                        ret = ypipe.Read(out element);
                    }
                }
                Soyo.Base.Thread.Sleep(1);
                count++;
            }
        }
示例#15
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);
        }
示例#16
0
        protected override void algorithm()
        {
            /* Serial Implementation:
             *
             * for (int x = 0; x < sizeX; x++)
             *    if (haystack[x] == needle)
             *        positions[k++] = x;
             *
             */

            int k = 0;

            Parallel.For(ExecuteOn, 0, sizeX, delegate(int x)
            {
                if (haystack[x] == needle)
                {
                    positions[k] = x;

                    // TODO postpone incrementing of k.
                    // TODO create local results first and insert them afterwards.
                    Atomic.Add(ref k, 1);
                }
            });
        }
示例#17
0
 public static ulong Increment(ref ulong value) => Atomic.Add(ref value, 1UL);
示例#18
0
 public static int Increment(ref int value) => Atomic.Add(ref value, 1);
 public static void AtomicAdd(this VariableView <Vector3> target, Vector3 operand)
 {
     Atomic.Add(ref target.GetSubView <float>(Vector3XOffset).Value, operand.X);
     Atomic.Add(ref target.GetSubView <float>(Vector3YOffset).Value, operand.Y);
     Atomic.Add(ref target.GetSubView <float>(Vector3ZOffset).Value, operand.Z);
 }
示例#20
0
 public static long Increment(ref long value) => Atomic.Add(ref value, 1L);
示例#21
0
 public static uint Increment(ref uint value) => Atomic.Add(ref value, 1U);
示例#22
0
 public static long Decrement(ref long value) => Atomic.Add(ref value, -1L);
示例#23
0
 public static ulong Decrement(ref ulong value) =>
 (ulong)Atomic.Add(ref Unsafe.As <ulong, long>(ref value), -1L);
示例#24
0
 public static uint Decrement(ref uint value) =>
 (uint)Atomic.Add(ref Unsafe.As <uint, int>(ref value), -1);
示例#25
0
 public static void AtomicAdd(this VariableView <Vector2> target, Vector2 operand)
 {
     Atomic.Add(ref target.SubView <float>(Vector2XOffset).Value, operand.X);
     Atomic.Add(ref target.SubView <float>(Vector2YOffset).Value, operand.Y);
 }
示例#26
0
 public static int Decrement(ref int value) => Atomic.Add(ref value, -1);