36 template <
typename U,
int M>
40 mutable cusparseMatDescr_t m_legacy_descr =
nullptr;
41 mutable cusparseSpMatDescr_t m_descr =
nullptr;
49 , m_legacy_descr{
nullptr}
56 , m_legacy_descr{other.m_legacy_descr}
57 , m_descr{other.m_descr}
59 other.m_legacy_descr =
nullptr;
60 other.m_descr =
nullptr;
69 m_legacy_descr =
nullptr;
80 m_legacy_descr = other.m_legacy_descr;
81 m_descr = other.m_descr;
82 other.m_legacy_descr =
nullptr;
83 other.m_descr =
nullptr;
92 (int)this->m_values.size(),
93 this->m_row_indices.data(),
94 this->m_col_indices.data(),
95 this->m_values.data(),
105 (int)this->m_values.size(),
106 this->m_row_indices.data(),
107 this->m_col_indices.data(),
108 this->m_values.data(),
114 auto cview()
const {
return view(); }
116 auto viewer() {
return view().viewer(); }
118 auto cviewer()
const {
return view().cviewer(); }
120 auto non_zeros()
const {
return this->m_values.size(); }
122 auto legacy_descr()
const
124 if(m_legacy_descr ==
nullptr)
126 checkCudaErrors(cusparseCreateMatDescr(&m_legacy_descr));
127 checkCudaErrors(cusparseSetMatType(m_legacy_descr, CUSPARSE_MATRIX_TYPE_GENERAL));
128 checkCudaErrors(cusparseSetMatIndexBase(m_legacy_descr, CUSPARSE_INDEX_BASE_ZERO));
130 return m_legacy_descr;
135 if(m_descr ==
nullptr)
137 checkCudaErrors(cusparseCreateCoo(&m_descr,
141 (
void*)this->m_row_indices.data(),
142 (
void*)this->m_col_indices.data(),
143 (
void*)this->m_values.data(),
145 CUSPARSE_INDEX_BASE_ZERO,
146 cuda_data_type<Ty>()));
164 void destroy_all_descr()
166 if(m_legacy_descr !=
nullptr)
168 checkCudaErrors(cusparseDestroyMatDescr(m_legacy_descr));
169 m_legacy_descr =
nullptr;
171 if(m_descr !=
nullptr)
173 checkCudaErrors(cusparseDestroySpMat(m_descr));