ViennaCL - The Vienna Computing Library
1.5.1
|
00001 #ifndef VIENNACL_SCHEDULER_EXECUTE_SCALAR_DISPATCHER_HPP 00002 #define VIENNACL_SCHEDULER_EXECUTE_SCALAR_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/scalar_operations.hpp" 00032 00033 namespace viennacl 00034 { 00035 namespace scheduler 00036 { 00037 namespace detail 00038 { 00040 template <typename ScalarType1> 00041 void as(lhs_rhs_element & s1, 00042 lhs_rhs_element const & s2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha) 00043 { 00044 assert( s1.type_family == SCALAR_TYPE_FAMILY && (s1.subtype == HOST_SCALAR_TYPE || s1.subtype == DEVICE_SCALAR_TYPE) 00045 && s2.type_family == SCALAR_TYPE_FAMILY && (s2.subtype == HOST_SCALAR_TYPE || s2.subtype == DEVICE_SCALAR_TYPE) 00046 && bool("Arguments are not vector types!")); 00047 00048 switch (s1.numeric_type) 00049 { 00050 case FLOAT_TYPE: 00051 assert(s2.numeric_type == FLOAT_TYPE && bool("Vectors do not have the same scalar type")); 00052 viennacl::linalg::av(*s1.vector_float, 00053 *s2.vector_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha); 00054 break; 00055 case DOUBLE_TYPE: 00056 assert(s2.numeric_type == DOUBLE_TYPE && bool("Vectors do not have the same scalar type")); 00057 viennacl::linalg::av(*s1.vector_double, 00058 *s2.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 asbs(lhs_rhs_element & s1, 00068 lhs_rhs_element const & s2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, 00069 lhs_rhs_element const & s3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta) 00070 { 00071 assert( s1.type_family == SCALAR_TYPE_FAMILY && (s1.subtype == HOST_SCALAR_TYPE || s1.subtype == DEVICE_SCALAR_TYPE) 00072 && s2.type_family == SCALAR_TYPE_FAMILY && (s2.subtype == HOST_SCALAR_TYPE || s2.subtype == DEVICE_SCALAR_TYPE) 00073 && s3.type_family == SCALAR_TYPE_FAMILY && (s3.subtype == HOST_SCALAR_TYPE || s3.subtype == DEVICE_SCALAR_TYPE) 00074 && bool("Arguments are not vector types!")); 00075 00076 switch (s1.numeric_type) 00077 { 00078 case FLOAT_TYPE: 00079 assert(s2.numeric_type == FLOAT_TYPE && s3.numeric_type == FLOAT_TYPE && bool("Vectors do not have the same scalar type")); 00080 viennacl::linalg::avbv(*s1.vector_float, 00081 *s2.vector_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha, 00082 *s3.vector_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta); 00083 break; 00084 case DOUBLE_TYPE: 00085 assert(s2.numeric_type == DOUBLE_TYPE && s3.numeric_type == DOUBLE_TYPE && bool("Vectors do not have the same scalar type")); 00086 viennacl::linalg::avbv(*s1.vector_double, 00087 *s2.vector_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha, 00088 *s3.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 asbs_s(lhs_rhs_element & s1, 00098 lhs_rhs_element const & s2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, 00099 lhs_rhs_element const & s3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta) 00100 { 00101 assert( s1.type_family == SCALAR_TYPE_FAMILY && (s1.subtype == HOST_SCALAR_TYPE || s1.subtype == DEVICE_SCALAR_TYPE) 00102 && s2.type_family == SCALAR_TYPE_FAMILY && (s2.subtype == HOST_SCALAR_TYPE || s2.subtype == DEVICE_SCALAR_TYPE) 00103 && s3.type_family == SCALAR_TYPE_FAMILY && (s3.subtype == HOST_SCALAR_TYPE || s3.subtype == DEVICE_SCALAR_TYPE) 00104 && bool("Arguments are not vector types!")); 00105 00106 switch (s1.numeric_type) 00107 { 00108 case FLOAT_TYPE: 00109 assert(s2.numeric_type == FLOAT_TYPE && s3.numeric_type == FLOAT_TYPE && bool("Vectors do not have the same scalar type")); 00110 viennacl::linalg::avbv_v(*s1.vector_float, 00111 *s2.vector_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha, 00112 *s3.vector_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta); 00113 break; 00114 case DOUBLE_TYPE: 00115 assert(s2.numeric_type == DOUBLE_TYPE && s3.numeric_type == DOUBLE_TYPE && bool("Vectors do not have the same scalar type")); 00116 viennacl::linalg::avbv_v(*s1.vector_double, 00117 *s2.vector_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha, 00118 *s3.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 00126 } // namespace detail 00127 } // namespace scheduler 00128 } // namespace viennacl 00129 00130 #endif 00131