This tutorial show how to use the low-level scheduler to generate efficient custom OpenCL kernels at run time. The purpose of the scheduler is to provide a low-level interface for interfacing ViennaCL from languages other than C++, yet providing the user the ability to specify complex operations. Typical consumers are scripting languages such as Python (e.g. PyViennaCL), but the facility should be used in the future to also fuse compute kernels on the fly.
We start this tutorial with including the necessary headers:
This tutorial sets up three vectors and finally assigns the sum of two to the third. Although this can be achieved with only a few lines of code using the standard ViennaCL C++ API, we go through the low-level interface for demonstration purposes.
Create three vectors, initialize two of them with ascending/descending integers:
Build expression graph for the operation vcl_vec3 = vcl_vec1 + vcl_vec2
This requires the following expression graph:
One expression node consists of two leaves and the operation connecting the two. Here we thus need two nodes: One for {vcl_vec3, = , link}, where 'link' points to the second node {vcl_vec1, +, vcl_vec2}.
The following is the lowest level on which one could build the expression tree. Even for a C API one would introduce some additional convenience layer such as add_vector_float_to_lhs(...); etc.
Create the full statement (aka. single line of code such as vcl_vec3 = vcl_vec1 + vcl_vec2):
Print the expression. Resembles the tree outlined in comments above.
Execute the operation
Print vectors in order to check the result:
That's it! Print success message and exit.