Go to the documentation of this file.00001 #ifndef _VIENNACL_SCALAR_KERNELS_HPP_
00002 #define _VIENNACL_SCALAR_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/scalar_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 scalar;
00018
00019
00021 template <>
00022 struct scalar<float, 1>
00023 {
00024 static std::string program_name()
00025 {
00026 return "f_scalar_1";
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(scalar_align1_inplace_sub);
00037 source.append(scalar_align1_cpu_inplace_div);
00038 source.append(scalar_align1_cpu_inplace_add);
00039 source.append(scalar_align1_cpu_sub);
00040 source.append(scalar_align1_cpu_mul);
00041 source.append(scalar_align1_sub);
00042 source.append(scalar_align1_inplace_mul);
00043 source.append(scalar_align1_cpu_inplace_mul);
00044 source.append(scalar_align1_mul);
00045 source.append(scalar_align1_cpu_add);
00046 source.append(scalar_align1_inplace_div);
00047 source.append(scalar_align1_add);
00048 source.append(scalar_align1_cpu_inplace_sub);
00049 source.append(scalar_align1_inplace_add);
00050 source.append(scalar_align1_divide);
00051 source.append(scalar_align1_cpu_div);
00052 std::string prog_name = program_name();
00053 #ifdef VIENNACL_BUILD_INFO
00054 std::cout << "Creating program " << prog_name << std::endl;
00055 #endif
00056 context_.add_program(source, prog_name);
00057 viennacl::ocl::program & prog_ = context_.get_program(prog_name);
00058 prog_.add_kernel("inplace_sub");
00059 prog_.add_kernel("cpu_inplace_div");
00060 prog_.add_kernel("cpu_inplace_add");
00061 prog_.add_kernel("cpu_sub");
00062 prog_.add_kernel("cpu_mul");
00063 prog_.add_kernel("sub");
00064 prog_.add_kernel("inplace_mul");
00065 prog_.add_kernel("cpu_inplace_mul");
00066 prog_.add_kernel("mul");
00067 prog_.add_kernel("cpu_add");
00068 prog_.add_kernel("inplace_div");
00069 prog_.add_kernel("add");
00070 prog_.add_kernel("cpu_inplace_sub");
00071 prog_.add_kernel("inplace_add");
00072 prog_.add_kernel("divide");
00073 prog_.add_kernel("cpu_div");
00074 init_done[context_.handle()] = true;
00075 }
00076 }
00077 };
00078
00079
00080
00082 template <>
00083 struct scalar<double, 1>
00084 {
00085 static std::string program_name()
00086 {
00087 return "d_scalar_1";
00088 }
00089 static void init()
00090 {
00091 viennacl::ocl::DOUBLE_PRECISION_CHECKER<double>::apply();
00092 static std::map<cl_context, bool> init_done;
00093 viennacl::ocl::context & context_ = viennacl::ocl::current_context();
00094 if (!init_done[context_.handle()])
00095 {
00096 std::string source;
00097 std::string fp64_ext = viennacl::ocl::current_device().double_support_extension();
00098 source.append(viennacl::tools::make_double_kernel(scalar_align1_inplace_sub, fp64_ext));
00099 source.append(viennacl::tools::make_double_kernel(scalar_align1_cpu_inplace_div, fp64_ext));
00100 source.append(viennacl::tools::make_double_kernel(scalar_align1_cpu_inplace_add, fp64_ext));
00101 source.append(viennacl::tools::make_double_kernel(scalar_align1_cpu_sub, fp64_ext));
00102 source.append(viennacl::tools::make_double_kernel(scalar_align1_cpu_mul, fp64_ext));
00103 source.append(viennacl::tools::make_double_kernel(scalar_align1_sub, fp64_ext));
00104 source.append(viennacl::tools::make_double_kernel(scalar_align1_inplace_mul, fp64_ext));
00105 source.append(viennacl::tools::make_double_kernel(scalar_align1_cpu_inplace_mul, fp64_ext));
00106 source.append(viennacl::tools::make_double_kernel(scalar_align1_mul, fp64_ext));
00107 source.append(viennacl::tools::make_double_kernel(scalar_align1_cpu_add, fp64_ext));
00108 source.append(viennacl::tools::make_double_kernel(scalar_align1_inplace_div, fp64_ext));
00109 source.append(viennacl::tools::make_double_kernel(scalar_align1_add, fp64_ext));
00110 source.append(viennacl::tools::make_double_kernel(scalar_align1_cpu_inplace_sub, fp64_ext));
00111 source.append(viennacl::tools::make_double_kernel(scalar_align1_inplace_add, fp64_ext));
00112 source.append(viennacl::tools::make_double_kernel(scalar_align1_divide, fp64_ext));
00113 source.append(viennacl::tools::make_double_kernel(scalar_align1_cpu_div, fp64_ext));
00114 std::string prog_name = program_name();
00115 #ifdef VIENNACL_BUILD_INFO
00116 std::cout << "Creating program " << prog_name << std::endl;
00117 #endif
00118 context_.add_program(source, prog_name);
00119 viennacl::ocl::program & prog_ = context_.get_program(prog_name);
00120 prog_.add_kernel("inplace_sub");
00121 prog_.add_kernel("cpu_inplace_div");
00122 prog_.add_kernel("cpu_inplace_add");
00123 prog_.add_kernel("cpu_sub");
00124 prog_.add_kernel("cpu_mul");
00125 prog_.add_kernel("sub");
00126 prog_.add_kernel("inplace_mul");
00127 prog_.add_kernel("cpu_inplace_mul");
00128 prog_.add_kernel("mul");
00129 prog_.add_kernel("cpu_add");
00130 prog_.add_kernel("inplace_div");
00131 prog_.add_kernel("add");
00132 prog_.add_kernel("cpu_inplace_sub");
00133 prog_.add_kernel("inplace_add");
00134 prog_.add_kernel("divide");
00135 prog_.add_kernel("cpu_div");
00136 init_done[context_.handle()] = true;
00137 }
00138 }
00139 };
00140
00141
00142 }
00143 }
00144 }
00145 #endif