How to implement a nested algorithm using boost::compute?

47 views Asked by At

The documentation demonstrates nicely how to compose trivial function objects to be passed to any algorithm provided by boost::compute. There is also a link provided [Custom OpenCL functions in C++ with Boost.Compute][1] which is dead meanwhile. The boost compute documentation does not say anything about nested algorithms: (This is supposed to be an implementation of a multiplication of a sparse matrix (_rM) with a vector (_rX).)

const std::vector<double> _rM, _rX;
const std::vector<std::size_t> _rRowStart;
const std::vector<unsigned int> _rCol;
std::vector<double> _rY;
std::transform(
        _rRowStart.begin(),
        std::prev(_rRowStart.end()),
        std::next(_rRowStart.begin()),
        _rY.begin(),
        [&](const std::size_t _iRowStart, const std::size_t _iRowEnd)
        {       return std::inner_product(
                        _rM.begin() + _iRowStart,
                        _rM.begin() + _iRowEnd,
                        boost::make_permutation_iterator(_rX.begin(), _rCol.begin() + _iRowStart),
                        0.0
                );
         }
);

So how does one implement a function object to be passed to an algorithm of boost::compute, with the function object calling in turn another algorithm from boost::compute? How does one pass variable references to this function object (&_rM, &_rX, &_rCol)? I would like to have the above algorithm implemented in boost::compute. (The inner_product can also be implemented without boost::permutation_iterator by using two input ranges and two function objects, one performing the accumulation (std::plus<double>) and one doing the multiplication AND the permutation.) [1]: http://kylelutz.blogspot.com/2014/03/custom-opencl-functions-in-c-with.html

0

There are 0 answers