ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
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-2015, 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 
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 (entry < 0 || entry > 0) // entry != 0 without compiler warnings
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  NumericT val = *col_it;
135  if (val < 0 || val > 0) // val != 0 without compiler warnings
136  {
137  ++num_entries;
138 
139  if (row_empty)
140  {
141  row_empty = false;
142  ++nonzero_rows;
143  }
144  }
145  }
146  }
147 
148  if (num_entries == 0) //we copy an empty matrix
149  num_entries = 1;
150 
151  //set up matrix entries:
152  viennacl::detail::copy_impl(cpu_matrix, gpu_matrix, nonzero_rows, num_entries);
153  }
154 }
155 
156 
157 //adapted for std::vector< std::map < > > argument:
163 template<typename SizeT, typename NumericT>
164 void copy(const std::vector< std::map<SizeT, NumericT> > & cpu_matrix,
166 {
167  vcl_size_t nonzero_rows = 0;
168  vcl_size_t nonzeros = 0;
169  vcl_size_t max_col = 0;
170  for (vcl_size_t i=0; i<cpu_matrix.size(); ++i)
171  {
172  if (cpu_matrix[i].size() > 0)
173  ++nonzero_rows;
174  nonzeros += cpu_matrix[i].size();
175  if (cpu_matrix[i].size() > 0)
176  max_col = std::max<vcl_size_t>(max_col, (cpu_matrix[i].rbegin())->first);
177  }
178 
179  viennacl::detail::copy_impl(tools::const_sparse_matrix_adapter<NumericT, SizeT>(cpu_matrix, cpu_matrix.size(), max_col + 1),
180  gpu_matrix,
181  nonzero_rows,
182  nonzeros);
183 }
184 
185 
186 //
187 // gpu to cpu:
188 //
198 template<typename CPUMatrixT, typename NumericT>
200  CPUMatrixT & cpu_matrix )
201 {
202  assert( (cpu_matrix.size1() == gpu_matrix.size1()) && bool("Size mismatch") );
203  assert( (cpu_matrix.size2() == gpu_matrix.size2()) && bool("Size mismatch") );
204 
205  if ( gpu_matrix.size1() > 0 && gpu_matrix.size2() > 0 )
206  {
207  //get raw data from memory:
208  viennacl::backend::typesafe_host_array<unsigned int> row_buffer(gpu_matrix.handle1(), gpu_matrix.nnz1() + 1);
209  viennacl::backend::typesafe_host_array<unsigned int> row_indices(gpu_matrix.handle1(), gpu_matrix.nnz1());
210  viennacl::backend::typesafe_host_array<unsigned int> col_buffer(gpu_matrix.handle2(), gpu_matrix.nnz());
211  std::vector<NumericT> elements(gpu_matrix.nnz());
212 
213  //std::cout << "GPU->CPU, nonzeros: " << gpu_matrix.nnz() << std::endl;
214 
215  viennacl::backend::memory_read(gpu_matrix.handle1(), 0, row_buffer.raw_size(), row_buffer.get());
216  viennacl::backend::memory_read(gpu_matrix.handle3(), 0, row_indices.raw_size(), row_indices.get());
217  viennacl::backend::memory_read(gpu_matrix.handle2(), 0, col_buffer.raw_size(), col_buffer.get());
218  viennacl::backend::memory_read(gpu_matrix.handle(), 0, sizeof(NumericT)* gpu_matrix.nnz(), &(elements[0]));
219 
220  //fill the cpu_matrix:
221  vcl_size_t data_index = 0;
222  for (vcl_size_t i = 1; i < row_buffer.size(); ++i)
223  {
224  while (data_index < row_buffer[i])
225  {
226  if (col_buffer[data_index] >= gpu_matrix.size2())
227  {
228  std::cerr << "ViennaCL encountered invalid data at colbuffer[" << data_index << "]: " << col_buffer[data_index] << std::endl;
229  return;
230  }
231 
232  NumericT val = elements[data_index];
233  if (val < 0 || val > 0) // val != 0 without compiler warning
234  cpu_matrix(row_indices[i-1], col_buffer[data_index]) = val;
235  ++data_index;
236  }
237  }
238  }
239 }
240 
241 
247 template<typename NumericT>
249  std::vector< std::map<unsigned int, NumericT> > & cpu_matrix)
250 {
251  tools::sparse_matrix_adapter<NumericT> temp(cpu_matrix, cpu_matrix.size(), cpu_matrix.size());
252  copy(gpu_matrix, temp);
253 }
254 
255 
257 
264 template<class NumericT>
266 {
267 public:
271 
273  compressed_compressed_matrix() : rows_(0), cols_(0), nonzero_rows_(0), nonzeros_(0) {}
274 
283  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())
284  : rows_(rows), cols_(cols), nonzero_rows_(nonzero_rows), nonzeros_(nonzeros)
285  {
286  row_buffer_.switch_active_handle_id(ctx.memory_type());
287  row_indices_.switch_active_handle_id(ctx.memory_type());
288  col_buffer_.switch_active_handle_id(ctx.memory_type());
289  elements_.switch_active_handle_id(ctx.memory_type());
290 
291 #ifdef VIENNACL_WITH_OPENCL
292  if (ctx.memory_type() == OPENCL_MEMORY)
293  {
294  row_buffer_.opencl_handle().context(ctx.opencl_context());
295  row_indices_.opencl_handle().context(ctx.opencl_context());
296  col_buffer_.opencl_handle().context(ctx.opencl_context());
297  elements_.opencl_handle().context(ctx.opencl_context());
298  }
299 #endif
300  if (rows > 0)
301  {
303  }
304  if (nonzeros > 0)
305  {
307  viennacl::backend::memory_create(elements_, sizeof(NumericT) * nonzeros, ctx);
308  }
309  }
310 
318  : rows_(rows), cols_(cols), nonzeros_(0)
319  {
320  row_buffer_.switch_active_handle_id(ctx.memory_type());
321  col_buffer_.switch_active_handle_id(ctx.memory_type());
322  elements_.switch_active_handle_id(ctx.memory_type());
323 
324 #ifdef VIENNACL_WITH_OPENCL
325  if (ctx.memory_type() == OPENCL_MEMORY)
326  {
327  row_buffer_.opencl_handle().context(ctx.opencl_context());
328  col_buffer_.opencl_handle().context(ctx.opencl_context());
329  elements_.opencl_handle().context(ctx.opencl_context());
330  }
331 #endif
332  if (rows > 0)
333  {
335  }
336  }
337 
338  explicit compressed_compressed_matrix(viennacl::context ctx) : rows_(0), cols_(0), nonzero_rows_(0), nonzeros_(0)
339  {
340  row_buffer_.switch_active_handle_id(ctx.memory_type());
341  row_indices_.switch_active_handle_id(ctx.memory_type());
342  col_buffer_.switch_active_handle_id(ctx.memory_type());
343  elements_.switch_active_handle_id(ctx.memory_type());
344 
345 #ifdef VIENNACL_WITH_OPENCL
346  if (ctx.memory_type() == OPENCL_MEMORY)
347  {
348  row_buffer_.opencl_handle().context(ctx.opencl_context());
349  row_indices_.opencl_handle().context(ctx.opencl_context());
350  col_buffer_.opencl_handle().context(ctx.opencl_context());
351  elements_.opencl_handle().context(ctx.opencl_context());
352  }
353 #endif
354  }
355 
356 
357 #ifdef VIENNACL_WITH_OPENCL
358  explicit compressed_compressed_matrix(cl_mem mem_row_buffer, cl_mem mem_row_indices, cl_mem mem_col_buffer, cl_mem mem_elements,
359  vcl_size_t rows, vcl_size_t cols, vcl_size_t nonzero_rows, vcl_size_t nonzeros) :
360  rows_(rows), cols_(cols), nonzero_rows_(nonzero_rows), nonzeros_(nonzeros)
361  {
363  row_buffer_.opencl_handle() = mem_row_buffer;
364  row_buffer_.opencl_handle().inc(); //prevents that the user-provided memory is deleted once the matrix object is destroyed.
365  row_buffer_.raw_size(sizeof(cl_uint) * (nonzero_rows + 1));
366 
368  row_indices_.opencl_handle() = mem_row_indices;
369  row_indices_.opencl_handle().inc(); //prevents that the user-provided memory is deleted once the matrix object is destroyed.
370  row_indices_.raw_size(sizeof(cl_uint) * nonzero_rows);
371 
373  col_buffer_.opencl_handle() = mem_col_buffer;
374  col_buffer_.opencl_handle().inc(); //prevents that the user-provided memory is deleted once the matrix object is destroyed.
375  col_buffer_.raw_size(sizeof(cl_uint) * nonzeros);
376 
378  elements_.opencl_handle() = mem_elements;
379  elements_.opencl_handle().inc(); //prevents that the user-provided memory is deleted once the matrix object is destroyed.
380  elements_.raw_size(sizeof(NumericT) * nonzeros);
381  }
382 #endif
383 
384 
387  {
388  assert( (rows_ == 0 || rows_ == other.size1()) && bool("Size mismatch") );
389  assert( (cols_ == 0 || cols_ == other.size2()) && bool("Size mismatch") );
390 
391  rows_ = other.size1();
392  cols_ = other.size2();
393  nonzero_rows_ = other.nnz1();
394  nonzeros_ = other.nnz();
395 
396  viennacl::backend::typesafe_memory_copy<unsigned int>(other.row_buffer_, row_buffer_);
397  viennacl::backend::typesafe_memory_copy<unsigned int>(other.row_indices_, row_indices_);
398  viennacl::backend::typesafe_memory_copy<unsigned int>(other.col_buffer_, col_buffer_);
399  viennacl::backend::typesafe_memory_copy<NumericT>(other.elements_, elements_);
400 
401  return *this;
402  }
403 
404 
416  void set(const void * row_jumper,
417  const void * row_indices,
418  const void * col_buffer,
419  const NumericT * elements,
420  vcl_size_t rows,
421  vcl_size_t cols,
422  vcl_size_t nonzero_rows,
423  vcl_size_t nonzeros)
424  {
425  assert( (rows > 0) && bool("Error in compressed_compressed_matrix::set(): Number of rows must be larger than zero!"));
426  assert( (cols > 0) && bool("Error in compressed_compressed_matrix::set(): Number of columns must be larger than zero!"));
427  assert( (nonzero_rows > 0) && bool("Error in compressed_compressed_matrix::set(): Number of nonzero rows must be larger than zero!"));
428  assert( (nonzeros > 0) && bool("Error in compressed_compressed_matrix::set(): Number of nonzeros must be larger than zero!"));
429  //std::cout << "Setting memory: " << cols + 1 << ", " << nonzeros << std::endl;
430 
431  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);
432  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);
434  viennacl::backend::memory_create(elements_, sizeof(NumericT) * nonzeros, viennacl::traits::context(elements_), elements);
435 
436  nonzeros_ = nonzeros;
437  nonzero_rows_ = nonzero_rows;
438  rows_ = rows;
439  cols_ = cols;
440  }
441 
443  void clear()
444  {
445  viennacl::backend::typesafe_host_array<unsigned int> host_row_buffer(row_buffer_, rows_ + 1);
446  viennacl::backend::typesafe_host_array<unsigned int> host_row_indices(row_indices_, rows_ + 1);
447  viennacl::backend::typesafe_host_array<unsigned int> host_col_buffer(col_buffer_, 1);
448  std::vector<NumericT> host_elements(1);
449 
450  viennacl::backend::memory_create(row_buffer_, host_row_buffer.element_size() * (rows_ + 1), viennacl::traits::context(row_buffer_), host_row_buffer.get());
451  viennacl::backend::memory_create(row_indices_, host_row_indices.element_size() * (rows_ + 1), viennacl::traits::context(row_indices_), host_row_indices.get());
452  viennacl::backend::memory_create(col_buffer_, host_col_buffer.element_size() * 1, viennacl::traits::context(col_buffer_), host_col_buffer.get());
453  viennacl::backend::memory_create(elements_, sizeof(NumericT) * 1, viennacl::traits::context(elements_), &(host_elements[0]));
454 
455  nonzeros_ = 0;
456  nonzero_rows_ = 0;
457  }
458 
460  const vcl_size_t & size1() const { return rows_; }
462  const vcl_size_t & size2() const { return cols_; }
464  const vcl_size_t & nnz1() const { return nonzero_rows_; }
466  const vcl_size_t & nnz() const { return nonzeros_; }
467 
469  const handle_type & handle1() const { return row_buffer_; }
471  const handle_type & handle2() const { return col_buffer_; }
473  const handle_type & handle3() const { return row_indices_; }
475  const handle_type & handle() const { return elements_; }
476 
478  handle_type & handle1() { return row_buffer_; }
480  handle_type & handle2() { return col_buffer_; }
482  handle_type & handle3() { return row_indices_; }
484  handle_type & handle() { return elements_; }
485 
487  {
488  viennacl::backend::switch_memory_context<unsigned int>(row_buffer_, new_ctx);
489  viennacl::backend::switch_memory_context<unsigned int>(row_indices_, new_ctx);
490  viennacl::backend::switch_memory_context<unsigned int>(col_buffer_, new_ctx);
491  viennacl::backend::switch_memory_context<NumericT>(elements_, new_ctx);
492  }
493 
495  {
496  return row_buffer_.get_active_handle_id();
497  }
498 
499 private:
500 
501  vcl_size_t rows_;
502  vcl_size_t cols_;
503  vcl_size_t nonzero_rows_;
504  vcl_size_t nonzeros_;
505  handle_type row_buffer_;
506  handle_type row_indices_;
507  handle_type col_buffer_;
508  handle_type elements_;
509 };
510 
511 
512 
513 //
514 // Specify available operations:
515 //
516 
519 namespace linalg
520 {
521 namespace detail
522 {
523  // x = A * y
524  template<typename T>
525  struct op_executor<vector_base<T>, op_assign, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> >
526  {
527  static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> const & rhs)
528  {
529  // check for the special case x = A * x
530  if (viennacl::traits::handle(lhs) == viennacl::traits::handle(rhs.rhs()))
531  {
532  viennacl::vector<T> temp(lhs);
533  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), temp);
534  lhs = temp;
535  }
536  else
537  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), lhs);
538  }
539  };
540 
541  template<typename T>
542  struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> >
543  {
544  static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> const & rhs)
545  {
546  viennacl::vector<T> temp(lhs);
547  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), temp);
548  lhs += temp;
549  }
550  };
551 
552  template<typename T>
553  struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> >
554  {
555  static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> const & rhs)
556  {
557  viennacl::vector<T> temp(lhs);
558  viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), temp);
559  lhs -= temp;
560  }
561  };
562 
563 
564  // x = A * vec_op
565  template<typename T, typename LHS, typename RHS, typename OP>
566  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> >
567  {
568  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)
569  {
570  viennacl::vector<T> temp(rhs.rhs());
571  viennacl::linalg::prod_impl(rhs.lhs(), temp, lhs);
572  }
573  };
574 
575  // x = A * vec_op
576  template<typename T, typename LHS, typename RHS, typename OP>
577  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> >
578  {
579  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)
580  {
581  viennacl::vector<T> temp(rhs.rhs(), viennacl::traits::context(rhs));
582  viennacl::vector<T> temp_result(lhs);
583  viennacl::linalg::prod_impl(rhs.lhs(), temp, temp_result);
584  lhs += temp_result;
585  }
586  };
587 
588  // x = A * vec_op
589  template<typename T, typename LHS, typename RHS, typename OP>
590  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> >
591  {
592  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)
593  {
594  viennacl::vector<T> temp(rhs.rhs(), viennacl::traits::context(rhs));
595  viennacl::vector<T> temp_result(lhs);
596  viennacl::linalg::prod_impl(rhs.lhs(), temp, temp_result);
597  lhs -= temp_result;
598  }
599  };
600 
601 } // namespace detail
602 } // namespace linalg
603 
605 }
606 
607 #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:227
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:163
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:201
handle_type & handle3()
Returns the OpenCL handle to the row index array.
vcl_size_t element_size(memory_types)
Definition: memory.hpp:299
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
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:34
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:235
Definition: blas3.hpp:36
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:75
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:345
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.