1 #ifndef VIENNACL_DEVICE_SPECIFIC_TREE_PARSING_HPP
2 #define VIENNACL_DEVICE_SPECIFIC_TREE_PARSING_HPP
37 namespace device_specific
39 namespace tree_parsing
57 fun.call_before_expansion(statement, root_idx);
80 fun.call_after_expansion(statement, root_idx);
88 filter(
pred_t pred, std::vector<vcl_size_t> & out) : pred_(pred), out_(out){ }
93 if (pred_(*root_node))
94 out_.push_back(root_idx);
98 std::vector<vcl_size_t> & out_;
110 out_.push_back(root_node->
lhs);
112 out_.push_back(root_node->
rhs);
116 std::vector<scheduler::lhs_rhs_element> & out_;
122 using namespace scheduler;
206 using namespace scheduler;
240 std::map<std::string, std::string>
const & accessors_;
265 mapping_type::key_type key = std::make_pair(root_idx, leaf);
269 str_ += mapping_.at(key)->evaluate(accessors_);
280 str_ += mapping_.at(key)->evaluate(accessors_);
286 str_ += mapping_.at(key)->evaluate(accessors_);
292 inline std::string
evaluate(
leaf_t leaf, std::map<std::string, std::string>
const & accessors,
304 traversal_functor(statement, root_idx, leaf);
311 traversal_functor(statement, root_idx, leaf);
322 statements_container::data_type::const_iterator sit;
323 std::vector<mapping_type>::const_iterator mit;
325 for (mit = mappings.begin(), sit = statements.
data().begin(); sit != statements.
data().end(); ++mit, ++sit)
326 stream <<
evaluate(leaf, accessors, *sit, sit->root(), *mit) <<
";" << std::endl;
335 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){ }
339 mapping_type::const_iterator it = mapping_.find(std::make_pair(root_idx, leaf));
340 if (it!=mapping_.end())
345 if (already_processed_.insert(obj->
process(
"#name")).second)
346 stream_ << obj->
process(to_process_) << std::endl;
352 std::string
const & type_key_;
353 std::string
const & to_process_;
356 std::set<std::string> & already_processed_;
370 traversal_functor(statement, root_idx, leaf);
377 traversal_functor(statement, root_idx, leaf);
388 statements_container::data_type::const_iterator sit;
389 std::vector<mapping_type>::const_iterator mit;
390 std::set<std::string> already_processed;
392 for (mit = mappings.begin(), sit = statements.
data().begin(); sit != statements.
data().end(); ++mit, ++sit)
393 process(stream, leaf, type_key, to_process, *sit, sit->root(), *mit, already_processed);
399 static void append_id(
char * & ptr,
unsigned int val)
406 *ptr++= (char)(
'0' + (val % 10));
416 template<
class NumericT>
425 template<
class NumericT>
434 template<
class NumericT>
443 template<
class NumericT>
452 template<
class NumericT>
462 template<
class NumericT>
470 static inline void append(
char*& p,
const char * str)
473 std::memcpy(p, str, n);
481 utils::call_on_element(root_node.
lhs, *
this);
483 utils::call_on_element(root_node.
rhs, *
this);
485 append_id(ptr_,root_node.
op.
type);
495 std::vector<char> program_name_vector(256);
496 char* program_name = program_name_vector.data();
502 for (statements_container::data_type::const_iterator it = statements.
data().begin(); it != statements.
data().end(); ++it)
505 return std::string(program_name_vector.data());
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)
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
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)