1 #ifndef VIENNACL_LINALG_OPENCL_KERNELS_SCALAR_HPP
2 #define VIENNACL_LINALG_OPENCL_KERNELS_SCALAR_HPP
59 template<
typename StringT>
62 source.append(
" *s1 "); source.append(cfg.
assign_op); source.append(1, sign_a); source.append(
" *s2 ");
64 source.append(
"* alpha ");
66 source.append(
"/ alpha ");
69 source.append(1, sign_b); source.append(
" *s3 ");
71 source.append(
"* beta");
73 source.append(
"/ beta");
75 source.append(
"; \n");
78 template<
typename StringT>
81 source.append(
" if (options2 & (1 << 1)) { \n");
84 source.append(
" if (options3 & (1 << 1)) \n");
86 source.append(
" else \n");
91 source.append(
" } else { \n");
94 source.append(
" if (options3 & (1 << 1)) \n");
96 source.append(
" else \n");
101 source.append(
" } \n");
105 template<
typename StringT>
108 source.append(
"__kernel void as");
115 source.append(
"_cpu");
117 source.append(
"_gpu");
120 source.append(
"_cpu");
122 source.append(
"_gpu");
123 source.append(
"( \n");
124 source.append(
" __global "); source.append(numeric_string); source.append(
" * s1, \n");
125 source.append(
" \n");
128 source.append(
" "); source.append(numeric_string); source.append(
" fac2, \n");
132 source.append(
" __global "); source.append(numeric_string); source.append(
" * fac2, \n");
134 source.append(
" unsigned int options2, \n");
135 source.append(
" __global const "); source.append(numeric_string); source.append(
" * s2");
139 source.append(
", \n\n");
142 source.append(
" "); source.append(numeric_string); source.append(
" fac3, \n");
146 source.append(
" __global "); source.append(numeric_string); source.append(
" * fac3, \n");
148 source.append(
" unsigned int options3, \n");
149 source.append(
" __global const "); source.append(numeric_string); source.append(
" * s3");
151 source.append(
") \n{ \n");
155 source.append(
" "); source.append(numeric_string); source.append(
" alpha = fac2; \n");
159 source.append(
" "); source.append(numeric_string); source.append(
" alpha = fac2[0]; \n");
161 source.append(
" \n");
165 source.append(
" "); source.append(numeric_string); source.append(
" beta = fac3; \n");
169 source.append(
" "); source.append(numeric_string); source.append(
" beta = fac3[0]; \n");
172 source.append(
" if (options2 & (1 << 0)) { \n");
175 source.append(
" if (options3 & (1 << 0)) { \n");
177 source.append(
" } else { \n");
179 source.append(
" } \n");
183 source.append(
" } else { \n");
186 source.append(
" if (options3 & (1 << 0)) { \n");
188 source.append(
" } else { \n");
190 source.append(
" } \n");
195 source.append(
" } \n");
196 source.append(
"} \n");
199 template<
typename StringT>
225 template<
typename StringT>
228 source.append(
"__kernel void swap( \n");
229 source.append(
" __global "); source.append(numeric_string); source.append(
" * s1, \n");
230 source.append(
" __global "); source.append(numeric_string); source.append(
" * s2) \n");
231 source.append(
"{ \n");
232 source.append(
" "); source.append(numeric_string); source.append(
" tmp = *s2; \n");
233 source.append(
" *s2 = *s1; \n");
234 source.append(
" *s1 = tmp; \n");
235 source.append(
"} \n");
242 template<
typename NumericT>
252 static std::map<cl_context, bool> init_done;
259 source.reserve(8192);
261 viennacl::ocl::append_double_precision_pragma<NumericT>(ctx, source);
269 #ifdef VIENNACL_BUILD_INFO
270 std::cout <<
"Creating program " << prog_name << std::endl;
272 ctx.add_program(source, prog_name);
273 init_done[ctx.handle().get()] =
true;
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
void generate_asbs_impl3(StringT &source, char sign_a, char sign_b, asbs_config const &cfg, bool mult_alpha, bool mult_beta)
Provides OpenCL-related utilities.
void generate_asbs(StringT &source, std::string const &numeric_string)
static std::string program_name()
const viennacl::ocl::handle< cl_context > & handle() const
Returns the context handle.
void generate_scalar_swap(StringT &source, std::string const &numeric_string)
static void apply(viennacl::ocl::context const &)
Main kernel class for generating OpenCL kernels for operations involving viennacl::scalar<>, but not viennacl::vector<> or viennacl::matrix<>.
const OCL_TYPE & get() const
static void init(viennacl::ocl::context &ctx)
Configuration struct for generating OpenCL kernels for linear combinations of viennacl::scalar<> obje...
bool with_stride_and_range
void generate_asbs_impl(StringT &source, std::string const &numeric_string, asbs_config const &cfg)
asbs_scalar_type
Enumeration for the scalar type in avbv-like operations.
Representation of an OpenCL kernel in ViennaCL.
Helper class for converting a type to its string representation.
void generate_asbs_impl2(StringT &source, char sign_a, char sign_b, asbs_config const &cfg)