Beispiel #1
0
        public void Test_BLAS2_SPMV()
        {
            ClearBuffer(hiMatrixANN);
            ClearBuffer(hiMatrixAPS);
            ClearBuffer(hiVectorXN);
            ClearBuffer(hiVectorYN);

            FillBuffer(hiMatrixANN);
            ConverToSymmetric(hiMatrixANN, N);
            FillBuffer(hiVectorXN);
            FillBuffer(hiVectorYN);
            diMatrixA  = _gpu.Allocate(hiMatrixAPS);
            diVectorYN = _gpu.Allocate(hiVectorYN);
            diVectorXN = _gpu.CopyToDevice(hiVectorXN);

            // Lower fill mode
            PackSymmetricMatrix(hiMatrixANN, hiMatrixAPS, N, cublasFillMode.Lower);
            _gpu.CopyToDevice(hiMatrixAPS, diMatrixA);

            _gpu.CopyToDevice(hiVectorYN, diVectorYN);

            _blas.SPMV(N, Alpha, diMatrixA, diVectorXN, Beta, diVectorYN);

            _gpu.CopyFromDevice(diVectorYN, gpuResultN);

            for (int i = 0; i < N; i++)
            {
                double cpuResult = 0.0;

                for (int j = 0; j < N; j++)
                {
                    cpuResult += Alpha * hiMatrixANN[GetIndexColumnMajor(i, j, N)] * hiVectorXN[j];
                }

                cpuResult += Beta * hiVectorYN[i];

                Assert.AreEqual(cpuResult, gpuResultN[i]);
            }

            // Upper fill mode
            PackSymmetricMatrix(hiMatrixANN, hiMatrixAPS, N, cublasFillMode.Upper);
            _gpu.CopyToDevice(hiMatrixAPS, diMatrixA);

            _gpu.CopyToDevice(hiVectorYN, diVectorYN);

            _blas.SPMV(N, Alpha, diMatrixA, diVectorXN, Beta, diVectorYN, cublasFillMode.Upper);

            _gpu.CopyFromDevice(diVectorYN, gpuResultN);

            for (int i = 0; i < N; i++)
            {
                double cpuResult = 0.0;

                for (int j = 0; j < N; j++)
                {
                    cpuResult += Alpha * hiMatrixANN[GetIndexColumnMajor(i, j, N)] * hiVectorXN[j];
                }

                cpuResult += Beta * hiVectorYN[i];

                Assert.AreEqual(cpuResult, gpuResultN[i]);
            }

            _gpu.FreeAll();
        }