From: Bruno Turcksin Date: Tue, 10 Apr 2018 22:11:59 +0000 (-0400) Subject: Add CG test using cuda X-Git-Tag: v9.0.0-rc1~186^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9af2384188610ff5653c660add14e3c6f6a5d081;p=dealii.git Add CG test using cuda --- diff --git a/tests/cuda/solver_01.cu b/tests/cuda/solver_01.cu new file mode 100644 index 0000000000..1389a5be80 --- /dev/null +++ b/tests/cuda/solver_01.cu @@ -0,0 +1,91 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2018 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + +// Check that dealii::SolverCG works with CUDAWrappers::SparseMatrix + +#include "../tests.h" +#include "../testmatrix.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +void test(cusparseHandle_t cusparse_handle) +{ + // Build the sparse matrix on the host + const unsigned int problem_size = 10; + unsigned int size = (problem_size-1)*(problem_size-1); + FDMatrix testproblem(problem_size, problem_size); + SparsityPattern structure(size, size, 5); + SparseMatrix A; + testproblem.five_point_structure(structure); + structure.compress(); + A.reinit(structure); + testproblem.five_point(A); + + // Solve on the host + PreconditionIdentity prec_no; + SolverControl control(100, 1.e-10); + SolverCG<> cg_host(control); + Vector sol_host(size); + Vector rhs_host(size); + for (unsigned int i=0; i(i); + cg_host.solve(A, sol_host, rhs_host, prec_no); + + // Solve on the device + CUDAWrappers::SparseMatrix A_dev(cusparse_handle, A); + LinearAlgebra::CUDAWrappers::Vector sol_dev(size); + LinearAlgebra::CUDAWrappers::Vector rhs_dev(size); + LinearAlgebra::ReadWriteVector rw_vector(size); + for (unsigned int i=0; i(i); + rhs_dev.import(rw_vector, VectorOperation::insert); + SolverCG> cg_dev(control); + cg_dev.solve(A_dev, sol_dev, rhs_dev, prec_no); + + // Check the result + rw_vector.import(sol_dev, VectorOperation::insert); + for (unsigned int i=0; i>::release_unused_memory(); + + cusparse_error_code = cusparseDestroy(cusparse_handle); + AssertCusparse(cusparse_error_code); + + deallog << "OK" <