public void Test_BLAS2_TRSV() { // Solve Ax = y, and x overwrites y. ClearBuffer(hiMatrixANN); ClearBuffer(hiVectorXN); ClearBuffer(hiVectorYN); diMatrixA = _gpu.CopyToDevice(hiMatrixANN); 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 // Test without transpose _gpu.CopyToDevice(hiVectorYN, diVectorYN); _blas.TRSV(N, 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.TRSV(N, 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 // Test without transpose _gpu.CopyToDevice(hiVectorYN, diVectorYN); _blas.TRSV(N, 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.TRSV(N, 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(); }