123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- #ifndef CERES_INTERNAL_DENSE_QR_H_
- #define CERES_INTERNAL_DENSE_QR_H_
- #include "ceres/internal/config.h"
- #include <memory>
- #include <vector>
- #include "Eigen/Dense"
- #include "ceres/context_impl.h"
- #include "ceres/internal/disable_warnings.h"
- #include "ceres/internal/eigen.h"
- #include "ceres/internal/export.h"
- #include "ceres/linear_solver.h"
- #include "glog/logging.h"
- #ifndef CERES_NO_CUDA
- #include "ceres/context_impl.h"
- #include "ceres/cuda_buffer.h"
- #include "cublas_v2.h"
- #include "cuda_runtime.h"
- #include "cusolverDn.h"
- #endif
- namespace ceres::internal {
- class CERES_NO_EXPORT DenseQR {
- public:
- static std::unique_ptr<DenseQR> Create(const LinearSolver::Options& options);
- virtual ~DenseQR();
-
-
-
-
-
-
-
-
-
- virtual LinearSolverTerminationType Factorize(int num_rows,
- int num_cols,
- double* lhs,
- std::string* message) = 0;
-
-
-
-
-
-
-
- virtual LinearSolverTerminationType Solve(const double* rhs,
- double* solution,
- std::string* message) = 0;
-
-
-
-
-
-
-
- LinearSolverTerminationType FactorAndSolve(int num_rows,
- int num_cols,
- double* lhs,
- const double* rhs,
- double* solution,
- std::string* message);
- };
- class CERES_NO_EXPORT EigenDenseQR final : public DenseQR {
- public:
- LinearSolverTerminationType Factorize(int num_rows,
- int num_cols,
- double* lhs,
- std::string* message) override;
- LinearSolverTerminationType Solve(const double* rhs,
- double* solution,
- std::string* message) override;
- private:
- using QRType = Eigen::HouseholderQR<Eigen::Ref<ColMajorMatrix>>;
- std::unique_ptr<QRType> qr_;
- };
- #ifndef CERES_NO_LAPACK
- class CERES_NO_EXPORT LAPACKDenseQR final : public DenseQR {
- public:
- LinearSolverTerminationType Factorize(int num_rows,
- int num_cols,
- double* lhs,
- std::string* message) override;
- LinearSolverTerminationType Solve(const double* rhs,
- double* solution,
- std::string* message) override;
- private:
- double* lhs_ = nullptr;
- int num_rows_;
- int num_cols_;
- LinearSolverTerminationType termination_type_ =
- LinearSolverTerminationType::FATAL_ERROR;
- Vector work_;
- Vector tau_;
- Vector q_transpose_rhs_;
- };
- #endif
- #ifndef CERES_NO_CUDA
- class CERES_NO_EXPORT CUDADenseQR final : public DenseQR {
- public:
- static std::unique_ptr<CUDADenseQR> Create(
- const LinearSolver::Options& options);
- CUDADenseQR(const CUDADenseQR&) = delete;
- CUDADenseQR& operator=(const CUDADenseQR&) = delete;
- LinearSolverTerminationType Factorize(int num_rows,
- int num_cols,
- double* lhs,
- std::string* message) override;
- LinearSolverTerminationType Solve(const double* rhs,
- double* solution,
- std::string* message) override;
- private:
- explicit CUDADenseQR(ContextImpl* context);
- ContextImpl* context_ = nullptr;
-
-
- size_t num_rows_ = 0;
-
-
- size_t num_cols_ = 0;
-
- CudaBuffer<double> lhs_;
-
- CudaBuffer<double> rhs_;
-
- CudaBuffer<double> tau_;
-
- CudaBuffer<double> device_workspace_;
-
- CudaBuffer<int> error_;
-
-
- LinearSolverTerminationType factorize_result_ =
- LinearSolverTerminationType::FATAL_ERROR;
- };
- #endif
- }
- #include "ceres/internal/reenable_warnings.h"
- #endif
|