public void Test_BLAS2_TBSV() { // Solve Ax = y, and x overwrites y. ClearBuffer(hiMatrixANN); ClearBuffer(hiMatrixASCBC); ClearBuffer(hiVectorXN); ClearBuffer(hiVectorYN); diMatrixA = _gpu.Allocate(hiMatrixASCBC); diVectorYN = _gpu.Allocate(hiVectorYN); // Because of there is no singular test, set matrix A to simple maindiagonal only matrix. CreateMainDiagonalOnlyMatrix(hiMatrixANN, N); FillBuffer(hiVectorYN); // Lower fill mode CompressSymmetricBandedMatrixToCBC(hiMatrixANN, hiMatrixASCBC, N, 0, cublasFillMode.Lower); _gpu.CopyToDevice(hiMatrixASCBC, diMatrixA); // Test without transpose _gpu.CopyToDevice(hiVectorYN, diVectorYN); _blas.TBSV(N, 0, diMatrixA, diVectorYN); _gpu.CopyFromDevice(diVectorYN, hiVectorXN); // Check solution error : y - Ax by elemental wise. double maxError = 0.0; for (int i = 0; i < N; i++) { double ax = 0.0; for (int j = 0; j < N; j++) { ax += hiMatrixANN[GetIndexColumnMajor(i, j, N)] * hiVectorXN[j]; } double error = Math.Abs(ax - hiVectorYN[i]); if (maxError < error) { maxError = error; } } Console.WriteLine("max error : {0} (lower fill mode, without transpose)", maxError); // Test with transpose _gpu.CopyToDevice(hiVectorYN, diVectorYN); _blas.TBSV(N, 0, diMatrixA, diVectorYN, cublasOperation.T); _gpu.CopyFromDevice(diVectorYN, hiVectorXN); // Check solution error : y - Ax by elemental wise. maxError = 0.0; for (int j = 0; j < N; j++) { double ax = 0.0; for (int i = 0; i < N; i++) { ax += hiMatrixANN[GetIndexColumnMajor(i, j, N)] * hiVectorXN[i]; } double error = Math.Abs(ax - hiVectorYN[j]); if (maxError < error) { maxError = error; } } Console.WriteLine("max error : {0} (lower fill mode, with transpose)", maxError); // Upper fill mode CompressSymmetricBandedMatrixToCBC(hiMatrixANN, hiMatrixASCBC, N, 0, cublasFillMode.Upper); _gpu.CopyToDevice(hiMatrixASCBC, diMatrixA); // Test without transpose _gpu.CopyToDevice(hiVectorYN, diVectorYN); _blas.TBSV(N, 0, diMatrixA, diVectorYN, cublasOperation.N, cublasFillMode.Upper); _gpu.CopyFromDevice(diVectorYN, hiVectorXN); // Check solution error : y - Ax by elemental wise. maxError = 0.0; for (int i = 0; i < N; i++) { double ax = 0.0; for (int j = 0; j < N; j++) { ax += hiMatrixANN[GetIndexColumnMajor(i, j, N)] * hiVectorXN[j]; } double error = Math.Abs(ax - hiVectorYN[i]); if (maxError < error) { maxError = error; } } Console.WriteLine("max error : {0} (upper fill mode, without transpose)", maxError); // Test with transpose _gpu.CopyToDevice(hiVectorYN, diVectorYN); _blas.TBSV(N, 0, diMatrixA, diVectorYN, cublasOperation.T, cublasFillMode.Upper); _gpu.CopyFromDevice(diVectorYN, hiVectorXN); // Check solution error : y - Ax by elemental wise. maxError = 0.0; for (int j = 0; j < N; j++) { double ax = 0.0; for (int i = 0; i < N; i++) { ax += hiMatrixANN[GetIndexColumnMajor(i, j, N)] * hiVectorXN[i]; } double error = Math.Abs(ax - hiVectorYN[j]); if (maxError < error) { maxError = error; } } Console.WriteLine("max error : {0} (upper fill mode, with transpose)", maxError); _gpu.FreeAll(); }