ViennaCL - The Vienna Computing Library
1.5.2
|
00001 #ifndef VIENNACL_LINALG_OPENCL_KERNELS_VECTOR_ELEMENT_HPP 00002 #define VIENNACL_LINALG_OPENCL_KERNELS_VECTOR_ELEMENT_HPP 00003 00004 #include "viennacl/tools/tools.hpp" 00005 #include "viennacl/ocl/kernel.hpp" 00006 #include "viennacl/ocl/platform.hpp" 00007 #include "viennacl/ocl/utils.hpp" 00008 00009 #include "viennacl/device_specific/database.hpp" 00010 00013 namespace viennacl 00014 { 00015 namespace linalg 00016 { 00017 namespace opencl 00018 { 00019 namespace kernels 00020 { 00021 00022 // main kernel class 00024 template <class TYPE> 00025 struct vector_element 00026 { 00027 static std::string program_name() 00028 { 00029 return viennacl::ocl::type_to_string<TYPE>::apply() + "_vector_element"; 00030 } 00031 00032 static void init(viennacl::ocl::context & ctx) 00033 { 00034 viennacl::ocl::DOUBLE_PRECISION_CHECKER<TYPE>::apply(ctx); 00035 std::string numeric_string = viennacl::ocl::type_to_string<TYPE>::apply(); 00036 00037 static std::map<cl_context, bool> init_done; 00038 if (!init_done[ctx.handle().get()]) 00039 { 00040 using namespace scheduler; 00041 00042 std::string source; 00043 source.reserve(8192); 00044 00045 viennacl::ocl::append_double_precision_pragma<TYPE>(ctx, source); 00046 00047 vector_axpy_template vtemplate = vector_axpy_template(database::get<TYPE>(database::vector_axpy)); 00048 00049 viennacl::vector<TYPE> x; 00050 viennacl::vector<TYPE> y; 00051 viennacl::vector<TYPE> z; 00052 00053 // unary operations 00054 if (numeric_string == "float" || numeric_string == "double") 00055 { 00056 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_ACOS_TYPE))); 00057 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_ASIN_TYPE))); 00058 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_ATAN_TYPE))); 00059 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_CEIL_TYPE))); 00060 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_COS_TYPE))); 00061 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_COSH_TYPE))); 00062 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_EXP_TYPE))); 00063 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_FABS_TYPE))); 00064 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_FLOOR_TYPE))); 00065 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_LOG_TYPE))); 00066 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_LOG10_TYPE))); 00067 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_SIN_TYPE))); 00068 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_SINH_TYPE))); 00069 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_SQRT_TYPE))); 00070 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_TAN_TYPE))); 00071 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_TANH_TYPE))); 00072 } 00073 else 00074 { 00075 source.append(vtemplate.generate(scheduler::preset::unary_element_op(&x, &y, OPERATION_UNARY_ABS_TYPE))); 00076 } 00077 00078 // binary operations 00079 source.append(vtemplate.generate(scheduler::preset::binary_element_op(&x, &y, &z, OPERATION_BINARY_ELEMENT_DIV_TYPE))); 00080 source.append(vtemplate.generate(scheduler::preset::binary_element_op(&x, &y, &z, OPERATION_BINARY_ELEMENT_PROD_TYPE))); 00081 if (numeric_string == "float" || numeric_string == "double") 00082 source.append(vtemplate.generate(scheduler::preset::binary_element_op(&x, &y, &z, OPERATION_BINARY_ELEMENT_POW_TYPE))); 00083 00084 std::string prog_name = program_name(); 00085 #ifdef VIENNACL_BUILD_INFO 00086 std::cout << "Creating program " << prog_name << std::endl; 00087 #endif 00088 ctx.add_program(source, prog_name); 00089 init_done[ctx.handle().get()] = true; 00090 } //if 00091 } //init 00092 }; 00093 00094 } // namespace kernels 00095 } // namespace opencl 00096 } // namespace linalg 00097 } // namespace viennacl 00098 #endif 00099