ViennaCL - The Vienna Computing Library  1.5.1
handle.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_TRAITS_HANDLE_HPP_
2 #define VIENNACL_TRAITS_HANDLE_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 
25 #include <string>
26 #include <fstream>
27 #include <sstream>
28 #include "viennacl/forwards.h"
29 
31 
32 namespace viennacl
33 {
34  namespace traits
35  {
36  //
37  // Generic memory handle
38  //
40  template <typename T>
42  {
43  return obj.handle();
44  }
45 
47  template <typename T>
48  viennacl::backend::mem_handle const & handle(T const & obj)
49  {
50  return obj.handle();
51  }
52 
54  inline char handle(char val) { return val; } //for unification purposes when passing CPU-scalars to kernels
55  inline short handle(short val) { return val; } //for unification purposes when passing CPU-scalars to kernels
56  inline int handle(int val) { return val; } //for unification purposes when passing CPU-scalars to kernels
57  inline long handle(long val) { return val; } //for unification purposes when passing CPU-scalars to kernels
58  inline float handle(float val) { return val; } //for unification purposes when passing CPU-scalars to kernels
59  inline double handle(double val) { return val; } //for unification purposes when passing CPU-scalars to kernels
60 
61  template <typename LHS, typename RHS, typename OP>
63  {
64  return handle(obj.lhs());
65  }
66 
67  template <typename LHS, typename RHS, typename OP>
69 
70  template <typename LHS, typename RHS, typename OP>
72 
73  template <typename LHS, typename RHS, typename OP>
75  {
76  return handle(obj.lhs());
77  }
78 
79  // proxy objects require extra care (at the moment)
80  template <typename T>
82  {
83  return obj.handle();
84  }
85 
86  template <typename T>
88  {
89  return obj.handle();
90  }
91 
92 
93 
94  template <typename T>
96  {
97  return obj.get().handle();
98  }
99 
100  template <typename T>
102  {
103  return obj.get().handle();
104  }
105 
106 
107  template <typename T>
109  {
110  return obj.get().handle();
111  }
112 
113  template <typename T>
115  {
116  return obj.get().handle();
117  }
118 
119  template <typename LHS, typename RHS, typename OP>
121  {
122  return handle(obj.lhs());
123  }
124 
125  template <typename LHS, typename RHS, typename OP>
127  {
128  return handle(obj.lhs());
129  }
130 
133  //
134  // RAM handle extraction
135  //
137  template <typename T>
139  {
140  return viennacl::traits::handle(obj).ram_handle();
141  }
142 
144  template <typename T>
146  {
147  return viennacl::traits::handle(obj).ram_handle();
148  }
149 
152  {
153  return h.ram_handle();
154  }
155 
157  {
158  return h.ram_handle();
159  }
162  //
163  // OpenCL handle extraction
164  //
165 #ifdef VIENNACL_WITH_OPENCL
166 
167  template <typename T>
168  viennacl::ocl::handle<cl_mem> & opencl_handle(T & obj)
169  {
170  return viennacl::traits::handle(obj).opencl_handle();
171  }
172 
174  template <typename T>
175  viennacl::ocl::handle<cl_mem> const & opencl_handle(T const & obj)
176  {
177  return viennacl::traits::handle(obj).opencl_handle();
178  }
179 
180  inline cl_char opencl_handle(char val) { return val; } //for unification purposes when passing CPU-scalars to kernels
181  inline cl_short opencl_handle(short val) { return val; } //for unification purposes when passing CPU-scalars to kernels
182  inline cl_int opencl_handle(int val) { return val; } //for unification purposes when passing CPU-scalars to kernels
183  inline cl_long opencl_handle(long val) { return val; } //for unification purposes when passing CPU-scalars to kernels
184  inline cl_uchar opencl_handle(unsigned char val) { return val; } //for unification purposes when passing CPU-scalars to kernels
185  inline cl_ushort opencl_handle(unsigned short val) { return val; } //for unification purposes when passing CPU-scalars to kernels
186  inline cl_uint opencl_handle(unsigned int val) { return val; } //for unification purposes when passing CPU-scalars to kernels
187  inline cl_ulong opencl_handle(unsigned long val) { return val; } //for unification purposes when passing CPU-scalars to kernels
188  inline float opencl_handle(float val) { return val; } //for unification purposes when passing CPU-scalars to kernels
189  inline double opencl_handle(double val) { return val; } //for unification purposes when passing CPU-scalars to kernels
190 
191 
192 #endif
193 
194 
195 
196  //
197  // Active handle ID
198  //
200  template <typename T>
202  {
203  return handle(obj).get_active_handle_id();
204  }
205 
207  template <typename T>
209 
210  template <typename T>
211  viennacl::memory_types active_handle_id(hankel_matrix<T> const &) { return OPENCL_MEMORY; }
212 
213  template <typename T>
214  viennacl::memory_types active_handle_id(toeplitz_matrix<T> const &) { return OPENCL_MEMORY; }
215 
216  template <typename T>
217  viennacl::memory_types active_handle_id(vandermonde_matrix<T> const &) { return OPENCL_MEMORY; }
218 
219  template <typename LHS, typename RHS, typename OP>
221 
222  template <typename LHS, typename RHS, typename OP>
224  {
225  return active_handle_id(obj.lhs());
226  }
227 
228  template <typename LHS, typename RHS, typename OP>
230  {
231  return active_handle_id(obj.lhs());
232  }
233 
234  template <typename LHS, typename RHS, typename OP>
236  {
237  return active_handle_id(obj.lhs());
238  }
241  } //namespace traits
242 } //namespace viennacl
243 
244 
245 #endif
ram_handle_type & ram_handle()
Returns the handle to a buffer in CPU RAM. NULL is returned if no such buffer has been allocated...
Definition: mem_handle.hpp:72
Class for representing strided submatrices of a bigger matrix A.
Definition: forwards.h:358
LHS & lhs() const
Returns the left hand side operand.
Definition: scalar.hpp:56
Expression template class for representing a tree of expressions which ultimately result in a matrix...
Definition: forwards.h:283
This file provides the forward declarations for the main types used within ViennaCL.
A proxy for scalar expressions (e.g. from inner vector products)
Definition: forwards.h:175
An expression template class that represents a binary operation that yields a vector.
Definition: forwards.h:181
memory_types
Definition: forwards.h:476
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:91
Definition: forwards.h:480
lhs_reference_type lhs() const
Get left hand side operand.
Definition: vector.hpp:181
Implements the multi-memory-domain handle.
Common base class for dense vectors, vector ranges, and vector slices.
Definition: forwards.h:205
viennacl::memory_types active_handle_id(T const &obj)
Returns an ID for the currently active memory domain of an object.
Definition: handle.hpp:201
handle_type & handle()
Returns the OpenCL handle, non-const-version.
Definition: matrix.hpp:654
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:62
A Circulant matrix class.
Definition: circulant_matrix.hpp:41
Class for representing non-strided submatrices of a bigger matrix A.
Definition: forwards.h:355
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
LHS & lhs() const
Get left hand side operand.
Definition: matrix.hpp:174
const handle_type & handle() const
Returns the memory handle.
Definition: vector.hpp:878
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