ViennaCL - The Vienna Computing Library  1.5.2
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-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 
26 
27 namespace viennacl
28 {
29  namespace linalg
30  {
31  namespace host_based
32  {
33  namespace detail
34  {
35  template <typename T, typename VectorType>
36  T * extract_raw_pointer(VectorType & vec)
37  {
38  return reinterpret_cast<T *>(viennacl::traits::ram_handle(vec).get());
39  }
40 
41  template <typename T, typename VectorType>
42  T const * extract_raw_pointer(VectorType const & vec)
43  {
44  return reinterpret_cast<T const *>(viennacl::traits::ram_handle(vec).get());
45  }
46 
48  template <typename NumericT>
50  {
51  public:
52  typedef NumericT value_type;
53 
54  vector_array_wrapper(value_type * A,
56  vcl_size_t inc)
57  : A_(A),
58  start_(start),
59  inc_(inc) {}
60 
61  value_type & operator()(vcl_size_t i)
62  {
63  return A_[i * inc_ + start_];
64  }
65 
66  private:
67  value_type * A_;
68  vcl_size_t start_;
69  vcl_size_t inc_;
70  };
71 
72 
73  inline bool is_row_major(viennacl::row_major_tag) { return true; }
74  inline bool is_row_major(viennacl::column_major_tag) { return false; }
75 
77  template <typename T>
79  {
80  typedef typename T::ERROR_UNRECOGNIZED_MAJORITY_CATEGORTY_TAG type;
81  };
82 
84  template <>
86  {
87  typedef viennacl::row_major type;
88  };
89 
90  template <>
91  struct majority_struct_for_orientation<viennacl::column_major_tag>
92  {
94  };
99  template <typename NumericT, typename MajorityCategory, bool is_transposed>
101  {
103 
104  public:
105  typedef NumericT value_type;
106 
107  matrix_array_wrapper(value_type * A,
109  vcl_size_t inc1, vcl_size_t inc2,
111  : A_(A),
112  start1_(start1), start2_(start2),
113  inc1_(inc1), inc2_(inc2),
114  internal_size1_(internal_size1), internal_size2_(internal_size2) {}
115 
116  value_type & operator()(vcl_size_t i, vcl_size_t j)
117  {
118  return A_[F::mem_index(i * inc1_ + start1_, j * inc2_ + start2_, internal_size1_, internal_size2_)];
119  }
120 
121  private:
122  value_type * A_;
123  vcl_size_t start1_, start2_;
124  vcl_size_t inc1_, inc2_;
125  vcl_size_t internal_size1_, internal_size2_;
126  };
127 
129  template <typename NumericT, typename MajorityCategory>
130  class matrix_array_wrapper<NumericT, MajorityCategory, true>
131  {
132  typedef typename majority_struct_for_orientation<MajorityCategory>::type F;
133 
134  public:
135  typedef NumericT value_type;
136 
137  matrix_array_wrapper(value_type * A,
139  vcl_size_t inc1, vcl_size_t inc2,
141  : A_(A),
142  start1_(start1), start2_(start2),
143  inc1_(inc1), inc2_(inc2),
144  internal_size1_(internal_size1), internal_size2_(internal_size2) {}
145 
146  value_type & operator()(vcl_size_t i, vcl_size_t j)
147  {
148  return A_[F::mem_index(j * inc1_ + start1_, i * inc2_ + start2_, internal_size1_, internal_size2_)]; //swapping row and column indices here
149  }
150 
151  private:
152  value_type * A_;
153  vcl_size_t start1_, start2_;
154  vcl_size_t inc1_, inc2_;
155  vcl_size_t internal_size1_, internal_size2_;
156  };
159  }
160 
161  } //namespace host_based
162  } //namespace linalg
163 } //namespace viennacl
164 
165 
166 #endif
T::ERROR_UNRECOGNIZED_MAJORITY_CATEGORTY_TAG type
Definition: common.hpp:80
bool is_row_major(viennacl::row_major_tag)
Definition: common.hpp:73
Helper class for accessing a strided subvector of a larger vector.
Definition: common.hpp:49
std::size_t vcl_size_t
Definition: forwards.h:58
T * extract_raw_pointer(VectorType &vec)
Definition: common.hpp:36
T * get() const
Definition: shared_ptr.hpp:134
result_of::size_type< T >::type start1(T const &obj)
Definition: start.hpp:64
vector_array_wrapper(value_type *A, vcl_size_t start, vcl_size_t inc)
Definition: common.hpp:54
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:29
value_type & operator()(vcl_size_t i)
Definition: common.hpp:61
result_of::size_type< T >::type start2(T const &obj)
Definition: start.hpp:83
Helper array for accessing a strided submatrix embedded in a larger matrix.
Definition: common.hpp:100
result_of::size_type< T >::type start(T const &obj)
Definition: start.hpp:43
Returns the row_major or column_major class of a dense matrix based on the majority-tag (layout-tag) ...
Definition: common.hpp:78
Tag class for indicating column-major layout of a matrix. Not passed to the matrix directly...
Definition: forwards.h:243
vcl_size_t internal_size2(matrix_base< NumericT, F > const &mat)
Helper routine for obtaining the internal number of entries per column of a ViennaCL matrix...
Definition: size.hpp:287
Tag class for indicating row-major layout of a matrix. Not passed to the matrix directly, see row_major type.
Definition: forwards.h:241
A tag for column-major storage of a dense matrix.
Definition: forwards.h:263
vcl_size_t internal_size1(matrix_base< NumericT, F > const &mat)
Helper routine for obtaining the internal number of entries per row of a ViennaCL matrix...
Definition: size.hpp:279
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
value_type & operator()(vcl_size_t i, vcl_size_t j)
Definition: common.hpp:116
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
A tag for row-major storage of a dense matrix.
Definition: forwards.h:246
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:107