1 #ifndef VIENNACL_LINALG_OPENCL_KERNELS_NMF_HPP
2 #define VIENNACL_LINALG_OPENCL_KERNELS_NMF_HPP
37 template<
typename StringT>
40 source.append(
"__kernel void el_wise_mul_div( \n");
41 source.append(
" __global "); source.append(numeric_string); source.append(
" * matrix1, \n");
42 source.append(
" __global const "); source.append(numeric_string); source.append(
" * matrix2, \n");
43 source.append(
" __global const "); source.append(numeric_string); source.append(
" * matrix3, \n");
44 source.append(
" unsigned int size) \n");
45 source.append(
"{ \n");
46 source.append(
" for (unsigned int i = get_global_id(0); i < size; i += get_global_size(0)) \n");
47 source.append(
" { \n");
48 source.append(
" "); source.append(numeric_string); source.append(
" val = matrix1[i] * matrix2[i]; \n");
49 source.append(
" "); source.append(numeric_string); source.append(
" divisor = matrix3[i]; \n");
50 source.append(
" matrix1[i] = (divisor > ("); source.append(numeric_string); source.append(
")0.00001) ? (val / divisor) : ("); source.append(numeric_string); source.append(
")0; \n");
51 source.append(
" } \n");
52 source.append(
"} \n");
57 template<
typename NumericT>
67 static std::map<cl_context, bool> init_done;
76 viennacl::ocl::append_double_precision_pragma<NumericT>(ctx, source);
79 if (numeric_string ==
"float" || numeric_string ==
"double")
85 #ifdef VIENNACL_BUILD_INFO
86 std::cout <<
"Creating program " << prog_name << std::endl;
88 ctx.add_program(source, prog_name);
89 init_done[ctx.handle().get()] =
true;
void generate_nmf_el_wise_mul_div(StringT &source, std::string const &numeric_string)
Manages an OpenCL context and provides the respective convenience functions for creating buffers...
Provides OpenCL-related utilities.
const viennacl::ocl::handle< cl_context > & handle() const
Returns the context handle.
static std::string program_name()
static void apply(viennacl::ocl::context const &)
const OCL_TYPE & get() const
Main kernel class for generating OpenCL kernels for nonnegative matrix factorization of a dense matri...
Representation of an OpenCL kernel in ViennaCL.
static void init(viennacl::ocl::context &ctx)
Helper class for converting a type to its string representation.