Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AMGCL_cuda #70

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ option(POLYSOLVE_WITH_CHOLMOD "Enable Cholmod library"
option(POLYSOLVE_WITH_UMFPACK "Enable UmfPack library" ON)
option(POLYSOLVE_WITH_SUPERLU "Enable SuperLU library" ON)
option(POLYSOLVE_WITH_MKL "Enable MKL library" ${POLYSOLVE_NOT_ON_APPLE_SILICON})
option(POLYSOLVE_WITH_CUSOLVER "Enable cuSOLVER library" OFF)
option(POLYSOLVE_WITH_CUSOLVER "Enable cuSOLVER library" ON)
option(POLYSOLVE_WITH_PARDISO "Enable Pardiso library" OFF)
option(POLYSOLVE_WITH_HYPRE "Enable hypre" ON)
option(POLYSOLVE_WITH_AMGCL "Use AMGCL" ON)
Expand Down Expand Up @@ -146,6 +146,10 @@ endif()

# Add an empty library and fill in the list of sources in `src/CMakeLists.txt`.
add_library(polysolve_linear)
if(POLYSOLVE_WITH_CUSOLVER)
include(cusolverdn)
endif()

add_library(polysolve::linear ALIAS polysolve_linear)
add_subdirectory(src/polysolve)
add_subdirectory(src/polysolve/linear)
Expand Down Expand Up @@ -272,8 +276,8 @@ endif()
# AMGCL solver
if(POLYSOLVE_WITH_AMGCL)
include(amgcl)
target_link_libraries(polysolve_linear PUBLIC amgcl::amgcl)
target_compile_definitions(polysolve_linear PUBLIC POLYSOLVE_WITH_AMGCL)
target_link_libraries(polysolve_linear PUBLIC amgcl::amgcl cuda_target)
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_AMGCL)
endif()

# Spectra (MPL 2.0)
Expand All @@ -284,14 +288,11 @@ if(POLYSOLVE_WITH_SPECTRA)
endif()

# cuSolver solvers
if(POLYSOLVE_WITH_CUSOLVER)
include(cusolverdn)
if(TARGET CUDA::cusolver)
target_link_libraries(polysolve_linear PUBLIC CUDA::cusolver)
target_compile_definitions(polysolve_linear PUBLIC POLYSOLVE_WITH_CUSOLVER)
else()
message(WARNING "cuSOLVER not found, solver will not be available.")
endif()
if(TARGET CUDA::cusolver)
target_link_libraries(polysolve_linear PUBLIC CUDA::cusolver)
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_CUSOLVER)
else()
message(WARNING "cuSOLVER not found, solver will not be available.")
endif()

# Sanitizers
Expand Down
26 changes: 14 additions & 12 deletions cmake/recipes/cusolverdn.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ endif()

message(STATUS "Third-party: creating targets 'CUDA::cusolver'")

# Nvidia RTX8000 -> compute_75
# Nvidia V100 -> compute_70
# Nvidia 1080/1080Ti -> compute_61
# Nvidia 3080Ti -> compute_86
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES 70 75 86)
endif()

include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
Expand All @@ -18,7 +26,7 @@ if(CMAKE_CUDA_COMPILER)
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -use_fast_math --expt-relaxed-constexpr -gencode arch=compute_86,code=sm_86")

