00001 #ifndef _VIENNACL_COMPRESSED_MATRIX_KERNELS_HPP_
00002 #define _VIENNACL_COMPRESSED_MATRIX_KERNELS_HPP_
00003 #include "viennacl/tools/tools.hpp"
00004 #include "viennacl/ocl/kernel.hpp"
00005 #include "viennacl/ocl/platform.hpp"
00006 #include "viennacl/ocl/utils.hpp"
00007 #include "viennacl/linalg/kernels/compressed_matrix_source.h"
00008
00009
00010 namespace viennacl
00011 {
00012 namespace linalg
00013 {
00014 namespace kernels
00015 {
00016 template<class TYPE, unsigned int alignment>
00017 struct compressed_matrix;
00018
00019
00021 template <>
00022 struct compressed_matrix<float, 4>
00023 {
00024 static std::string program_name()
00025 {
00026 return "f_compressed_matrix_4";
00027 }
00028 static void init()
00029 {
00030 viennacl::ocl::DOUBLE_PRECISION_CHECKER<float>::apply();
00031 static std::map<cl_context, bool> init_done;
00032 viennacl::ocl::context & context_ = viennacl::ocl::current_context();
00033 if (!init_done[context_.handle()])
00034 {
00035 std::string source;
00036 source.append(compressed_matrix_align1_jacobi);
00037 source.append(compressed_matrix_align4_vec_mul);
00038 source.append(compressed_matrix_align1_row_scaling_2);
00039 source.append(compressed_matrix_align1_jacobi_precond);
00040 source.append(compressed_matrix_align1_row_scaling_1);
00041 source.append(compressed_matrix_align1_lu_forward);
00042 source.append(compressed_matrix_align1_bicgstab_kernel2);
00043 source.append(compressed_matrix_align1_lu_backward);
00044 source.append(compressed_matrix_align1_bicgstab_kernel1);
00045 std::string prog_name = program_name();
00046 #ifdef VIENNACL_BUILD_INFO
00047 std::cout << "Creating program " << prog_name << std::endl;
00048 #endif
00049 context_.add_program(source, prog_name);
00050 viennacl::ocl::program & prog_ = context_.get_program(prog_name);
00051 prog_.add_kernel("jacobi");
00052 prog_.add_kernel("vec_mul");
00053 prog_.add_kernel("row_scaling_2");
00054 prog_.add_kernel("jacobi_precond");
00055 prog_.add_kernel("row_scaling_1");
00056 prog_.add_kernel("lu_forward");
00057 prog_.add_kernel("bicgstab_kernel2");
00058 prog_.add_kernel("lu_backward");
00059 prog_.add_kernel("bicgstab_kernel1");
00060 init_done[context_.handle()] = true;
00061 }
00062 }
00063 };
00064
00065 template <>
00066 struct compressed_matrix<float, 1>
00067 {
00068 static std::string program_name()
00069 {
00070 return "f_compressed_matrix_1";
00071 }
00072 static void init()
00073 {
00074 viennacl::ocl::DOUBLE_PRECISION_CHECKER<float>::apply();
00075 static std::map<cl_context, bool> init_done;
00076 viennacl::ocl::context & context_ = viennacl::ocl::current_context();
00077 if (!init_done[context_.handle()])
00078 {
00079 std::string source;
00080 source.append(compressed_matrix_align1_jacobi);
00081 source.append(compressed_matrix_align1_vec_mul);
00082 source.append(compressed_matrix_align1_row_scaling_2);
00083 source.append(compressed_matrix_align1_jacobi_precond);
00084 source.append(compressed_matrix_align1_row_scaling_1);
00085 source.append(compressed_matrix_align1_lu_forward);
00086 source.append(compressed_matrix_align1_bicgstab_kernel2);
00087 source.append(compressed_matrix_align1_lu_backward);
00088 source.append(compressed_matrix_align1_bicgstab_kernel1);
00089 std::string prog_name = program_name();
00090 #ifdef VIENNACL_BUILD_INFO
00091 std::cout << "Creating program " << prog_name << std::endl;
00092 #endif
00093 context_.add_program(source, prog_name);
00094 viennacl::ocl::program & prog_ = context_.get_program(prog_name);
00095 prog_.add_kernel("jacobi");
00096 prog_.add_kernel("vec_mul");
00097 prog_.add_kernel("row_scaling_2");
00098 prog_.add_kernel("jacobi_precond");
00099 prog_.add_kernel("row_scaling_1");
00100 prog_.add_kernel("lu_forward");
00101 prog_.add_kernel("bicgstab_kernel2");
00102 prog_.add_kernel("lu_backward");
00103 prog_.add_kernel("bicgstab_kernel1");
00104 init_done[context_.handle()] = true;
00105 }
00106 }
00107 };
00108
00109 template <>
00110 struct compressed_matrix<float, 8>
00111 {
00112 static std::string program_name()
00113 {
00114 return "f_compressed_matrix_8";
00115 }
00116 static void init()
00117 {
00118 viennacl::ocl::DOUBLE_PRECISION_CHECKER<float>::apply();
00119 static std::map<cl_context, bool> init_done;
00120 viennacl::ocl::context & context_ = viennacl::ocl::current_context();
00121 if (!init_done[context_.handle()])
00122 {
00123 std::string source;
00124 source.append(compressed_matrix_align1_jacobi);
00125 source.append(compressed_matrix_align8_vec_mul);
00126 source.append(compressed_matrix_align1_row_scaling_2);
00127 source.append(compressed_matrix_align1_jacobi_precond);
00128 source.append(compressed_matrix_align1_row_scaling_1);
00129 source.append(compressed_matrix_align1_lu_forward);
00130 source.append(compressed_matrix_align1_bicgstab_kernel2);
00131 source.append(compressed_matrix_align1_lu_backward);
00132 source.append(compressed_matrix_align1_bicgstab_kernel1);
00133 std::string prog_name = program_name();
00134 #ifdef VIENNACL_BUILD_INFO
00135 std::cout << "Creating program " << prog_name << std::endl;
00136 #endif
00137 context_.add_program(source, prog_name);
00138 viennacl::ocl::program & prog_ = context_.get_program(prog_name);
00139 prog_.add_kernel("jacobi");
00140 prog_.add_kernel("vec_mul");
00141 prog_.add_kernel("row_scaling_2");
00142 prog_.add_kernel("jacobi_precond");
00143 prog_.add_kernel("row_scaling_1");
00144 prog_.add_kernel("lu_forward");
00145 prog_.add_kernel("bicgstab_kernel2");
00146 prog_.add_kernel("lu_backward");
00147 prog_.add_kernel("bicgstab_kernel1");
00148 init_done[context_.handle()] = true;
00149 }
00150 }
00151 };
00152
00153
00154
00156 template <>
00157 struct compressed_matrix<double, 4>
00158 {
00159 static std::string program_name()
00160 {
00161 return "d_compressed_matrix_4";
00162 }
00163 static void init()
00164 {
00165 viennacl::ocl::DOUBLE_PRECISION_CHECKER<double>::apply();
00166 static std::map<cl_context, bool> init_done;
00167 viennacl::ocl::context & context_ = viennacl::ocl::current_context();
00168 if (!init_done[context_.handle()])
00169 {
00170 std::string source;
00171 std::string fp64_ext = viennacl::ocl::current_device().double_support_extension();
00172 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_jacobi, fp64_ext));
00173 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align4_vec_mul, fp64_ext));
00174 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_row_scaling_2, fp64_ext));
00175 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_jacobi_precond, fp64_ext));
00176 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_row_scaling_1, fp64_ext));
00177 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_lu_forward, fp64_ext));
00178 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_bicgstab_kernel2, fp64_ext));
00179 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_lu_backward, fp64_ext));
00180 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_bicgstab_kernel1, fp64_ext));
00181 std::string prog_name = program_name();
00182 #ifdef VIENNACL_BUILD_INFO
00183 std::cout << "Creating program " << prog_name << std::endl;
00184 #endif
00185 context_.add_program(source, prog_name);
00186 viennacl::ocl::program & prog_ = context_.get_program(prog_name);
00187 prog_.add_kernel("jacobi");
00188 prog_.add_kernel("vec_mul");
00189 prog_.add_kernel("row_scaling_2");
00190 prog_.add_kernel("jacobi_precond");
00191 prog_.add_kernel("row_scaling_1");
00192 prog_.add_kernel("lu_forward");
00193 prog_.add_kernel("bicgstab_kernel2");
00194 prog_.add_kernel("lu_backward");
00195 prog_.add_kernel("bicgstab_kernel1");
00196 init_done[context_.handle()] = true;
00197 }
00198 }
00199 };
00200
00201 template <>
00202 struct compressed_matrix<double, 1>
00203 {
00204 static std::string program_name()
00205 {
00206 return "d_compressed_matrix_1";
00207 }
00208 static void init()
00209 {
00210 viennacl::ocl::DOUBLE_PRECISION_CHECKER<double>::apply();
00211 static std::map<cl_context, bool> init_done;
00212 viennacl::ocl::context & context_ = viennacl::ocl::current_context();
00213 if (!init_done[context_.handle()])
00214 {
00215 std::string source;
00216 std::string fp64_ext = viennacl::ocl::current_device().double_support_extension();
00217 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_jacobi, fp64_ext));
00218 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_vec_mul, fp64_ext));
00219 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_row_scaling_2, fp64_ext));
00220 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_jacobi_precond, fp64_ext));
00221 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_row_scaling_1, fp64_ext));
00222 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_lu_forward, fp64_ext));
00223 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_bicgstab_kernel2, fp64_ext));
00224 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_lu_backward, fp64_ext));
00225 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_bicgstab_kernel1, fp64_ext));
00226 std::string prog_name = program_name();
00227 #ifdef VIENNACL_BUILD_INFO
00228 std::cout << "Creating program " << prog_name << std::endl;
00229 #endif
00230 context_.add_program(source, prog_name);
00231 viennacl::ocl::program & prog_ = context_.get_program(prog_name);
00232 prog_.add_kernel("jacobi");
00233 prog_.add_kernel("vec_mul");
00234 prog_.add_kernel("row_scaling_2");
00235 prog_.add_kernel("jacobi_precond");
00236 prog_.add_kernel("row_scaling_1");
00237 prog_.add_kernel("lu_forward");
00238 prog_.add_kernel("bicgstab_kernel2");
00239 prog_.add_kernel("lu_backward");
00240 prog_.add_kernel("bicgstab_kernel1");
00241 init_done[context_.handle()] = true;
00242 }
00243 }
00244 };
00245
00246 template <>
00247 struct compressed_matrix<double, 8>
00248 {
00249 static std::string program_name()
00250 {
00251 return "d_compressed_matrix_8";
00252 }
00253 static void init()
00254 {
00255 viennacl::ocl::DOUBLE_PRECISION_CHECKER<double>::apply();
00256 static std::map<cl_context, bool> init_done;
00257 viennacl::ocl::context & context_ = viennacl::ocl::current_context();
00258 if (!init_done[context_.handle()])
00259 {
00260 std::string source;
00261 std::string fp64_ext = viennacl::ocl::current_device().double_support_extension();
00262 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_jacobi, fp64_ext));
00263 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align8_vec_mul, fp64_ext));
00264 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_row_scaling_2, fp64_ext));
00265 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_jacobi_precond, fp64_ext));
00266 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_row_scaling_1, fp64_ext));
00267 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_lu_forward, fp64_ext));
00268 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_bicgstab_kernel2, fp64_ext));
00269 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_lu_backward, fp64_ext));
00270 source.append(viennacl::tools::make_double_kernel(compressed_matrix_align1_bicgstab_kernel1, fp64_ext));
00271 std::string prog_name = program_name();
00272 #ifdef VIENNACL_BUILD_INFO
00273 std::cout << "Creating program " << prog_name << std::endl;
00274 #endif
00275 context_.add_program(source, prog_name);
00276 viennacl::ocl::program & prog_ = context_.get_program(prog_name);
00277 prog_.add_kernel("jacobi");
00278 prog_.add_kernel("vec_mul");
00279 prog_.add_kernel("row_scaling_2");
00280 prog_.add_kernel("jacobi_precond");
00281 prog_.add_kernel("row_scaling_1");
00282 prog_.add_kernel("lu_forward");
00283 prog_.add_kernel("bicgstab_kernel2");
00284 prog_.add_kernel("lu_backward");
00285 prog_.add_kernel("bicgstab_kernel1");
00286 init_done[context_.handle()] = true;
00287 }
00288 }
00289 };
00290
00291
00292 }
00293 }
00294 }
00295 #endif