예제 #1
0
        static void Main()
        {
            // Create the graphics buffer
            int width  = 10;
            int height = 10;

            float[] array = new float[width * height];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = i + 1;
            }

            using ReadWriteBuffer <float> gpuBuffer = Gpu.Default.AllocateReadWriteBuffer(array);

            // Run the shader
            Gpu.Default.For(100, new MainKernel(gpuBuffer));

            // Print the initial matrix
            PrintMatrix(array, width, height, "BEFORE");

            // Get the data back
            gpuBuffer.CopyTo(array);

            // Print the updated matrix
            PrintMatrix(array, width, height, "AFTER");
        }
예제 #2
0
        public void GpuWithTemporaryBuffers()
        {
            using ReadOnlyBuffer <float> x  = Gpu.Default.AllocateReadOnlyBuffer(X !);
            using ReadOnlyBuffer <float> w  = Gpu.Default.AllocateReadOnlyBuffer(W !);
            using ReadOnlyBuffer <float> b  = Gpu.Default.AllocateReadOnlyBuffer(B !);
            using ReadWriteBuffer <float> y = Gpu.Default.AllocateReadWriteBuffer <float>(Y !.Length);

            BlasHelpers.FullyConnectedForwardGpu(Gpu.Default, C, N, M, P, x, w, b, y);

            y.CopyTo(Y);
        }
예제 #3
0
        private static void YUVToRGB(Image image)
        {
            using ReadWriteBuffer <int> xBuffer = Gpu.Default.AllocateReadWriteBuffer(image.X.Values);
            using ReadWriteBuffer <int> yBuffer = Gpu.Default.AllocateReadWriteBuffer(image.Y.Values);
            using ReadWriteBuffer <int> zBuffer = Gpu.Default.AllocateReadWriteBuffer(image.Z.Values);
            Gpu.Default.For(image.X.Width * image.X.Height, new YUVToRGB(xBuffer, yBuffer, zBuffer));

            xBuffer.CopyTo(image.X.Values);
            yBuffer.CopyTo(image.Y.Values);
            zBuffer.CopyTo(image.Z.Values);
        }
예제 #4
0
        static void Test <T>(Device device)
            where T : unmanaged
        {
            T[] array = new T[128];

            new Random().NextBytes(array.AsSpan().AsBytes());

            using ReadWriteBuffer <T> texture = device.Get().AllocateReadWriteBuffer <T>(array);

            using (ComputeContext context = device.Get().CreateComputeContext())
            {
                context.Clear(texture);
            }

            texture.CopyTo(array);

            foreach (byte value in array.AsSpan().AsBytes())
            {
                Assert.AreEqual(value, 0);
            }
        }