Esempio n. 1
0
        static void SubViewAccess(ArrayView <int> view)
        {
            // Creates a sub view that represents a view from index 10 to view.Length - 1
            var subView = view.SubView(10);

            Debug.Assert(subView.Length == view.Length - 10);

            // Write value to sub view and output value
            subView[0] = 42;
            Console.WriteLine($"Value of sub view at index 0: {subView[0]} = value of view at index 10: {view[10]}");

            // Creates a sub view that represents a view from index 10 with length 20
            // (up to index 10 + 20)
            var subView2 = view.SubView(10, 20);

            Debug.Assert(subView2.Length == 20);
            Console.WriteLine($"Value of sub view 2 at index 0: {subView2[0]} = value of view at index 10: {view[10]}");

            // Creates a sub view that represents a view from index 20 with length 2
            var subView3 = subView2.SubView(10, 2);

            subView3[1] = 23;

            // An access of the form subView3[2] will trigger an OutOfBounds assertion
            Debug.Assert(subView3.Length == 2);
            Console.WriteLine($"Value of sub view 3 at index 1: {subView3[1]} = value of view at index 21: {view[21]}");
        }
Esempio n. 2
0
        static void OffsetCopyAccess(ArrayView <int> view)
        {
            // Replace the first 256 items on the accelerator with the value 42.
            var replacementValues = Enumerable.Repeat(42, 256).ToArray();

            view.SubView(0, replacementValues.Length).CopyFromCPU(replacementValues);

            // Replace the next 256 items on the accelerator with the value 97.
            var nextReplacementValues = Enumerable.Repeat(97, 256).ToArray();

            view.SubView(256, nextReplacementValues.Length).CopyFromCPU(nextReplacementValues);

            // Copy a range of values from the accelerator to the CPU into a new array.
            var fromGPU = view.SubView(128, 256).GetAsArray();

            // Copy a range of values from the accelerator to the CPU into an existing array.
            view.SubView(0, 128).CopyToCPU(fromGPU.AsSpan().Slice(128));
        }
Esempio n. 3
0
        internal static void ArrayViewGetSubViewImplicitLengthKernel(
            Index1D index,
            ArrayView1D <int, Stride1D.Dense> length,
            ArrayView1D <int, Stride1D.Dense> source,
            int subViewOffset)
        {
            ArrayView <int> rawView = source;
            var             subView = rawView.SubView(subViewOffset);

            length[index] = subView.IntLength;
        }