ViennaCL - The Vienna Computing Library
1.5.1
|
00001 #ifndef VIENNACL_GENERATOR_FORWARDS_H 00002 #define VIENNACL_GENERATOR_FORWARDS_H 00003 00004 /* ========================================================================= 00005 Copyright (c) 2010-2014, Institute for Microelectronics, 00006 Institute for Analysis and Scientific Computing, 00007 TU Wien. 00008 Portions of this software are copyright by UChicago Argonne, LLC. 00009 00010 ----------------- 00011 ViennaCL - The Vienna Computing Library 00012 ----------------- 00013 00014 Project Head: Karl Rupp rupp@iue.tuwien.ac.at 00015 00016 (A list of authors and contributors can be found in the PDF manual) 00017 00018 License: MIT (X11), see file LICENSE in the base directory 00019 ============================================================================= */ 00020 00021 00026 #include <map> 00027 #include <set> 00028 #include <list> 00029 #include <stdexcept> 00030 00031 #include "viennacl/tools/shared_ptr.hpp" 00032 #include "viennacl/scheduler/forwards.h" 00033 00034 namespace viennacl{ 00035 00036 namespace generator{ 00037 00038 inline void generate_enqueue_statement(viennacl::scheduler::statement const & s, scheduler::statement_node const & root_node); 00039 inline void generate_enqueue_statement(viennacl::scheduler::statement const & s); 00040 00041 enum expression_type_family{ 00042 SCALAR_SAXPY_FAMILY, 00043 VECTOR_SAXPY_FAMILY, 00044 MATRIX_SAXPY_FAMILY, 00045 SCALAR_REDUCE_FAMILY, 00046 VECTOR_REDUCE_FAMILY, 00047 MATRIX_PRODUCT_FAMILY, 00048 INVALID_EXPRESSION_FAMILY 00049 }; 00050 00051 enum expression_type{ 00052 SCALAR_SAXPY_TYPE, 00053 VECTOR_SAXPY_TYPE, 00054 MATRIX_SAXPY_TYPE, 00055 SCALAR_REDUCE_TYPE, 00056 VECTOR_REDUCE_Nx_TYPE, 00057 VECTOR_REDUCE_Tx_TYPE, 00058 MATRIX_PRODUCT_NN_TYPE, 00059 MATRIX_PRODUCT_TN_TYPE, 00060 MATRIX_PRODUCT_NT_TYPE, 00061 MATRIX_PRODUCT_TT_TYPE, 00062 INVALID_EXPRESSION_TYPE 00063 }; 00064 00065 inline const char * expression_type_to_string(expression_type type){ 00066 switch(type){ 00067 case SCALAR_SAXPY_TYPE : return "Scalar SAXPY"; 00068 case VECTOR_SAXPY_TYPE : return "Vector SAXPY"; 00069 case MATRIX_SAXPY_TYPE : return "Matrix SAXPY"; 00070 case SCALAR_REDUCE_TYPE : return "Inner Product"; 00071 case VECTOR_REDUCE_Nx_TYPE : return "Matrix-Vector Product : Ax"; 00072 case VECTOR_REDUCE_Tx_TYPE : return "Matrix-Vector Product : Tx"; 00073 case MATRIX_PRODUCT_NN_TYPE : return "Matrix-Matrix Product : AA"; 00074 case MATRIX_PRODUCT_TN_TYPE : return "Matrix-Matrix Product : TA"; 00075 case MATRIX_PRODUCT_NT_TYPE : return "Matrix-Matrix Product : AT"; 00076 case MATRIX_PRODUCT_TT_TYPE : return "Matrix-Matrix Product : TT"; 00077 default : return "INVALID EXPRESSION"; 00078 } 00079 } 00080 00081 typedef std::pair<expression_type, vcl_size_t> expression_key_type; 00082 00084 struct expression_descriptor{ 00085 expression_key_type make_key() const { return expression_key_type(type,scalartype_size); } 00086 bool operator==(expression_descriptor const & other) const 00087 { 00088 return type_family == other.type_family && type == other.type && scalartype_size==other.scalartype_size; 00089 } 00090 expression_type_family type_family; 00091 expression_type type; 00092 vcl_size_t scalartype_size; 00093 }; 00094 00096 template <typename KeyT, typename ValueT> 00097 ValueT const & at(std::map<KeyT, ValueT> const & map, KeyT const & key) 00098 { 00099 typename std::map<KeyT, ValueT>::const_iterator it = map.find(key); 00100 if (it != map.end()) 00101 return it->second; 00102 00103 throw std::out_of_range("Generator: Key not found in map"); 00104 } 00105 00106 namespace utils{ 00107 class kernel_generation_stream; 00108 } 00109 00110 namespace detail{ 00111 00112 enum node_type{ 00113 LHS_NODE_TYPE, 00114 PARENT_NODE_TYPE, 00115 RHS_NODE_TYPE 00116 }; 00117 00118 class mapped_object; 00119 00120 typedef std::pair<viennacl::scheduler::statement_node const *, node_type> key_type; 00121 typedef tools::shared_ptr<detail::mapped_object> container_ptr_type; 00122 typedef std::map<key_type, container_ptr_type> mapping_type; 00123 00124 template<class Fun> 00125 static void traverse(viennacl::scheduler::statement const & statement, viennacl::scheduler::statement_node const & root_node, Fun const & fun, bool recurse_binary_leaf = true); 00126 inline std::string generate(std::pair<std::string, std::string> const & index, int vector_element, mapped_object const & s); 00127 static std::string & append_kernel_arguments(std::set<std::string> & already_generated, std::string & str, unsigned int vector_size, mapped_object const & s); 00128 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); 00129 inline const char * generate(viennacl::scheduler::operation_node_type type); 00130 static void generate_all_rhs(viennacl::scheduler::statement const & statement 00131 , viennacl::scheduler::statement_node const & root_node 00132 , std::pair<std::string, std::string> const & index 00133 , int vector_element 00134 , std::string & str 00135 , detail::mapping_type const & mapping); 00136 00137 } 00138 00139 } 00140 00141 } 00142 #endif