ViennaCL - The Vienna Computing Library  1.6.0
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
compressed_compressed_matrix.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_COMPRESSED_compressed_compressed_matrix_HPP_
2 #define VIENNACL_COMPRESSED_compressed_compressed_matrix_HPP_
3 
4 /* =========================================================================
5  Copyright (c) 2010-2014, 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 PDF manual)
17 
18  License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20 
25 #include <vector>
26 #include <list>
27 #include <map>
28 #include "viennacl/forwards.h"
29 #include "viennacl/vector.hpp"
30 
32 
33 #include "viennacl/tools/tools.hpp"
35 
36 namespace viennacl
37 {
38 namespace detail
39 {
40  template<typename CPUMatrixT, typename NumericT>
41  void copy_impl(const CPUMatrixT & cpu_matrix,
43  vcl_size_t nonzero_rows,
44  vcl_size_t nonzeros)
45  {
46  assert( (gpu_matrix.size1() == 0 || viennacl::traits::size1(cpu_matrix) == gpu_matrix.size1()) && bool("Size mismatch") );
47  assert( (gpu_matrix.size2() == 0 || viennacl::traits::size2(cpu_matrix) == gpu_matrix.size2()) && bool("Size mismatch") );
48 
49  viennacl::backend::typesafe_host_array<unsigned int> row_buffer(gpu_matrix.handle1(), nonzero_rows + 1);
50  viennacl::backend::typesafe_host_array<unsigned int> row_indices(gpu_matrix.handle3(), nonzero_rows);
51  viennacl::backend::typesafe_host_array<unsigned int> col_buffer(gpu_matrix.handle2(), nonzeros);
52  std::vector<NumericT> elements(nonzeros);
53 
54  vcl_size_t row_index = 0;
55  vcl_size_t data_index = 0;
56 
57  for (typename CPUMatrixT::const_iterator1 row_it = cpu_matrix.begin1();
58  row_it != cpu_matrix.end1();
59  ++row_it)
60  {
61  bool row_empty = true;
62 
63  for (typename CPUMatrixT::const_iterator2 col_it = row_it.begin();
64  col_it != row_it.end();
65  ++col_it)
66  {
67  NumericT entry = *col_it;
68  if (bool(entry))
69  {
70  if (row_empty)
71  {
72  assert(row_index < nonzero_rows && bool("Provided count of nonzero rows exceeded!"));
73 
74  row_empty = false;
75  row_buffer.set(row_index, data_index);
76  row_indices.set(row_index, col_it.index1());
77  ++row_index;
78  }
79 
80  col_buffer.set(data_index, col_it.index2());
81  elements[data_index] = entry;
82  ++data_index;
83  }
84  }
85  }
86  row_buffer.set(row_index, data_index);
87 
88  gpu_matrix.set(row_buffer.get(),
89  row_indices.get(),
90  col_buffer.get(),
91  &elements[0],
92  cpu_matrix.size1(),
93  cpu_matrix.size2(),
94  nonzero_rows,
95  nonzeros);
96  }
97 }
98 
99 //provide copy-operation:
114 template<typename CPUMatrixT, typename NumericT>
115 void copy(const CPUMatrixT & cpu_matrix,
117 {
118  //std::cout << "copy for (" << cpu_matrix.size1() << ", " << cpu_matrix.size2() << ", " << cpu_matrix.nnz() << ")" << std::endl;
119 
120  if ( cpu_matrix.size1() > 0 && cpu_matrix.size2() > 0 )
121  {
122  //determine nonzero rows and total nonzeros:
123  vcl_size_t num_entries = 0;
124  vcl_size_t nonzero_rows = 0;
125  for (typename CPUMatrixT::const_iterator1 row_it = cpu_matrix.begin1();
126  row_it != cpu_matrix.end1();
127  ++row_it)
128  {
129  bool row_empty = true;
130  for (typename CPUMatrixT::const_iterator2 col_it = row_it.begin();
131  col_it != row_it.end();
132  ++col_it)
133  {
134  if (bool(*col_it))
135  {
136  ++num_entries;
137 
138  if (row_empty)
139  {
140  row_empty = false;
141  ++nonzero_rows;
142  }
143  }
144  }
145  }
146 
147  if (num_entries == 0) //we copy an empty matrix
148  num_entries = 1;
149 
150  //set up matrix entries:
151  viennacl::detail::copy_impl(cpu_matrix, gpu_matrix, nonzero_rows, num_entries);
152  }
153 }
154 
155 
156 //adapted for std::vector< std::map < > > argument:
162 template<typename SizeT, typename NumericT>
163 void copy(const std::vector< std::map<SizeT, NumericT> > & cpu_matrix,
165 {
166  vcl_size_t nonzero_rows = 0;
167  vcl_size_t nonzeros = 0;
168  vcl_size_t max_col = 0;
169  for (vcl_size_t i=0; i<cpu_matrix.size(); ++i)
170  {
171  if (cpu_matrix[i].size() > 0)
172  ++nonzero_rows;
173  nonzeros += cpu_matrix[i].size();
174  if (cpu_matrix[i].size() > 0)
175  max_col = std::max<vcl_size_t>(max_col, (cpu_matrix[i].rbegin())->first);
176  }
177 
178  viennacl::detail::copy_impl(tools::const_sparse_matrix_adapter<NumericT, SizeT>(cpu_matrix, cpu_matrix.size(), max_col + 1),
179  gpu_matrix,
180  nonzero_rows,
181  nonzeros);
182 }
183 
184 
185 //
186 // gpu to cpu:
187 //
197 template<typename CPUMatrixT, typename NumericT>
199  CPUMatrixT & cpu_matrix )
200 {
201  assert( (cpu_matrix.size1() == gpu_matrix.size1()) && bool("Size mismatch") );
202  assert( (cpu_matrix.size2() == gpu_matrix.size2()) && bool("Size mismatch") );
203 
204  if ( gpu_matrix.size1() > 0 && gpu_matrix.size2() > 0 )
205  {
206  //get raw data from memory:
207  viennacl::backend::typesafe_host_array<unsigned int> row_buffer(gpu_matrix.handle1(), gpu_matrix.nnz1() + 1);
208  viennacl::backend::typesafe_host_array<unsigned int> row_indices(gpu_matrix.handle1(), gpu_matrix.nnz1());
209  viennacl::backend::typesafe_host_array<unsigned int> col_buffer(gpu_matrix.handle2(), gpu_matrix.nnz());
210  std::vector<NumericT> elements(gpu_matrix.nnz());
211 
212  //std::cout << "GPU->CPU, nonzeros: " << gpu_matrix.nnz() << std::endl;
213 
214  viennacl::backend::memory_read(gpu_matrix.handle1(), 0, row_buffer.raw_size(), row_buffer.get());
215  viennacl::backend::memory_read(gpu_matrix.handle3(), 0, row_indices.raw_size(), row_indices.get());
216  viennacl::backend::memory_read(gpu_matrix.handle2(), 0, col_buffer.raw_size(), col_buffer.get());
217  viennacl::backend::memory_read(gpu_matrix.handle(), 0, sizeof(NumericT)* gpu_matrix.nnz(), &(elements[0]));
218 
219  //fill the cpu_matrix:
220  vcl_size_t data_index = 0;
221  for (vcl_size_t i = 1; i < row_buffer.size(); ++i)
222  {
223  while (data_index < row_buffer[i])
224  {
225  if (col_buffer[data_index] >= gpu_matrix.size2())
226  {
227  std::cerr << "ViennaCL encountered invalid data at colbuffer[" << data_index << "]: " << col_buffer[data_index] << std::endl;
228  return;
229  }
230 
231  if (bool(elements[data_index]))
232  cpu_matrix(row_indices[i-1], col_buffer[data_index]) = elements[data_index];
233  ++data_index;
234  }
235  }
236  }
237 }
238 
239 
245 template<typename NumericT>
247  std::vector< std::map<unsigned int, NumericT> > & cpu_matrix)
248 {
249  tools::sparse_matrix_adapter<NumericT> temp(cpu_matrix, cpu_matrix.size(), cpu_matrix.size());
250  copy(gpu_matrix, temp);
251 }
252 
253 
255 
262 template<class NumericT>
264 {
265 public:
269 
271  compressed_compressed_matrix() : rows_(0), cols_(0), nonzero_rows_(0), nonzeros_(0) {}
272 
281  explicit compressed_compressed_matrix(vcl_size_t rows, vcl_size_t cols, vcl_size_t nonzero_rows = 0, vcl_size_t nonzeros = 0, viennacl::context ctx = viennacl::context())
282  : rows_(rows), cols_(cols), nonzero_rows_(nonzero_rows), nonzeros_(nonzeros)
283  {
284  row_buffer_.switch_active_handle_id(ctx.memory_type());
285  row_indices_.switch_active_handle_id(ctx.memory_type());
286  col_buffer_.switch_active_handle_id(ctx.memory_type());
287  elements_.switch_active_handle_id(ctx.memory_type());
288 
289 #ifdef VIENNACL_WITH_OPENCL
290  if (ctx.memory_type() == OPENCL_MEMORY)
291  {
292  row_buffer_.opencl_handle().context(ctx.opencl_context());
293  row_indices_.opencl_handle().context(ctx.opencl_context());
294  col_buffer_.opencl_handle().context(ctx.opencl_context());
295  elements_.opencl_handle().context(ctx.opencl_context());
296  }
297 #endif
298  if (rows > 0)
299  {
301  }
302  if (nonzeros > 0)
303  {
305  viennacl::backend::memory_create(elements_, sizeof(NumericT) * nonzeros, ctx);
306  }
307  }
308 
316  : rows_(rows), cols_(cols), nonzeros_(0)
317  {
318  row_buffer_.switch_active_handle_id(ctx.memory_type());
319  col_buffer_.switch_active_handle_id(ctx.memory_type());
320  elements_.switch_active_handle_id(ctx.memory_type());
321 
322 #ifdef VIENNACL_WITH_OPENCL
323  if (ctx.memory_type() == OPENCL_MEMORY)
324  {
325  row_buffer_.opencl_handle().context(ctx.opencl_context());
326  col_buffer_.opencl_handle().context(ctx.opencl_context());
327  elements_.opencl_handle().context(ctx.opencl_context());
328  }
329 #endif
330  if (rows > 0)
331  {
333  }
334  }
335 
336  explicit compressed_compressed_matrix(viennacl::context ctx) : rows_(0), cols_(0), nonzero_rows_(0), nonzeros_(0)
337  {
338  row_buffer_.switch_active_handle_id(ctx.memory_type());
339  row_indices_.switch_active_handle_id(ctx.memory_type());
340  col_buffer_.switch_active_handle_id(ctx.memory_type());
341  elements_.switch_active_handle_id(ctx.memory_type());
342 
343 #ifdef VIENNACL_WITH_OPENCL
344  if (ctx.memory_type() == OPENCL_MEMORY)
345  {
346  row_buffer_.opencl_handle().context(ctx.opencl_context());
347  row_indices_.opencl_handle().context(ctx.opencl_context());
348  col_buffer_.opencl_handle().context(ctx.opencl_context());
349  elements_.opencl_handle().context(ctx.opencl_context());
350  }
351 #endif
352  }
353 
354 
355 #ifdef VIENNACL_WITH_OPENCL
356  explicit compressed_compressed_matrix(cl_mem mem_row_buffer, cl_mem mem_row_indices, cl_mem mem_col_buffer, cl_mem mem_elements,
357  vcl_size_t rows, vcl_size_t cols, vcl_size_t nonzero_rows, vcl_size_t nonzeros) :
358  rows_(rows), cols_(cols), nonzero_rows_(nonzero_rows), nonzeros_(nonzeros)
359  {
361  row_buffer_.opencl_handle() = mem_row_buffer;
362  row_buffer_.opencl_handle().inc(); //prevents that the user-provided memory is deleted once the matrix object is destroyed.
363  row_buffer_.raw_size(sizeof(cl_uint) * (nonzero_rows + 1));
364 
366  row_indices_.opencl_handle() = mem_row_indices;
367  row_indices_.opencl_handle().inc(); //prevents that the user-provided memory is deleted once the matrix object is destroyed.
368  row_indices_.raw_size(sizeof(cl_uint) * nonzero_rows);
369 
371  col_buffer_.opencl_handle() = mem_col_buffer;
372  col_buffer_.opencl_handle().inc(); //prevents that the user-provided memory is deleted once the matrix object is destroyed.
373  col_buffer_.raw_size(sizeof(cl_uint) * nonzeros);
374 
376  elements_.opencl_handle() = mem_elements;
377  elements_.opencl_handle().inc(); //prevents that the user-provided memory is deleted once the matrix object is destroyed.
378  elements_.raw_size(sizeof(NumericT) * nonzeros);
379  }
380 #endif
381 
382 
385  {
386  assert( (rows_ == 0 || rows_ == other.size1()) && bool("Size mismatch") );
387  assert( (cols_ == 0 || cols_ == other.size2()) && bool("Size mismatch") );
388 
389  rows_ = other.size1();
390  cols_ = other.size2();
391  nonzero_rows_ = other.nnz1();
392  nonzeros_ = other.nnz();
393 
394  viennacl::backend::typesafe_memory_copy<unsigned int>(other.row_buffer_, row_buffer_);
395  viennacl::backend::typesafe_memory_copy<unsigned int>(other.row_indices_, row_indices_);
396  viennacl::backend::typesafe_memory_copy<unsigned int>(other.col_buffer_, col_buffer_);
397  viennacl::backend::typesafe_memory_copy<NumericT>(other.elements_, elements_);
398 
399  return *this;
400  }
401 
402 
414  void set(const void * row_jumper,
415  const void * row_indices,
416  const void * col_buffer,
417  const NumericT * elements,
418  vcl_size_t rows,
419  vcl_size_t cols,
420  vcl_size_t nonzero_rows,
421  vcl_size_t nonzeros)
422  {
423  assert( (rows > 0) && bool("Error in compressed_compressed_matrix::set(): Number of rows must be larger than zero!"));
424  assert( (cols > 0) && bool("Error in compressed_compressed_matrix::set(): Number of columns must be larger than zero!"));
425  assert( (nonzero_rows > 0) && bool("Error in compressed_compressed_matrix::set(): Number of nonzero rows must be larger than zero!"));
426  assert( (nonzeros > 0) && bool("Error in compressed_compressed_matrix::set(): Number of nonzeros must be larger than zero!"));
427  //std::cout << "Setting memory: " << cols + 1 << ", " << nonzeros << std::endl;
428 
429  viennacl::backend::memory_create(row_buffer_, viennacl::backend::typesafe_host_array<unsigned int>(row_buffer_).element_size() * (nonzero_rows + 1), viennacl::traits::context(row_buffer_), row_jumper);
430  viennacl::backend::memory_create(row_indices_, viennacl::backend::typesafe_host_array<unsigned int>(row_indices_).element_size() * nonzero_rows, viennacl::traits::context(row_indices_), row_indices);
432  viennacl::backend::memory_create(elements_, sizeof(NumericT) * nonzeros, viennacl::traits::context(elements_), elements);
433 
434  nonzeros_ = nonzeros;
435  nonzero_rows_ = nonzero_rows;
436  rows_ = rows;
437  cols_ = cols;
438  }
439 
441  void clear()
442  {
443  viennacl::backend::typesafe_host_array<unsigned int> host_row_buffer(row_buffer_, 1);
444  viennacl::backend::typesafe_host_array<unsigned int> host_row_indices(row_indices_, 1);
445  viennacl::backend::typesafe_host_array<unsigned int> host_col_buffer(col_buffer_, 1);
446  std::vector<NumericT> host_elements(1);
447 
448  viennacl::backend::memory_create(row_buffer_, host_row_buffer.element_size() * (rows_ + 1), viennacl::traits::context(row_buffer_), host_row_buffer.get());
449  viennacl::backend::memory_create(row_indices_, host_row_indices.element_size() * (rows_ + 1), viennacl::traits::context(row_indices_), host_row_indices.get());
450  viennacl::backend::memory_create(col_buffer_, host_col_buffer.element_size() * 1, viennacl::traits::context(col_buffer_), host_col_buffer.get());
451  viennacl::backend::memory_create(elements_, sizeof(NumericT) * 1, viennacl::traits::context(elements_), &(host_elements[0]));
452 
453  nonzeros_ = 0;
454  nonzero_rows_ = 0;
455  }
456 
458  const vcl_size_t & size1() const { return rows_; }
460  const vcl_size_t & size2() const { return cols_; }
462  const vcl_size_t & nnz1() const { return nonzero_rows_; }
464  const vcl_size_t & nnz() const { return nonzeros_; }
465 
467  const handle_type & handle1() const { return row_buffer_; }
469  const handle_type & handle2() const { return col_buffer_; }
471  const handle_type & handle3() const { return row_indices_; }
473  const handle_type & handle() const { return elements_; }
474 
476  handle_type & handle1() { return row_buffer_; }
478  handle_type & handle2() { return col_buffer_; }
480  handle_type & handle3() { return row_indices_; }
482  handle_type & handle() { return elements_; }
483 
485  {
486  viennacl::backend::switch_memory_context<unsigned int>(row_buffer_, new_ctx);
487  viennacl::backend::switch_memory_context<unsigned int>(row_indices_, new_ctx);
488  viennacl::backend::switch_memory_context<unsigned int>(col_buffer_, new_ctx);
489  viennacl::backend::switch_memory_context<NumericT>(elements_, new_ctx);
490  }
491 
493  {
494  return row_buffer_.get_active_handle_id();
495  }
496 
497 private:
498 
499  vcl_size_t rows_;
500  vcl_size_t cols_;
501  vcl_size_t nonzero_rows_;
502  vcl_size_t nonzeros_;
503  handle_type row_buffer_;
504  handle_type row_indices_;
505  handle_type col_buffer_;
506  handle_type elements_;
507 };
508 
509 
510 
511 //
512 // Specify available operations:
513 //
514 
517 namespace linalg
518 {
519 namespace detail
520 {
521  // x = A * y
522  template<typename T>
523  struct op_executor<vector_base<T>, op_assign, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> >
524  {
525  static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> const & rhs)
526  {
527  // check for the special case x = A * x
528  if (viennacl::traits::handle(lhs) == viennacl::traits::handle(rhs.rhs()))
529  {
530  viennacl::vector<T> temp(lhs);
531  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), temp);
532  lhs = temp;
533  }
534  else
535  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), lhs);
536  }
537  };
538 
539  template<typename T>
540  struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> >
541  {
542  static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> const & rhs)
543  {
544  viennacl::vector<T> temp(lhs);
545  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), temp);
546  lhs += temp;
547  }
548  };
549 
550  template<typename T>
551  struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> >
552  {
553  static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> const & rhs)
554  {
555  viennacl::vector<T> temp(lhs);
556  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), temp);
557  lhs -= temp;
558  }
559  };
560 
561 
562  // x = A * vec_op
563  template<typename T, typename LHS, typename RHS, typename OP>
564  struct op_executor<vector_base<T>, op_assign, vector_expression<const compressed_compressed_matrix<T>, const vector_expression<const LHS, const RHS, OP>, op_prod> >
565  {
566  static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, const vector_expression<const LHS, const RHS, OP>, op_prod> const & rhs)
567  {
568  viennacl::vector<T> temp(rhs.rhs());
569  viennacl::linalg::prod_impl(rhs.lhs(), temp, lhs);
570  }
571  };
572 
573  // x = A * vec_op
574  template<typename T, typename LHS, typename RHS, typename OP>
575  struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const compressed_compressed_matrix<T>, vector_expression<const LHS, const RHS, OP>, op_prod> >
576  {
577  static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, vector_expression<const LHS, const RHS, OP>, op_prod> const & rhs)
578  {
579  viennacl::vector<T> temp(rhs.rhs(), viennacl::traits::context(rhs));
580  viennacl::vector<T> temp_result(lhs);
581  viennacl::linalg::prod_impl(rhs.lhs(), temp, temp_result);
582  lhs += temp_result;
583  }
584  };
585 
586  // x = A * vec_op
587  template<typename T, typename LHS, typename RHS, typename OP>
588  struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const compressed_compressed_matrix<T>, const vector_expression<const LHS, const RHS, OP>, op_prod> >
589  {
590  static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, const vector_expression<const LHS, const RHS, OP>, op_prod> const & rhs)
591  {
592  viennacl::vector<T> temp(rhs.rhs(), viennacl::traits::context(rhs));
593  viennacl::vector<T> temp_result(lhs);
594  viennacl::linalg::prod_impl(rhs.lhs(), temp, temp_result);
595  lhs -= temp_result;
596  }
597  };
598 
599 } // namespace detail
600 } // namespace linalg
601 
603 }
604 
605 #endif
const vcl_size_t & nnz() const
Returns the number of nonzero entries.
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:226
scalar< typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT< NumericT >::ResultType > value_type
void switch_memory_context(viennacl::context new_ctx)
void set(const void *row_jumper, const void *row_indices, const void *col_buffer, const NumericT *elements, vcl_size_t rows, vcl_size_t cols, vcl_size_t nonzero_rows, vcl_size_t nonzeros)
Sets the row, column and value arrays of the compressed matrix.
const handle_type & handle2() const
Returns the OpenCL handle to the column index array.
const handle_type & handle1() const
Returns the OpenCL handle to the row index array.
Various little tools used here and there in ViennaCL.
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
Definition: size.hpp:216
A proxy class for entries in a vector.
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
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:245
handle_type & handle3()
Returns the OpenCL handle to the row index array.
vcl_size_t element_size(memory_types)
Definition: memory.hpp:299
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
Definition: context.hpp:39
const handle_type & handle() const
Returns the OpenCL handle to the matrix entry array.
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:144
handle_type & handle()
Returns the OpenCL handle to the matrix entry array.
const handle_type & handle3() const
Returns the OpenCL handle to the row index array.
A sparse square matrix in compressed sparse rows format optimized for the case that only a few rows c...
Implementations of operations using sparse matrices.
compressed_compressed_matrix(vcl_size_t rows, vcl_size_t cols, vcl_size_t nonzero_rows=0, vcl_size_t nonzeros=0, viennacl::context ctx=viennacl::context())
Construction of a compressed matrix with the supplied number of rows and columns. If the number of no...
compressed_compressed_matrix & operator=(compressed_compressed_matrix const &other)
Assignment a compressed matrix from possibly another memory domain.
void clear()
Resets all entries in the matrix back to zero without changing the matrix size. Resets the sparsity p...
Adapts a constant sparse matrix type made up from std::vector > to basic ub...
Definition: adapter.hpp:183
const vcl_size_t & size2() const
Returns the number of columns.
std::size_t vcl_size_t
Definition: forwards.h:74
const vcl_size_t & size1() const
Returns the number of rows.
viennacl::memory_types memory_type() const
Definition: context.hpp:76
void copy_impl(const CPUMatrixT &cpu_matrix, compressed_compressed_matrix< NumericT > &gpu_matrix, vcl_size_t nonzero_rows, vcl_size_t nonzeros)
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 ...
handle_type & handle2()
Returns the OpenCL handle to the column index array.
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) ...
const vcl_size_t & nnz1() const
Returns the number of nonzero entries.
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:89
vcl_size_t raw_size() const
Returns the number of bytes of the currently active buffer.
Definition: mem_handle.hpp:230
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
void prod_impl(const matrix_base< NumericT > &mat, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
memory_types
Definition: forwards.h:344
compressed_compressed_matrix()
Default construction of a compressed matrix. No memory is allocated.
compressed_compressed_matrix(vcl_size_t rows, vcl_size_t cols, viennacl::context ctx)
Construction of a compressed matrix with the supplied number of rows and columns. If the number of no...
memory_types get_active_handle_id() const
Returns an ID for the currently active memory buffer. Other memory buffers might contain old or no da...
Definition: mem_handle.hpp:118
handle_type & handle1()
Returns the OpenCL handle to the row index array.