
On Tuesday 18 September 2012 13:58:24 Felipe Magno de Almeida wrote:
On Tue, Sep 18, 2012 at 1:28 PM, Kyle Lutz <kyle.r.lutz@gmail.com> wrote:
Thanks for all the comments and feedback so far! I’ve written up answers to your questions below (which should serve as a good start for a FAQ for the library). Please let me know if anything is not clear or if I forgot to answer your question.
[snip]
*** Is it possible to use ordinary C++ functions/functors or C++11 lambdas with Boost.Compute? ***
Unfortunately no. OpenCL relies on having C99 source code available at run-time in order to execute code on the GPU. Thus compiled C++ functions or C++11 lambdas cannot simply be passed to the OpenCL environment to be executed on the GPU.
This is the reason why I wrote the Boost.Compute lambda library. Basically it takes C++ lambda expressions (e.g. _1 * sqrt(_1) + 4) and transforms them into C99 source code fragments (e.g. “input[i] * sqrt(input[i]) + 4)”) which are then passed to the Boost.Compute STL-style algorithms for execution. While not perfect, it allows the user to write code closer to C++ that still can be executed through OpenCL.
Could it use boost.phoenix v3? IUC, Phoenix v3 creates a boost.proto expression. The library could make transformations to these expressions.
Phoenix actors do contain Proto expressions. But as I understand, actors and the additional components Phoenix implements to evaluate expressions in a functional manner are useless in context of Boost.Compute. IIUC, the constructed expressions are not invoked but translated into strings (the C99 source code). Using Proto directly seems more appropriate.