ViennaCL - The Vienna Computing Library  1.5.2
set_arguments_functor.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_GENERATOR_ENQUEUE_TREE_HPP
2 #define VIENNACL_GENERATOR_ENQUEUE_TREE_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 
21 
26 #include <set>
27 
28 #include "viennacl/matrix.hpp"
29 #include "viennacl/vector.hpp"
30 
31 #include "viennacl/forwards.h"
34 
36 
38 
39 #include "viennacl/ocl/kernel.hpp"
40 
44 
45 
46 namespace viennacl{
47 
48  namespace generator{
49 
50  namespace detail{
51 
54  public:
55  typedef void result_type;
56 
57  set_arguments_functor(std::set<void *> & memory, unsigned int & current_arg, viennacl::ocl::kernel & kernel) : memory_(memory), current_arg_(current_arg), kernel_(kernel){ }
58 
59  template<class ScalarType>
60  result_type operator()(ScalarType const & scal) const {
61  typedef typename viennacl::result_of::cl_type<ScalarType>::type cl_scalartype;
62  kernel_.arg(current_arg_++, cl_scalartype(scal));
63  }
64 
66  template<class ScalarType>
67  result_type operator()(scalar<ScalarType> const & scal) const {
68  if(memory_.insert((void*)&scal).second)
69  kernel_.arg(current_arg_++, scal.handle().opencl_handle());
70  }
71 
73  template<class ScalarType>
74  result_type operator()(vector_base<ScalarType> const & vec) const {
75  if(memory_.insert((void*)&vec).second){
76  kernel_.arg(current_arg_++, vec.handle().opencl_handle());
77  if(viennacl::traits::start(vec)>0)
78  kernel_.arg(current_arg_++, cl_uint(viennacl::traits::start(vec)));
79  if(vec.stride()>1)
80  kernel_.arg(current_arg_++, cl_uint(viennacl::traits::stride(vec)));
81  }
82  }
83 
85  template<class ScalarType>
86  result_type operator()(implicit_vector_base<ScalarType> const & vec) const {
87  typedef typename viennacl::result_of::cl_type<ScalarType>::type cl_scalartype;
88  if(memory_.insert((void*)&vec).second){
89  if(vec.is_value_static()==false)
90  kernel_.arg(current_arg_++, cl_scalartype(vec.value()));
91  if(vec.has_index())
92  kernel_.arg(current_arg_++, cl_uint(vec.index()));
93  }
94  }
95 
97  template<class ScalarType, class Layout>
98  result_type operator()(matrix_base<ScalarType, Layout> const & mat) const {
99  //typedef typename matrix_base<ScalarType, Layout>::size_type size_type;
100  if(memory_.insert((void*)&mat).second){
101  kernel_.arg(current_arg_++, mat.handle().opencl_handle());
102  if(viennacl::traits::start1(mat)>0)
103  kernel_.arg(current_arg_++, cl_uint(viennacl::traits::start1(mat)));
104  if(viennacl::traits::stride1(mat)>1)
105  kernel_.arg(current_arg_++, cl_uint(viennacl::traits::stride1(mat)));
106  if(viennacl::traits::start2(mat)>0)
107  kernel_.arg(current_arg_++, cl_uint(viennacl::traits::start2(mat)));
108  if(viennacl::traits::stride2(mat)>1)
109  kernel_.arg(current_arg_++, cl_uint(viennacl::traits::stride2(mat)));
110  }
111  }
112 
114  template<class ScalarType>
115  result_type operator()(implicit_matrix_base<ScalarType> const & mat) const {
116  if(mat.is_value_static()==false)
117  kernel_.arg(current_arg_++, mat.value());
118  }
119 
121  void operator()(scheduler::statement const * /*statement*/, scheduler::statement_node const * root_node, detail::node_type node_type) const {
123  utils::call_on_element(root_node->lhs, *this);
124  else if(node_type==RHS_NODE_TYPE && root_node->rhs.type_family != scheduler::COMPOSITE_OPERATION_FAMILY)
125  utils::call_on_element(root_node->rhs, *this);
126  }
127 
128  private:
129  std::set<void *> & memory_;
130  unsigned int & current_arg_;
131  viennacl::ocl::kernel & kernel_;
132  };
133 
134  }
135 
136  }
137 
138 }
139 #endif
void arg(unsigned int pos, cl_char val)
Sets a char argument at the provided position.
Definition: kernel.hpp:124
void result_type
Definition: set_arguments_functor.hpp:55
result_of::size_type< matrix_base< NumericT, F > >::type stride2(matrix_base< NumericT, F > const &s)
Definition: stride.hpp:68
set_arguments_functor(std::set< void * > &memory, unsigned int &current_arg, viennacl::ocl::kernel &kernel)
Definition: set_arguments_functor.hpp:57
void operator()(scheduler::statement const *, scheduler::statement_node const *root_node, detail::node_type node_type) const
Traversal functor:
Definition: set_arguments_functor.hpp:121
bool is_value_static() const
Definition: vector.hpp:64
Internal utils for a dynamic OpenCL kernel generation.
Represents an OpenCL kernel within ViennaCL.
Definition: kernel.hpp:59
Implementation of the dense matrix class.
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Definition: forwards.h:172
lhs_rhs_element lhs
Definition: forwards.h:422
Common base class for representing vectors where the entries are not all stored explicitly.
Definition: forwards.h:190
result_of::size_type< viennacl::vector_base< T > >::type stride(viennacl::vector_base< T > const &s)
Definition: stride.hpp:46
This file provides the forward declarations for the main types used within ViennaCL.
result_of::size_type< T >::type start1(T const &obj)
Definition: start.hpp:64
lhs_rhs_element rhs
Definition: forwards.h:424
vcl_size_t index() const
Definition: vector.hpp:66
result_type operator()(ScalarType const &scal) const
Definition: set_arguments_functor.hpp:60
result_type operator()(scalar< ScalarType > const &scal) const
Scalar mapping.
Definition: set_arguments_functor.hpp:67
result_type operator()(vector_base< ScalarType > const &vec) const
Vector mapping.
Definition: set_arguments_functor.hpp:74
Helper class for setting the arguments of a kernel.
Definition: set_arguments_functor.hpp:53
Implementation of a shared pointer class (cf. std::shared_ptr, boost::shared_ptr). Will be used until C++11 is widely available.
A dense matrix class.
Definition: forwards.h:290
result_of::size_type< matrix_base< NumericT, F > >::type stride1(matrix_base< NumericT, F > const &s)
Definition: stride.hpp:57
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:29
several code generation helpers
result_of::size_type< T >::type start2(T const &obj)
Definition: start.hpp:83
Map ViennaCL objects to generator wrappers.
base functor class for traversing a statement
Definition: helpers.hpp:145
Base class for representing matrices where the individual entries are not all stored explicitly...
Definition: forwards.h:296
result_of::size_type< T >::type start(T const &obj)
Definition: start.hpp:43
cpu_value_type value() const
Definition: vector.hpp:62
handle_type & handle()
Returns the memory handle, non-const version.
Definition: scalar.hpp:704
Forwards declaration.
result_type operator()(implicit_matrix_base< ScalarType > const &mat) const
Implicit matrix mapping.
Definition: set_arguments_functor.hpp:115
bool is_value_static() const
Definition: matrix.hpp:57
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
handle_type & handle()
Returns the OpenCL handle, non-const-version.
Definition: matrix.hpp:654
result_type operator()(matrix_base< ScalarType, Layout > const &mat) const
Matrix mapping.
Definition: set_arguments_functor.hpp:98
T type
Definition: result_of.hpp:590
node_type
Definition: forwards.h:112
Representation of an OpenCL kernel in ViennaCL.
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
const handle_type & handle() const
Returns the memory handle.
Definition: vector.hpp:856
statement_node_type_family type_family
Definition: forwards.h:269
The main class for representing a statement such as x = inner_prod(y,z); at runtime.
Definition: forwards.h:447
result_type operator()(implicit_vector_base< ScalarType > const &vec) const
Implicit vector mapping.
Definition: set_arguments_functor.hpp:86
A collection of compile time type deductions.
SCALARTYPE value() const
Definition: matrix.hpp:56
Main datastructure for an node in the statement tree.
Definition: forwards.h:420
size_type stride() const
Returns the stride within the buffer (in multiples of sizeof(SCALARTYPE))
Definition: vector.hpp:849
bool has_index() const
Definition: vector.hpp:68