ViennaCL - The Vienna Computing Library  1.7.1
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
hyb_matrix.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_HYB_MATRIX_HPP_
2 #define VIENNACL_HYB_MATRIX_HPP_
3 
4 /* =========================================================================
5  Copyright (c) 2010-2016, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8  Portions of this software are copyright by UChicago Argonne, LLC.
9 
10  -----------------
11  ViennaCL - The Vienna Computing Library
12  -----------------
13 
14  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15 
16  (A list of authors and contributors can be found in the manual)
17 
18  License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20 
27 #include "viennacl/forwards.h"
28 #include "viennacl/vector.hpp"
29 
30 #include "viennacl/tools/tools.hpp"
31 
33 
34 namespace viennacl
35 {
37 template<typename NumericT, unsigned int AlignmentV /* see forwards.h for default argument */>
38 class hyb_matrix
39 {
40 public:
43 
44  hyb_matrix() : csr_threshold_(NumericT(0.8)), rows_(0), cols_(0) {}
45 
46  hyb_matrix(viennacl::context ctx) : csr_threshold_(NumericT(0.8)), rows_(0), cols_(0)
47  {
48  ell_coords_.switch_active_handle_id(ctx.memory_type());
49  ell_elements_.switch_active_handle_id(ctx.memory_type());
50 
51  csr_rows_.switch_active_handle_id(ctx.memory_type());
52  csr_cols_.switch_active_handle_id(ctx.memory_type());
53  csr_elements_.switch_active_handle_id(ctx.memory_type());
54 
55 #ifdef VIENNACL_WITH_OPENCL
56  if (ctx.memory_type() == OPENCL_MEMORY)
57  {
58  ell_coords_.opencl_handle().context(ctx.opencl_context());
59  ell_elements_.opencl_handle().context(ctx.opencl_context());
60 
61  csr_rows_.opencl_handle().context(ctx.opencl_context());
62  csr_cols_.opencl_handle().context(ctx.opencl_context());
63  csr_elements_.opencl_handle().context(ctx.opencl_context());
64  }
65 #endif
66  }
67 
69  void clear()
70  {
71  // ELL part:
72  ellnnz_ = 0;
73 
75  std::vector<NumericT> host_elements(internal_size1());
76 
77  viennacl::backend::memory_create(ell_coords_, host_coords_buffer.element_size() * internal_size1(), viennacl::traits::context(ell_coords_), host_coords_buffer.get());
78  viennacl::backend::memory_create(ell_elements_, sizeof(NumericT) * internal_size1(), viennacl::traits::context(ell_elements_), &(host_elements[0]));
79 
80  // CSR part:
81  csrnnz_ = 0;
82 
83  viennacl::backend::typesafe_host_array<unsigned int> host_row_buffer(csr_rows_, rows_ + 1);
84  viennacl::backend::typesafe_host_array<unsigned int> host_col_buffer(csr_cols_, 1);
85  host_elements.resize(1);
86 
87  viennacl::backend::memory_create(csr_rows_, host_row_buffer.element_size() * (rows_ + 1), viennacl::traits::context(csr_rows_), host_row_buffer.get());
88  viennacl::backend::memory_create(csr_cols_, host_col_buffer.element_size() * 1, viennacl::traits::context(csr_cols_), host_col_buffer.get());
89  viennacl::backend::memory_create(csr_elements_, sizeof(NumericT) * 1, viennacl::traits::context(csr_elements_), &(host_elements[0]));
90  }
91 
92  NumericT csr_threshold() const { return csr_threshold_; }
93  void csr_threshold(NumericT thr) { csr_threshold_ = thr; }
94 
95  vcl_size_t internal_size1() const { return viennacl::tools::align_to_multiple<vcl_size_t>(rows_, AlignmentV); }
96  vcl_size_t internal_size2() const { return viennacl::tools::align_to_multiple<vcl_size_t>(cols_, AlignmentV); }
97 
98  vcl_size_t size1() const { return rows_; }
99  vcl_size_t size2() const { return cols_; }
100 
101  vcl_size_t internal_ellnnz() const {return viennacl::tools::align_to_multiple<vcl_size_t>(ellnnz_, AlignmentV); }
102  vcl_size_t ell_nnz() const { return ellnnz_; }
103  vcl_size_t csr_nnz() const { return csrnnz_; }
104 
105  const handle_type & handle() const { return ell_elements_; }
106  const handle_type & handle2() const { return ell_coords_; }
107  const handle_type & handle3() const { return csr_rows_; }
108  const handle_type & handle4() const { return csr_cols_; }
109  const handle_type & handle5() const { return csr_elements_; }
110 
111 public:
112 #if defined(_MSC_VER) && _MSC_VER < 1500 //Visual Studio 2005 needs special treatment
113  template<typename CPUMatrixT>
114  friend void copy(const CPUMatrixT & cpu_matrix, hyb_matrix & gpu_matrix );
115 #else
116  template<typename CPUMatrixT, typename T, unsigned int ALIGN>
117  friend void copy(const CPUMatrixT & cpu_matrix, hyb_matrix<T, ALIGN> & gpu_matrix );
118 #endif
119 
120 private:
121  NumericT csr_threshold_;
122  vcl_size_t rows_;
123  vcl_size_t cols_;
124  vcl_size_t ellnnz_;
125  vcl_size_t csrnnz_;
126 
127  handle_type ell_coords_; // ell coords
128  handle_type ell_elements_; // ell elements
129 
130  handle_type csr_rows_;
131  handle_type csr_cols_;
132  handle_type csr_elements_;
133 };
134 
135 template<typename CPUMatrixT, typename NumericT, unsigned int AlignmentV>
136 void copy(const CPUMatrixT& cpu_matrix, hyb_matrix<NumericT, AlignmentV>& gpu_matrix )
137 {
138  assert( (gpu_matrix.size1() == 0 || viennacl::traits::size1(cpu_matrix) == gpu_matrix.size1()) && bool("Size mismatch") );
139  assert( (gpu_matrix.size2() == 0 || viennacl::traits::size2(cpu_matrix) == gpu_matrix.size2()) && bool("Size mismatch") );
140 
141  if (cpu_matrix.size1() > 0 && cpu_matrix.size2() > 0)
142  {
143  //determine max capacity for row
144  vcl_size_t max_entries_per_row = 0;
145  std::vector<vcl_size_t> hist_entries(cpu_matrix.size2() + 1, 0);
146 
147  for (typename CPUMatrixT::const_iterator1 row_it = cpu_matrix.begin1(); row_it != cpu_matrix.end1(); ++row_it)
148  {
149  vcl_size_t num_entries = 0;
150  for (typename CPUMatrixT::const_iterator2 col_it = row_it.begin(); col_it != row_it.end(); ++col_it)
151  {
152  ++num_entries;
153  }
154 
155  hist_entries[num_entries] += 1;
156  max_entries_per_row = std::max(max_entries_per_row, num_entries);
157  }
158 
159  vcl_size_t sum = 0;
160  for (vcl_size_t ind = 0; ind <= max_entries_per_row; ind++)
161  {
162  sum += hist_entries[ind];
163 
164  if (NumericT(sum) >= NumericT(gpu_matrix.csr_threshold()) * NumericT(cpu_matrix.size1()))
165  {
166  max_entries_per_row = ind;
167  break;
168  }
169  }
170 
171  //setup GPU matrix
172  gpu_matrix.ellnnz_ = max_entries_per_row;
173  gpu_matrix.rows_ = cpu_matrix.size1();
174  gpu_matrix.cols_ = cpu_matrix.size2();
175 
176  vcl_size_t nnz = gpu_matrix.internal_size1() * gpu_matrix.internal_ellnnz();
177 
178  viennacl::backend::typesafe_host_array<unsigned int> ell_coords(gpu_matrix.ell_coords_, nnz);
179  viennacl::backend::typesafe_host_array<unsigned int> csr_rows(gpu_matrix.csr_rows_, cpu_matrix.size1() + 1);
180  std::vector<unsigned int> csr_cols;
181 
182  std::vector<NumericT> ell_elements(nnz);
183  std::vector<NumericT> csr_elements;
184 
185  vcl_size_t csr_index = 0;
186 
187  for (typename CPUMatrixT::const_iterator1 row_it = cpu_matrix.begin1(); row_it != cpu_matrix.end1(); ++row_it)
188  {
189  vcl_size_t data_index = 0;
190 
191  csr_rows.set(row_it.index1(), csr_index);
192 
193  for (typename CPUMatrixT::const_iterator2 col_it = row_it.begin(); col_it != row_it.end(); ++col_it)
194  {
195  if (data_index < max_entries_per_row)
196  {
197  ell_coords.set(gpu_matrix.internal_size1() * data_index + col_it.index1(), col_it.index2());
198  ell_elements[gpu_matrix.internal_size1() * data_index + col_it.index1()] = *col_it;
199  }
200  else
201  {
202  csr_cols.push_back(static_cast<unsigned int>(col_it.index2()));
203  csr_elements.push_back(*col_it);
204 
205  csr_index++;
206  }
207 
208  data_index++;
209  }
210 
211  }
212 
213  if (csr_cols.empty())
214  {
215  csr_cols.push_back(0);
216  csr_elements.push_back(0);
217  }
218 
219  csr_rows.set(csr_rows.size() - 1, csr_index);
220 
221  gpu_matrix.csrnnz_ = csr_cols.size();
222 
223  viennacl::backend::typesafe_host_array<unsigned int> csr_cols_for_gpu(gpu_matrix.csr_cols_, csr_cols.size());
224  for (vcl_size_t i=0; i<csr_cols.size(); ++i)
225  csr_cols_for_gpu.set(i, csr_cols[i]);
226 
227  viennacl::backend::memory_create(gpu_matrix.ell_coords_, ell_coords.raw_size(), traits::context(gpu_matrix.ell_coords_), ell_coords.get());
228  viennacl::backend::memory_create(gpu_matrix.ell_elements_, sizeof(NumericT) * ell_elements.size(), traits::context(gpu_matrix.ell_elements_), &(ell_elements[0]));
229 
230  viennacl::backend::memory_create(gpu_matrix.csr_rows_, csr_rows.raw_size(), traits::context(gpu_matrix.csr_rows_), csr_rows.get());
231  viennacl::backend::memory_create(gpu_matrix.csr_cols_, csr_cols_for_gpu.raw_size(), traits::context(gpu_matrix.csr_cols_), csr_cols_for_gpu.get());
232  viennacl::backend::memory_create(gpu_matrix.csr_elements_, sizeof(NumericT) * csr_elements.size(), traits::context(gpu_matrix.csr_elements_), &(csr_elements[0]));
233  }
234 }
235 
236 
242 template<typename IndexT, typename NumericT, unsigned int AlignmentV>
243 void copy(std::vector< std::map<IndexT, NumericT> > const & cpu_matrix,
245 {
246  vcl_size_t max_col = 0;
247  for (vcl_size_t i=0; i<cpu_matrix.size(); ++i)
248  {
249  if (cpu_matrix[i].size() > 0)
250  max_col = std::max<vcl_size_t>(max_col, (cpu_matrix[i].rbegin())->first);
251  }
252 
253  viennacl::copy(tools::const_sparse_matrix_adapter<NumericT, IndexT>(cpu_matrix, cpu_matrix.size(), max_col + 1), gpu_matrix);
254 }
255 
256 
257 
258 
259 template<typename CPUMatrixT, typename NumericT, unsigned int AlignmentV>
260 void copy(const hyb_matrix<NumericT, AlignmentV>& gpu_matrix, CPUMatrixT& cpu_matrix)
261 {
262  assert( (viennacl::traits::size1(cpu_matrix) == gpu_matrix.size1()) && bool("Size mismatch") );
263  assert( (viennacl::traits::size2(cpu_matrix) == gpu_matrix.size2()) && bool("Size mismatch") );
264 
265  if (gpu_matrix.size1() > 0 && gpu_matrix.size2() > 0)
266  {
267  std::vector<NumericT> ell_elements(gpu_matrix.internal_size1() * gpu_matrix.internal_ellnnz());
268  viennacl::backend::typesafe_host_array<unsigned int> ell_coords(gpu_matrix.handle2(), gpu_matrix.internal_size1() * gpu_matrix.internal_ellnnz());
269 
270  std::vector<NumericT> csr_elements(gpu_matrix.csr_nnz());
271  viennacl::backend::typesafe_host_array<unsigned int> csr_rows(gpu_matrix.handle3(), gpu_matrix.size1() + 1);
272  viennacl::backend::typesafe_host_array<unsigned int> csr_cols(gpu_matrix.handle4(), gpu_matrix.csr_nnz());
273 
274  viennacl::backend::memory_read(gpu_matrix.handle(), 0, sizeof(NumericT) * ell_elements.size(), &(ell_elements[0]));
275  viennacl::backend::memory_read(gpu_matrix.handle2(), 0, ell_coords.raw_size(), ell_coords.get());
276  viennacl::backend::memory_read(gpu_matrix.handle3(), 0, csr_rows.raw_size(), csr_rows.get());
277  viennacl::backend::memory_read(gpu_matrix.handle4(), 0, csr_cols.raw_size(), csr_cols.get());
278  viennacl::backend::memory_read(gpu_matrix.handle5(), 0, sizeof(NumericT) * csr_elements.size(), &(csr_elements[0]));
279 
280 
281  for (vcl_size_t row = 0; row < gpu_matrix.size1(); row++)
282  {
283  for (vcl_size_t ind = 0; ind < gpu_matrix.internal_ellnnz(); ind++)
284  {
285  vcl_size_t offset = gpu_matrix.internal_size1() * ind + row;
286 
287  NumericT val = ell_elements[offset];
288  if (val <= 0 && val >= 0) // val == 0 without compiler warnings
289  continue;
290 
291  if (ell_coords[offset] >= gpu_matrix.size2())
292  {
293  std::cerr << "ViennaCL encountered invalid data " << offset << " " << ind << " " << row << " " << ell_coords[offset] << " " << gpu_matrix.size2() << std::endl;
294  return;
295  }
296 
297  cpu_matrix(row, ell_coords[offset]) = val;
298  }
299 
300  for (vcl_size_t ind = csr_rows[row]; ind < csr_rows[row+1]; ind++)
301  {
302  NumericT val = csr_elements[ind];
303  if (val <= 0 && val >= 0) // val == 0 without compiler warnings
304  continue;
305 
306  if (csr_cols[ind] >= gpu_matrix.size2())
307  {
308  std::cerr << "ViennaCL encountered invalid data " << std::endl;
309  return;
310  }
311 
312  cpu_matrix(row, csr_cols[ind]) = val;
313  }
314  }
315  }
316 }
317 
323 template<typename NumericT, unsigned int AlignmentV, typename IndexT>
324 void copy(const hyb_matrix<NumericT, AlignmentV> & gpu_matrix,
325  std::vector< std::map<IndexT, NumericT> > & cpu_matrix)
326 {
327  if (cpu_matrix.size() == 0)
328  cpu_matrix.resize(gpu_matrix.size1());
329 
330  assert(cpu_matrix.size() == gpu_matrix.size1() && bool("Matrix dimension mismatch!"));
331 
332  tools::sparse_matrix_adapter<NumericT, IndexT> temp(cpu_matrix, cpu_matrix.size(), gpu_matrix.size2());
333  viennacl::copy(gpu_matrix, temp);
334 }
335 
336 //
337 // Specify available operations:
338 //
339 
342 namespace linalg
343 {
344 namespace detail
345 {
346  // x = A * y
347  template<typename T, unsigned int A>
348  struct op_executor<vector_base<T>, op_assign, vector_expression<const hyb_matrix<T, A>, const vector_base<T>, op_prod> >
349  {
350  static void apply(vector_base<T> & lhs, vector_expression<const hyb_matrix<T, A>, const vector_base<T>, op_prod> const & rhs)
351  {
352  // check for the special case x = A * x
353  if (viennacl::traits::handle(lhs) == viennacl::traits::handle(rhs.rhs()))
354  {
355  viennacl::vector<T> temp(lhs);
356  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(1), temp, T(0));
357  lhs = temp;
358  }
359  else
360  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(1), lhs, T(0));
361  }
362  };
363 
364  template<typename T, unsigned int A>
365  struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const hyb_matrix<T, A>, const vector_base<T>, op_prod> >
366  {
367  static void apply(vector_base<T> & lhs, vector_expression<const hyb_matrix<T, A>, const vector_base<T>, op_prod> const & rhs)
368  {
369  // check for the special case x += A * x
370  if (viennacl::traits::handle(lhs) == viennacl::traits::handle(rhs.rhs()))
371  {
372  viennacl::vector<T> temp(lhs);
373  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(1), temp, T(0));
374  lhs += temp;
375  }
376  else
377  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(1), lhs, T(1));
378  }
379  };
380 
381  template<typename T, unsigned int A>
382  struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const hyb_matrix<T, A>, const vector_base<T>, op_prod> >
383  {
384  static void apply(vector_base<T> & lhs, vector_expression<const hyb_matrix<T, A>, const vector_base<T>, op_prod> const & rhs)
385  {
386  // check for the special case x -= A * x
387  if (viennacl::traits::handle(lhs) == viennacl::traits::handle(rhs.rhs()))
388  {
389  viennacl::vector<T> temp(lhs);
390  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(1), temp, T(0));
391  lhs -= temp;
392  }
393  else
394  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(-1), lhs, T(1));
395  }
396  };
397 
398 
399  // x = A * vec_op
400  template<typename T, unsigned int A, typename LHS, typename RHS, typename OP>
401  struct op_executor<vector_base<T>, op_assign, vector_expression<const hyb_matrix<T, A>, const vector_expression<const LHS, const RHS, OP>, op_prod> >
402  {
403  static void apply(vector_base<T> & lhs, vector_expression<const hyb_matrix<T, A>, const vector_expression<const LHS, const RHS, OP>, op_prod> const & rhs)
404  {
405  viennacl::vector<T> temp(rhs.rhs(), viennacl::traits::context(rhs));
406  viennacl::linalg::prod_impl(rhs.lhs(), temp, lhs);
407  }
408  };
409 
410  // x = A * vec_op
411  template<typename T, unsigned int A, typename LHS, typename RHS, typename OP>
412  struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const hyb_matrix<T, A>, const vector_expression<const LHS, const RHS, OP>, op_prod> >
413  {
414  static void apply(vector_base<T> & lhs, vector_expression<const hyb_matrix<T, A>, const vector_expression<const LHS, const RHS, OP>, op_prod> const & rhs)
415  {
416  viennacl::vector<T> temp(rhs.rhs(), viennacl::traits::context(rhs));
417  viennacl::vector<T> temp_result(lhs);
418  viennacl::linalg::prod_impl(rhs.lhs(), temp, temp_result);
419  lhs += temp_result;
420  }
421  };
422 
423  // x = A * vec_op
424  template<typename T, unsigned int A, typename LHS, typename RHS, typename OP>
425  struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const hyb_matrix<T, A>, const vector_expression<const LHS, const RHS, OP>, op_prod> >
426  {
427  static void apply(vector_base<T> & lhs, vector_expression<const hyb_matrix<T, A>, const vector_expression<const LHS, const RHS, OP>, op_prod> const & rhs)
428  {
429  viennacl::vector<T> temp(rhs.rhs(), viennacl::traits::context(rhs));
430  viennacl::vector<T> temp_result(lhs);
431  viennacl::linalg::prod_impl(rhs.lhs(), temp, temp_result);
432  lhs -= temp_result;
433  }
434  };
435 
436 } // namespace detail
437 } // namespace linalg
438 
440 }
441 
442 #endif
vcl_size_t internal_ellnnz() const
Definition: hyb_matrix.hpp:101
Sparse matrix class using a hybrid format composed of the ELL and CSR format for storing the nonzeros...
Definition: forwards.h:406
Helper class implementing an array on the host. Default case: No conversion necessary.
Definition: util.hpp:92
vcl_size_t element_size() const
Definition: util.hpp:112
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Definition: forwards.h:227
viennacl::scalar_expression< const viennacl::vector_base< NumericT >, const viennacl::vector_base< NumericT >, viennacl::op_sum > sum(viennacl::vector_base< NumericT > const &x)
User interface function for computing the sum of all elements of a vector.
Definition: sum.hpp:45
const handle_type & handle3() const
Definition: hyb_matrix.hpp:107
Various little tools used here and there in ViennaCL.
const handle_type & handle() const
Definition: hyb_matrix.hpp:105
void clear()
Resets all entries in the matrix back to zero without changing the matrix size. Resets the sparsity p...
Definition: hyb_matrix.hpp:69
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
Definition: size.hpp:163
vcl_size_t internal_size1() const
Definition: hyb_matrix.hpp:95
This file provides the forward declarations for the main types used within ViennaCL.
void memory_read(mem_handle const &src_buffer, vcl_size_t src_offset, vcl_size_t bytes_to_read, void *ptr, bool async=false)
Reads data from a buffer back to main RAM.
Definition: memory.hpp:261
const handle_type & handle4() const
Definition: hyb_matrix.hpp:108
T max(const T &lhs, const T &rhs)
Maximum.
Definition: util.hpp:59
result_of::size_type< MatrixType >::type size2(MatrixType const &mat)
Generic routine for obtaining the number of columns of a matrix (ViennaCL, uBLAS, etc...
Definition: size.hpp:201
NumericT csr_threshold() const
Definition: hyb_matrix.hpp:92
float NumericT
Definition: bisect.cpp:40
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
Definition: context.hpp:39
vcl_size_t csr_nnz() const
Definition: hyb_matrix.hpp:103
const handle_type & handle2() const
Definition: hyb_matrix.hpp:106
viennacl::backend::mem_handle handle_type
Definition: hyb_matrix.hpp:41
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:239
vcl_size_t internal_size2() const
Definition: hyb_matrix.hpp:96
scalar< typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT< NumericT >::ResultType > value_type
Definition: hyb_matrix.hpp:42
Implementations of operations using sparse matrices.
vcl_size_t size2() const
Definition: hyb_matrix.hpp:99
Adapts a constant sparse matrix type made up from std::vector > to basic ub...
Definition: adapter.hpp:183
std::size_t vcl_size_t
Definition: forwards.h:75
vector_expression< const matrix_base< NumericT, F >, const unsigned int, op_row > row(const matrix_base< NumericT, F > &A, unsigned int i)
Definition: matrix.hpp:910
viennacl::memory_types memory_type() const
Definition: context.hpp:76
void switch_active_handle_id(memory_types new_id)
Switches the currently active handle. If no support for that backend is provided, an exception is thr...
Definition: mem_handle.hpp:121
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
Definition: context.hpp:40
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
void set(vcl_size_t index, U value)
Definition: util.hpp:115
vcl_size_t ell_nnz() const
Definition: hyb_matrix.hpp:102
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:89
hyb_matrix(viennacl::context ctx)
Definition: hyb_matrix.hpp:46
Adapts a non-const sparse matrix type made up from std::vector > to basic u...
Definition: adapter.hpp:357
void memory_create(mem_handle &handle, vcl_size_t size_in_bytes, viennacl::context const &ctx, const void *host_ptr=NULL)
Creates an array of the specified size. If the second argument is provided, the buffer is initialized...
Definition: memory.hpp:87
const handle_type & handle5() const
Definition: hyb_matrix.hpp:109
void prod_impl(const matrix_base< NumericT > &mat, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
vcl_size_t size1() const
Definition: hyb_matrix.hpp:98
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
friend void copy(const CPUMatrixT &cpu_matrix, hyb_matrix< T, ALIGN > &gpu_matrix)
vcl_size_t raw_size() const
Definition: util.hpp:111
void csr_threshold(NumericT thr)
Definition: hyb_matrix.hpp:93