ViennaCL - The Vienna Computing Library: viennacl/linalg/host_based/common.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
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-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 "viennacl/traits/handle.hpp"
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>
50 class vector_array_wrapper
51 {
52 public:
53 typedef NumericT value_type;
54
55 vector_array_wrapper(value_type * A,
56 vcl_size_t start,
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>
73 class matrix_array_wrapper
74 {
75 public:
76 typedef NumericT value_type;
77
78 matrix_array_wrapper(value_type * A,
79 vcl_size_t start1, vcl_size_t start2,
80 vcl_size_t inc1, vcl_size_t inc2,
81 vcl_size_t internal_size1, vcl_size_t internal_size2)
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,
114 vcl_size_t start1, vcl_size_t start2,
115 vcl_size_t inc1, vcl_size_t inc2,
116 vcl_size_t internal_size1, vcl_size_t internal_size2)
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
viennacl::linalg::host_based::detail::matrix_array_wrapper::operator()
value_type & operator()(vcl_size_t i, vcl_size_t j)
Definition: common.hpp:87
viennacl::linalg::host_based::detail::vector_array_wrapper::value_type
NumericT value_type
Definition: common.hpp:53
viennacl::linalg::host_based::detail::vector_array_wrapper
Helper class for accessing a strided subvector of a larger vector.
Definition: common.hpp:50
viennacl::linalg::host_based::detail::matrix_array_wrapper::operator()
value_type & operator()(long i, long j)
Definition: common.hpp:97
viennacl::linalg::host_based::detail::matrix_array_wrapper::value_type
NumericT value_type
Definition: common.hpp:76
viennacl::linalg::host_based::detail::matrix_array_wrapper::operator()
value_type & operator()(vcl_size_t i, long j)
Definition: common.hpp:95
viennacl::traits::internal_size1
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:386
viennacl::linalg::host_based::detail::matrix_array_wrapper::operator()
value_type & operator()(long i, vcl_size_t j)
Definition: common.hpp:96
viennacl::traits::internal_size2
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:394
viennacl::traits::start1
result_of::size_type< T >::type start1(T const &obj)
Definition: start.hpp:65
NumericT
float NumericT
Definition: bisect.cpp:40
viennacl::linalg::host_based::detail::matrix_array_wrapper::matrix_array_wrapper
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
viennacl::traits::start2
result_of::size_type< T >::type start2(T const &obj)
Definition: start.hpp:84
viennacl::linalg::host_based::detail::matrix_array_wrapper
Helper array for accessing a strided submatrix embedded in a larger matrix.
Definition: common.hpp:73
viennacl::traits::start
result_of::size_type< T >::type start(T const &obj)
Definition: start.hpp:44
viennacl::linalg::host_based::detail::vector_array_wrapper::vector_array_wrapper
vector_array_wrapper(value_type *A, vcl_size_t start, vcl_size_t inc)
Definition: common.hpp:55
viennacl::linalg::host_based::detail::vector_array_wrapper::operator()
value_type & operator()(vcl_size_t i)
Definition: common.hpp:62
viennacl::linalg::host_based::detail::extract_raw_pointer
ResultT * extract_raw_pointer(VectorT &vec)
Definition: common.hpp:37
viennacl::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
viennacl::tools::shared_ptr::get
T * get() const
Definition: shared_ptr.hpp:101
handle.hpp
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
viennacl::traits::ram_handle
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