Check CUDA is available in solver.cc

Add logic for checking for availability of CUDA as the
dense linear algebra library before allowing the user
to use it.

Change-Id: I0ceafa1052632504b33685bc731366ef6933e518
This commit is contained in:
Sameer Agarwal
2022-02-14 13:37:56 -08:00
parent 7d2e4152ec
commit bb29966810
2 changed files with 18 additions and 5 deletions
+9 -5
View File
@@ -141,16 +141,20 @@ bool TrustRegionOptionsAreValid(const Solver::Options& options, string* error) {
return false;
}
if (options.dense_linear_algebra_library_type == LAPACK &&
!IsDenseLinearAlgebraLibraryTypeAvailable(LAPACK) &&
if (!IsDenseLinearAlgebraLibraryTypeAvailable(
options.dense_linear_algebra_library_type) &&
(options.linear_solver_type == DENSE_NORMAL_CHOLESKY ||
options.linear_solver_type == DENSE_QR ||
options.linear_solver_type == DENSE_SCHUR)) {
*error = StringPrintf(
"Can't use %s with "
"Solver::Options::dense_linear_algebra_library_type = LAPACK "
"because LAPACK was not enabled when Ceres was built.",
LinearSolverTypeToString(options.linear_solver_type));
"Solver::Options::dense_linear_algebra_library_type = %s "
"because %s was not enabled when Ceres was built.",
LinearSolverTypeToString(options.linear_solver_type),
DenseLinearAlgebraLibraryTypeToString(
options.dense_linear_algebra_library_type),
DenseLinearAlgebraLibraryTypeToString(
options.dense_linear_algebra_library_type));
return false;
}
+9
View File
@@ -420,6 +420,7 @@ bool IsDenseLinearAlgebraLibraryTypeAvailable(
if (type == EIGEN) {
return true;
}
if (type == LAPACK) {
#ifdef CERES_NO_LAPACK
return false;
@@ -428,6 +429,14 @@ bool IsDenseLinearAlgebraLibraryTypeAvailable(
#endif
}
if (type == CUDA) {
#ifdef CERES_NO_CUDA
return false;
#else
return false;
#endif
}
LOG(WARNING) << "Unknown dense linear algebra library " << type;
return false;
}