DuckQueen - 2 months ago 32

C++ Question

I wonder if there is an analog to boost compute Function (http://www.boost.org/doc/libs/1_61_0/libs/compute/doc/html/boost_compute/advanced_topics.html#boost_compute.advanced_topics.custom_functions ) that turns into kernel and can be created as embedded inline code that turns into a kernel?

Answer

In thrust, you can use function/functor with `__device__`

qualifier. An example of vector operation `saxpy`

is shown in the link, where you could find the functor `saxpy_functor`

http://docs.nvidia.com/cuda/thrust/#transformations

Similar to `boost::compute`

, you could also use thrust lambda expression as

```
thrust::transform(X.begin(), X.end(), Y.begin(), Y.begin(), A * _1 + _2);
```

or more standard C++ lambda expression as shown by @RobertCrovella.