ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
common.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_HOST_BASED_COMMON_HPP_
2 #define VIENNACL_LINALG_HOST_BASED_COMMON_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 
26 
27 namespace viennacl
28 {
29 namespace linalg
30 {
31 namespace host_based
32 {
33 namespace detail
34 {
35 
36 template<typename ResultT, typename VectorT>
37 ResultT * extract_raw_pointer(VectorT & vec)
38 {
39  return reinterpret_cast<ResultT *>(viennacl::traits::ram_handle(vec).get());
40 }
41 
42 template<typename ResultT, typename VectorT>
43 ResultT const * extract_raw_pointer(VectorT const & vec)
44 {
45  return reinterpret_cast<ResultT const *>(viennacl::traits::ram_handle(vec).get());
46 }
47 
49 template<typename NumericT>
51 {
52 public:
54 
55  vector_array_wrapper(value_type * A,
57  vcl_size_t inc)
58  : A_(A),
59  start_(start),
60  inc_(inc) {}
61 
62  value_type & operator()(vcl_size_t i) { return A_[i * inc_ + start_]; }
63 
64 private:
65  value_type * A_;
66  vcl_size_t start_;
67  vcl_size_t inc_;
68 };
69 
70 
72 template<typename NumericT, typename LayoutT, bool is_transposed>
74 {
75  public:
77 
78  matrix_array_wrapper(value_type * A,
80  vcl_size_t inc1, vcl_size_t inc2,
82  : A_(A),
83  start1_(start1), start2_(start2),
84  inc1_(inc1), inc2_(inc2),
85  internal_size1_(internal_size1), internal_size2_(internal_size2) {}
86 
87  value_type & operator()(vcl_size_t i, vcl_size_t j)
88  {
89  return A_[LayoutT::mem_index(i * inc1_ + start1_,
90  j * inc2_ + start2_,
91  internal_size1_, internal_size2_)];
92  }
93 
94  // convenience overloads to address signed index types for OpenMP:
95  value_type & operator()(vcl_size_t i, long j) { return operator()(i, static_cast<vcl_size_t>(j)); }
96  value_type & operator()(long i, vcl_size_t j) { return operator()(static_cast<vcl_size_t>(i), j); }
97  value_type & operator()(long i, long j) { return operator()(static_cast<vcl_size_t>(i), static_cast<vcl_size_t>(j)); }
98 
99  private:
100  value_type * A_;
101  vcl_size_t start1_, start2_;
102  vcl_size_t inc1_, inc2_;
103  vcl_size_t internal_size1_, internal_size2_;
104 };
105 
107 template<typename NumericT, typename LayoutT>
108 class matrix_array_wrapper<NumericT, LayoutT, true>
109 {
110 public:
111  typedef NumericT value_type;
112 
113  matrix_array_wrapper(value_type * A,
115  vcl_size_t inc1, vcl_size_t inc2,
117  : A_(A),
118  start1_(start1), start2_(start2),
119  inc1_(inc1), inc2_(inc2),
120  internal_size1_(internal_size1), internal_size2_(internal_size2) {}
121 
122  value_type & operator()(vcl_size_t i, vcl_size_t j)
123  {
124  //swapping row and column indices here
125  return A_[LayoutT::mem_index(j * inc1_ + start1_,
126  i * inc2_ + start2_,
127  internal_size1_, internal_size2_)];
128  }
129 
130  // convenience overloads to address signed index types for OpenMP:
131  value_type & operator()(vcl_size_t i, long j) { return operator()(i, static_cast<vcl_size_t>(j)); }
132  value_type & operator()(long i, vcl_size_t j) { return operator()(static_cast<vcl_size_t>(i), j); }
133  value_type & operator()(long i, long j) { return operator()(static_cast<vcl_size_t>(i), static_cast<vcl_size_t>(j)); }
134 
135 private:
136  value_type * A_;
137  vcl_size_t start1_, start2_;
138  vcl_size_t inc1_, inc2_;
139  vcl_size_t internal_size1_, internal_size2_;
140 };
143 } //namespace detail
144 } //namespace host_based
145 } //namespace linalg
146 } //namespace viennacl
147 
148 
149 #endif
value_type & operator()(vcl_size_t i, vcl_size_t j)
Definition: common.hpp:87
Helper class for accessing a strided subvector of a larger vector.
Definition: common.hpp:50
value_type & operator()(vcl_size_t i, long j)
Definition: common.hpp:95
vcl_size_t internal_size1(matrix_base< NumericT > const &mat)
Helper routine for obtaining the internal number of entries per row of a ViennaCL matrix...
Definition: size.hpp:382
value_type & operator()(long i, vcl_size_t j)
Definition: common.hpp:96
vcl_size_t internal_size2(matrix_base< NumericT > const &mat)
Helper routine for obtaining the internal number of entries per column of a ViennaCL matrix...
Definition: size.hpp:390
result_of::size_type< T >::type start1(T const &obj)
Definition: start.hpp:65
float NumericT
Definition: bisect.cpp:40
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:34
matrix_array_wrapper(value_type *A, vcl_size_t start1, vcl_size_t start2, vcl_size_t inc1, vcl_size_t inc2, vcl_size_t internal_size1, vcl_size_t internal_size2)
Definition: common.hpp:78
result_of::size_type< T >::type start2(T const &obj)
Definition: start.hpp:84
Helper array for accessing a strided submatrix embedded in a larger matrix.
Definition: common.hpp:73
Definition: blas3.hpp:36
result_of::size_type< T >::type start(T const &obj)
Definition: start.hpp:44
vector_array_wrapper(value_type *A, vcl_size_t start, vcl_size_t inc)
Definition: common.hpp:55
ResultT * extract_raw_pointer(VectorT &vec)
Definition: common.hpp:37
std::size_t vcl_size_t
Definition: forwards.h:75
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
viennacl::backend::mem_handle::ram_handle_type & ram_handle(T &obj)
Generic helper routine for extracting the RAM handle of a ViennaCL object. Non-const version...
Definition: handle.hpp:138