1 #ifndef VIENNACL_DEVICE_SPECIFIC_MAPPED_TYPE_HPP
2 #define VIENNACL_DEVICE_SPECIFIC_MAPPED_TYPE_HPP
35 namespace device_specific
46 virtual void postprocess(std::string &)
const { }
56 while ((pos=str.find(
"$OFFSET", pos))!=std::string::npos)
58 std::string postprocessed;
62 if (
MorphBase2D const * p2d = dynamic_cast<MorphBase2D const *>(&morph))
65 std::string i = str.substr(pos_po + 1, pos_comma - pos_po - 1);
66 std::string j = str.substr(pos_comma + 1, pos_pe - pos_comma - 1);
67 postprocessed = (*p2d)(i, j);
69 else if (
MorphBase1D const * p1d = dynamic_cast<MorphBase1D const *>(&morph))
71 std::string i = str.substr(pos_po + 1, pos_pe - pos_po - 1);
72 postprocessed = (*p1d)(i);
75 str.replace(pos, pos_pe + 1 - pos, postprocessed);
80 void register_attribute(std::string & attribute, std::string
const & key, std::string
const & value)
111 std::string
process(std::string
const & in)
const
114 for (std::map<std::string,std::string>::const_iterator it =
keywords_.begin(); it !=
keywords_.end(); ++it)
120 std::string
evaluate(std::map<std::string, std::string>
const & accessors)
const
122 if (accessors.find(
type_key_)==accessors.end())
225 if (already_generated.insert(
name_).second)
238 virtual void append_optional_arguments(std::string &)
const = 0;
248 if (already_generated.insert(
name_).second)
251 append_optional_arguments(str);
257 std::string pointer_;
268 void append_optional_arguments(std::string &)
const{ }
290 void append_optional_arguments(std::string & str)
const
292 str += generate_value_kernel_argument(
"unsigned int", start_);
293 str += generate_value_kernel_argument(
"unsigned int", stride_);
315 void append_optional_arguments(std::string & str)
const
317 str += generate_value_kernel_argument(
"unsigned int", ld_);
318 str += generate_value_kernel_argument(
"unsigned int", start1_);
319 str += generate_value_kernel_argument(
"unsigned int", start2_);
320 str += generate_value_kernel_argument(
"unsigned int", stride1_);
321 str += generate_value_kernel_argument(
"unsigned int", stride2_);
324 void postprocess(std::string & str)
const
328 Morph(
bool _is_row_major, std::string
const & _ld) :
is_row_major(_is_row_major),
ld(_ld){ }
329 std::string operator()(std::string
const & i, std::string
const & j)
const
332 return "(" + i +
") * " +
ld +
" + (" + j +
")";
333 return "(" + i +
") + (" + j +
") * " +
ld;
337 std::string
const &
ld;
371 std::string stride1_;
372 std::string stride2_;
383 void postprocess(std::string &res)
const
385 std::map<std::string, std::string> accessors;
387 accessors[
"vector"] = res;
403 void postprocess(std::string &res)
const
405 std::map<std::string, std::string> accessors;
406 accessors[
"matrix"] = res;
421 void postprocess(std::string &res)
const
423 std::map<std::string, std::string> accessors;
425 accessors[
"matrix"] = res;
442 void postprocess(std::string &res)
const
444 std::map<std::string, std::string> accessors;
446 accessors[
"matrix"] = res;
462 void postprocess(std::string &res)
const
464 std::map<std::string, std::string> accessors;
466 accessors[
"matrix"] = res;
std::string & append_kernel_arguments(std::set< std::string > &, std::string &str, unsigned int width) const
mapped_implicit_matrix(std::string const &scalartype, unsigned int id)
std::string & append_kernel_arguments(std::set< std::string > &already_generated, std::string &str, unsigned int width) const
std::string type_key() const
vcl_size_t root_idx() const
Helper class for checking whether a matrix has a row-major layout.
std::string evaluate_recursive(leaf_t leaf, std::map< std::string, std::string > const &accessors)
std::string & append_kernel_arguments(std::set< std::string > &already_generated, std::string &str, unsigned int width) const
mapped_handle(std::string const &scalartype, unsigned int id, std::string const &type_key)
virtual std::string & append_kernel_arguments(std::set< std::string > &, std::string &str, unsigned int) const
std::string & append_kernel_arguments(std::set< std::string > &, std::string &str, unsigned int width) const
container_type const & array() const
std::string evaluate(std::map< std::string, std::string > const &accessors) const
Struct for holding the type family as well as the type of an operation (could be addition, subtraction, norm, etc.)
mapped_implicit_vector(std::string const &scalartype, unsigned int id)
virtual std::string operator()(std::string const &i, std::string const &j) const =0
mapped_matrix_product(std::string const &scalartype, unsigned int id, node_info info)
mapped_matrix_diag(std::string const &scalartype, unsigned int id, node_info info)
mapped_trans(std::string const &scalartype, unsigned int id, node_info info)
vcl_size_t ld(matrix_base< NumericT > const &mat)
Helper routine for obtaining the internal number of entries per row of a ViennaCL matrix...
mapping_type const * mapping
virtual std::string operator()(std::string const &i) const =0
void register_attribute(std::string &attribute, std::string const &key, std::string const &value)
bool is_index_reduction() const
mapped_host_scalar(std::string const &scalartype, unsigned int id)
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)
std::map< std::string, std::string > keywords_
binary_leaf(mapped_object::node_info info)
std::string process(std::string const &in) const
mapped_vector(std::string const &scalartype, unsigned int id)
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value >::type swap(ScalarT1 &s1, ScalarT2 &s2)
Swaps the contents of two scalars, data is copied.
node_info(mapping_type const *_mapping, scheduler::statement const *_statement, vcl_size_t _root_idx)
mapped_matrix_row(std::string const &scalartype, unsigned int id, node_info info)
std::map< mapping_key, tools::shared_ptr< mapped_object > > mapping_type
mapped_row_wise_reduction(std::string const &scalartype, unsigned int id, node_info info)
mapped_matrix(std::string const &scalartype, unsigned int id, bool row_major)
mapped_buffer(std::string const &scalartype, unsigned int id, std::string const &type_key)
mapped_object(std::string const &scalartype, unsigned int id, std::string const &type_key)
mapped_scalar_reduction(std::string const &scalartype, unsigned int id, node_info info)
void process_recursive(utils::kernel_generation_stream &stream, leaf_t leaf, std::string const &key, std::string const &process_str, std::set< std::string > &already_fetched)
bool is_index_reduction(scheduler::op_element const &op)
mapped_scalar(std::string const &scalartype, unsigned int id)
mapped_vector_diag(std::string const &scalartype, unsigned int id, node_info info)
The main class for representing a statement such as x = inner_prod(y,z); at runtime.
scheduler::op_element root_op() const
mapped_object::node_info info_
ValueT const & at(std::map< KeyT, ValueT > const &map, KeyT const &key)
Emulation of C++11's .at() member for std::map<>, const-version.
std::string const & name() const
mapped_reduction(std::string const &scalartype, unsigned int id, node_info info, std::string const &type_key)
static void replace_offset(std::string &str, MorphBase const &morph)
A tag for row-major storage of a dense matrix.
scheduler::statement const & statement() const
Main datastructure for an node in the statement tree.
mapped_matrix_column(std::string const &scalartype, unsigned int id, node_info info)
scheduler::statement_node root_node() const
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)
std::string append_width(std::string const &str, unsigned int width)
scheduler::statement const * statement