1 #ifndef VIENNACL_GENERATOR_MAPPED_TYPE_HPP
2 #define VIENNACL_GENERATOR_MAPPED_TYPE_HPP
45 node_info() : mapping(NULL), statement(NULL), root_node(NULL) { }
51 virtual std::string
generate_default(std::pair<std::string, std::string>
const & index)
const = 0;
56 virtual std::string &
append_kernel_arguments(std::set<std::string> &, std::string & str,
unsigned int)
const{
return str; }
60 virtual std::string
generate(std::pair<std::string, std::string>
const & index,
int)
const{
80 std::string
generate_default(std::pair<std::string, std::string>
const &)
const {
return "";}
118 std::string generate_default(std::pair<std::string, std::string>
const &)
const{
return name_; }
121 std::string
const &
name() {
return name_; }
123 if(already_generated.insert(name_).second)
124 str += detail::generate_value_kernel_argument(
scalartype_, name_);
134 virtual std::string offset(std::pair<std::string, std::string>
const & index)
const = 0;
135 virtual void append_optional_arguments(std::string &)
const{ }
136 std::string generate_default(std::pair<std::string, std::string>
const & index)
const{
return name_ +
'[' + offset(index) +
']'; }
143 std::string new_access_name =
name_ +
"_private";
144 if(fetched.find(
name_)==fetched.end()){
146 if(vectorization > 1) stream << vectorization;
147 stream <<
" " << new_access_name <<
" = " << generate_default(index) <<
';' << std::endl;
148 fetched.insert(
name_);
156 if(fetched.find(
name_)!=fetched.end()){
157 stream << generate_default(index) <<
" = " << old_access_name <<
';' << std::endl;
158 fetched.erase(
name_);
162 std::string &
append_kernel_arguments(std::set<std::string> & already_generated, std::string & str,
unsigned int vector_size)
const{
163 if(already_generated.insert(
name_).second){
165 str += detail::generate_pointer_kernel_argument(
"__global", vector_scalartype,
name_);
166 append_optional_arguments(str);
179 std::string offset(std::pair<std::string, std::string>
const &)
const {
return "0"; }
196 virtual std::string
generate(std::pair<std::string, std::string>
const & index,
int vector_element)
const{
197 if(vector_element>-1)
207 std::string offset(std::pair<std::string, std::string>
const & index)
const {
210 detail::generate_all_rhs(*info_.statement, *info_.root_node, index, -1, str, *info_.mapping);
217 void append_optional_arguments(std::string & str)
const{
218 if(!start_name_.empty())
219 str += detail::generate_value_kernel_argument(
"unsigned int", start_name_);
220 if(!stride_name_.empty())
221 str += detail::generate_value_kernel_argument(
"unsigned int", stride_name_);
222 if(!shift_name_.empty())
223 str += detail::generate_value_kernel_argument(
"unsigned int", shift_name_);
230 std::string start_name_;
231 std::string stride_name_;
232 std::string shift_name_;
238 void append_optional_arguments(std::string & str)
const{
239 if(!start1_name_.empty())
240 str += detail::generate_value_kernel_argument(
"unsigned int", start1_name_);
241 if(!stride1_name_.empty())
242 str += detail::generate_value_kernel_argument(
"unsigned int", stride1_name_);
243 if(!start2_name_.empty())
244 str += detail::generate_value_kernel_argument(
"unsigned int", start2_name_);
245 if(!stride2_name_.empty())
246 str += detail::generate_value_kernel_argument(
"unsigned int", stride2_name_);
253 std::string
const &
size1()
const {
return size1_; }
255 std::string
const &
size2()
const {
return size2_; }
262 std::string
offset(std::pair<std::string, std::string>
const & index)
const {
263 std::string i = index.first;
264 std::string j = index.second;
267 return '(' + i +
')' +
'*' + size2_;
269 return '(' + i +
')' +
'*' + size2_ +
"+ (" + j +
')';
272 return "(" + j +
')' +
'*' + size1_;
274 return '(' + i +
')' +
"+ (" + j +
')' +
'*' + size1_;
278 mutable std::string size1_;
279 mutable std::string size2_;
281 std::string start1_name_;
282 std::string stride1_name_;
283 std::string shift1_name_;
284 std::string start2_name_;
285 std::string stride2_name_;
286 std::string shift2_name_;
293 std::string value_name_;
294 std::string index_name_;
301 if(!value_name_.empty())
302 str += detail::generate_value_kernel_argument(
scalartype_, value_name_);
303 if(!index_name_.empty())
304 str += detail::generate_value_kernel_argument(
"unsigned int", index_name_);
312 std::string value_name_;
319 if(!value_name_.empty())
320 str += detail::generate_value_kernel_argument(
scalartype_, value_name_);
325 inline std::string
generate(std::pair<std::string, std::string>
const & index,
int vector_element,
mapped_object const & s){
326 return s.
generate(index, vector_element);
329 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){
330 if(mapped_handle * p = dynamic_cast<mapped_handle *>(&s))
331 p->fetch(index, vectorization, fetched, stream);
334 static std::string & append_kernel_arguments(std::set<std::string> & already_generated, std::string & str,
unsigned int vector_size, mapped_object
const & s){
335 return s.append_kernel_arguments(already_generated, str, vector_size);
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::string access_name_
Definition: mapped_objects.hpp:68
mapped_handle(std::string const &scalartype)
Definition: mapped_objects.hpp:138
mapped_matrix(std::string const &scalartype)
Definition: mapped_objects.hpp:249
std::string generate_default(std::pair< std::string, std::string > const &) const
Definition: mapped_objects.hpp:297
node_info info_
Definition: mapped_objects.hpp:82
Internal utils for a dynamic OpenCL kernel generation.
std::string offset(std::pair< std::string, std::string > const &index) const
Definition: mapped_objects.hpp:262
scheduler::statement_node const & root_node() const
Definition: mapped_objects.hpp:79
viennacl::scheduler::operation_node_type reduction_type() const
Definition: mapped_objects.hpp:96
Base class for datastructures passed by pointer.
Definition: mapped_objects.hpp:133
Mapping of a matrix to a generator class.
Definition: mapped_objects.hpp:236
Base class for mapping viennacl datastructure to generator-friendly structures.
Definition: mapped_objects.hpp:41
virtual std::string generate(std::pair< std::string, std::string > const &index, int) const
Definition: mapped_objects.hpp:60
Mapping of a scalar reduction (based on inner product)
Definition: mapped_objects.hpp:102
Base class for mapping a reduction.
Definition: mapped_objects.hpp:93
std::string const & size2() const
Definition: mapped_objects.hpp:255
void write_back(std::pair< std::string, std::string > const &index, std::set< std::string > &fetched, utils::kernel_generation_stream &stream)
Definition: mapped_objects.hpp:153
mapped_host_scalar(std::string const &scalartype)
Definition: mapped_objects.hpp:120
std::string const & name() const
Definition: mapped_objects.hpp:140
std::string name_
Definition: mapped_objects.hpp:172
Mapping of a scalar to a generator class.
Definition: mapped_objects.hpp:176
virtual std::string generate(std::pair< std::string, std::string > const &index, int vector_element) const
Definition: mapped_objects.hpp:196
mapped_vector_reduction(std::string const &scalartype)
Definition: mapped_objects.hpp:112
virtual std::string & append_kernel_arguments(std::set< std::string > &, std::string &str, unsigned int) const
Definition: mapped_objects.hpp:56
std::string const & access_name() const
Definition: mapped_objects.hpp:59
void fetch(std::pair< std::string, std::string > const &index, unsigned int vectorization, std::set< std::string > &fetched, utils::kernel_generation_stream &stream)
Definition: mapped_objects.hpp:142
std::string const & size1() const
Definition: mapped_objects.hpp:253
mapped_vector(std::string const &scalartype)
Definition: mapped_objects.hpp:226
mapped_matrix_product(std::string const &scalartype)
Definition: mapped_objects.hpp:89
std::string & append_kernel_arguments(std::set< std::string > &already_generated, std::string &str, unsigned int vector_size) const
Definition: mapped_objects.hpp:162
bool is_row_major() const
Definition: mapped_objects.hpp:251
Functor to map the statements to the types defined in mapped_objects.hpp.
Definition: map_functor.hpp:47
mapped_buffer(std::string const &scalartype)
Definition: mapped_objects.hpp:195
void access_name(std::string const &str)
Definition: mapped_objects.hpp:58
mapped_implicit_vector(std::string const &scalartype)
Definition: mapped_objects.hpp:296
virtual std::string append_vector_size(std::string const &scalartype, unsigned int) const
Definition: mapped_objects.hpp:52
mapped_scalar_reduction(std::string const &scalartype)
Definition: mapped_objects.hpp:105
mapped_implicit_matrix(std::string const &scalartype)
Definition: mapped_objects.hpp:314
Base class for mapping binary leaves (inner product-based, matrix vector product-base, matrix-matrix product based...)
Definition: mapped_objects.hpp:74
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
Mapping of a vector to a generator class.
Definition: mapped_objects.hpp:205
operation_node_type
Enumeration for identifying the possible operations.
Definition: forwards.h:61
Mapping of a host scalar to a generator class.
Definition: mapped_objects.hpp:116
mapping_type const & mapping() const
Definition: mapped_objects.hpp:77
std::string & append_kernel_arguments(std::set< std::string > &, std::string &str, unsigned int) const
Definition: mapped_objects.hpp:318
std::string append_vector_size(std::string const &scalartype, unsigned int vector_size) const
Definition: mapped_objects.hpp:188
mapped_reduction(std::string const &scalartype)
Definition: mapped_objects.hpp:95
std::string & append_kernel_arguments(std::set< std::string > &already_generated, std::string &str, unsigned int) const
Definition: mapped_objects.hpp:122
mapped_object(std::string const &scalartype)
Definition: mapped_objects.hpp:55
void bind_sizes(std::string const &size1, std::string const &size2) const
Definition: mapped_objects.hpp:257
std::string to_string(T const t)
Definition: utils.hpp:204
std::string generate_default(std::pair< std::string, std::string > const &) const
Definition: mapped_objects.hpp:315
Base class for mapping buffer-based objects to a generator class.
Definition: mapped_objects.hpp:186
std::string generate_default(std::pair< std::string, std::string > const &) const
Definition: mapped_objects.hpp:80
Mapping of a vector reduction (based on matrix-vector product)
Definition: mapped_objects.hpp:109
std::string & append_kernel_arguments(std::set< std::string > &, std::string &str, unsigned int) const
Definition: mapped_objects.hpp:300
mapped_binary_leaf(std::string const &scalartype)
Definition: mapped_objects.hpp:76
scheduler::statement const & statement() const
Definition: mapped_objects.hpp:78
The main class for representing a statement such as x = inner_prod(y,z); at runtime.
Definition: forwards.h:447
virtual std::string generate_default(std::pair< std::string, std::string > const &index) const =0
std::string scalartype_
Definition: mapped_objects.hpp:69
std::string generate(std::pair< std::string, std::string > const &index, int vector_element, mapped_object const &s)
Definition: mapped_objects.hpp:325
std::string const & scalartype() const
Definition: mapped_objects.hpp:57
virtual ~mapped_object()
Definition: mapped_objects.hpp:66
Mapping of a implicit matrix to a generator class.
Definition: mapped_objects.hpp:310
mapped_scalar(std::string const &scalartype)
Definition: mapped_objects.hpp:181
Main datastructure for an node in the statement tree.
Definition: forwards.h:420
std::string const & name()
Definition: mapped_objects.hpp:121
Mapping of a matrix product.
Definition: mapped_objects.hpp:86
Mapping of a implicit vector to a generator class.
Definition: mapped_objects.hpp:291