Ginkgo  Generated from pipelines/2662685947 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
csr.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_MATRIX_CSR_HPP_
6 #define GKO_PUBLIC_CORE_MATRIX_CSR_HPP_
7 
8 
9 #include <ginkgo/core/base/array.hpp>
10 #include <ginkgo/core/base/index_set.hpp>
11 #include <ginkgo/core/base/lin_op.hpp>
12 #include <ginkgo/core/base/math.hpp>
13 #include <ginkgo/core/matrix/permutation.hpp>
14 #include <ginkgo/core/matrix/scaled_permutation.hpp>
15 
16 
17 namespace gko {
18 namespace matrix {
19 
20 
21 template <typename ValueType>
22 class Dense;
23 
24 template <typename ValueType>
25 class Diagonal;
26 
27 template <typename ValueType, typename IndexType>
28 class Coo;
29 
30 template <typename ValueType, typename IndexType>
31 class Ell;
32 
33 template <typename ValueType, typename IndexType>
34 class Hybrid;
35 
36 template <typename ValueType, typename IndexType>
37 class Sellp;
38 
39 template <typename ValueType, typename IndexType>
41 
42 template <typename ValueType, typename IndexType>
43 class Csr;
44 
45 template <typename ValueType, typename IndexType>
46 class Fbcsr;
47 
48 template <typename ValueType, typename IndexType>
49 class CsrBuilder;
50 
51 template <typename IndexType>
53 
54 
55 namespace detail {
56 
57 
58 template <typename ValueType = default_precision, typename IndexType = int32>
59 void strategy_rebuild_helper(Csr<ValueType, IndexType>* result);
60 
61 
62 } // namespace detail
63 
64 
103 template <typename ValueType = default_precision, typename IndexType = int32>
104 class Csr : public LinOp,
105  public EnableCloneable<Csr<ValueType, IndexType>>,
106  public ConvertibleTo<Csr<next_precision<ValueType>, IndexType>>,
107 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
108  public ConvertibleTo<Csr<next_precision<ValueType, 2>, IndexType>>,
109 #endif
110 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
111  public ConvertibleTo<Csr<next_precision<ValueType, 3>, IndexType>>,
112 #endif
113  public ConvertibleTo<Dense<ValueType>>,
114  public ConvertibleTo<Coo<ValueType, IndexType>>,
115  public ConvertibleTo<Ell<ValueType, IndexType>>,
116  public ConvertibleTo<Fbcsr<ValueType, IndexType>>,
117  public ConvertibleTo<Hybrid<ValueType, IndexType>>,
118  public ConvertibleTo<Sellp<ValueType, IndexType>>,
119  public ConvertibleTo<SparsityCsr<ValueType, IndexType>>,
120  public DiagonalExtractable<ValueType>,
121  public ReadableFromMatrixData<ValueType, IndexType>,
122  public WritableToMatrixData<ValueType, IndexType>,
123  public Transposable,
124  public Permutable<IndexType>,
126  remove_complex<Csr<ValueType, IndexType>>>,
127  public ScaledIdentityAddable {
128  friend class EnableCloneable<Csr>;
129  friend class Coo<ValueType, IndexType>;
130  friend class Dense<ValueType>;
131  friend class Diagonal<ValueType>;
132  friend class Ell<ValueType, IndexType>;
133  friend class Hybrid<ValueType, IndexType>;
134  friend class Sellp<ValueType, IndexType>;
135  friend class SparsityCsr<ValueType, IndexType>;
136  friend class Fbcsr<ValueType, IndexType>;
137  friend class CsrBuilder<ValueType, IndexType>;
138  friend class Csr<to_complex<ValueType>, IndexType>;
139  GKO_ASSERT_SUPPORTED_VALUE_AND_INDEX_TYPE;
140 
141 public:
144  using ConvertibleTo<Csr<next_precision<ValueType>, IndexType>>::convert_to;
145  using ConvertibleTo<Csr<next_precision<ValueType>, IndexType>>::move_to;
146  using ConvertibleTo<Dense<ValueType>>::convert_to;
147  using ConvertibleTo<Dense<ValueType>>::move_to;
148  using ConvertibleTo<Coo<ValueType, IndexType>>::convert_to;
150  using ConvertibleTo<Ell<ValueType, IndexType>>::convert_to;
161 
162  using value_type = ValueType;
163  using index_type = IndexType;
164  using transposed_type = Csr<ValueType, IndexType>;
165  using mat_data = matrix_data<ValueType, IndexType>;
166  using device_mat_data = device_matrix_data<ValueType, IndexType>;
167  using absolute_type = remove_complex<Csr>;
168 
169  class automatical;
170 
178  friend class automatical;
179 
180  public:
186  strategy_type(std::string name) : name_(name) {}
187 
188  virtual ~strategy_type() = default;
189 
195  std::string get_name() { return name_; }
196 
203  virtual void process(const array<index_type>& mtx_row_ptrs,
204  array<index_type>* mtx_srow) = 0;
205 
213  virtual int64_t clac_size(const int64_t nnz) = 0;
214 
219  virtual std::shared_ptr<strategy_type> copy() = 0;
220 
221  protected:
222  void set_name(std::string name) { name_ = name; }
223 
224  private:
225  std::string name_;
226  };
227 
234  class classical : public strategy_type {
235  public:
239  classical() : strategy_type("classical"), max_length_per_row_(0) {}
240 
241  void process(const array<index_type>& mtx_row_ptrs,
242  array<index_type>* mtx_srow) override
243  {
244  auto host_mtx_exec = mtx_row_ptrs.get_executor()->get_master();
245  array<index_type> row_ptrs_host(host_mtx_exec);
246  const bool is_mtx_on_host{host_mtx_exec ==
247  mtx_row_ptrs.get_executor()};
248  const index_type* row_ptrs{};
249  if (is_mtx_on_host) {
250  row_ptrs = mtx_row_ptrs.get_const_data();
251  } else {
252  row_ptrs_host = mtx_row_ptrs;
253  row_ptrs = row_ptrs_host.get_const_data();
254  }
255  auto num_rows = mtx_row_ptrs.get_size() - 1;
256  max_length_per_row_ = 0;
257  for (size_type i = 0; i < num_rows; i++) {
258  max_length_per_row_ = std::max(max_length_per_row_,
259  row_ptrs[i + 1] - row_ptrs[i]);
260  }
261  }
262 
263  int64_t clac_size(const int64_t nnz) override { return 0; }
264 
265  index_type get_max_length_per_row() const noexcept
266  {
267  return max_length_per_row_;
268  }
269 
270  std::shared_ptr<strategy_type> copy() override
271  {
272  return std::make_shared<classical>();
273  }
274 
275  private:
276  index_type max_length_per_row_;
277  };
278 
284  class merge_path : public strategy_type {
285  public:
289  merge_path() : strategy_type("merge_path") {}
290 
291  void process(const array<index_type>& mtx_row_ptrs,
292  array<index_type>* mtx_srow) override
293  {}
294 
295  int64_t clac_size(const int64_t nnz) override { return 0; }
296 
297  std::shared_ptr<strategy_type> copy() override
298  {
299  return std::make_shared<merge_path>();
300  }
301  };
302 
309  class cusparse : public strategy_type {
310  public:
314  cusparse() : strategy_type("cusparse") {}
315 
316  void process(const array<index_type>& mtx_row_ptrs,
317  array<index_type>* mtx_srow) override
318  {}
319 
320  int64_t clac_size(const int64_t nnz) override { return 0; }
321 
322  std::shared_ptr<strategy_type> copy() override
323  {
324  return std::make_shared<cusparse>();
325  }
326  };
327 
333  class sparselib : public strategy_type {
334  public:
338  sparselib() : strategy_type("sparselib") {}
339 
340  void process(const array<index_type>& mtx_row_ptrs,
341  array<index_type>* mtx_srow) override
342  {}
343 
344  int64_t clac_size(const int64_t nnz) override { return 0; }
345 
346  std::shared_ptr<strategy_type> copy() override
347  {
348  return std::make_shared<sparselib>();
349  }
350  };
351 
355  class load_balance : public strategy_type {
356  public:
363  [[deprecated]] load_balance()
364  : load_balance(std::move(
366  {}
367 
373  load_balance(std::shared_ptr<const CudaExecutor> exec)
374  : load_balance(exec->get_num_warps(), exec->get_warp_size())
375  {}
376 
382  load_balance(std::shared_ptr<const HipExecutor> exec)
383  : load_balance(exec->get_num_warps(), exec->get_warp_size(), false)
384  {}
385 
393  load_balance(std::shared_ptr<const DpcppExecutor> exec)
394  : load_balance(exec->get_num_subgroups(), 32, false, "intel")
395  {}
396 
408  load_balance(int64_t nwarps, int warp_size = 32,
409  bool cuda_strategy = true,
410  std::string strategy_name = "none")
411  : strategy_type("load_balance"),
412  nwarps_(nwarps),
413  warp_size_(warp_size),
414  cuda_strategy_(cuda_strategy),
415  strategy_name_(strategy_name)
416  {}
417 
418  void process(const array<index_type>& mtx_row_ptrs,
419  array<index_type>* mtx_srow) override
420  {
421  auto nwarps = mtx_srow->get_size();
422 
423  if (nwarps > 0) {
424  auto host_srow_exec = mtx_srow->get_executor()->get_master();
425  auto host_mtx_exec = mtx_row_ptrs.get_executor()->get_master();
426  const bool is_srow_on_host{host_srow_exec ==
427  mtx_srow->get_executor()};
428  const bool is_mtx_on_host{host_mtx_exec ==
429  mtx_row_ptrs.get_executor()};
430  array<index_type> row_ptrs_host(host_mtx_exec);
431  array<index_type> srow_host(host_srow_exec);
432  const index_type* row_ptrs{};
433  index_type* srow{};
434  if (is_srow_on_host) {
435  srow = mtx_srow->get_data();
436  } else {
437  srow_host = *mtx_srow;
438  srow = srow_host.get_data();
439  }
440  if (is_mtx_on_host) {
441  row_ptrs = mtx_row_ptrs.get_const_data();
442  } else {
443  row_ptrs_host = mtx_row_ptrs;
444  row_ptrs = row_ptrs_host.get_const_data();
445  }
446  for (size_type i = 0; i < nwarps; i++) {
447  srow[i] = 0;
448  }
449  const auto num_rows = mtx_row_ptrs.get_size() - 1;
450  const auto num_elems = row_ptrs[num_rows];
451  const auto bucket_divider =
452  num_elems > 0 ? ceildiv(num_elems, warp_size_) : 1;
453  for (size_type i = 0; i < num_rows; i++) {
454  auto bucket =
455  ceildiv((ceildiv(row_ptrs[i + 1], warp_size_) * nwarps),
456  bucket_divider);
457  if (bucket < nwarps) {
458  srow[bucket]++;
459  }
460  }
461  // find starting row for thread i
462  for (size_type i = 1; i < nwarps; i++) {
463  srow[i] += srow[i - 1];
464  }
465  if (!is_srow_on_host) {
466  *mtx_srow = srow_host;
467  }
468  }
469  }
470 
471  int64_t clac_size(const int64_t nnz) override
472  {
473  if (warp_size_ > 0) {
474  int multiple = 8;
475  if (nnz >= static_cast<int64_t>(2e8)) {
476  multiple = 2048;
477  } else if (nnz >= static_cast<int64_t>(2e7)) {
478  multiple = 512;
479  } else if (nnz >= static_cast<int64_t>(2e6)) {
480  multiple = 128;
481  } else if (nnz >= static_cast<int64_t>(2e5)) {
482  multiple = 32;
483  }
484  if (strategy_name_ == "intel") {
485  multiple = 8;
486  if (nnz >= static_cast<int64_t>(2e8)) {
487  multiple = 256;
488  } else if (nnz >= static_cast<int64_t>(2e7)) {
489  multiple = 32;
490  }
491  }
492 #if GINKGO_HIP_PLATFORM_HCC
493  if (!cuda_strategy_) {
494  multiple = 8;
495  if (nnz >= static_cast<int64_t>(1e7)) {
496  multiple = 64;
497  } else if (nnz >= static_cast<int64_t>(1e6)) {
498  multiple = 16;
499  }
500  }
501 #endif // GINKGO_HIP_PLATFORM_HCC
502 
503  auto nwarps = nwarps_ * multiple;
504  return min(ceildiv(nnz, warp_size_), nwarps);
505  } else {
506  return 0;
507  }
508  }
509 
510  std::shared_ptr<strategy_type> copy() override
511  {
512  return std::make_shared<load_balance>(
513  nwarps_, warp_size_, cuda_strategy_, strategy_name_);
514  }
515 
516  private:
517  int64_t nwarps_;
518  int warp_size_;
519  bool cuda_strategy_;
520  std::string strategy_name_;
521  };
522 
523  class automatical : public strategy_type {
524  public:
525  /* Use imbalance strategy when the maximum number of nonzero per row is
526  * more than 1024 on NVIDIA hardware */
527  const index_type nvidia_row_len_limit = 1024;
528  /* Use imbalance strategy when the matrix has more more than 1e6 on
529  * NVIDIA hardware */
530  const index_type nvidia_nnz_limit{static_cast<index_type>(1e6)};
531  /* Use imbalance strategy when the maximum number of nonzero per row is
532  * more than 768 on AMD hardware */
533  const index_type amd_row_len_limit = 768;
534  /* Use imbalance strategy when the matrix has more more than 1e8 on AMD
535  * hardware */
536  const index_type amd_nnz_limit{static_cast<index_type>(1e8)};
537  /* Use imbalance strategy when the maximum number of nonzero per row is
538  * more than 25600 on Intel hardware */
539  const index_type intel_row_len_limit = 25600;
540  /* Use imbalance strategy when the matrix has more more than 3e8 on
541  * Intel hardware */
542  const index_type intel_nnz_limit{static_cast<index_type>(3e8)};
543 
544  public:
551  [[deprecated]] automatical()
552  : automatical(std::move(
554  {}
555 
561  automatical(std::shared_ptr<const CudaExecutor> exec)
562  : automatical(exec->get_num_warps(), exec->get_warp_size())
563  {}
564 
570  automatical(std::shared_ptr<const HipExecutor> exec)
571  : automatical(exec->get_num_warps(), exec->get_warp_size(), false)
572  {}
573 
581  automatical(std::shared_ptr<const DpcppExecutor> exec)
582  : automatical(exec->get_num_subgroups(), 32, false, "intel")
583  {}
584 
596  automatical(int64_t nwarps, int warp_size = 32,
597  bool cuda_strategy = true,
598  std::string strategy_name = "none")
599  : strategy_type("automatical"),
600  nwarps_(nwarps),
601  warp_size_(warp_size),
602  cuda_strategy_(cuda_strategy),
603  strategy_name_(strategy_name),
604  max_length_per_row_(0)
605  {}
606 
607  void process(const array<index_type>& mtx_row_ptrs,
608  array<index_type>* mtx_srow) override
609  {
610  // if the number of stored elements is larger than <nnz_limit> or
611  // the maximum number of stored elements per row is larger than
612  // <row_len_limit>, use load_balance otherwise use classical
613  index_type nnz_limit = nvidia_nnz_limit;
614  index_type row_len_limit = nvidia_row_len_limit;
615  if (strategy_name_ == "intel") {
616  nnz_limit = intel_nnz_limit;
617  row_len_limit = intel_row_len_limit;
618  }
619 #if GINKGO_HIP_PLATFORM_HCC
620  if (!cuda_strategy_) {
621  nnz_limit = amd_nnz_limit;
622  row_len_limit = amd_row_len_limit;
623  }
624 #endif // GINKGO_HIP_PLATFORM_HCC
625  auto host_mtx_exec = mtx_row_ptrs.get_executor()->get_master();
626  const bool is_mtx_on_host{host_mtx_exec ==
627  mtx_row_ptrs.get_executor()};
628  array<index_type> row_ptrs_host(host_mtx_exec);
629  const index_type* row_ptrs{};
630  if (is_mtx_on_host) {
631  row_ptrs = mtx_row_ptrs.get_const_data();
632  } else {
633  row_ptrs_host = mtx_row_ptrs;
634  row_ptrs = row_ptrs_host.get_const_data();
635  }
636  const auto num_rows = mtx_row_ptrs.get_size() - 1;
637  if (row_ptrs[num_rows] > nnz_limit) {
638  load_balance actual_strategy(nwarps_, warp_size_,
639  cuda_strategy_, strategy_name_);
640  if (is_mtx_on_host) {
641  actual_strategy.process(mtx_row_ptrs, mtx_srow);
642  } else {
643  actual_strategy.process(row_ptrs_host, mtx_srow);
644  }
645  this->set_name(actual_strategy.get_name());
646  } else {
647  index_type maxnum = 0;
648  for (size_type i = 0; i < num_rows; i++) {
649  maxnum = std::max(maxnum, row_ptrs[i + 1] - row_ptrs[i]);
650  }
651  if (maxnum > row_len_limit) {
652  load_balance actual_strategy(
653  nwarps_, warp_size_, cuda_strategy_, strategy_name_);
654  if (is_mtx_on_host) {
655  actual_strategy.process(mtx_row_ptrs, mtx_srow);
656  } else {
657  actual_strategy.process(row_ptrs_host, mtx_srow);
658  }
659  this->set_name(actual_strategy.get_name());
660  } else {
661  classical actual_strategy;
662  if (is_mtx_on_host) {
663  actual_strategy.process(mtx_row_ptrs, mtx_srow);
664  max_length_per_row_ =
665  actual_strategy.get_max_length_per_row();
666  } else {
667  actual_strategy.process(row_ptrs_host, mtx_srow);
668  max_length_per_row_ =
669  actual_strategy.get_max_length_per_row();
670  }
671  this->set_name(actual_strategy.get_name());
672  }
673  }
674  }
675 
676  int64_t clac_size(const int64_t nnz) override
677  {
678  return std::make_shared<load_balance>(
679  nwarps_, warp_size_, cuda_strategy_, strategy_name_)
680  ->clac_size(nnz);
681  }
682 
683  index_type get_max_length_per_row() const noexcept
684  {
685  return max_length_per_row_;
686  }
687 
688  std::shared_ptr<strategy_type> copy() override
689  {
690  return std::make_shared<automatical>(
691  nwarps_, warp_size_, cuda_strategy_, strategy_name_);
692  }
693 
694  private:
695  int64_t nwarps_;
696  int warp_size_;
697  bool cuda_strategy_;
698  std::string strategy_name_;
699  index_type max_length_per_row_;
700  };
701 
702  friend class Csr<previous_precision<ValueType>, IndexType>;
703 
704  void convert_to(
705  Csr<next_precision<ValueType>, IndexType>* result) const override;
706 
707  void move_to(Csr<next_precision<ValueType>, IndexType>* result) override;
708 
709 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
710  friend class Csr<previous_precision<ValueType, 2>, IndexType>;
711  using ConvertibleTo<
712  Csr<next_precision<ValueType, 2>, IndexType>>::convert_to;
713  using ConvertibleTo<Csr<next_precision<ValueType, 2>, IndexType>>::move_to;
714 
715  void convert_to(
716  Csr<next_precision<ValueType, 2>, IndexType>* result) const override;
717 
718  void move_to(Csr<next_precision<ValueType, 2>, IndexType>* result) override;
719 #endif
720 
721 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
722  friend class Csr<previous_precision<ValueType, 3>, IndexType>;
723  using ConvertibleTo<
724  Csr<next_precision<ValueType, 3>, IndexType>>::convert_to;
725  using ConvertibleTo<Csr<next_precision<ValueType, 3>, IndexType>>::move_to;
726 
727  void convert_to(
728  Csr<next_precision<ValueType, 3>, IndexType>* result) const override;
729 
730  void move_to(Csr<next_precision<ValueType, 3>, IndexType>* result) override;
731 #endif
732 
733  void convert_to(Dense<ValueType>* other) const override;
734 
735  void move_to(Dense<ValueType>* other) override;
736 
737  void convert_to(Coo<ValueType, IndexType>* result) const override;
738 
739  void move_to(Coo<ValueType, IndexType>* result) override;
740 
741  void convert_to(Ell<ValueType, IndexType>* result) const override;
742 
743  void move_to(Ell<ValueType, IndexType>* result) override;
744 
745  void convert_to(Fbcsr<ValueType, IndexType>* result) const override;
746 
747  void move_to(Fbcsr<ValueType, IndexType>* result) override;
748 
749  void convert_to(Hybrid<ValueType, IndexType>* result) const override;
750 
751  void move_to(Hybrid<ValueType, IndexType>* result) override;
752 
753  void convert_to(Sellp<ValueType, IndexType>* result) const override;
754 
755  void move_to(Sellp<ValueType, IndexType>* result) override;
756 
757  void convert_to(SparsityCsr<ValueType, IndexType>* result) const override;
758 
759  void move_to(SparsityCsr<ValueType, IndexType>* result) override;
760 
761  void read(const mat_data& data) override;
762 
763  void read(const device_mat_data& data) override;
764 
765  void read(device_mat_data&& data) override;
766 
767  void write(mat_data& data) const override;
768 
769  std::unique_ptr<LinOp> transpose() const override;
770 
771  std::unique_ptr<LinOp> conj_transpose() const override;
772 
779  friend class Csr;
780 
781  public:
782  explicit multiply_reuse_info();
783 
785 
786  multiply_reuse_info(const multiply_reuse_info&) = delete;
787 
789 
790  multiply_reuse_info& operator=(const multiply_reuse_info&) = delete;
791 
792  multiply_reuse_info& operator=(multiply_reuse_info&&) noexcept;
793 
800  ptr_param<Csr> out) const;
801 
802  private:
803  struct lookup_data;
804 
805  explicit multiply_reuse_info(std::unique_ptr<lookup_data> data);
806 
807  std::unique_ptr<lookup_data> internal;
808  };
809 
820  std::unique_ptr<Csr> multiply(ptr_param<const Csr> other) const;
821 
838  std::pair<std::unique_ptr<Csr>, multiply_reuse_info> multiply_reuse(
839  ptr_param<const Csr> other) const;
840 
847  friend class Csr;
848 
849  public:
850  explicit multiply_add_reuse_info();
851 
853 
855 
857 
859  delete;
860 
861  multiply_add_reuse_info& operator=(multiply_add_reuse_info&&) noexcept;
862 
871  ptr_param<const Dense<value_type>> scale_mult,
872  ptr_param<const Csr> mtx_mult,
874  ptr_param<const Csr> mtx_add,
875  ptr_param<Csr> out) const;
876 
877  private:
878  struct lookup_data;
879 
880  explicit multiply_add_reuse_info(std::unique_ptr<lookup_data> data);
881 
882  std::unique_ptr<lookup_data> internal;
883  };
884 
900  std::unique_ptr<Csr> multiply_add(
901  ptr_param<const Dense<value_type>> scale_mult,
902  ptr_param<const Csr> mtx_mult,
904  ptr_param<const Csr> mtx_add) const;
905 
927  std::pair<std::unique_ptr<Csr>, multiply_add_reuse_info> multiply_add_reuse(
928  ptr_param<const Dense<value_type>> scale_mult,
929  ptr_param<const Csr> mtx_mult,
931  ptr_param<const Csr> mtx_add) const;
932 
939  friend class Csr;
940 
941  public:
942  explicit scale_add_reuse_info();
943 
945 
947 
949 
950  scale_add_reuse_info& operator=(const scale_add_reuse_info&) = delete;
951 
952  scale_add_reuse_info& operator=(scale_add_reuse_info&&) noexcept;
953 
960  void update_values(ptr_param<const Dense<value_type>> scale1,
962  ptr_param<const Dense<value_type>> scale2,
963  ptr_param<const Csr> mtx2, ptr_param<Csr> out) const;
964 
965  private:
966  struct lookup_data;
967 
968  explicit scale_add_reuse_info(std::unique_ptr<lookup_data> data);
969 
970  std::unique_ptr<lookup_data> internal;
971  };
972 
987  std::unique_ptr<Csr> scale_add(
988  ptr_param<const Dense<value_type>> scale_this,
989  ptr_param<const Dense<value_type>> scale_other,
990  ptr_param<const Csr> mtx_other) const;
991 
1013  std::pair<std::unique_ptr<Csr>, scale_add_reuse_info> add_scale_reuse(
1014  ptr_param<const Dense<value_type>> scale_this,
1015  ptr_param<const Dense<value_type>> scale_other,
1016  ptr_param<const Csr> mtx_other) const;
1017 
1024  explicit permuting_reuse_info();
1025 
1027  explicit permuting_reuse_info(
1028  std::unique_ptr<Permutation<index_type>> value_permutation);
1029 
1038  ptr_param<Csr> output) const;
1039 
1040  std::unique_ptr<Permutation<IndexType>> value_permutation;
1041  };
1042 
1055  std::pair<std::unique_ptr<Csr>, permuting_reuse_info> transpose_reuse()
1056  const;
1057 
1072  std::unique_ptr<Csr> permute(
1073  ptr_param<const Permutation<index_type>> permutation,
1075 
1089  std::unique_ptr<Csr> permute(
1090  ptr_param<const Permutation<index_type>> row_permutation,
1091  ptr_param<const Permutation<index_type>> column_permutation,
1092  bool invert = false) const;
1093 
1114  std::pair<std::unique_ptr<Csr>, permuting_reuse_info> permute_reuse(
1115  ptr_param<const Permutation<index_type>> permutation,
1117 
1136  std::pair<std::unique_ptr<Csr>, permuting_reuse_info> permute_reuse(
1137  ptr_param<const Permutation<index_type>> row_permutation,
1138  ptr_param<const Permutation<index_type>> column_permutation,
1139  bool invert = false) const;
1140 
1150  std::unique_ptr<Csr> scale_permute(
1153 
1166  std::unique_ptr<Csr> scale_permute(
1168  row_permutation,
1170  column_permutation,
1171  bool invert = false) const;
1172 
1173  std::unique_ptr<LinOp> permute(
1174  const array<IndexType>* permutation_indices) const override;
1175 
1176  std::unique_ptr<LinOp> inverse_permute(
1177  const array<IndexType>* inverse_permutation_indices) const override;
1178 
1179  std::unique_ptr<LinOp> row_permute(
1180  const array<IndexType>* permutation_indices) const override;
1181 
1182  std::unique_ptr<LinOp> column_permute(
1183  const array<IndexType>* permutation_indices) const override;
1184 
1185  std::unique_ptr<LinOp> inverse_row_permute(
1186  const array<IndexType>* inverse_permutation_indices) const override;
1187 
1188  std::unique_ptr<LinOp> inverse_column_permute(
1189  const array<IndexType>* inverse_permutation_indices) const override;
1190 
1191  std::unique_ptr<Diagonal<ValueType>> extract_diagonal() const override;
1192 
1193  std::unique_ptr<absolute_type> compute_absolute() const override;
1194 
1195  void compute_absolute_inplace() override;
1196 
1200  void sort_by_column_index();
1201 
1202  /*
1203  * Tests if all row entry pairs (value, col_idx) are sorted by column index
1204  *
1205  * @returns True if all row entry pairs (value, col_idx) are sorted by
1206  * column index
1207  */
1208  bool is_sorted_by_column_index() const;
1209 
1215  value_type* get_values() noexcept { return values_.get_data(); }
1216 
1224  const value_type* get_const_values() const noexcept
1225  {
1226  return values_.get_const_data();
1227  }
1228 
1233  std::unique_ptr<Dense<ValueType>> create_value_view();
1234 
1239  std::unique_ptr<const Dense<ValueType>> create_const_value_view() const;
1240 
1246  index_type* get_col_idxs() noexcept { return col_idxs_.get_data(); }
1247 
1255  const index_type* get_const_col_idxs() const noexcept
1256  {
1257  return col_idxs_.get_const_data();
1258  }
1259 
1265  index_type* get_row_ptrs() noexcept { return row_ptrs_.get_data(); }
1266 
1274  const index_type* get_const_row_ptrs() const noexcept
1275  {
1276  return row_ptrs_.get_const_data();
1277  }
1278 
1284  index_type* get_srow() noexcept { return srow_.get_data(); }
1285 
1293  const index_type* get_const_srow() const noexcept
1294  {
1295  return srow_.get_const_data();
1296  }
1297 
1304  {
1305  return srow_.get_size();
1306  }
1307 
1314  {
1315  return values_.get_size();
1316  }
1317 
1322  std::shared_ptr<strategy_type> get_strategy() const noexcept
1323  {
1324  return strategy_;
1325  }
1326 
1332  void set_strategy(std::shared_ptr<strategy_type> strategy)
1333  {
1334  strategy_ = std::move(strategy->copy());
1335  this->make_srow();
1336  }
1337 
1345  {
1346  auto exec = this->get_executor();
1347  GKO_ASSERT_EQUAL_DIMENSIONS(alpha, dim<2>(1, 1));
1348  this->scale_impl(make_temporary_clone(exec, alpha).get());
1349  }
1350 
1358  {
1359  auto exec = this->get_executor();
1360  GKO_ASSERT_EQUAL_DIMENSIONS(alpha, dim<2>(1, 1));
1361  this->inv_scale_impl(make_temporary_clone(exec, alpha).get());
1362  }
1363 
1372  static std::unique_ptr<Csr> create(std::shared_ptr<const Executor> exec,
1373  std::shared_ptr<strategy_type> strategy);
1374 
1386  static std::unique_ptr<Csr> create(
1387  std::shared_ptr<const Executor> exec, const dim<2>& size = {},
1388  size_type num_nonzeros = {},
1389  std::shared_ptr<strategy_type> strategy = nullptr);
1390 
1410  static std::unique_ptr<Csr> create(
1411  std::shared_ptr<const Executor> exec, const dim<2>& size,
1412  array<value_type> values, array<index_type> col_idxs,
1413  array<index_type> row_ptrs,
1414  std::shared_ptr<strategy_type> strategy = nullptr);
1415 
1420  template <typename InputValueType, typename InputColumnIndexType,
1421  typename InputRowPtrType>
1422  GKO_DEPRECATED(
1423  "explicitly construct the gko::array argument instead of passing "
1424  "initializer lists")
1425  static std::unique_ptr<Csr> create(
1426  std::shared_ptr<const Executor> exec, const dim<2>& size,
1427  std::initializer_list<InputValueType> values,
1428  std::initializer_list<InputColumnIndexType> col_idxs,
1429  std::initializer_list<InputRowPtrType> row_ptrs)
1430  {
1431  return create(exec, size, array<value_type>{exec, std::move(values)},
1432  array<index_type>{exec, std::move(col_idxs)},
1433  array<index_type>{exec, std::move(row_ptrs)});
1434  }
1435 
1451  static std::unique_ptr<const Csr> create_const(
1452  std::shared_ptr<const Executor> exec, const dim<2>& size,
1453  gko::detail::const_array_view<ValueType>&& values,
1454  gko::detail::const_array_view<IndexType>&& col_idxs,
1455  gko::detail::const_array_view<IndexType>&& row_ptrs,
1456  std::shared_ptr<strategy_type> strategy = nullptr);
1457 
1470  std::unique_ptr<Csr<ValueType, IndexType>> create_submatrix(
1471  const index_set<IndexType>& row_index_set,
1472  const index_set<IndexType>& column_index_set) const;
1473 
1485  std::unique_ptr<Csr<ValueType, IndexType>> create_submatrix(
1486  const span& row_span, const span& column_span) const;
1487 
1491  Csr& operator=(const Csr&);
1492 
1498  Csr& operator=(Csr&&);
1499 
1503  Csr(const Csr&);
1504 
1510  Csr(Csr&&);
1511 
1512 protected:
1513  Csr(std::shared_ptr<const Executor> exec, const dim<2>& size = {},
1514  size_type num_nonzeros = {},
1515  std::shared_ptr<strategy_type> strategy = nullptr);
1516 
1517  Csr(std::shared_ptr<const Executor> exec, const dim<2>& size,
1518  array<value_type> values, array<index_type> col_idxs,
1519  array<index_type> row_ptrs,
1520  std::shared_ptr<strategy_type> strategy = nullptr);
1521 
1522  void apply_impl(const LinOp* b, LinOp* x) const override;
1523 
1524  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
1525  LinOp* x) const override;
1526 
1527  // TODO: This provides some more sane settings. Please fix this!
1528  static std::shared_ptr<strategy_type> make_default_strategy(
1529  std::shared_ptr<const Executor> exec)
1530  {
1531  auto cuda_exec = std::dynamic_pointer_cast<const CudaExecutor>(exec);
1532  auto hip_exec = std::dynamic_pointer_cast<const HipExecutor>(exec);
1533  auto dpcpp_exec = std::dynamic_pointer_cast<const DpcppExecutor>(exec);
1534  std::shared_ptr<strategy_type> new_strategy;
1535  if (cuda_exec) {
1536  new_strategy = std::make_shared<automatical>(cuda_exec);
1537  } else if (hip_exec) {
1538  new_strategy = std::make_shared<automatical>(hip_exec);
1539  } else if (dpcpp_exec) {
1540  new_strategy = std::make_shared<automatical>(dpcpp_exec);
1541  } else {
1542  new_strategy = std::make_shared<classical>();
1543  }
1544  return new_strategy;
1545  }
1546 
1547  // TODO clean this up as soon as we improve strategy_type
1548  template <typename CsrType>
1549  void convert_strategy_helper(CsrType* result) const
1550  {
1551  auto strat = this->get_strategy().get();
1552  std::shared_ptr<typename CsrType::strategy_type> new_strat;
1553  if (dynamic_cast<classical*>(strat)) {
1554  new_strat = std::make_shared<typename CsrType::classical>();
1555  } else if (dynamic_cast<merge_path*>(strat)) {
1556  new_strat = std::make_shared<typename CsrType::merge_path>();
1557  } else if (dynamic_cast<cusparse*>(strat)) {
1558  new_strat = std::make_shared<typename CsrType::cusparse>();
1559  } else if (dynamic_cast<sparselib*>(strat)) {
1560  new_strat = std::make_shared<typename CsrType::sparselib>();
1561  } else {
1562  auto rexec = result->get_executor();
1563  auto cuda_exec =
1564  std::dynamic_pointer_cast<const CudaExecutor>(rexec);
1565  auto hip_exec = std::dynamic_pointer_cast<const HipExecutor>(rexec);
1566  auto dpcpp_exec =
1567  std::dynamic_pointer_cast<const DpcppExecutor>(rexec);
1568  auto lb = dynamic_cast<load_balance*>(strat);
1569  if (cuda_exec) {
1570  if (lb) {
1571  new_strat =
1572  std::make_shared<typename CsrType::load_balance>(
1573  cuda_exec);
1574  } else {
1575  new_strat = std::make_shared<typename CsrType::automatical>(
1576  cuda_exec);
1577  }
1578  } else if (hip_exec) {
1579  if (lb) {
1580  new_strat =
1581  std::make_shared<typename CsrType::load_balance>(
1582  hip_exec);
1583  } else {
1584  new_strat = std::make_shared<typename CsrType::automatical>(
1585  hip_exec);
1586  }
1587  } else if (dpcpp_exec) {
1588  if (lb) {
1589  new_strat =
1590  std::make_shared<typename CsrType::load_balance>(
1591  dpcpp_exec);
1592  } else {
1593  new_strat = std::make_shared<typename CsrType::automatical>(
1594  dpcpp_exec);
1595  }
1596  } else {
1597  // Try to preserve this executor's configuration
1598  auto this_cuda_exec =
1599  std::dynamic_pointer_cast<const CudaExecutor>(
1600  this->get_executor());
1601  auto this_hip_exec =
1602  std::dynamic_pointer_cast<const HipExecutor>(
1603  this->get_executor());
1604  auto this_dpcpp_exec =
1605  std::dynamic_pointer_cast<const DpcppExecutor>(
1606  this->get_executor());
1607  if (this_cuda_exec) {
1608  if (lb) {
1609  new_strat =
1610  std::make_shared<typename CsrType::load_balance>(
1611  this_cuda_exec);
1612  } else {
1613  new_strat =
1614  std::make_shared<typename CsrType::automatical>(
1615  this_cuda_exec);
1616  }
1617  } else if (this_hip_exec) {
1618  if (lb) {
1619  new_strat =
1620  std::make_shared<typename CsrType::load_balance>(
1621  this_hip_exec);
1622  } else {
1623  new_strat =
1624  std::make_shared<typename CsrType::automatical>(
1625  this_hip_exec);
1626  }
1627  } else if (this_dpcpp_exec) {
1628  if (lb) {
1629  new_strat =
1630  std::make_shared<typename CsrType::load_balance>(
1631  this_dpcpp_exec);
1632  } else {
1633  new_strat =
1634  std::make_shared<typename CsrType::automatical>(
1635  this_dpcpp_exec);
1636  }
1637  } else {
1638  // FIXME: this changes strategies.
1639  // We had a load balance or automatical strategy from a non
1640  // HIP or Cuda executor and are moving to a non HIP or Cuda
1641  // executor.
1642  new_strat = std::make_shared<typename CsrType::classical>();
1643  }
1644  }
1645  }
1646  result->set_strategy(new_strat);
1647  }
1648 
1652  void make_srow()
1653  {
1654  srow_.resize_and_reset(strategy_->clac_size(values_.get_size()));
1655  strategy_->process(row_ptrs_, &srow_);
1656  }
1657 
1664  virtual void scale_impl(const LinOp* alpha);
1665 
1672  virtual void inv_scale_impl(const LinOp* alpha);
1673 
1674 private:
1675  std::shared_ptr<strategy_type> strategy_;
1676  array<value_type> values_;
1677  array<index_type> col_idxs_;
1678  array<index_type> row_ptrs_;
1679  array<index_type> srow_;
1680 
1681  void add_scaled_identity_impl(const LinOp* a, const LinOp* b) override;
1682 };
1683 
1684 
1685 namespace detail {
1686 
1687 
1694 template <typename ValueType, typename IndexType>
1695 void strategy_rebuild_helper(Csr<ValueType, IndexType>* result)
1696 {
1697  using load_balance = typename Csr<ValueType, IndexType>::load_balance;
1698  using automatical = typename Csr<ValueType, IndexType>::automatical;
1699  auto strategy = result->get_strategy();
1700  auto executor = result->get_executor();
1701  if (std::dynamic_pointer_cast<load_balance>(strategy)) {
1702  if (auto exec =
1703  std::dynamic_pointer_cast<const HipExecutor>(executor)) {
1704  result->set_strategy(std::make_shared<load_balance>(exec));
1705  } else if (auto exec = std::dynamic_pointer_cast<const CudaExecutor>(
1706  executor)) {
1707  result->set_strategy(std::make_shared<load_balance>(exec));
1708  }
1709  } else if (std::dynamic_pointer_cast<automatical>(strategy)) {
1710  if (auto exec =
1711  std::dynamic_pointer_cast<const HipExecutor>(executor)) {
1712  result->set_strategy(std::make_shared<automatical>(exec));
1713  } else if (auto exec = std::dynamic_pointer_cast<const CudaExecutor>(
1714  executor)) {
1715  result->set_strategy(std::make_shared<automatical>(exec));
1716  }
1717  }
1718 }
1719 
1720 
1721 } // namespace detail
1722 } // namespace matrix
1723 } // namespace gko
1724 
1725 
1726 #endif // GKO_PUBLIC_CORE_MATRIX_CSR_HPP_
gko::matrix::Csr::automatical
Definition: csr.hpp:523
gko::matrix::Csr::get_const_srow
const index_type * get_const_srow() const noexcept
Returns the starting rows.
Definition: csr.hpp:1293
gko::matrix::Csr::load_balance::load_balance
load_balance(std::shared_ptr< const HipExecutor > exec)
Creates a load_balance strategy with HIP executor.
Definition: csr.hpp:382
gko::matrix::Csr::operator=
Csr & operator=(const Csr &)
Copy-assigns a Csr matrix.
gko::matrix::Csr::cusparse::process
void process(const array< index_type > &mtx_row_ptrs, array< index_type > *mtx_srow) override
Computes srow according to row pointers.
Definition: csr.hpp:316
gko::matrix::Csr::get_col_idxs
index_type * get_col_idxs() noexcept
Returns the column indexes of the matrix.
Definition: csr.hpp:1246
gko::matrix::Fbcsr
Fixed-block compressed sparse row storage matrix format.
Definition: csr.hpp:46
gko::matrix::Csr
CSR is a matrix format which stores only the nonzero coefficients by compressing each row of the matr...
Definition: matrix.hpp:30
gko::matrix::Csr::get_const_row_ptrs
const index_type * get_const_row_ptrs() const noexcept
Returns the row pointers of the matrix.
Definition: csr.hpp:1274
gko::matrix::Csr::sparselib::sparselib
sparselib()
Creates a sparselib strategy.
Definition: csr.hpp:338
gko::matrix::Csr::multiply
std::unique_ptr< Csr > multiply(ptr_param< const Csr > other) const
Computes the sparse matrix product this * other on the executor of this matrix.
gko::LinOp
Definition: lin_op.hpp:117
gko::matrix::Csr::add_scale_reuse
std::pair< std::unique_ptr< Csr >, scale_add_reuse_info > add_scale_reuse(ptr_param< const Dense< value_type >> scale_this, ptr_param< const Dense< value_type >> scale_other, ptr_param< const Csr > mtx_other) const
Computes the sparse matrix sum scale_this * this + scale_other * mtx_add on the executor of this matr...
gko::matrix::Csr::permute_reuse
std::pair< std::unique_ptr< Csr >, permuting_reuse_info > permute_reuse(ptr_param< const Permutation< index_type >> permutation, permute_mode mode=permute_mode::symmetric) const
Computes the operations necessary to propagate changed values from a matrix A to a permuted matrix.
gko::matrix::Dense
Dense is a matrix format which explicitly stores all values of the matrix.
Definition: dense_cache.hpp:28
gko::matrix::Csr::multiply_add_reuse_info
Class describing the internal lookup structures created by multiply_add_reuse to recompute a sparse m...
Definition: csr.hpp:846
gko::matrix::CsrBuilder
Definition: csr.hpp:49
gko::matrix::Csr::inverse_row_permute
std::unique_ptr< LinOp > inverse_row_permute(const array< IndexType > *inverse_permutation_indices) const override
Returns a LinOp representing the row permutation of the inverse permuted object.
gko::matrix::Csr::sparselib
sparselib is a strategy_type which uses the sparselib csr.
Definition: csr.hpp:333
gko::DiagonalExtractable
The diagonal of a LinOp implementing this interface can be extracted.
Definition: lin_op.hpp:702
gko::matrix::SparsityCsr
SparsityCsr is a matrix format which stores only the sparsity pattern of a sparse matrix by compressi...
Definition: csr.hpp:40
gko::matrix::Csr::load_balance
load_balance is a strategy_type which uses the load balance algorithm.
Definition: csr.hpp:355
gko::matrix::Csr::multiply_reuse
std::pair< std::unique_ptr< Csr >, multiply_reuse_info > multiply_reuse(ptr_param< const Csr > other) const
Computes the sparse matrix product this * other on the executor of this matrix, and necessary data fo...
gko::matrix::Csr::multiply_add_reuse_info::update_values
void update_values(ptr_param< const Csr > mtx, ptr_param< const Dense< value_type >> scale_mult, ptr_param< const Csr > mtx_mult, ptr_param< const Dense< value_type >> scale_add, ptr_param< const Csr > mtx_add, ptr_param< Csr > out) const
Recomputes the sparse matrix-matrix product out = scale_mult * mtx * mtx_mult + scale_add * mtx_add w...
gko::matrix::Csr::scale
void scale(ptr_param< const LinOp > alpha)
Scales the matrix with a scalar.
Definition: csr.hpp:1344
gko::matrix::Csr::automatical::automatical
automatical(std::shared_ptr< const HipExecutor > exec)
Creates an automatical strategy with HIP executor.
Definition: csr.hpp:570
gko::Transposable
Linear operators which support transposition should implement the Transposable interface.
Definition: lin_op.hpp:392
gko::matrix::Csr::column_permute
std::unique_ptr< LinOp > column_permute(const array< IndexType > *permutation_indices) const override
Returns a LinOp representing the column permutation of the Permutable object.
gko::matrix::Csr::strategy_type::get_name
std::string get_name()
Returns the name of strategy.
Definition: csr.hpp:195
gko::matrix::Csr::classical::clac_size
int64_t clac_size(const int64_t nnz) override
Computes the srow size according to the number of nonzeros.
Definition: csr.hpp:263
gko::matrix::ScaledPermutation
ScaledPermutation is a matrix combining a permutation with scaling factors.
Definition: scaled_permutation.hpp:36
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:90
gko::matrix::Csr::strategy_type::copy
virtual std::shared_ptr< strategy_type > copy()=0
Copy a strategy.
gko::matrix::Csr::get_srow
index_type * get_srow() noexcept
Returns the starting rows.
Definition: csr.hpp:1284
gko::matrix::Csr::sparselib::clac_size
int64_t clac_size(const int64_t nnz) override
Computes the srow size according to the number of nonzeros.
Definition: csr.hpp:344
gko::matrix::Csr::transpose_reuse
std::pair< std::unique_ptr< Csr >, permuting_reuse_info > transpose_reuse() const
Computes the necessary data to update a transposed matrix from its original matrix.
gko::matrix::Permutation
Permutation is a matrix format that represents a permutation matrix, i.e.
Definition: csr.hpp:52
gko::matrix::Csr::automatical::process
void process(const array< index_type > &mtx_row_ptrs, array< index_type > *mtx_srow) override
Computes srow according to row pointers.
Definition: csr.hpp:607
gko::matrix::Csr::permuting_reuse_info::permuting_reuse_info
permuting_reuse_info()
Creates an empty reuse info.
gko::matrix::Csr::row_permute
std::unique_ptr< LinOp > row_permute(const array< IndexType > *permutation_indices) const override
Returns a LinOp representing the row permutation of the Permutable object.
gko::matrix::Csr::classical::copy
std::shared_ptr< strategy_type > copy() override
Copy a strategy.
Definition: csr.hpp:270
gko::CudaExecutor
This is the Executor subclass which represents the CUDA device.
Definition: executor.hpp:1541
gko::matrix::Csr::strategy_type::process
virtual void process(const array< index_type > &mtx_row_ptrs, array< index_type > *mtx_srow)=0
Computes srow according to row pointers.
gko::Permutable
Linear operators which support permutation should implement the Permutable interface.
Definition: lin_op.hpp:443
gko::matrix::Csr::transpose
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
gko::matrix::Csr::load_balance::load_balance
load_balance(std::shared_ptr< const DpcppExecutor > exec)
Creates a load_balance strategy with DPCPP executor.
Definition: csr.hpp:393
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
gko::matrix::Csr::load_balance::process
void process(const array< index_type > &mtx_row_ptrs, array< index_type > *mtx_srow) override
Computes srow according to row pointers.
Definition: csr.hpp:418
gko::matrix::Csr::inv_scale
void inv_scale(ptr_param< const LinOp > alpha)
Scales the matrix with the inverse of a scalar.
Definition: csr.hpp:1357
gko::matrix::Csr::extract_diagonal
std::unique_ptr< Diagonal< ValueType > > extract_diagonal() const override
Extracts the diagonal entries of the matrix into a vector.
gko::array< index_type >
gko::matrix::Csr::multiply_add
std::unique_ptr< Csr > multiply_add(ptr_param< const Dense< value_type >> scale_mult, ptr_param< const Csr > mtx_mult, ptr_param< const Dense< value_type >> scale_add, ptr_param< const Csr > mtx_add) const
Computes the sparse matrix product scale_mult * this * mtx_mult + scale_add * mtx_add on the executor...
gko::matrix::Csr::cusparse
cusparse is a strategy_type which uses the sparselib csr.
Definition: csr.hpp:309
gko::matrix::Csr::inverse_permute
std::unique_ptr< LinOp > inverse_permute(const array< IndexType > *inverse_permutation_indices) const override
Returns a LinOp representing the symmetric inverse row and column permutation of the Permutable objec...
gko::matrix::Csr::get_row_ptrs
index_type * get_row_ptrs() noexcept
Returns the row pointers of the matrix.
Definition: csr.hpp:1265
gko::array::resize_and_reset
void resize_and_reset(size_type size)
Resizes the array so it is able to hold the specified number of elements.
Definition: array.hpp:622
gko::span
A span is a lightweight structure used to create sub-ranges from other ranges.
Definition: range.hpp:46
gko::dim< 2 >
gko::matrix_data
This structure is used as an intermediate data type to store a sparse matrix.
Definition: matrix_data.hpp:126
gko::matrix::Csr::load_balance::clac_size
int64_t clac_size(const int64_t nnz) override
Computes the srow size according to the number of nonzeros.
Definition: csr.hpp:471
gko::matrix::Csr::merge_path
merge_path is a strategy_type which uses the merge_path algorithm.
Definition: csr.hpp:284
gko::matrix::Csr::permute
std::unique_ptr< Csr > permute(ptr_param< const Permutation< index_type >> permutation, permute_mode mode=permute_mode::symmetric) const
Creates a permuted copy of this matrix with the given permutation .
gko::index_set
An index set class represents an ordered set of intervals.
Definition: index_set.hpp:56
gko::matrix::Csr::automatical::automatical
automatical()
Creates an automatical strategy.
Definition: csr.hpp:551
gko::matrix::Csr::merge_path::copy
std::shared_ptr< strategy_type > copy() override
Copy a strategy.
Definition: csr.hpp:297
gko::matrix::Csr::load_balance::load_balance
load_balance(int64_t nwarps, int warp_size=32, bool cuda_strategy=true, std::string strategy_name="none")
Creates a load_balance strategy with specified parameters.
Definition: csr.hpp:408
gko::matrix::Diagonal
This class is a utility which efficiently implements the diagonal matrix (a linear operator which sca...
Definition: lin_op.hpp:31
gko::matrix::Csr::strategy_type::clac_size
virtual int64_t clac_size(const int64_t nnz)=0
Computes the srow size according to the number of nonzeros.
gko::matrix::Csr::load_balance::load_balance
load_balance(std::shared_ptr< const CudaExecutor > exec)
Creates a load_balance strategy with CUDA executor.
Definition: csr.hpp:373
gko::ptr_param
This class is used for function parameters in the place of raw pointers.
Definition: utils_helper.hpp:43
gko::array::get_data
value_type * get_data() noexcept
Returns a pointer to the block of memory used to store the elements of the array.
Definition: array.hpp:687
gko::ReadableFromMatrixData
A LinOp implementing this interface can read its data from a matrix_data structure.
Definition: lin_op.hpp:564
gko::OmpExecutor
This is the Executor subclass which represents the OpenMP device (typically CPU).
Definition: executor.hpp:1387
gko::matrix::Csr::conj_transpose
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
gko::WritableToMatrixData
A LinOp implementing this interface can write its data to a matrix_data structure.
Definition: lin_op.hpp:619
gko::matrix::permute_mode::symmetric
The rows and columns will be permuted.
gko::matrix::Csr::sparselib::process
void process(const array< index_type > &mtx_row_ptrs, array< index_type > *mtx_srow) override
Computes srow according to row pointers.
Definition: csr.hpp:340
gko::matrix::Csr::cusparse::cusparse
cusparse()
Creates a cusparse strategy.
Definition: csr.hpp:314
gko::matrix::Csr::cusparse::clac_size
int64_t clac_size(const int64_t nnz) override
Computes the srow size according to the number of nonzeros.
Definition: csr.hpp:320
gko::matrix::Csr::merge_path::merge_path
merge_path()
Creates a merge_path strategy.
Definition: csr.hpp:289
gko::matrix::Csr::get_const_values
const value_type * get_const_values() const noexcept
Returns the values of the matrix.
Definition: csr.hpp:1224
gko::stop::mode
mode
The mode for the residual norm criterion.
Definition: residual_norm.hpp:37
gko::matrix::Csr::load_balance::load_balance
load_balance()
Creates a load_balance strategy.
Definition: csr.hpp:363
gko::array::get_executor
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor associated with the array.
Definition: array.hpp:703
gko::matrix::Csr::get_num_stored_elements
size_type get_num_stored_elements() const noexcept
Returns the number of elements explicitly stored in the matrix.
Definition: csr.hpp:1313
gko::matrix::Csr::create_submatrix
std::unique_ptr< Csr< ValueType, IndexType > > create_submatrix(const index_set< IndexType > &row_index_set, const index_set< IndexType > &column_index_set) const
Creates a submatrix from this Csr matrix given row and column index_set objects.
gko::ScaledIdentityAddable
Adds the operation M <- a I + b M for matrix M, identity operator I and scalars a and b,...
Definition: lin_op.hpp:777
gko::matrix::Csr::permuting_reuse_info
A struct describing a transformation of the matrix that reorders the values of the matrix into the tr...
Definition: csr.hpp:1022
gko::matrix::Csr::load_balance::copy
std::shared_ptr< strategy_type > copy() override
Copy a strategy.
Definition: csr.hpp:510
gko::next_precision
typename detail::find_precision_impl< T, step >::type next_precision
Obtains the next move type of T in the singly-linked precision corresponding bfloat16/half.
Definition: math.hpp:466
gko::matrix::Csr::classical::classical
classical()
Creates a classical strategy.
Definition: csr.hpp:239
gko::matrix::Csr::strategy_type::strategy_type
strategy_type(std::string name)
Creates a strategy_type.
Definition: csr.hpp:186
gko::matrix::Csr::sort_by_column_index
void sort_by_column_index()
Sorts all (value, col_idx) pairs in each row by column index.
gko::matrix::Csr::merge_path::process
void process(const array< index_type > &mtx_row_ptrs, array< index_type > *mtx_srow) override
Computes srow according to row pointers.
Definition: csr.hpp:291
gko::matrix::Csr::create_const
static std::unique_ptr< const Csr > create_const(std::shared_ptr< const Executor > exec, const dim< 2 > &size, gko::detail::const_array_view< ValueType > &&values, gko::detail::const_array_view< IndexType > &&col_idxs, gko::detail::const_array_view< IndexType > &&row_ptrs, std::shared_ptr< strategy_type > strategy=nullptr)
Creates a constant (immutable) Csr matrix from a set of constant arrays.
gko::matrix::Csr::scale_add
std::unique_ptr< Csr > scale_add(ptr_param< const Dense< value_type >> scale_this, ptr_param< const Dense< value_type >> scale_other, ptr_param< const Csr > mtx_other) const
Computes the sparse matrix sum scale_this * this + scale_other * mtx_add on the executor of this matr...
gko::previous_precision
typename detail::find_precision_impl< T, -step >::type previous_precision
Obtains the previous move type of T in the singly-linked precision corresponding bfloat16/half.
Definition: math.hpp:473
gko::matrix::Csr::automatical::copy
std::shared_ptr< strategy_type > copy() override
Copy a strategy.
Definition: csr.hpp:688
gko::matrix::Csr::classical
classical is a strategy_type which uses the same number of threads on each row.
Definition: csr.hpp:234
gko::matrix::Csr::get_strategy
std::shared_ptr< strategy_type > get_strategy() const noexcept
Returns the strategy.
Definition: csr.hpp:1322
gko::matrix::Csr::permuting_reuse_info::update_values
void update_values(ptr_param< const Csr > input, ptr_param< Csr > output) const
Propagates the values from an input matrix to the transformed matrix.
gko::matrix::Csr::set_strategy
void set_strategy(std::shared_ptr< strategy_type > strategy)
Set the strategy.
Definition: csr.hpp:1332
gko::EnableCloneable
This mixin is used to enable a default Cloneable::clone() implementation and similar for objects that...
Definition: polymorphic_object.hpp:369
gko::matrix::Csr::scale_add_reuse_info::update_values
void update_values(ptr_param< const Dense< value_type >> scale1, ptr_param< const Csr > mtx1, ptr_param< const Dense< value_type >> scale2, ptr_param< const Csr > mtx2, ptr_param< Csr > out) const
Recomputes the sparse matrix-matrix sum out = scale1 * mtx1 + scale2 * mtx2 when only the values of m...
gko::matrix::Ell
ELL is a matrix format where stride with explicit zeros is used such that all rows have the same numb...
Definition: csr.hpp:31
gko::matrix::Csr::create_const_value_view
std::unique_ptr< const Dense< ValueType > > create_const_value_view() const
Creates a const Dense view of the value array of this matrix as a column vector of dimensions nnz x 1...
gko::ConvertibleTo
ConvertibleTo interface is used to mark that the implementer can be converted to the object of Result...
Definition: polymorphic_object.hpp:140
gko::matrix::Csr::compute_absolute
std::unique_ptr< absolute_type > compute_absolute() const override
Gets the AbsoluteLinOp.
gko::matrix::Csr::strategy_type
strategy_type is to decide how to set the csr algorithm.
Definition: csr.hpp:177
gko::make_temporary_clone
detail::temporary_clone< detail::pointee< Ptr > > make_temporary_clone(std::shared_ptr< const Executor > exec, Ptr &&ptr)
Creates a temporary_clone.
Definition: temporary_clone.hpp:208
gko::matrix::Csr::multiply_add_reuse
std::pair< std::unique_ptr< Csr >, multiply_add_reuse_info > multiply_add_reuse(ptr_param< const Dense< value_type >> scale_mult, ptr_param< const Csr > mtx_mult, ptr_param< const Dense< value_type >> scale_add, ptr_param< const Csr > mtx_add) const
Computes the sparse matrix product scale_mult * this * mtx_mult + scale_add * mtx_add on the executor...
gko::Executor
The first step in using the Ginkgo library consists of creating an executor.
Definition: executor.hpp:616
gko::matrix::Hybrid
HYBRID is a matrix format which splits the matrix into ELLPACK and COO format.
Definition: coo.hpp:33
gko::array::get_const_data
const value_type * get_const_data() const noexcept
Returns a constant pointer to the block of memory used to store the elements of the array.
Definition: array.hpp:696
gko::matrix::Csr::write
void write(mat_data &data) const override
Writes a matrix to a matrix_data structure.
gko::matrix::permute_mode
permute_mode
Specifies how a permutation will be applied to a matrix.
Definition: permutation.hpp:42
gko::matrix::Csr::multiply_reuse_info::update_values
void update_values(ptr_param< const Csr > mtx1, ptr_param< const Csr > mtx2, ptr_param< Csr > out) const
Recomputes the sparse matrix-matrix product out = mtx1 * mtx2 when only the values of mtx1 and mtx2 c...
gko::matrix::Sellp
SELL-P is a matrix format similar to ELL format.
Definition: csr.hpp:37
gko::min
constexpr T min(const T &x, const T &y)
Returns the smaller of the arguments.
Definition: math.hpp:750
gko::matrix::Csr::cusparse::copy
std::shared_ptr< strategy_type > copy() override
Copy a strategy.
Definition: csr.hpp:322
gko::matrix::Csr::get_const_col_idxs
const index_type * get_const_col_idxs() const noexcept
Returns the column indexes of the matrix.
Definition: csr.hpp:1255
gko::ceildiv
constexpr int64 ceildiv(int64 num, int64 den)
Performs integer division with rounding up.
Definition: math.hpp:614
gko::matrix::Csr::automatical::automatical
automatical(std::shared_ptr< const DpcppExecutor > exec)
Creates an automatical strategy with Dpcpp executor.
Definition: csr.hpp:581
gko::matrix::Csr::merge_path::clac_size
int64_t clac_size(const int64_t nnz) override
Computes the srow size according to the number of nonzeros.
Definition: csr.hpp:295
gko::EnableAbsoluteComputation
The EnableAbsoluteComputation mixin provides the default implementations of compute_absolute_linop an...
Definition: lin_op.hpp:753
gko::matrix::Csr::inverse_column_permute
std::unique_ptr< LinOp > inverse_column_permute(const array< IndexType > *inverse_permutation_indices) const override
Returns a LinOp representing the row permutation of the inverse permuted object.
gko::matrix::Csr::Csr
Csr(const Csr &)
Copy-constructs a Csr matrix.
gko::matrix::Csr::automatical::automatical
automatical(std::shared_ptr< const CudaExecutor > exec)
Creates an automatical strategy with CUDA executor.
Definition: csr.hpp:561
gko::PolymorphicObject::get_executor
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition: polymorphic_object.hpp:62
gko::array::get_size
size_type get_size() const noexcept
Returns the number of elements in the array.
Definition: array.hpp:670
gko::matrix::Csr::automatical::clac_size
int64_t clac_size(const int64_t nnz) override
Computes the srow size according to the number of nonzeros.
Definition: csr.hpp:676
gko::matrix::Csr::automatical::automatical
automatical(int64_t nwarps, int warp_size=32, bool cuda_strategy=true, std::string strategy_name="none")
Creates an automatical strategy with specified parameters.
Definition: csr.hpp:596
gko::matrix::Csr::classical::process
void process(const array< index_type > &mtx_row_ptrs, array< index_type > *mtx_srow) override
Computes srow according to row pointers.
Definition: csr.hpp:241
gko::remove_complex
typename detail::remove_complex_s< T >::type remove_complex
Obtain the type which removed the complex of complex/scalar type or the template parameter of class b...
Definition: math.hpp:264
gko::matrix::Csr::compute_absolute_inplace
void compute_absolute_inplace() override
Compute absolute inplace on each element.
gko::matrix::Csr::scale_permute
std::unique_ptr< Csr > scale_permute(ptr_param< const ScaledPermutation< value_type, index_type >> permutation, permute_mode=permute_mode::symmetric) const
Creates a scaled and permuted copy of this matrix.
gko::device_matrix_data
This type is a device-side equivalent to matrix_data.
Definition: device_matrix_data.hpp:36
gko::matrix::Csr::read
void read(const mat_data &data) override
Reads a matrix from a matrix_data structure.
gko::matrix::Csr::create
static std::unique_ptr< Csr > create(std::shared_ptr< const Executor > exec, std::shared_ptr< strategy_type > strategy)
Creates an uninitialized CSR matrix of the specified size.
gko::matrix::Csr::create_value_view
std::unique_ptr< Dense< ValueType > > create_value_view()
Creates a Dense view of the value array of this matrix as a column vector of dimensions nnz x 1.
gko::matrix::Csr::sparselib::copy
std::shared_ptr< strategy_type > copy() override
Copy a strategy.
Definition: csr.hpp:346
gko::matrix::Csr::get_values
value_type * get_values() noexcept
Returns the values of the matrix.
Definition: csr.hpp:1215
gko::matrix::Csr::multiply_reuse_info
Class describing the internal lookup structures created by multiply_reuse(const Csr*) to recompute a ...
Definition: csr.hpp:778
gko::matrix::Csr::get_num_srow_elements
size_type get_num_srow_elements() const noexcept
Returns the number of the srow stored elements (involved warps)
Definition: csr.hpp:1303
gko::matrix::Csr::scale_add_reuse_info
Class describing the internal lookup structures created by scale_add_reuse to recompute a sparse matr...
Definition: csr.hpp:938
gko::LinOp::LinOp
LinOp(const LinOp &)=default
Copy-constructs a LinOp.
gko::to_complex
typename detail::to_complex_s< T >::type to_complex
Obtain the type which adds the complex of complex/scalar type or the template parameter of class by a...
Definition: math.hpp:283
gko::matrix::Coo
COO stores a matrix in the coordinate matrix format.
Definition: coo.hpp:51