ViennaCL - The Vienna Computing Library
1.5.2
|
00001 #ifndef VIENNACL_SCHEDULER_EXECUTE_VECTOR_DISPATCHER_HPP 00002 #define VIENNACL_SCHEDULER_EXECUTE_VECTOR_DISPATCHER_HPP 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 <assert.h> 00027 00028 #include "viennacl/forwards.h" 00029 #include "viennacl/scheduler/forwards.h" 00030 #include "viennacl/scheduler/execute_util.hpp" 00031 #include "viennacl/linalg/vector_operations.hpp" 00032 00033 namespace viennacl 00034 { 00035 namespace scheduler 00036 { 00037 namespace detail 00038 { 00040 template <typename ScalarType1> 00041 void av(lhs_rhs_element & vec1, 00042 lhs_rhs_element const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha) 00043 { 00044 assert( vec1.type_family == VECTOR_TYPE_FAMILY && vec1.subtype == DENSE_VECTOR_TYPE 00045 && vec2.type_family == VECTOR_TYPE_FAMILY && vec2.subtype == DENSE_VECTOR_TYPE 00046 && bool("Arguments are not vector types!")); 00047 00048 switch (vec1.numeric_type) 00049 { 00050 case FLOAT_TYPE: 00051 assert(vec2.numeric_type == FLOAT_TYPE && bool("Vectors do not have the same scalar type")); 00052 viennacl::linalg::av(*vec1.vector_float, 00053 *vec2.vector_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha); 00054 break; 00055 case DOUBLE_TYPE: 00056 assert(vec2.numeric_type == DOUBLE_TYPE && bool("Vectors do not have the same scalar type")); 00057 viennacl::linalg::av(*vec1.vector_double, 00058 *vec2.vector_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha); 00059 break; 00060 default: 00061 throw statement_not_supported_exception("Invalid arguments in scheduler when calling av()"); 00062 } 00063 } 00064 00066 template <typename ScalarType1, typename ScalarType2> 00067 void avbv(lhs_rhs_element & vec1, 00068 lhs_rhs_element const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, 00069 lhs_rhs_element const & vec3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta) 00070 { 00071 assert( vec1.type_family == VECTOR_TYPE_FAMILY && vec1.subtype == DENSE_VECTOR_TYPE 00072 && vec2.type_family == VECTOR_TYPE_FAMILY && vec2.subtype == DENSE_VECTOR_TYPE 00073 && vec3.type_family == VECTOR_TYPE_FAMILY && vec3.subtype == DENSE_VECTOR_TYPE 00074 && bool("Arguments are not vector types!")); 00075 00076 switch (vec1.numeric_type) 00077 { 00078 case FLOAT_TYPE: 00079 assert(vec2.numeric_type == FLOAT_TYPE && vec3.numeric_type == FLOAT_TYPE && bool("Vectors do not have the same scalar type")); 00080 viennacl::linalg::avbv(*vec1.vector_float, 00081 *vec2.vector_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha, 00082 *vec3.vector_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta); 00083 break; 00084 case DOUBLE_TYPE: 00085 assert(vec2.numeric_type == DOUBLE_TYPE && vec3.numeric_type == DOUBLE_TYPE && bool("Vectors do not have the same scalar type")); 00086 viennacl::linalg::avbv(*vec1.vector_double, 00087 *vec2.vector_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha, 00088 *vec3.vector_double, convert_to_double(beta), len_beta, reciprocal_beta, flip_sign_beta); 00089 break; 00090 default: 00091 throw statement_not_supported_exception("Invalid arguments in scheduler when calling avbv()"); 00092 } 00093 } 00094 00096 template <typename ScalarType1, typename ScalarType2> 00097 void avbv_v(lhs_rhs_element & vec1, 00098 lhs_rhs_element const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, 00099 lhs_rhs_element const & vec3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta) 00100 { 00101 assert( vec1.type_family == VECTOR_TYPE_FAMILY && vec1.subtype == DENSE_VECTOR_TYPE 00102 && vec2.type_family == VECTOR_TYPE_FAMILY && vec2.subtype == DENSE_VECTOR_TYPE 00103 && vec3.type_family == VECTOR_TYPE_FAMILY && vec3.subtype == DENSE_VECTOR_TYPE 00104 && bool("Arguments are not vector types!")); 00105 00106 switch (vec1.numeric_type) 00107 { 00108 case FLOAT_TYPE: 00109 assert(vec2.numeric_type == FLOAT_TYPE && vec3.numeric_type == FLOAT_TYPE && bool("Vectors do not have the same scalar type")); 00110 viennacl::linalg::avbv_v(*vec1.vector_float, 00111 *vec2.vector_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha, 00112 *vec3.vector_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta); 00113 break; 00114 case DOUBLE_TYPE: 00115 assert(vec2.numeric_type == DOUBLE_TYPE && vec3.numeric_type == DOUBLE_TYPE && bool("Vectors do not have the same scalar type")); 00116 viennacl::linalg::avbv_v(*vec1.vector_double, 00117 *vec2.vector_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha, 00118 *vec3.vector_double, convert_to_double(beta), len_beta, reciprocal_beta, flip_sign_beta); 00119 break; 00120 default: 00121 throw statement_not_supported_exception("Invalid arguments in scheduler when calling avbv_v()"); 00122 } 00123 } 00124 00125 00127 inline void norm_impl(lhs_rhs_element const & x, 00128 lhs_rhs_element const & s, 00129 operation_node_type op_type) 00130 { 00131 assert( x.type_family == VECTOR_TYPE_FAMILY && x.subtype == DENSE_VECTOR_TYPE && bool("Argument is not a dense vector type!")); 00132 assert( s.type_family == SCALAR_TYPE_FAMILY && s.subtype == DEVICE_SCALAR_TYPE && bool("Argument is not a scalar type!")); 00133 00134 switch (x.numeric_type) 00135 { 00136 case FLOAT_TYPE: 00137 assert(s.numeric_type == FLOAT_TYPE && bool("Vector and scalar do not have the same numeric type")); 00138 if (op_type == OPERATION_UNARY_NORM_1_TYPE) 00139 viennacl::linalg::norm_1_impl(*x.vector_float, *s.scalar_float); 00140 else if (op_type == OPERATION_UNARY_NORM_2_TYPE) 00141 viennacl::linalg::norm_2_impl(*x.vector_float, *s.scalar_float); 00142 else if (op_type == OPERATION_UNARY_NORM_INF_TYPE) 00143 viennacl::linalg::norm_inf_impl(*x.vector_float, *s.scalar_float); 00144 else 00145 throw statement_not_supported_exception("Invalid norm type in scheduler::detail::norm_impl()"); 00146 break; 00147 case DOUBLE_TYPE: 00148 if (op_type == OPERATION_UNARY_NORM_1_TYPE) 00149 viennacl::linalg::norm_1_impl(*x.vector_double, *s.scalar_double); 00150 else if (op_type == OPERATION_UNARY_NORM_2_TYPE) 00151 viennacl::linalg::norm_2_impl(*x.vector_double, *s.scalar_double); 00152 else if (op_type == OPERATION_UNARY_NORM_INF_TYPE) 00153 viennacl::linalg::norm_inf_impl(*x.vector_double, *s.scalar_double); 00154 else 00155 throw statement_not_supported_exception("Invalid norm type in scheduler::detail::norm_impl()"); 00156 break; 00157 default: 00158 throw statement_not_supported_exception("Invalid numeric type in scheduler when calling norm_impl()"); 00159 } 00160 } 00161 00163 inline void inner_prod_impl(lhs_rhs_element const & x, 00164 lhs_rhs_element const & y, 00165 lhs_rhs_element const & s) 00166 { 00167 assert( x.type_family == VECTOR_TYPE_FAMILY && x.subtype == DENSE_VECTOR_TYPE && bool("Argument is not a dense vector type!")); 00168 assert( y.type_family == VECTOR_TYPE_FAMILY && y.subtype == DENSE_VECTOR_TYPE && bool("Argument is not a dense vector type!")); 00169 assert( s.type_family == SCALAR_TYPE_FAMILY && s.subtype == DEVICE_SCALAR_TYPE && bool("Argument is not a scalar type!")); 00170 00171 switch (x.numeric_type) 00172 { 00173 case FLOAT_TYPE: 00174 assert(y.numeric_type == FLOAT_TYPE && s.numeric_type == FLOAT_TYPE && bool("Vector and scalar do not have the same numeric type")); 00175 viennacl::linalg::inner_prod_impl(*x.vector_float, *y.vector_float, *s.scalar_float); 00176 break; 00177 case DOUBLE_TYPE: 00178 assert(y.numeric_type == DOUBLE_TYPE && s.numeric_type == DOUBLE_TYPE && bool("Vector and scalar do not have the same numeric type")); 00179 viennacl::linalg::inner_prod_impl(*x.vector_double, *y.vector_double, *s.scalar_double); 00180 break; 00181 default: 00182 throw statement_not_supported_exception("Invalid arguments in scheduler when calling av()"); 00183 } 00184 } 00185 00186 } // namespace detail 00187 } // namespace scheduler 00188 } // namespace viennacl 00189 00190 #endif 00191