Beispiel #1
0
        public void Test_BLAS2_SYR()
        {
            ClearBuffer(hiMatrixANN);
            ClearBuffer(hiVectorXN);

            FillBuffer(hiMatrixANN);
            ConverToSymmetric(hiMatrixANN, N);
            FillBuffer(hiVectorXN);

            diMatrixA  = _gpu.Allocate(hiMatrixANN);
            diVectorXN = _gpu.CopyToDevice(hiVectorXN);

            // Lower fill mode
            _gpu.CopyToDevice(hiMatrixANN, diMatrixA);

            _blas.SYR(N, Alpha, diVectorXN, diMatrixA);

            _gpu.CopyFromDevice(diMatrixA, gpuResultNN);

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

            // Upper fill mode
            _gpu.CopyToDevice(hiMatrixANN, diMatrixA);

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

            _gpu.CopyFromDevice(diMatrixA, gpuResultNN);

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

            _gpu.FreeAll();
        }