1 #ifndef VIENNACL_GENERATOR_UTILS_HPP
2 #define VIENNACL_GENERATOR_UTILS_HPP
41 static typename Fun::result_type call_on_host_scalar(scheduler::lhs_rhs_element element, Fun
const & fun){
43 switch(element.numeric_type){
45 return fun(element.host_float);
47 return fun(element.host_double);
49 throw "not implemented";
54 static typename Fun::result_type call_on_scalar(scheduler::lhs_rhs_element element, Fun
const & fun){
56 switch(element.numeric_type){
58 return fun(*element.scalar_float);
60 return fun(*element.scalar_double);
62 throw "not implemented";
67 static typename Fun::result_type call_on_vector(scheduler::lhs_rhs_element element, Fun
const & fun){
69 switch(element.numeric_type){
71 return fun(*element.vector_float);
73 return fun(*element.vector_double);
75 throw "not implemented";
80 static typename Fun::result_type call_on_implicit_vector(scheduler::lhs_rhs_element element, Fun
const & fun){
83 switch(element.numeric_type){
85 return fun(*element.implicit_vector_float);
87 return fun(*element.implicit_vector_double);
89 throw "not implemented";
94 static typename Fun::result_type call_on_matrix(scheduler::lhs_rhs_element element, Fun
const & fun){
98 switch(element.numeric_type){
100 return fun(*element.matrix_row_float);
102 return fun(*element.matrix_row_double);
104 throw "not implemented";
109 switch(element.numeric_type){
111 return fun(*element.matrix_col_float);
113 return fun(*element.matrix_col_double);
115 throw "not implemented";
122 static typename Fun::result_type call_on_implicit_matrix(scheduler::lhs_rhs_element element, Fun
const & fun){
125 switch(element.numeric_type){
127 return fun(*element.implicit_matrix_float);
129 return fun(*element.implicit_matrix_double);
131 throw "not implemented";
136 static typename Fun::result_type call_on_element(scheduler::lhs_rhs_element
const & element, Fun
const & fun){
137 switch(element.type_family){
140 return call_on_host_scalar(element, fun);
142 return call_on_scalar(element, fun);
145 return call_on_implicit_vector(element, fun);
147 return call_on_vector(element, fun);
150 return call_on_implicit_matrix(element, fun);
152 return call_on_matrix(element,fun);
154 throw "not implemented";
195 template<
class T,
class U>
206 std::stringstream ss;
217 template<>
struct type_to_string<float> {
static const char * value() {
return "float"; } };
218 template<>
struct type_to_string<double> {
static const char * value() {
return "double"; } };
227 template<>
struct first_letter_of_type<double> {
static char value() {
return 'd'; } };
228 template<>
struct first_letter_of_type<viennacl::row_major> {
static char value() {
return 'r'; } };
229 template<>
struct first_letter_of_type<viennacl::column_major> {
static char value() {
return 'c'; } };
236 class kgenstream :
public std::stringbuf{
238 kgenstream(std::ostringstream& oss,
unsigned int const & tab_count) : oss_(oss), tab_count_(tab_count){ }
240 for(
unsigned int i=0 ; i<tab_count_;++i)
246 ~kgenstream() { pubsync(); }
249 unsigned int const & tab_count_;
255 std::string
str(){
return oss.str(); }
264 unsigned int tab_count_;
265 std::ostringstream oss;
A stream class where the kernel sources are streamed to. Takes care of indentation of the sources...
Definition: utils.hpp:233
This file provides the forward declarations for the OpenCL layer of ViennaCL.
Functor for obtaining the OpenCL handle from ViennaCL objects (vector, matrix, etc.).
Definition: utils.hpp:174
std::size_t vcl_size_t
Definition: forwards.h:58
Generic size and resize functionality for different vector and matrix types.
Definition: forwards.h:192
Definition: forwards.h:176
vcl_size_t result_type
Definition: utils.hpp:160
std::string str()
Definition: utils.hpp:255
vcl_size_t result_type
Definition: utils.hpp:182
Definition: forwards.h:217
Helper struct for obtaining the first letter of a type. Used internally by the generator only...
Definition: utils.hpp:223
Helper metafunction for checking whether two types are the same.
Definition: utils.hpp:196
Helper struct for converting a numerical type to its string representation.
Definition: utils.hpp:213
Definition: utils.hpp:196
Definition: forwards.h:190
Functor for obtaining the internal number of columns of a ViennaCL matrix.
Definition: utils.hpp:188
result_type operator()(T const &t) const
Definition: utils.hpp:170
vcl_size_t result_type
Definition: utils.hpp:189
vcl_size_t internal_size(vector_base< NumericT > const &vec)
Helper routine for obtaining the buffer length of a ViennaCL vector.
Definition: size.hpp:268
result_type operator()(T const &) const
Definition: utils.hpp:163
Definition: forwards.h:170
Functor for obtaining the internal number of rows of a ViennaCL matrix.
Definition: utils.hpp:181
result_type operator()(float const &) const
Definition: utils.hpp:161
Functor for returning the size of the underlying scalar type in bytes.
Definition: utils.hpp:159
Definition: forwards.h:184
Definition: forwards.h:173
void dec_tab()
Definition: utils.hpp:259
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
vcl_size_t internal_size2(matrix_base< NumericT, F > const &mat)
Helper routine for obtaining the internal number of entries per column of a ViennaCL matrix...
Definition: size.hpp:287
Definition: forwards.h:188
kernel_generation_stream()
Definition: utils.hpp:253
T::ERROR_CANNOT_DEDUCE_CPU_SCALAR_TYPE_FOR_T type
Definition: result_of.hpp:276
void inc_tab()
Definition: utils.hpp:257
std::string to_string(T const t)
Definition: utils.hpp:204
std::string type_to_string(viennacl::row_major)
Definition: matrix.hpp:868
result_type operator()(T const &t) const
Definition: utils.hpp:191
result_type operator()(double const &) const
Definition: utils.hpp:162
vcl_size_t internal_size1(matrix_base< NumericT, F > const &mat)
Helper routine for obtaining the internal number of entries per row of a ViennaCL matrix...
Definition: size.hpp:279
Definition: forwards.h:216
result_type operator()(T const &t) const
Definition: utils.hpp:184
result_type operator()(T const &t) const
Definition: utils.hpp:177
Functor for returning the internal size of a vector.
Definition: utils.hpp:167
vcl_size_t result_type
Definition: utils.hpp:168
~kernel_generation_stream()
Definition: utils.hpp:261
cl_mem result_type
Definition: utils.hpp:175