Exemple #1
0
        static void Main(string[] args)
        {
            Random    random = new Random();
            Stopwatch watch  = Stopwatch.StartNew();

            GPUOperator <DoubleWrapper> gpu = new GPUOperator <DoubleWrapper>();

            Console.WriteLine($"GPU init: {watch.ElapsedMilliseconds}ms");
            watch.Restart();

            SingleThreadedOperator <DoubleWrapper> cpu = new SingleThreadedOperator <DoubleWrapper>();

            Console.WriteLine($"CPU init: {watch.ElapsedMilliseconds}ms");
            watch.Restart();

            MultiThreadedOperator <DoubleWrapper> cpumult = new MultiThreadedOperator <DoubleWrapper>();

            Console.WriteLine($"Parallel init: {watch.ElapsedMilliseconds}ms");
            watch.Restart();

            BufferedFastMatrix <DoubleWrapper> one = new BufferedFastMatrix <DoubleWrapper>(64, 64);
            BufferedFastMatrix <DoubleWrapper> two = new BufferedFastMatrix <DoubleWrapper>(64, 64);

            Console.WriteLine($"Two 100x100 allocations: {watch.ElapsedMilliseconds}ms");
            watch.Restart();

            one.CopyToGPU();
            two.CopyToGPU();
            Console.WriteLine($"Copy: {watch.ElapsedMilliseconds}ms");
            watch.Restart();

            Utilities.FillMatrix(one, 10);
            Utilities.FillMatrix(two, 20);
            Console.WriteLine($"Filling matrices: {watch.ElapsedMilliseconds}ms");
            watch.Restart();

            var bruh = gpu.AddShared(one, two);

            Console.WriteLine($"GPU Add: {watch.ElapsedMilliseconds}ms");
            watch.Restart();
            gpu.Multiply(one, two);
            Console.WriteLine($"GPU Mult: {watch.ElapsedMilliseconds}ms");
            watch.Restart();

            cpu.Add(one, two);
            Console.WriteLine($"CPU Add: {watch.ElapsedMilliseconds}ms");
            watch.Restart();
            cpu.Multiply(one, two);
            Console.WriteLine($"CPU Mult: {watch.ElapsedMilliseconds}ms");
            watch.Restart();

            cpumult.Add(one, two);
            Console.WriteLine($"Parallel Add: {watch.ElapsedMilliseconds}ms");
            watch.Restart();
            cpumult.Multiply(one, two);
            Console.WriteLine($"Parallel Mult: {watch.ElapsedMilliseconds}ms");
            watch.Restart();
        }
Exemple #2
0
        static void Multiply()
        {
            GPUOperator op = new GPUOperator();

            //two 5*3 matrices
            FastMatrix one = new FastMatrix(5, 3);
            FastMatrix two = new FastMatrix(3, 5);

            Utilities.FillMatrix(one, 5);
            Utilities.FillMatrix(two, 10);

            FastMatrix result = op.Multiply(one, two);
        }
Exemple #3
0
        static void Multiply()
        {
            GPUOperator <IntWrapper> op = new GPUOperator <IntWrapper>();

            //two 5*3 matrices
            BufferedFastMatrix <IntWrapper> one = new BufferedFastMatrix <IntWrapper>(5, 3);
            BufferedFastMatrix <IntWrapper> two = new BufferedFastMatrix <IntWrapper>(3, 5);

            Utilities.FillMatrix(one, 5);
            Utilities.FillMatrix(two, 10);

            BufferedFastMatrix <IntWrapper> result = op.Multiply(one, two);
        }
Exemple #4
0
        static void Transpose()
        {
            GPUOperator <IntWrapper> op = new GPUOperator <IntWrapper>();

            //5*3 matrix
            BufferedFastMatrix <IntWrapper> one = new BufferedFastMatrix <IntWrapper>(5, 3);

            Utilities.FillMatrix(one, 5);

            //10 will start at the bottom left and go to the top right
            one[0, one.Rows - 1] = 10;
            BufferedFastMatrix <IntWrapper> result = op.Transpose(one);
        }
Exemple #5
0
        static void Main()
        {
            GPUOperator <Vector3> op = new GPUOperator <Vector3>();

            //two 5*3 matrices
            BufferedFastMatrix <Vector3> one = new BufferedFastMatrix <Vector3>(5, 3);
            BufferedFastMatrix <Vector3> two = new BufferedFastMatrix <Vector3>(5, 3);

            Utilities.FillMatrix(one, new Vector3(10, 10, 10));
            Utilities.FillMatrix(two, new Vector3(5, 5, 5));

            op.Add(one, two);
        }
        static void Transpose()
        {
            GPUOperator op = new GPUOperator();

            //5*3 matrix
            FastMatrix one = new FastMatrix(5, 3);

            Utilities.FillMatrix(one, 5);

            //10 will start at the bottom left and go to the top right
            one[0, one.GetSize(0) - 1] = 10;
            FastMatrix result = op.Transpose(one);
        }
Exemple #7
0
        //you do not have to opy, but the earlier you start it the better
        static void GPUCopy()
        {
            GPUOperator <IntWrapper>        op     = new GPUOperator <IntWrapper>();
            BufferedFastMatrix <IntWrapper> matrix = new BufferedFastMatrix <IntWrapper>(5, 5);

            //start copying to the GPU
            matrix.CopyToGPU();

            //do other stuff here...

            //all operations on the GPU will automatically finish the copy
            //when starting an operation
            op.Transpose(matrix);
        }
Exemple #8
0
        static void Add()
        {
            //common wrappers are included in this library by default
            //see DefaultTypeOperators.cs under FastMatrixOperations
            GPUOperator op = new GPUOperator();

            //two 5*3 matrices
            FastMatrix one = new FastMatrix(5, 3);
            FastMatrix two = new FastMatrix(5, 3);

            Utilities.FillMatrix(one, 5);
            Utilities.FillMatrix(two, 10);

            FastMatrix result = op.Add(one, two);
        }
Exemple #9
0
        static void Add()
        {
            //common wrappers are included in this library by default
            //see DefaultTypeOperators.cs under FastMatrixOperations
            GPUOperator <IntWrapper> op = new GPUOperator <IntWrapper>();

            //two 5*3 matrices
            BufferedFastMatrix <IntWrapper> one = new BufferedFastMatrix <IntWrapper>(5, 3);
            BufferedFastMatrix <IntWrapper> two = new BufferedFastMatrix <IntWrapper>(5, 3);

            Utilities.FillMatrix(one, 5);
            Utilities.FillMatrix(two, 10);

            BufferedFastMatrix <IntWrapper> result = op.Add(one, two);
        }