ViennaCL - The Vienna Computing Library
1.5.2
|
00001 #ifndef VIENNACL_LINALG_OPENCL_COMMON_HPP_ 00002 #define VIENNACL_LINALG_OPENCL_COMMON_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 00025 #include <cmath> 00026 00027 #include "viennacl/forwards.h" 00028 #include "viennacl/ocl/platform.hpp" 00029 00030 #include "viennacl/linalg/opencl/kernels/matrix.hpp" 00031 00032 namespace viennacl 00033 { 00034 namespace linalg 00035 { 00036 namespace opencl 00037 { 00038 00039 namespace detail 00040 { 00041 00042 template <typename NumericT> 00043 viennacl::ocl::program & program_for_matrix(matrix_base<NumericT> const & A) 00044 { 00045 viennacl::ocl::context & ctx = const_cast<viennacl::ocl::context &>(viennacl::traits::opencl_handle(A).context()); 00046 00047 if (A.row_major()) 00048 { 00049 typedef viennacl::linalg::opencl::kernels::matrix<NumericT, row_major> KernelClass; 00050 KernelClass::init(ctx); 00051 return ctx.get_program(KernelClass::program_name()); 00052 } 00053 00054 typedef viennacl::linalg::opencl::kernels::matrix<NumericT, column_major> KernelClass; 00055 KernelClass::init(ctx); 00056 return ctx.get_program(KernelClass::program_name()); 00057 } 00058 00059 template <typename NumericT> 00060 viennacl::ocl::kernel & kernel_for_matrix(matrix_base<NumericT> const & A, std::string kernel_name) 00061 { 00062 return program_for_matrix(A).get_kernel(kernel_name); 00063 } 00064 00065 inline cl_uint make_options(vcl_size_t length, bool reciprocal, bool flip_sign) 00066 { 00067 return static_cast<cl_uint>( ((length > 1) ? (cl_uint(length) << 2) : 0) + (reciprocal ? 2 : 0) + (flip_sign ? 1 : 0) ); 00068 } 00069 00070 00072 inline std::string sparse_dense_matmult_kernel_name(bool B_transposed, bool B_row_major, bool C_row_major) 00073 { 00074 if (B_transposed) 00075 { 00076 if (B_row_major && C_row_major) 00077 return "trans_mat_mult_row_row"; 00078 if (B_row_major && !C_row_major) 00079 return "trans_mat_mult_row_col"; 00080 if (!B_row_major && C_row_major) 00081 return "trans_mat_mult_col_row"; 00082 00083 return "trans_mat_mult_col_col"; 00084 } 00085 00086 if (B_row_major && C_row_major) 00087 return "mat_mult_row_row"; 00088 if (B_row_major && !C_row_major) 00089 return "mat_mult_row_col"; 00090 if (!B_row_major && C_row_major) 00091 return "mat_mult_col_row"; 00092 00093 return "mat_mult_col_col"; 00094 } 00095 00096 00097 inline std::string op_to_string(op_abs) { return "abs"; } 00098 inline std::string op_to_string(op_acos) { return "acos"; } 00099 inline std::string op_to_string(op_asin) { return "asin"; } 00100 inline std::string op_to_string(op_atan) { return "atan"; } 00101 inline std::string op_to_string(op_ceil) { return "ceil"; } 00102 inline std::string op_to_string(op_cos) { return "cos"; } 00103 inline std::string op_to_string(op_cosh) { return "cosh"; } 00104 inline std::string op_to_string(op_exp) { return "exp"; } 00105 inline std::string op_to_string(op_fabs) { return "fabs"; } 00106 inline std::string op_to_string(op_floor) { return "floor"; } 00107 inline std::string op_to_string(op_log) { return "log"; } 00108 inline std::string op_to_string(op_log10) { return "log10"; } 00109 inline std::string op_to_string(op_sin) { return "sin"; } 00110 inline std::string op_to_string(op_sinh) { return "sinh"; } 00111 inline std::string op_to_string(op_sqrt) { return "sqrt"; } 00112 inline std::string op_to_string(op_tan) { return "tan"; } 00113 inline std::string op_to_string(op_tanh) { return "tanh"; } 00114 } 00115 00116 } //namespace opencl 00117 } //namespace linalg 00118 } //namespace viennacl 00119 00120 00121 #endif