ViennaCL - The Vienna Computing Library  1.5.2
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 CPU_MATRIX, typename SCALARTYPE>
41  void copy_impl(const CPU_MATRIX & 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<SCALARTYPE> elements(nonzeros);
53 
54  vcl_size_t row_index = 0;
55  vcl_size_t data_index = 0;
56 
57  for (typename CPU_MATRIX::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 CPU_MATRIX::const_iterator2 col_it = row_it.begin();
64  col_it != row_it.end();
65  ++col_it)
66  {
67  SCALARTYPE entry = *col_it;
68  if (entry != SCALARTYPE(0))
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 CPU_MATRIX, typename SCALARTYPE>
115  void copy(const CPU_MATRIX & 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 CPU_MATRIX::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 CPU_MATRIX::const_iterator2 col_it = row_it.begin();
131  col_it != row_it.end();
132  ++col_it)
133  {
134  if (*col_it != SCALARTYPE(0))
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  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 SizeType, typename SCALARTYPE>
163  void copy(const std::vector< std::map<SizeType, SCALARTYPE> > & 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 
179  gpu_matrix,
180  nonzero_rows,
181  nonzeros);
182  }
183 
184 
185  //
186  // gpu to cpu:
187  //
197  template <typename CPU_MATRIX, typename SCALARTYPE>
199  CPU_MATRIX & 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<SCALARTYPE> 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(SCALARTYPE)* 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 (elements[data_index] != static_cast<SCALARTYPE>(0.0))
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 SCALARTYPE>
247  std::vector< std::map<unsigned int, SCALARTYPE> > & cpu_matrix)
248  {
249  tools::sparse_matrix_adapter<SCALARTYPE> temp(cpu_matrix, cpu_matrix.size(), cpu_matrix.size());
250  copy(gpu_matrix, temp);
251  }
252 
253 
255 
262  template<class SCALARTYPE>
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(SCALARTYPE) * 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(SCALARTYPE) * 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<SCALARTYPE>(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 SCALARTYPE * 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 
430  viennacl::backend::memory_create(row_indices_, viennacl::backend::typesafe_host_array<unsigned int>(row_indices_).element_size() * (rows + 1), viennacl::traits::context(row_indices_), row_indices);
432  viennacl::backend::memory_create(elements_, sizeof(SCALARTYPE) * nonzeros, viennacl::traits::context(elements_), elements);
433 
434  nonzeros_ = nonzeros;
435  nonzero_rows_ = nonzero_rows;
436  rows_ = rows;
437  cols_ = cols;
438  }
439 
441  const vcl_size_t & size1() const { return rows_; }
443  const vcl_size_t & size2() const { return cols_; }
445  const vcl_size_t & nnz1() const { return nonzero_rows_; }
447  const vcl_size_t & nnz() const { return nonzeros_; }
448 
450  const handle_type & handle1() const { return row_buffer_; }
452  const handle_type & handle2() const { return col_buffer_; }
454  const handle_type & handle3() const { return row_indices_; }
456  const handle_type & handle() const { return elements_; }
457 
459  handle_type & handle1() { return row_buffer_; }
461  handle_type & handle2() { return col_buffer_; }
463  handle_type & handle3() { return row_indices_; }
465  handle_type & handle() { return elements_; }
466 
468  {
469  viennacl::backend::switch_memory_context<unsigned int>(row_buffer_, new_ctx);
470  viennacl::backend::switch_memory_context<unsigned int>(row_indices_, new_ctx);
471  viennacl::backend::switch_memory_context<unsigned int>(col_buffer_, new_ctx);
472  viennacl::backend::switch_memory_context<SCALARTYPE>(elements_, new_ctx);
473  }
474 
476  {
477  return row_buffer_.get_active_handle_id();
478  }
479 
480  private:
481 
482  vcl_size_t rows_;
483  vcl_size_t cols_;
484  vcl_size_t nonzero_rows_;
485  vcl_size_t nonzeros_;
486  handle_type row_buffer_;
487  handle_type row_indices_;
488  handle_type col_buffer_;
489  handle_type elements_;
490  };
491 
492 
493 
494  //
495  // Specify available operations:
496  //
497 
500  namespace linalg
501  {
502  namespace detail
503  {
504  // x = A * y
505  template <typename T>
506  struct op_executor<vector_base<T>, op_assign, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> >
507  {
508  static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> const & rhs)
509  {
510  // check for the special case x = A * x
511  if (viennacl::traits::handle(lhs) == viennacl::traits::handle(rhs.rhs()))
512  {
513  viennacl::vector<T> temp(lhs);
514  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), temp);
515  lhs = temp;
516  }
517  else
518  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), lhs);
519  }
520  };
521 
522  template <typename T>
523  struct op_executor<vector_base<T>, op_inplace_add, 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  viennacl::vector<T> temp(lhs);
528  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), temp);
529  lhs += temp;
530  }
531  };
532 
533  template <typename T>
534  struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> >
535  {
536  static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> const & rhs)
537  {
538  viennacl::vector<T> temp(lhs);
539  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), temp);
540  lhs -= temp;
541  }
542  };
543 
544 
545  // x = A * vec_op
546  template <typename T, typename LHS, typename RHS, typename OP>
547  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> >
548  {
549  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)
550  {
551  viennacl::vector<T> temp(rhs.rhs());
552  viennacl::linalg::prod_impl(rhs.lhs(), temp, lhs);
553  }
554  };
555 
556  // x = A * vec_op
557  template <typename T, typename LHS, typename RHS, typename OP>
558  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> >
559  {
560  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)
561  {
562  viennacl::vector<T> temp(rhs.rhs(), viennacl::traits::context(rhs));
563  viennacl::vector<T> temp_result(lhs);
564  viennacl::linalg::prod_impl(rhs.lhs(), temp, temp_result);
565  lhs += temp_result;
566  }
567  };
568 
569  // x = A * vec_op
570  template <typename T, typename LHS, typename RHS, typename OP>
571  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> >
572  {
573  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)
574  {
575  viennacl::vector<T> temp(rhs.rhs(), viennacl::traits::context(rhs));
576  viennacl::vector<T> temp_result(lhs);
577  viennacl::linalg::prod_impl(rhs.lhs(), temp, temp_result);
578  lhs -= temp_result;
579  }
580  };
581 
582  } // namespace detail
583  } // namespace linalg
584 
586 }
587 
588 #endif
Helper class implementing an array on the host. Default case: No conversion necessary.
Definition: util.hpp:95
const handle_type & handle2() const
Returns the OpenCL handle to the column index array.
Definition: compressed_compressed_matrix.hpp:452
std::size_t vcl_size_t
Definition: forwards.h:58
void switch_memory_context(viennacl::context new_ctx)
Definition: compressed_compressed_matrix.hpp:467
const handle_type & handle() const
Returns the OpenCL handle to the matrix entry array.
Definition: compressed_compressed_matrix.hpp:456
const handle_type & handle1() const
Returns the OpenCL handle to the row index array.
Definition: compressed_compressed_matrix.hpp:450
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Definition: forwards.h:172
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
viennacl::memory_types memory_context() const
Definition: compressed_compressed_matrix.hpp:475
A proxy class for entries in a vector.
void set(const void *row_jumper, const void *row_indices, const void *col_buffer, const SCALARTYPE *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.
Definition: compressed_compressed_matrix.hpp:414
void copy_impl(const CPU_MATRIX &cpu_matrix, compressed_compressed_matrix< SCALARTYPE > &gpu_matrix, vcl_size_t nonzero_rows, vcl_size_t nonzeros)
Definition: compressed_compressed_matrix.hpp:41
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
memory_types
Definition: forwards.h:476
handle_type & handle3()
Returns the OpenCL handle to the row index array.
Definition: compressed_compressed_matrix.hpp:463
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
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:91
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...
Definition: compressed_compressed_matrix.hpp:315
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:29
const vcl_size_t & nnz1() const
Returns the number of nonzero entries.
Definition: compressed_compressed_matrix.hpp:445
viennacl::backend::mem_handle handle_type
Definition: compressed_compressed_matrix.hpp:266
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:144
const vcl_size_t & nnz() const
Returns the number of nonzero entries.
Definition: compressed_compressed_matrix.hpp:447
Definition: forwards.h:480
vcl_size_t size_type
Definition: compressed_compressed_matrix.hpp:268
A sparse square matrix in compressed sparse rows format optimized for the case that only a few rows c...
Definition: compressed_compressed_matrix.hpp:263
const handle_type & handle3() const
Returns the OpenCL handle to the row index array.
Definition: compressed_compressed_matrix.hpp:454
Implementations of operations using sparse matrices.
handle_type & handle2()
Returns the OpenCL handle to the column index array.
Definition: compressed_compressed_matrix.hpp:461
void copy(std::vector< SCALARTYPE > &cpu_vec, circulant_matrix< SCALARTYPE, ALIGNMENT > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
Definition: circulant_matrix.hpp:150
Adapts a constant sparse matrix type made up from std::vector > to bas...
Definition: adapter.hpp:176
compressed_compressed_matrix & operator=(compressed_compressed_matrix const &other)
Assignment a compressed matrix from possibly another memory domain.
Definition: compressed_compressed_matrix.hpp:384
viennacl::memory_types memory_type() const
Definition: context.hpp:76
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...
Definition: compressed_compressed_matrix.hpp:281
compressed_compressed_matrix()
Default construction of a compressed matrix. No memory is allocated.
Definition: compressed_compressed_matrix.hpp:271
A vector class representing a linear memory sequence on the GPU. Inspired by boost::numeric::ublas::v...
Definition: forwards.h:208
vcl_size_t raw_size() const
Returns the number of bytes of the currently active buffer.
Definition: mem_handle.hpp:203
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
Definition: context.hpp:41
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
const vcl_size_t & size2() const
Returns the number of columns.
Definition: compressed_compressed_matrix.hpp:443
handle_type & handle()
Returns the OpenCL handle to the matrix entry array.
Definition: compressed_compressed_matrix.hpp:465
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:62
Adapts a non-const sparse matrix type made up from std::vector > to ba...
Definition: adapter.hpp:345
void prod_impl(const matrix_base< NumericT, F > &mat, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
Definition: matrix_operations.hpp:350
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
handle_type & handle1()
Returns the OpenCL handle to the row index array.
Definition: compressed_compressed_matrix.hpp:459
scalar< typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT< SCALARTYPE >::ResultType > value_type
Definition: compressed_compressed_matrix.hpp:267
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:94
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
compressed_compressed_matrix(viennacl::context ctx)
Definition: compressed_compressed_matrix.hpp:336
const vcl_size_t & size1() const
Returns the number of rows.
Definition: compressed_compressed_matrix.hpp:441