ViennaCL - The Vienna Computing Library  1.5.2
forwards.h
Go to the documentation of this file.
1 #ifndef VIENNACL_GENERATOR_FORWARDS_H
2 #define VIENNACL_GENERATOR_FORWARDS_H
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 <map>
27 #include <set>
28 #include <list>
29 #include <stdexcept>
30 
33 
34 namespace viennacl{
35 
36  namespace generator{
37 
38  inline void generate_enqueue_statement(viennacl::scheduler::statement const & s, scheduler::statement_node const & root_node);
40 
49  };
50 
63  };
64 
65  inline const char * expression_type_to_string(expression_type type){
66  switch(type){
67  case SCALAR_SAXPY_TYPE : return "Scalar SAXPY";
68  case VECTOR_SAXPY_TYPE : return "Vector SAXPY";
69  case MATRIX_SAXPY_TYPE : return "Matrix SAXPY";
70  case SCALAR_REDUCE_TYPE : return "Inner Product";
71  case VECTOR_REDUCE_Nx_TYPE : return "Matrix-Vector Product : Ax";
72  case VECTOR_REDUCE_Tx_TYPE : return "Matrix-Vector Product : Tx";
73  case MATRIX_PRODUCT_NN_TYPE : return "Matrix-Matrix Product : AA";
74  case MATRIX_PRODUCT_TN_TYPE : return "Matrix-Matrix Product : TA";
75  case MATRIX_PRODUCT_NT_TYPE : return "Matrix-Matrix Product : AT";
76  case MATRIX_PRODUCT_TT_TYPE : return "Matrix-Matrix Product : TT";
77  default : return "INVALID EXPRESSION";
78  }
79  }
80 
81  typedef std::pair<expression_type, vcl_size_t> expression_key_type;
82 
85  expression_key_type make_key() const { return expression_key_type(type,scalartype_size); }
86  bool operator==(expression_descriptor const & other) const
87  {
88  return type_family == other.type_family && type == other.type && scalartype_size==other.scalartype_size;
89  }
93  };
94 
96  template <typename KeyT, typename ValueT>
97  ValueT const & at(std::map<KeyT, ValueT> const & map, KeyT const & key)
98  {
99  typename std::map<KeyT, ValueT>::const_iterator it = map.find(key);
100  if (it != map.end())
101  return it->second;
102 
103  throw std::out_of_range("Generator: Key not found in map");
104  }
105 
106  namespace utils{
107  class kernel_generation_stream;
108  }
109 
110  namespace detail{
111 
112  enum node_type{
116  };
117 
119 
120  typedef std::pair<viennacl::scheduler::statement_node const *, node_type> key_type;
122  typedef std::map<key_type, container_ptr_type> mapping_type;
123 
124  template<class Fun>
125  static void traverse(viennacl::scheduler::statement const & statement, viennacl::scheduler::statement_node const & root_node, Fun const & fun, bool recurse_binary_leaf = true);
126  inline std::string generate(std::pair<std::string, std::string> const & index, int vector_element, mapped_object const & s);
127  static std::string & append_kernel_arguments(std::set<std::string> & already_generated, std::string & str, unsigned int vector_size, mapped_object const & s);
128  static void fetch(std::pair<std::string, std::string> const & index, unsigned int vectorization, std::set<std::string> & fetched, utils::kernel_generation_stream & stream, mapped_object & s);
129  inline const char * generate(viennacl::scheduler::operation_node_type type);
130  static void generate_all_rhs(viennacl::scheduler::statement const & statement
131  , viennacl::scheduler::statement_node const & root_node
132  , std::pair<std::string, std::string> const & index
133  , int vector_element
134  , std::string & str
135  , detail::mapping_type const & mapping);
136 
137  }
138 
139  }
140 
141 }
142 #endif
A stream class where the kernel sources are streamed to. Takes care of indentation of the sources...
Definition: utils.hpp:233
std::map< key_type, container_ptr_type > mapping_type
Definition: forwards.h:122
std::size_t vcl_size_t
Definition: forwards.h:58
expression_type
Definition: forwards.h:51
tools::shared_ptr< detail::mapped_object > container_ptr_type
Definition: forwards.h:121
expression_type_family
Definition: forwards.h:41
std::pair< viennacl::scheduler::statement_node const *, node_type > key_type
Definition: forwards.h:118
Base class for mapping viennacl datastructure to generator-friendly structures.
Definition: mapped_objects.hpp:41
ValueT const & at(std::map< KeyT, ValueT > const &map, KeyT const &key)
Emulation of C++11's .at() member for std::map<>
Definition: forwards.h:97
A class for holding meta information such as the type or the underlying scalar type of an expression ...
Definition: forwards.h:84
Implementation of a shared pointer class (cf. std::shared_ptr, boost::shared_ptr). Will be used until C++11 is widely available.
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:29
void generate_enqueue_statement(viennacl::scheduler::statement const &s, scheduler::statement_node const &root_node)
Generate and enqueue a statement plus root_node into the current queue.
Definition: generate.hpp:395
expression_key_type make_key() const
Definition: forwards.h:85
A shared pointer class similar to boost::shared_ptr. Reimplemented in order to avoid a Boost-dependen...
Definition: shared_ptr.hpp:83
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
operation_node_type
Enumeration for identifying the possible operations.
Definition: forwards.h:61
expression_type type
Definition: forwards.h:91
node_type
Definition: forwards.h:112
bool operator==(expression_descriptor const &other) const
Definition: forwards.h:86
const char * expression_type_to_string(expression_type type)
Definition: forwards.h:65
std::pair< expression_type, vcl_size_t > expression_key_type
Definition: forwards.h:81
The main class for representing a statement such as x = inner_prod(y,z); at runtime.
Definition: forwards.h:447
std::string generate(std::pair< std::string, std::string > const &index, int vector_element, mapped_object const &s)
Definition: mapped_objects.hpp:325
vcl_size_t scalartype_size
Definition: forwards.h:92
expression_type_family type_family
Definition: forwards.h:90
Main datastructure for an node in the statement tree.
Definition: forwards.h:420