1 #ifndef VIENNACL_GENERATOR_GENERATE_UTILS_HPP
2 #define VIENNACL_GENERATOR_GENERATE_UTILS_HPP
29 #include <OpenCL/cl.h>
47 static std::string generate_value_kernel_argument(std::string
const & scalartype, std::string
const & name){
48 return scalartype +
' ' + name +
",";
52 static std::string generate_pointer_kernel_argument(std::string
const & address_space, std::string
const & scalartype, std::string
const & name){
53 return address_space +
" " + scalartype +
"* " + name +
",";
73 default :
throw "not implemented";
110 fun.call_before_expansion();
112 traverse(statement, statement.
array()[root_node.
lhs.
node_index], fun, recurse_binary_leaf);
114 fun.call_after_expansion();
120 fun.call_before_expansion();
125 traverse(statement, statement.
array()[root_node.
lhs.
node_index], fun, recurse_binary_leaf);
135 traverse(statement, statement.
array()[root_node.
rhs.
node_index], fun, recurse_binary_leaf);
139 fun.call_after_expansion();
154 std::set<std::string> & already_generated_;
156 unsigned int vector_size_;
159 prototype_generation_traversal(std::set<std::string> & already_generated, std::string & str,
unsigned int vector_size,
mapping_type const & mapping) : already_generated_(already_generated), str_(str), vector_size_(vector_size), mapping_(mapping){ }
164 append_kernel_arguments(already_generated_, str_, vector_size_, *
at(mapping_, std::make_pair(root_node,node_type)));
171 std::set<std::string> & fetched_;
172 std::pair<std::string, std::string> index_string_;
173 unsigned int vectorization_;
177 fetch_traversal(std::set<std::string> & fetched, std::pair<std::string, std::string>
const & index,
unsigned int vectorization,
utils::kernel_generation_stream & stream,
mapping_type const & mapping) : fetched_(fetched), index_string_(index), vectorization_(vectorization), stream_(stream), mapping_(mapping){ }
182 fetch(index_string_, vectorization_, fetched_, stream_, *
at(mapping_, std::make_pair(root_node, node_type)));
190 static void fetch_all_lhs(std::set<std::string> & fetched
193 , std::pair<std::string, std::string>
const & index
200 detail::fetch(index, static_cast<unsigned int>(vectorization),fetched, stream, *
at(mapping, std::make_pair(&root_node,
detail::LHS_NODE_TYPE)));
208 static void fetch_all_rhs(std::set<std::string> & fetched
211 , std::pair<std::string, std::string>
const & index
213 , utils::kernel_generation_stream & stream
216 detail::traverse(statement, statement.
array()[root_node.
rhs.
node_index], detail::fetch_traversal(fetched, index, static_cast<unsigned int>(vectorization), stream, mapping));
218 detail::fetch(index, static_cast<unsigned int>(vectorization),fetched, stream, *
at(mapping, std::make_pair(&root_node,
detail::RHS_NODE_TYPE)));
226 std::pair<std::string, std::string> index_string_;
232 expression_generation_traversal(std::pair<std::string, std::string>
const & index,
int vector_element, std::string & str,
mapping_type const & mapping) : index_string_(index), vector_element_(vector_element), str_(str), mapping_(mapping){ }
241 str_ +=
generate(index_string_, vector_element_, *
at(mapping_, std::make_pair(root_node, node_type)));
248 str_ +=
detail::generate(index_string_,vector_element_, *
at(mapping_, std::make_pair(root_node,node_type)));
252 str_ +=
detail::generate(index_string_,vector_element_, *
at(mapping_, std::make_pair(root_node,node_type)));
260 , std::pair<std::string, std::string>
const & index
273 , std::pair<std::string, std::string>
const & index
278 detail::traverse(statement, statement.
array()[root_node.
rhs.
node_index], detail::expression_generation_traversal(index, vector_element, str, mapping));
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
Definition: forwards.h:83
void call_after_expansion() const
Definition: helpers.hpp:148
vcl_size_t node_index
Definition: forwards.h:276
Internal utils for a dynamic OpenCL kernel generation.
Definition: forwards.h:56
lhs_rhs_element lhs
Definition: forwards.h:422
expression_generation_traversal(std::pair< std::string, std::string > const &index, int vector_element, std::string &str, mapping_type const &mapping)
Definition: helpers.hpp:232
Definition: forwards.h:114
Definition: forwards.h:66
fetch_traversal(std::set< std::string > &fetched, std::pair< std::string, std::string > const &index, unsigned int vectorization, utils::kernel_generation_stream &stream, mapping_type const &mapping)
Definition: helpers.hpp:177
This file provides the forward declarations for the main types used within ViennaCL.
operation_node_type_family type_family
Definition: forwards.h:415
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
lhs_rhs_element rhs
Definition: forwards.h:424
void call_before_expansion() const
Definition: helpers.hpp:147
Definition: forwards.h:93
prototype_generation_traversal(std::set< std::string > &already_generated, std::string &str, unsigned int vector_size, mapping_type const &mapping)
Definition: helpers.hpp:159
void operator()(viennacl::scheduler::statement const *, viennacl::scheduler::statement_node const *root_node, detail::node_type node_type) const
Definition: helpers.hpp:237
void operator()(viennacl::scheduler::statement const *, viennacl::scheduler::statement_node const *root_node, detail::node_type node_type) const
Definition: helpers.hpp:179
functor for fetching the elements of a statement
Definition: helpers.hpp:169
base functor class for traversing a statement
Definition: helpers.hpp:145
functor for generating the prototype of a statement
Definition: helpers.hpp:152
Definition: forwards.h:92
Definition: forwards.h:113
Definition: forwards.h:98
Definition: forwards.h:89
Definition: forwards.h:99
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
node_type
Definition: forwards.h:112
Definition: forwards.h:90
Definition: forwards.h:115
Definition: forwards.h:96
Definition: forwards.h:100
container_type const & array() const
Definition: forwards.h:473
void operator()(viennacl::scheduler::statement const *, viennacl::scheduler::statement_node const *root_node, detail::node_type node_type) const
Definition: helpers.hpp:161
Definition: forwards.h:97
Definition: forwards.h:95
Definition: forwards.h:101
bool is_binary_leaf_operator(viennacl::scheduler::operation_node_type const &op_type)
checks whether an operator is both a binary node and a leaf
Definition: helpers.hpp:78
Definition: forwards.h:94
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
void call_after_expansion() const
Definition: helpers.hpp:235
std::string generate(std::pair< std::string, std::string > const &index, int vector_element, mapped_object const &s)
Definition: mapped_objects.hpp:325
Definition: forwards.h:57
void call_before_expansion() const
Definition: helpers.hpp:234
bool is_arithmetic_operator(viennacl::scheduler::operation_node_type const &op_type)
checks whether an operator is arithmetic or not
Definition: helpers.hpp:85
op_element op
Definition: forwards.h:423
Definition: forwards.h:91
functor for generating the expression string from a statement
Definition: helpers.hpp:224
Main datastructure for an node in the statement tree.
Definition: forwards.h:420
operation_node_type type
Definition: forwards.h:416
Definition: forwards.h:167