target_compile_options(polysolve PUBLIC $<$<COMPILE_LANGUAGE:CUDA>:
target_compile_options(polysolve_linear PUBLIC $<$<COMPILE_LANGUAGE:CUDA>:

--generate-line-info
--use_fast_math
Expand All @@ -33,21 +41,15 @@ if(CMAKE_CUDA_COMPILER)

)

target_link_libraries(polysolve PUBLIC CUDA::toolkit)
set_target_properties(polysolve PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
# Nvidia RTX8000 -> compute_75
# Nvidia V100 -> compute_70
# Nvidia 1080/1080Ti -> compute_61
# Nvidia 3080Ti -> compute_86
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES 70 75 86)
endif()
set_target_properties(polysolve PROPERTIES CUDA_ARCHITECTURES "70;75;86")
set_target_properties(polysolve_linear PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
set_target_properties(polysolve_linear PROPERTIES CUDA_ARCHITECTURES native)
# set_target_properties(polysolve PROPERTIES CUDA_ARCHITECTURES "70;75;86")
target_link_libraries(polysolve_linear PUBLIC CUDA::toolkit CUDA::cudart)

if(APPLE)
# We need to add the path to the driver (libcuda.dylib) as an rpath,
# so that the static cuda runtime can find it at runtime.
set_property(TARGET polysolve
set_property(TARGET polysolve_linear
PROPERTY
BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
endif()
Expand Down
146 changes: 145 additions & 1 deletion linear-solver-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"Eigen::MINRES",
"Pardiso",
"Hypre",
"AMGCL"
"AMGCL",
"AMGCL_cuda"
],
"doc": "Settings for the linear solver."
},
Expand All @@ -42,6 +43,7 @@
"Pardiso",
"Hypre",
"AMGCL",
"AMGCL_cuda",
"Eigen::LeastSquaresConjugateGradient",
"Eigen::DGMRES",
"Eigen::ConjugateGradient",
Expand Down Expand Up @@ -153,6 +155,16 @@
],
"doc": "Settings for the AMGCL solver."
},
{
"pointer": "/AMGCL_cuda",
"default": null,
"type": "object",
"optional": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it have opts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

"solver",
"precond"
],
"doc": "Settings for the AMGCL_cuda solver."
},
{
"pointer": "/Eigen::LeastSquaresConjugateGradient/max_iter",
"default": 1000,
Expand Down Expand Up @@ -421,5 +433,137 @@
"default": 0,
"type": "float",
"doc": "Aggregation epsilon strong."
},
{
"pointer": "/AMGCL_cuda/solver",
"default": null,
"type": "object",
"optional": [
"tol",
"maxiter",
"type"
],
"doc": "Solver settings for the AMGCL."
},
{
"pointer": "/AMGCL_cuda/precond",
"default": null,
"type": "object",
"optional": [
"relax",
"class",
"max_levels",
"direct_coarse",
"ncycle",
"coarsening"
],
"doc": "Preconditioner settings for the AMGCL."
},
{
"pointer": "/AMGCL_cuda/solver/maxiter",
"default": 1000,
"type": "int",
"doc": "Maximum number of iterations."
},
{
"pointer": "/AMGCL_cuda/solver/tol",
"default": 1e-10,
"type": "float",
"doc": "Convergence tolerance."
},
{
"pointer": "/AMGCL_cuda/solver/type",
"default": "cg",
"type": "string",
"doc": "Type of solver to use."
},
{
"pointer": "/AMGCL_cuda/precond/relax",
"default": null,
"type": "object",
"optional": [
"degree",
"type",
"power_iters",
"higher",
"lower",
"scale"
],
"doc": "Preconditioner settings for the AMGCL."
},
{
"pointer": "/AMGCL_cuda/precond/class",
"default": "amg",
"type": "string",
"doc": "Type of preconditioner to use."
},
{
"pointer": "/AMGCL_cuda/precond/max_levels",
"default": 6,
"type": "int",
"doc": "Maximum number of levels."
},
{
"pointer": "/AMGCL_cuda/precond/direct_coarse",
"default": false,
"type": "bool",
"doc": "Use direct solver for the coarsest level."
},
{
"pointer": "/AMGCL_cuda/precond/ncycle",
"default": 2,
"type": "int",
"doc": "Number of cycles."
},
{
"pointer": "/AMGCL_cuda/precond/coarsening",
"default": null,
"type": "object",
"optional": [
"type",
"estimate_spectral_radius",
"relax",
"aggr"
],
"doc": "Coarsening parameters."
},
{
"pointer": "/AMGCL_cuda/precond/relax/type",
"default": "spai0",
"type": "string",
"doc": "Type of relaxation to use."
},
{
"pointer": "/AMGCL_cuda/precond/coarsening/type",
"default": "smoothed_aggregation",
"type": "string",
"doc": "Coarsening type."
},
{
"pointer": "/AMGCL_cuda/precond/coarsening/estimate_spectral_radius",
"default": true,
"type": "bool",
"doc": "Should the spectral radius be estimated."
},
{
"pointer": "/AMGCL_cuda/precond/coarsening/relax",
"default": 1,
"type": "float",
"doc": "Coarsening relaxation."
},
{
"pointer": "/AMGCL_cuda/precond/coarsening/aggr",
"default": null,
"type": "object",
"optional": [
"eps_strong"
],
"doc": "Aggregation settings."
},
{
"pointer": "/AMGCL_cuda/precond/coarsening/aggr/eps_strong",
"default": 0,
"type": "float",
"doc": "Aggregation epsilon strong."
}
]
Loading
Loading