Skip to content

Commit 2fd4aab

Browse files
committed
[wip] [skip ci] CMake option to choose between OpenCL and CUDA amgcl backends
Also rename use_opencl option to use_gpgpu, and rename KRATOS_USE_OPENCL cmake option to AMGCL_GPGPU. The new cmake option is called AMGCL_GPGPU_BACKEND and can be either "OpenCL" or "CUDA".
1 parent 4b6bf58 commit 2fd4aab

4 files changed

Lines changed: 37 additions & 32 deletions

File tree

applications/trilinos_application/amgcl_mpi_solver_impl.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <amgcl/mpi/direct_solver/runtime.hpp>
2222
#include <amgcl/mpi/partition/runtime.hpp>
2323

24-
#ifdef KRATOS_HAVE_OPENCL
24+
#ifdef AMGCL_GPGPU
2525
# include <amgcl/backend/vexcl.hpp>
2626
# include <amgcl/backend/vexcl_static_matrix.hpp>
2727
#endif
@@ -33,7 +33,7 @@
3333
namespace Kratos
3434
{
3535

36-
#ifdef KRATOS_HAVE_OPENCL
36+
#ifdef AMGCL_GPGPU
3737
vex::Context& vexcl_context();
3838

3939
template <int TBlockSize>
@@ -51,11 +51,11 @@ AMGCLScalarSolve(
5151
double& rResidual,
5252
const boost::property_tree::ptree &amgclParams,
5353
int verbosity_level,
54-
bool use_opencl
54+
bool use_gpgpu
5555
)
5656
{
57-
#ifdef KRATOS_HAVE_OPENCL
58-
if (use_opencl && vexcl_context()) {
57+
#ifdef AMGCL_GPGPU
58+
if (use_gpgpu && vexcl_context()) {
5959
auto &ctx = vexcl_context();
6060

6161
typedef amgcl::backend::vexcl<double> Backend;
@@ -126,7 +126,7 @@ AMGCLBlockSolve(
126126
double& rResidual,
127127
boost::property_tree::ptree amgclParams,
128128
int verbosity_level,
129-
bool use_opencl
129+
bool use_gpgpu
130130
)
131131
{
132132
amgclParams.put("precond.coarsening.aggr.block_size",1);
@@ -137,8 +137,8 @@ AMGCLBlockSolve(
137137
std::size_t n = rA.RowMap().NumMyElements();
138138
std::size_t nb = n / TBlockSize;
139139

140-
#ifdef KRATOS_HAVE_OPENCL
141-
if (use_opencl && vexcl_context()) {
140+
#ifdef AMGCL_GPGPU
141+
if (use_gpgpu && vexcl_context()) {
142142
auto &ctx = vexcl_context();
143143
register_vexcl_static_matrix_type<TBlockSize>();
144144

@@ -218,7 +218,7 @@ template void AMGCLScalarSolve< TrilinosSpace<Epetra_FECrsMatrix, Epetra_FEVecto
218218
double& rResidual,
219219
const boost::property_tree::ptree &amgclParams,
220220
int verbosity_level,
221-
bool use_opencl
221+
bool use_gpgpu
222222
);
223223

224224
#define INSTANTIATE_BLOCK_SOLVER(B) \
@@ -230,7 +230,7 @@ template void AMGCLBlockSolve<B, TrilinosSpace<Epetra_FECrsMatrix, Epetra_FEVect
230230
double& rResidual, \
231231
boost::property_tree::ptree amgclParams, \
232232
int verbosity_level, \
233-
bool use_opencl \
233+
bool use_gpgpu \
234234
)
235235

236236
INSTANTIATE_BLOCK_SOLVER(2);

kratos/CMakeLists.txt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,21 @@ add_library(KratosCore SHARED ${KRATOS_CORE_SOURCES} ${KRATOS_CORE_TESTING_ENGIN
154154
target_link_libraries(KratosCore PUBLIC gidpost) #${Boost_LIBRARIES} ${PYTHON_LIBRARIES} gidpost )
155155
set_target_properties(KratosCore PROPERTIES COMPILE_DEFINITIONS "KRATOS_CORE=IMPORT,API")
156156

157-
if(NOT DEFINED KRATOS_USE_OPENCL)
158-
message("KRATOS_USE_OPENCL not defined. Setting to OFF")
159-
SET (KRATOS_USE_OPENCL OFF)
160-
endif()
161-
162-
if (${KRATOS_USE_OPENCL} MATCHES ON)
157+
option(AMGCL_GPGPU "Enable GPGPU backend for AMGCL linear solver" OFF)
158+
if (AMGCL_GPGPU)
163159
find_package(VexCL)
164-
if (TARGET VexCL::OpenCL)
160+
161+
set(AMGCL_GPGPU_BACKEND "OpenCL" CACHE STRING "Select AMGCL GPGPU backend (OpenCL/CUDA)")
162+
set_property(CACHE AMGCL_GPGPU_BACKEND PROPERTY STRINGS "OpenCL" "CUDA")
163+
164+
if ("${AMGCL_GPGPU_BACKEND}" STREQUAL "OpenCL" AND TARGET VexCL::OpenCL)
165165
target_link_libraries(KratosCore VexCL::OpenCL)
166-
target_compile_definitions(KratosCore PUBLIC KRATOS_HAVE_OPENCL)
166+
target_compile_definitions(KratosCore PUBLIC AMGCL_GPGPU)
167+
elseif ("${AMGCL_GPGPU_BACKEND}" STREQUAL "CUDA" AND TARGET VexCL::CUDA)
168+
target_link_libraries(KratosCore VexCL::CUDA)
169+
target_compile_definitions(KratosCore PUBLIC AMGCL_GPGPU)
170+
else()
171+
message(WARNING "AMGCL GPGPU backend not found")
167172
endif()
168173
endif()
169174

kratos/linear_solvers/amgcl_solver.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ AMGCLScalarSolve(
8585
double& rResidual,
8686
const boost::property_tree::ptree &amgclParams,
8787
int verbosity_level,
88-
bool use_opencl
88+
bool use_gpgpu
8989
);
9090

9191
/**
@@ -106,7 +106,7 @@ AMGCLBlockSolve(
106106
double& rResidual,
107107
boost::property_tree::ptree amgclParams,
108108
int verbosity_level,
109-
bool use_opencl
109+
bool use_gpgpu
110110
);
111111

112112
///@}
@@ -185,7 +185,7 @@ class AMGCLSolver : public LinearSolver< TSparseSpaceType,
185185
"max_levels" : -1,
186186
"pre_sweeps" : 1,
187187
"post_sweeps" : 1,
188-
"use_opencl" : false
188+
"use_gpgpu" : false
189189
} )" );
190190

191191
// Now validate agains defaults -- this also ensures no type mismatch
@@ -277,7 +277,7 @@ class AMGCLSolver : public LinearSolver< TSparseSpaceType,
277277
ThisParameters["use_block_matrices_if_possible"].SetBool(false);
278278
}
279279

280-
mUseOpenCL = ThisParameters["use_opencl"].GetBool();
280+
mUseOpenCL = ThisParameters["use_gpgpu"].GetBool();
281281
}
282282

283283
/**

kratos/linear_solvers/amgcl_solver_impl.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <amgcl/solver/runtime.hpp>
1313
#include <amgcl/preconditioner/runtime.hpp>
1414

15-
#ifdef KRATOS_HAVE_OPENCL
15+
#ifdef AMGCL_GPGPU
1616
# include <amgcl/backend/vexcl.hpp>
1717
# include <amgcl/backend/vexcl_static_matrix.hpp>
1818
#endif
@@ -21,7 +21,7 @@
2121

2222
namespace Kratos {
2323

24-
#ifdef KRATOS_HAVE_OPENCL
24+
#ifdef AMGCL_GPGPU
2525
vex::Context& vexcl_context() {
2626
static vex::Context ctx(vex::Filter::Env);
2727
static bool run_once = [](){
@@ -49,11 +49,11 @@ AMGCLScalarSolve(
4949
double& rResidual,
5050
const boost::property_tree::ptree &amgclParams,
5151
int verbosity_level,
52-
bool use_opencl
52+
bool use_gpgpu
5353
)
5454
{
55-
#ifdef KRATOS_HAVE_OPENCL
56-
if (use_opencl && vexcl_context()) {
55+
#ifdef AMGCL_GPGPU
56+
if (use_gpgpu && vexcl_context()) {
5757
auto &ctx = vexcl_context();
5858

5959
typedef amgcl::backend::vexcl<double> Backend;
@@ -114,7 +114,7 @@ AMGCLBlockSolve(
114114
double& rResidual,
115115
boost::property_tree::ptree amgclParams,
116116
int verbosity_level,
117-
bool use_opencl
117+
bool use_gpgpu
118118
)
119119
{
120120
if(amgclParams.get<std::string>("precond.class") != "amg")
@@ -128,8 +128,8 @@ AMGCLBlockSolve(
128128
std::size_t n = TSparseSpaceType::Size1(rA);
129129
std::size_t nb = n / TBlockSize;
130130

131-
#ifdef KRATOS_HAVE_OPENCL
132-
if (use_opencl && vexcl_context()) {
131+
#ifdef AMGCL_GPGPU
132+
if (use_gpgpu && vexcl_context()) {
133133
auto &ctx = vexcl_context();
134134
register_vexcl_static_matrix_type<TBlockSize>();
135135

@@ -197,7 +197,7 @@ template void AMGCLScalarSolve< TUblasSparseSpace<double> >(
197197
double& rResidual,
198198
const boost::property_tree::ptree &amgclParams,
199199
int verbosity_level,
200-
bool use_opencl
200+
bool use_gpgpu
201201
);
202202

203203
#define INSTANTIATE_BLOCK_SOLVER(B) \
@@ -209,7 +209,7 @@ template void AMGCLBlockSolve<B, TUblasSparseSpace<double> >( \
209209
double& rResidual, \
210210
boost::property_tree::ptree amgclParams, \
211211
int verbosity_level, \
212-
bool use_opencl \
212+
bool use_gpgpu \
213213
)
214214

215215
INSTANTIATE_BLOCK_SOLVER(2);

0 commit comments

Comments
 (0)