ViennaCL - The Vienna Computing Library: viennacl/compressed_compressed_matrix.hpp Source File

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
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-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
25 #include <vector>
26 #include <list>
27 #include <map>
28 #include "viennacl/forwards.h"
29 #include "viennacl/vector.hpp"
30
31 #include "viennacl/linalg/sparse_matrix_operations.hpp"
32
33 #include "viennacl/tools/tools.hpp"
34 #include "viennacl/tools/entry_proxy.hpp"
35
36 namespace viennacl
37 {
38 namespace detail
39 {
40 template<typename CPUMatrixT, typename NumericT>
41 void copy_impl(const CPUMatrixT & cpu_matrix,
42 compressed_compressed_matrix<NumericT> & gpu_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,
116 compressed_compressed_matrix<NumericT> & gpu_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,
165 compressed_compressed_matrix<NumericT> & gpu_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>
199 void copy(const compressed_compressed_matrix<NumericT> & gpu_matrix,
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>
248 void copy(const compressed_compressed_matrix<NumericT> & gpu_matrix,
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>
265 class compressed_compressed_matrix
266 {
267 public:
268 typedef viennacl::backend::mem_handle handle_type;
269 typedef scalar<typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT<NumericT>::ResultType> value_type;
270 typedef vcl_size_t size_type;
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 {
302 viennacl::backend::memory_create(row_buffer_, viennacl::backend::typesafe_host_array<unsigned int>().element_size() * (rows + 1), ctx);
303 }
304 if (nonzeros > 0)
305 {
306 viennacl::backend::memory_create(col_buffer_, viennacl::backend::typesafe_host_array<unsigned int>().element_size() * nonzeros, ctx);
307 viennacl::backend::memory_create(elements_, sizeof(NumericT) * nonzeros, ctx);
308 }
309 }
310
317 explicit compressed_compressed_matrix(vcl_size_t rows, vcl_size_t cols, viennacl::context ctx)
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 {
334 viennacl::backend::memory_create(row_buffer_, viennacl::backend::typesafe_host_array<unsigned int>().element_size() * (rows + 1), ctx);
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 {
362 row_buffer_.switch_active_handle_id(viennacl::OPENCL_MEMORY);
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
367 row_indices_.switch_active_handle_id(viennacl::OPENCL_MEMORY);
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
372 col_buffer_.switch_active_handle_id(viennacl::OPENCL_MEMORY);
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
377 elements_.switch_active_handle_id(viennacl::OPENCL_MEMORY);
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
386 compressed_compressed_matrix & operator=(compressed_compressed_matrix const & other)
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);
433 viennacl::backend::memory_create(col_buffer_, viennacl::backend::typesafe_host_array<unsigned int>(col_buffer_).element_size() * nonzeros, viennacl::traits::context(col_buffer_), col_buffer);
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
486 void switch_memory_context(viennacl::context new_ctx)
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
494 viennacl::memory_types memory_context() const
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(), T(1), temp, T(0));
534 lhs = temp;
535 }
536 else
537 viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(1), lhs, T(0));
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 // check for the special case x += A * x
547 if (viennacl::traits::handle(lhs) == viennacl::traits::handle(rhs.rhs()))
548 {
549 viennacl::vector<T> temp(lhs);
550 viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(1), temp, T(0));
551 lhs += temp;
552 }
553 else
554 viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(1), lhs, T(1));
555 }
556 };
557
558 template<typename T>
559 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> >
560 {
561 static void apply(vector_base<T> & lhs, vector_expression<const compressed_compressed_matrix<T>, const vector_base<T>, op_prod> const & rhs)
562 {
563 // check for the special case x -= A * x
564 if (viennacl::traits::handle(lhs) == viennacl::traits::handle(rhs.rhs()))
565 {
566 viennacl::vector<T> temp(lhs);
567 viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(1), temp, T(0));
568 lhs -= temp;
569 }
570 else
571 viennacl::linalg::prod_impl(rhs.lhs(), rhs.rhs(), T(-1), lhs, T(1));
572 }
573 };
574
575
576 // x = A * vec_op
577 template<typename T, typename LHS, typename RHS, typename OP>
578 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> >
579 {
580 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)
581 {
582 viennacl::vector<T> temp(rhs.rhs());
583 viennacl::linalg::prod_impl(rhs.lhs(), temp, lhs);
584 }
585 };
586
587 // x = A * vec_op
588 template<typename T, typename LHS, typename RHS, typename OP>
589 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> >
590 {
591 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)
592 {
593 viennacl::vector<T> temp(rhs.rhs(), viennacl::traits::context(rhs));
594 viennacl::vector<T> temp_result(lhs);
595 viennacl::linalg::prod_impl(rhs.lhs(), temp, temp_result);
596 lhs += temp_result;
597 }
598 };
599
600 // x = A * vec_op
601 template<typename T, typename LHS, typename RHS, typename OP>
602 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> >
603 {
604 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)
605 {
606 viennacl::vector<T> temp(rhs.rhs(), viennacl::traits::context(rhs));
607 viennacl::vector<T> temp_result(lhs);
608 viennacl::linalg::prod_impl(rhs.lhs(), temp, temp_result);
609 lhs -= temp_result;
610 }
611 };
612
613 } // namespace detail
614 } // namespace linalg
615
617 }
618
619 #endif
viennacl::compressed_compressed_matrix::nnz
const vcl_size_t & nnz() const
Returns the number of nonzero entries.
Definition: compressed_compressed_matrix.hpp:466
viennacl::backend::typesafe_host_array
Helper class implementing an array on the host. Default case: No conversion necessary.
Definition: util.hpp:92
viennacl::backend::typesafe_host_array::element_size
vcl_size_t element_size() const
Definition: util.hpp:112
viennacl::scalar
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Definition: forwards.h:227
viennacl::compressed_compressed_matrix::value_type
scalar< typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT< NumericT >::ResultType > value_type
Definition: compressed_compressed_matrix.hpp:269
viennacl::compressed_compressed_matrix::switch_memory_context
void switch_memory_context(viennacl::context new_ctx)
Definition: compressed_compressed_matrix.hpp:486
viennacl::compressed_compressed_matrix::set
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.
Definition: compressed_compressed_matrix.hpp:416
viennacl::compressed_compressed_matrix::handle2
const handle_type & handle2() const
Returns the OpenCL handle to the column index array.
Definition: compressed_compressed_matrix.hpp:471
viennacl::compressed_compressed_matrix::handle1
const handle_type & handle1() const
Returns the OpenCL handle to the row index array.
Definition: compressed_compressed_matrix.hpp:469
tools.hpp
Various little tools used here and there in ViennaCL.
viennacl::traits::size1
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
entry_proxy.hpp
A proxy class for entries in a vector.
viennacl::OPENCL_MEMORY
Definition: forwards.h:349
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::backend::typesafe_host_array::get
void * get()
Definition: util.hpp:110
viennacl::backend::memory_read
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
viennacl::traits::size2
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
viennacl::compressed_compressed_matrix::handle3
handle_type & handle3()
Returns the OpenCL handle to the row index array.
Definition: compressed_compressed_matrix.hpp:482
viennacl::backend::detail::element_size
vcl_size_t element_size(memory_types)
Definition: memory.hpp:299
NumericT
float NumericT
Definition: bisect.cpp:40
viennacl::context
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
Definition: context.hpp:39
viennacl::compressed_compressed_matrix::handle
const handle_type & handle() const
Returns the OpenCL handle to the matrix entry array.
Definition: compressed_compressed_matrix.hpp:475
viennacl::traits::size
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:239
viennacl::compressed_compressed_matrix::handle
handle_type & handle()
Returns the OpenCL handle to the matrix entry array.
Definition: compressed_compressed_matrix.hpp:484
viennacl::compressed_compressed_matrix::handle3
const handle_type & handle3() const
Returns the OpenCL handle to the row index array.
Definition: compressed_compressed_matrix.hpp:473
viennacl::compressed_compressed_matrix
A sparse square matrix in compressed sparse rows format optimized for the case that only a few rows c...
Definition: compressed_compressed_matrix.hpp:265
sparse_matrix_operations.hpp
Implementations of operations using sparse matrices.
viennacl::compressed_compressed_matrix::compressed_compressed_matrix
compressed_compressed_matrix(viennacl::context ctx)
Definition: compressed_compressed_matrix.hpp:338
viennacl::compressed_compressed_matrix::compressed_compressed_matrix
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:283
viennacl::compressed_compressed_matrix::operator=
compressed_compressed_matrix & operator=(compressed_compressed_matrix const &other)
Assignment a compressed matrix from possibly another memory domain.
Definition: compressed_compressed_matrix.hpp:386
viennacl::compressed_compressed_matrix::clear
void clear()
Resets all entries in the matrix back to zero without changing the matrix size. Resets the sparsity p...
Definition: compressed_compressed_matrix.hpp:443
viennacl::tools::const_sparse_matrix_adapter
Adapts a constant sparse matrix type made up from std::vector > to basic ub...
Definition: adapter.hpp:183
viennacl::compressed_compressed_matrix::size2
const vcl_size_t & size2() const
Returns the number of columns.
Definition: compressed_compressed_matrix.hpp:462
viennacl::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
viennacl::vector
Definition: forwards.h:266
viennacl::compressed_compressed_matrix::size1
const vcl_size_t & size1() const
Returns the number of rows.
Definition: compressed_compressed_matrix.hpp:460
viennacl::context::memory_type
viennacl::memory_types memory_type() const
Definition: context.hpp:76
viennacl::detail::copy_impl
void copy_impl(const CPUMatrixT &cpu_matrix, compressed_compressed_matrix< NumericT > &gpu_matrix, vcl_size_t nonzero_rows, vcl_size_t nonzeros)
Definition: compressed_compressed_matrix.hpp:41
viennacl::backend::mem_handle::switch_active_handle_id
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::traits::context
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
Definition: context.hpp:40
vector.hpp
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
viennacl::compressed_compressed_matrix::handle2
handle_type & handle2()
Returns the OpenCL handle to the column index array.
Definition: compressed_compressed_matrix.hpp:480
viennacl::copy
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) ...
Definition: circulant_matrix.hpp:150
viennacl::compressed_compressed_matrix::nnz1
const vcl_size_t & nnz1() const
Returns the number of nonzero entries.
Definition: compressed_compressed_matrix.hpp:464
viennacl::backend::mem_handle
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:89
viennacl::backend::mem_handle::raw_size
vcl_size_t raw_size() const
Returns the number of bytes of the currently active buffer.
Definition: mem_handle.hpp:230
viennacl::tools::sparse_matrix_adapter
Adapts a non-const sparse matrix type made up from std::vector > to basic u...
Definition: adapter.hpp:357
viennacl::backend::memory_create
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
viennacl::compressed_compressed_matrix::memory_context
viennacl::memory_types memory_context() const
Definition: compressed_compressed_matrix.hpp:494
viennacl::linalg::prod_impl
void prod_impl(const matrix_base< NumericT > &mat, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
Definition: matrix_operations.hpp:438
viennacl::traits::handle
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
viennacl::memory_types
memory_types
Definition: forwards.h:345
viennacl::compressed_compressed_matrix::compressed_compressed_matrix
compressed_compressed_matrix()
Default construction of a compressed matrix. No memory is allocated.
Definition: compressed_compressed_matrix.hpp:273
viennacl::compressed_compressed_matrix::compressed_compressed_matrix
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:317
op_assign
Definition: self_assign.cpp:132
viennacl::compressed_compressed_matrix::handle_type
viennacl::backend::mem_handle handle_type
Definition: compressed_compressed_matrix.hpp:268
viennacl::compressed_compressed_matrix::size_type
vcl_size_t size_type
Definition: compressed_compressed_matrix.hpp:270
viennacl::backend::mem_handle::get_active_handle_id
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
viennacl::compressed_compressed_matrix::handle1
handle_type & handle1()
Returns the OpenCL handle to the row index array.
Definition: compressed_compressed_matrix.hpp:478