30 #ifndef VIENNACL_WITH_OPENCL
31 #define VIENNACL_WITH_OPENCL
58 static const char * my_compute_program =
59 "__kernel void elementwise_prod(\n"
60 " __global const float * vec1,\n"
61 " __global const float * vec2, \n"
62 " __global float * result,\n"
63 " unsigned int size) \n"
65 " for (unsigned int i = get_global_id(0); i < size; i += get_global_size(0))\n"
66 " result[i] = vec1[i] * vec2[i];\n"
68 "__kernel void elementwise_div(\n"
69 " __global const float * vec1,\n"
70 " __global const float * vec2, \n"
71 " __global float * result,\n"
72 " unsigned int size) \n"
74 " for (unsigned int i = get_global_id(0); i < size; i += get_global_size(0))\n"
75 " result[i] = vec1[i] / vec2[i];\n"
88 unsigned int vector_size = 10;
97 for (
unsigned int i=0; i<vector_size; ++i)
99 vec1[i] =
static_cast<ScalarType
>(i);
100 vec2[i] =
static_cast<ScalarType
>(vector_size-i);
128 std::cout <<
" vec1: " << vec1 << std::endl;
129 std::cout <<
" vec2: " << vec2 << std::endl;
130 std::cout <<
"vec1 .* vec2: " << result_mul << std::endl;
131 std::cout <<
"vec1 /* vec2: " << result_div << std::endl;
138 std::cout <<
"!!!! TUTORIAL COMPLETED SUCCESSFULLY !!!!" << std::endl;
T norm_2(std::vector< T, A > const &v1)
Generic interface for the l^2-norm. See viennacl/linalg/vector_operations.hpp for implementations...
Represents an OpenCL kernel within ViennaCL.
viennacl::ocl::context & current_context()
Convenience function for returning the current context.
viennacl::ocl::program & add_program(cl_program p, std::string const &prog_name)
Adds a program to the context.
Wrapper class for an OpenCL program.
Implementations of the OpenCL backend, where all contexts are stored in.
void enqueue(KernelType &k, viennacl::ocl::command_queue const &queue)
Enqueues a kernel in the provided queue.
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
viennacl::ocl::kernel & get_kernel(std::string const &name)
Returns the kernel with the provided name.