MUDA
Loading...
Searching...
No Matches
device_bcoo_vector.h
1#pragma once
3#include <muda/ext/linear_system/bcoo_vector_view.h>
4#include <muda/ext/linear_system/device_doublet_vector.h>
5
6namespace muda
7{
8template <typename T, int N>
10{
11 friend class details::MatrixFormatConverter<T, N>;
12
13 public:
14 using SegmentVector = Eigen::Matrix<T, N, 1>;
15
16 DeviceBCOOVector() = default;
17 ~DeviceBCOOVector() = default;
18 DeviceBCOOVector(const DeviceBCOOVector&) = default;
20 DeviceBCOOVector& operator=(const DeviceBCOOVector&) = default;
21 DeviceBCOOVector& operator=(DeviceBCOOVector&&) = default;
22
23 auto non_zero_segments() const { return this->m_segment_values.size(); }
24};
25
26template <typename T>
27class DeviceBCOOVector<T, 1> : public DeviceDoubletVector<T, 1>
28{
29 template <typename U, int N>
31
32 protected:
33 mutable cusparseSpVecDescr_t m_descr = nullptr;
34
35 public:
36 DeviceBCOOVector() = default;
37 ~DeviceBCOOVector() { destroy_descr(); }
38
41 , m_descr(nullptr)
42 {
43 }
44
46 : DeviceDoubletVector<T, 1>(std::move(other))
47 , m_descr(other.m_descr)
48 {
49 other.m_descr = nullptr;
50 }
51
52 DeviceBCOOVector& operator=(const DeviceBCOOVector& other)
53 {
55 destroy_descr();
56 return *this;
57 }
58
59 DeviceBCOOVector& operator=(DeviceBCOOVector&& other)
60 {
62 destroy_descr();
63 m_descr = other.m_descr;
64 other.m_descr = nullptr;
65 return *this;
66 }
67
68 auto non_zeros() const { this->m_values.size(); }
69 auto descr() const
70 {
71 if(!m_descr)
72 {
73 checkCudaErrors(cusparseCreateSpVec(
74 &m_descr,
75 this->m_size,
76 this->m_values.size(),
77 (int*)this->m_indices.data(),
78 (T*)this->m_values.data(),
79 cusparse_index_type<decltype(this->m_indices)::value_type>(),
80 CUSPARSE_INDEX_BASE_ZERO,
81 cuda_data_type<T>()));
82 }
83 return m_descr;
84 }
85
86 auto view() {
87 }
88
89 private:
90 void destroy_descr() const
91 {
92 if(m_descr)
93 {
94 checkCudaErrors(cusparseDestroySpVec(m_descr));
95 m_descr = nullptr;
96 }
97 }
98};
99
100template <typename T>
102} // namespace muda
103
104
105#include "details/device_bcoo_vector.inl"
Definition device_bcoo_vector.h:28
Definition device_bcoo_vector.h:10
Definition device_doublet_vector.h:16
Definition matrix_format_converter_impl.h:53
A light-weight wrapper of cuda device memory. Like std::vector, allow user to resize,...