ddemidov / amgcl

C++ library for solving large sparse linear systems with algebraic multigrid method
http://amgcl.readthedocs.org/
MIT License
728 stars 112 forks source link

Using CPR with CUDA backend #210

Closed Tongdongq closed 3 years ago

Tongdongq commented 3 years ago

Does the CUDA backend support CPR? I've tried to adapt tutorials/1.poisson3Db/poisson3Db_cuda.cu to use CPR with the definitions in examples/cpr.cpp. This is the error

../../amgcl/backend/cuda.hpp(383): error: static assertion failed with "Unsupported value type for cuda backend"

The cuda backend appears the only one that has that static_assert(std::is_same<real, float>::value || std::is_same<real, double>::value, "Unsupported value type for cuda backend");

I'd like to try it in opm-simulators.

ddemidov commented 3 years ago

The cuda backend uses CUSPARSE for the SPMV operations, and CUSPARSE does not support block-valued matrices, which is the reason for the static assert you hit. You could use VexCL AMGCL backend with CUDA VexCL backend (this is probably hard to understand: VexCL is the backend that AMGCL should use, with the CUDA backend for VexCL). Or you could use the CUDA backend, but with scalar value type, see here for an example (vs the block version below).

ddemidov commented 3 years ago

A better example would be examples/cpr_drs.cpp, which is compiled for CUDA backend among others, but explicitly checks that compile-time block size Is 1.

Tongdongq commented 3 years ago

I've made a blocked ilu0-bicgstab solver in cusparse that worked. In particular the cusparseXbsrmv() and cusparseXbsrilu02() were used. It probably doesn't matter, since I need to use amg anyway, so I'll try the VexCL-CUDA solution.

ddemidov commented 3 years ago

Thanks for pointing the block versions out. It does look like extending the cuda backend to support block values should be possible. I am not sure when (or if) that would be available, so using VexCL-CUDA should be the easiest option for now.

Tongdongq commented 3 years ago

I got that working now, thanks!