Ginkgo  Generated from pipelines/2662685947 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
cudss.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_EXTENSIONS_CUDA_SOLVER_CUDSS_HPP_
6 #define GKO_PUBLIC_EXTENSIONS_CUDA_SOLVER_CUDSS_HPP_
7 
8 
9 #include <complex>
10 #include <memory>
11 #include <type_traits>
12 
13 #include <ginkgo/core/base/lin_op.hpp>
14 #include <ginkgo/core/base/types.hpp>
15 #include <ginkgo/core/config/config.hpp>
16 #include <ginkgo/core/config/registry.hpp>
17 
18 
19 namespace gko {
20 namespace ext {
21 namespace cuda {
22 namespace solver {
23 
24 
25 namespace detail {
26 
27 
28 template <typename T>
29 struct is_cudss_supported_value_type : std::false_type {};
30 
31 template <>
32 struct is_cudss_supported_value_type<float> : std::true_type {};
33 template <>
34 struct is_cudss_supported_value_type<double> : std::true_type {};
35 template <>
36 struct is_cudss_supported_value_type<std::complex<float>> : std::true_type {};
37 template <>
38 struct is_cudss_supported_value_type<std::complex<double>> : std::true_type {};
39 
40 
41 } // namespace detail
42 
43 
44 #define GKO_EXT_CUDSS_ASSERT_SUPPORTED_VALUE_TYPE \
45  static_assert( \
46  ::gko::ext::cuda::solver::detail::is_cudss_supported_value_type< \
47  ValueType>::value, \
48  "cuDSS only supports float, double, std::complex<float>, and " \
49  "std::complex<double> value types")
50 
51 
66 template <typename ValueType, typename IndexType = int32>
67 class Cudss : public LinOp {
68  GKO_EXT_CUDSS_ASSERT_SUPPORTED_VALUE_TYPE;
69  GKO_ASSERT_SUPPORTED_INDEX_TYPE;
70 
71 public:
72  using value_type = ValueType;
73  using index_type = IndexType;
74 
75  class Factory;
76 
77  struct parameters_type : enable_parameters_type<parameters_type, Factory> {
98 
114 
119 
124 
129  };
132 
136  static parameters_type parse(
137  const config::pnode& config, const config::registry& context,
138  const config::type_descriptor& td_for_child =
139  config::make_type_descriptor<ValueType, IndexType>());
140 
146  static config::configuration_map get_config_map();
147 
149  Cudss(const Cudss&);
150 
152  Cudss(Cudss&&) noexcept;
153 
154  Cudss& operator=(const Cudss&);
155 
156  Cudss& operator=(Cudss&&) noexcept;
157 
168  void refactorize(std::shared_ptr<const LinOp> new_matrix);
169 
170 protected:
171  explicit Cudss(std::shared_ptr<const Executor> exec);
172 
173  Cudss(const Factory* factory, std::shared_ptr<const LinOp> system_matrix);
174 
175  void apply_impl(const LinOp* b, LinOp* x) const override;
176 
177  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
178  LinOp* x) const override;
179 
180 private:
181  struct state;
182  // system_matrix_ must be declared before state_ so that the CSR data
183  // is destroyed after the cuDSS handles that reference it via zero-copy.
184  std::shared_ptr<const LinOp> system_matrix_;
185  std::shared_ptr<state> state_;
186 };
187 
188 
189 } // namespace solver
190 } // namespace cuda
191 } // namespace ext
192 } // namespace gko
193 
194 
195 #endif // GKO_PUBLIC_EXTENSIONS_CUDA_SOLVER_CUDSS_HPP_
gko::ext::cuda::solver::Cudss::Factory
Definition: cudss.hpp:130
gko::ext::cuda::solver::Cudss::parameters_type::hybrid_memory
bool hybrid_memory
Enable hybrid CPU+GPU memory.
Definition: cudss.hpp:128
gko::config::pnode
pnode describes a tree of properties.
Definition: property_tree.hpp:28
gko::log::profile_event_category::solver
Solver events.
gko::ext::cuda::solver::Cudss::parse
static parameters_type parse(const config::pnode &config, const config::registry &context, const config::type_descriptor &td_for_child=config::make_type_descriptor< ValueType, IndexType >())
Parse parameters from a configuration property tree.
gko::LinOp
Definition: lin_op.hpp:117
gko::ext::cuda::solver::Cudss
A direct solver using NVIDIA's cuDSS library.
Definition: cudss.hpp:67
gko::ext::cuda::solver::Cudss::parameters_type::reordering_alg
int reordering_alg
Reordering algorithm.
Definition: cudss.hpp:118
gko::ext::cuda::solver::Cudss::get_config_map
static config::configuration_map get_config_map()
Returns a configuration_map for registering this type with a config::registry.
GKO_FACTORY_PARAMETER_SCALAR
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Creates a scalar factory parameter in the factory parameters structure.
Definition: abstract_factory.hpp:437
gko::ext::cuda::solver::Cudss::parameters_type::matrix_type
int matrix_type
cuDSS matrix type, mapping to cudssMatrixType_t:
Definition: cudss.hpp:97
gko::config::type_descriptor
This class describes the value and index types to be used when building a Ginkgo type from a configur...
Definition: type_descriptor.hpp:39
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
gko::ext::cuda::solver::Cudss::refactorize
void refactorize(std::shared_ptr< const LinOp > new_matrix)
Re-run the numeric factorization with updated matrix values.
GKO_ENABLE_LIN_OP_FACTORY
#define GKO_ENABLE_LIN_OP_FACTORY(_lin_op, _parameters_name, _factory_name)
This macro will generate a default implementation of a LinOpFactory for the LinOp subclass it is defi...
Definition: lin_op.hpp:900
gko::ext::cuda::solver::Cudss::parameters_type::hybrid_execute
bool hybrid_execute
Enable hybrid host/device execution.
Definition: cudss.hpp:123
gko::ext::cuda::solver::Cudss::parameters_type::matrix_view
int matrix_view
cuDSS matrix view, mapping to cudssMatrixViewType_t:
Definition: cudss.hpp:113
gko::ext::cuda::solver::Cudss::Cudss
Cudss(const Cudss &)
Creates a copy of the solver (shares factorization state).
gko::config::registry
This class stores additional context for creating Ginkgo objects from configuration files.
Definition: registry.hpp:167
GKO_ENABLE_BUILD_METHOD
#define GKO_ENABLE_BUILD_METHOD(_factory_name)
Defines a build method for the factory, simplifying its construction by removing the repetitive typin...
Definition: abstract_factory.hpp:386
gko::Executor
The first step in using the Ginkgo library consists of creating an executor.
Definition: executor.hpp:616
gko::enable_parameters_type
The enable_parameters_type mixin is used to create a base implementation of the factory parameters st...
Definition: abstract_factory.hpp:203
gko::ext::cuda::solver::Cudss::parameters_type
Definition: cudss.hpp:77