コード例 #1
0
        public void Test_BLAS2_SBMV()
        {
            ClearBuffer(hiMatrixANN);
            ClearBuffer(hiMatrixASCBC);
            ClearBuffer(hiVectorXN);
            ClearBuffer(hiVectorYN);

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

            // Lower fill mode
            CompressSymmetricBandedMatrixToCBC(hiMatrixANN, hiMatrixASCBC, N, K, cublasFillMode.Lower);
            _gpu.CopyToDevice(hiMatrixASCBC, diMatrixA);

            _gpu.CopyToDevice(hiVectorYN, diVectorYN);

            _blas.SBMV(N, K, 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
            CompressSymmetricBandedMatrixToCBC(hiMatrixANN, hiMatrixASCBC, N, K, cublasFillMode.Upper);
            _gpu.CopyToDevice(hiMatrixASCBC, diMatrixA);

            _gpu.CopyToDevice(hiVectorYN, diVectorYN);

            _blas.SBMV(N, K, 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();
        }