Beispiel #1
0
        /// <summary>
        /// Demonstrates the batched-sequence functionality.
        /// </summary>
        /// <param name="accl">The target accelerator.</param>
        static void BatchedSequence(Accelerator accl)
        {
            using (var buffer = accl.Allocate <int>(64))
            {
                // Creates a sequence (from 0 to buffer.Length / 2 - 1):
                // - [0, sequenceBatchLength - 1] = 0,,
                // - [sequenceBatchLength, sequenceBatchLength * 2 -1] = 1,
                // Note that in this case, the sequencer uses the default accelerator stream.
                accl.BatchedSequence(
                    buffer.View.GetSubView(0, buffer.Length / 2),
                    2
                    , new Int32Sequencer());

                // Creates a sequence (from 0 to buffer.Length / 2 - 1).
                // Note that this overload requires an explicit accelerator stream.
                accl.BatchedSequence(
                    accl.DefaultStream,
                    buffer.View.GetSubView(buffer.Length / 2),
                    4,
                    new Int32Sequencer());

                accl.Synchronize();

                var data = buffer.GetAsArray();
                for (int i = 0, e = data.Length; i < e; ++i)
                {
                    Console.WriteLine($"BatchedData[{i}] = {data[i]}");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Demonstrates the batched-sequence functionality.
        /// </summary>
        /// <param name="accl">The target accelerator.</param>
        static void BatchedSequence(Accelerator accl)
        {
            using (var buffer = accl.Allocate1D <int>(64))
            {
                // Creates a sequence (from 0 to buffer.Length):
                // - [0, sequenceBatchLength - 1] = 0,
                // - [sequenceBatchLength, sequenceBatchLength * 2 -1] = 1,
                accl.BatchedSequence(
                    accl.DefaultStream,
                    buffer.View,
                    2,
                    new Int32Sequencer());

                accl.Synchronize();

                var data = buffer.GetAsArray1D();
                for (int i = 0, e = data.Length; i < e; ++i)
                {
                    Console.WriteLine($"BatchedData[{i}] = {data[i]}");
                }

                // There is also a CreateBatchedSequencer function that avoids
                // unnecessary heap allocations.
            }
        }
Beispiel #3
0
        /// <summary>
        /// Demonstrates the batched-sequence functionality.
        /// </summary>
        /// <param name="accl">The target accelerator.</param>
        static void BatchedSequence(Accelerator accl)
        {
            using var buffer = accl.Allocate1D <int>(64);

            // Creates a sequence (from 0 to buffer.Length):
            // - [0, sequenceBatchLength - 1] = 0,
            // - [sequenceBatchLength, sequenceBatchLength * 2 -1] = 1,
            accl.BatchedSequence(
                accl.DefaultStream,
                buffer.View,
                2,
                new Int32Sequencer());

            // Reads data from the GPU buffer into a new CPU array.
            // Implicitly calls accl.DefaultStream.Synchronize() to ensure
            // that the kernel and memory copy are completed first.
            var data = buffer.GetAsArray1D();

            for (int i = 0, e = data.Length; i < e; ++i)
            {
                Console.WriteLine($"BatchedData[{i}] = {data[i]}");
            }

            // There is also a CreateBatchedSequencer function that avoids
            // unnecessary heap allocations.
        }
Beispiel #4
0
 /// <summary>
 /// Computes a new sequence of batched values of length sequenceBatchLength, and writes
 /// the computed values to the given view. Afterwards, the target view will contain the following values:
 /// - [0, sequenceBatchLength - 1] = 0,,
 /// - [sequenceBatchLength, sequenceBatchLength * 2 -1] = 1,
 /// - ...
 /// </summary>
 /// <typeparam name="T">The element type.</typeparam>
 /// <typeparam name="TSequencer">The type of the sequencer to use.</typeparam>
 /// <param name="accelerator">The accelerator.</param>
 /// <param name="view">The target view.</param>
 /// <param name="sequenceBatchLength">The length of a single batch.</param>
 /// <param name="sequencer">The used sequencer.</param>
 public static void BatchedSequence <T, TSequencer>(
     this Accelerator accelerator,
     ArrayView <T> view,
     Index sequenceBatchLength,
     TSequencer sequencer)
     where T : struct
     where TSequencer : struct, ISequencer <T>
 {
     accelerator.BatchedSequence(
         accelerator.DefaultStream,
         view,
         sequenceBatchLength,
         sequencer);
 }