1 #ifndef VIENNACL_DEVICE_SPECIFIC_TREE_PARSING_HPP
2 #define VIENNACL_DEVICE_SPECIFIC_TREE_PARSING_HPP
38 namespace device_specific
40 namespace tree_parsing
58 fun.call_before_expansion(statement, root_idx);
81 fun.call_after_expansion(statement, root_idx);
89 filter(
pred_t pred, std::vector<vcl_size_t> & out) : pred_(pred), out_(out){ }
94 if (pred_(*root_node))
95 out_.push_back(root_idx);
99 std::vector<vcl_size_t> & out_;
111 out_.push_back(root_node->
lhs);
113 out_.push_back(root_node->
rhs);
117 std::vector<scheduler::lhs_rhs_element> & out_;
123 using namespace scheduler;
207 using namespace scheduler;
241 std::map<std::string, std::string>
const & accessors_;
266 mapping_type::key_type key = std::make_pair(root_idx, leaf);
270 str_ +=
at(mapping_, key)->evaluate(accessors_);
281 str_ +=
at(mapping_, key)->evaluate(accessors_);
287 str_ +=
at(mapping_, key)->evaluate(accessors_);
293 inline std::string
evaluate(
leaf_t leaf, std::map<std::string, std::string>
const & accessors,
305 traversal_functor(statement, root_idx, leaf);
312 traversal_functor(statement, root_idx, leaf);
323 statements_container::data_type::const_iterator sit;
324 std::vector<mapping_type>::const_iterator mit;
326 for (mit = mappings.begin(), sit = statements.
data().begin(); sit != statements.
data().end(); ++mit, ++sit)
327 stream <<
evaluate(leaf, accessors, *sit, sit->root(), *mit) <<
";" << std::endl;
336 mapping_type const & mapping, std::set<std::string> & already_processed) : type_key_(type_key), to_process_(to_process), stream_(stream), mapping_(mapping), already_processed_(already_processed){ }
340 mapping_type::const_iterator it = mapping_.find(std::make_pair(root_idx, leaf));
341 if (it!=mapping_.end())
346 if (already_processed_.insert(obj->
process(
"#name")).second)
347 stream_ << obj->
process(to_process_) << std::endl;
353 std::string
const & type_key_;
354 std::string
const & to_process_;
357 std::set<std::string> & already_processed_;
371 traversal_functor(statement, root_idx, leaf);
378 traversal_functor(statement, root_idx, leaf);
389 statements_container::data_type::const_iterator sit;
390 std::vector<mapping_type>::const_iterator mit;
391 std::set<std::string> already_processed;
393 for (mit = mappings.begin(), sit = statements.
data().begin(); sit != statements.
data().end(); ++mit, ++sit)
394 process(stream, leaf, type_key, to_process, *sit, sit->root(), *mit, already_processed);
400 static void append_id(
char * & ptr,
unsigned int val)
407 *ptr++= (char)(
'0' + (val % 10));
417 template<
class NumericT>
426 template<
class NumericT>
435 template<
class NumericT>
444 template<
class NumericT>
453 template<
class NumericT>
463 template<
class NumericT>
471 static inline void append(
char*& p,
const char * str)
474 std::memcpy(p, str, n);
482 utils::call_on_element(root_node.
lhs, *
this);
484 utils::call_on_element(root_node.
rhs, *
this);
486 append_id(ptr_,root_node.
op.
type);
496 std::vector<char> program_name_vector(256);
497 char* program_name = &(program_name_vector[0]);
503 for (statements_container::data_type::const_iterator it = statements.
data().begin(); it != statements.
data().end(); ++it)
506 return std::string(&(program_name_vector[0]));
evaluate_expression_traversal(std::map< std::string, std::string > const &accessors, std::string &str, mapping_type const &mapping)
void operator()(scheduler::statement const &statement, vcl_size_t root_idx, leaf_t leaf) const
std::string type_key() const
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
void call_before_expansion(scheduler::statement const &, vcl_size_t) const
void call_before_expansion(scheduler::statement const &statement, vcl_size_t root_idx) const
void operator()(scheduler::statement const &statement, vcl_size_t root_idx, leaf_t) const
Exception for the case the generator is unable to deal with the operation.
process_traversal(std::string const &type_key, std::string const &to_process, utils::kernel_generation_stream &stream, mapping_type const &mapping, std::set< std::string > &already_processed)
result_type operator()(NumericT const &) const
void traverse(scheduler::statement const &statement, vcl_size_t root_idx, Fun const &fun, bool inspect)
Recursively execute a functor on a statement.
statement_node_subtype subtype
bool elementwise_operator(scheduler::op_element const &op)
This file provides the forward declarations for the main types used within ViennaCL.
statement_node_type_family type_family
container_type const & array() const
std::list< scheduler::statement > const & data() const
bool node_leaf(scheduler::op_element const &op)
operation_node_type_family type_family
bool(* pred_t)(scheduler::statement_node const &node)
result_type operator()(matrix_base< NumericT > const &mat) const
Matrix mapping.
void operator()(scheduler::statement const &statement, vcl_size_t root_idx, leaf_t) const
statement_node_subtype
Encodes the type of a node in the statement tree.
static void append(char *&p, const char *str)
Base class for representing matrices where the individual entries are not all stored explicitly...
bool elementwise_function(scheduler::op_element const &op)
Map ViennaCL objects to generator wrappers.
result_type operator()(implicit_vector_base< NumericT > const &) const
Implicit vector mapping.
std::string evaluate(leaf_t leaf, std::map< std::string, std::string > const &accessors, scheduler::statement const &statement, vcl_size_t root_idx, mapping_type const &mapping)
statement_representation_functor(symbolic_binder &binder, char *&ptr)
virtual unsigned int get(viennacl::backend::mem_handle const *ph)=0
std::string process(std::string const &in) const
base functor class for traversing a statement
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
functor for fetching or writing-back the elements in a statement
operation_node_type
Enumeration for identifying the possible operations.
result_type operator()(implicit_matrix_base< NumericT > const &) const
Implicit matrix mapping.
std::map< mapping_key, tools::shared_ptr< mapped_object > > mapping_type
std::string statements_representation(statements_container const &statements, binding_policy_t binding_policy)
void operator()(scheduler::statement const &statement, vcl_size_t root_idx, leaf_t leaf_t) const
result_type operator()(vector_base< NumericT > const &vec) const
Vector mapping.
filter(pred_t pred, std::vector< vcl_size_t > &out)
result_type operator()(scalar< NumericT > const &scal) const
Scalar mapping.
void call_after_expansion(scheduler::statement const &, vcl_size_t) const
void call_after_expansion(scheduler::statement const &, vcl_size_t) const
The main class for representing a statement such as x = inner_prod(y,z); at runtime.
Common base class for representing vectors where the entries are not all stored explicitly.
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
const char * operator_string(scheduler::operation_node_type type)
void operator()(scheduler::statement const &, vcl_size_t root_idx, leaf_t leaf) const
ValueT const & at(std::map< KeyT, ValueT > const &map, KeyT const &key)
Emulation of C++11's .at() member for std::map<>, const-version.
Main datastructure for an node in the statement tree.
tools::shared_ptr< symbolic_binder > make_binder(binding_policy_t policy)
functor for generating the expression string from a statement
void process(utils::kernel_generation_stream &stream, leaf_t leaf, std::string const &type_key, std::string const &to_process, scheduler::statement const &statement, vcl_size_t root_idx, mapping_type const &mapping, std::set< std::string > &already_processed)
filter_elements(scheduler::statement_node_subtype subtype, std::vector< scheduler::lhs_rhs_element > &out)