Пример #1
0
        public void Test_BLAS2_SPR2()
        {
            ClearBuffer(hiMatrixANN);
            ClearBuffer(hiMatrixAPS);
            ClearBuffer(hiVectorXN);
            ClearBuffer(hiVectorYN);

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

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

            _blas.SPR2(N, Alpha, diVectorXN, diVectorYN, diMatrixA);

            _gpu.CopyFromDevice(diMatrixA, gpuResultP);

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    double cpuResult = Alpha * (hiVectorXN[i] * hiVectorYN[j] + hiVectorYN[i] * hiVectorXN[j]) + hiMatrixANN[GetIndexColumnMajor(i, j, N)];
                    Assert.AreEqual(cpuResult, gpuResultP[GetIndexPackedSymmetric(i, j, N, cublasFillMode.Lower)]);
                }
            }

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

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

            _gpu.CopyFromDevice(diMatrixA, gpuResultP);

            for (int i = 0; i < N; i++)
            {
                for (int j = i; j < N; j++)
                {
                    double cpuResult = Alpha * (hiVectorXN[i] * hiVectorYN[j] + hiVectorYN[i] * hiVectorXN[j]) + hiMatrixANN[GetIndexColumnMajor(i, j, N)];
                    Assert.AreEqual(cpuResult, gpuResultP[GetIndexPackedSymmetric(i, j, N, cublasFillMode.Upper)]);
                }
            }

            _gpu.FreeAll();
        }