简体   繁体   中英

How do I use boost.compute functions in a functor which will be used by Thrust on a GPU?

I'm trying to use a special function provided by boost.math in a thrust algorithm.

Basically, I want to do a transformation, like so

  thrust::device_vector<double> in(1000);
  thrust::device_vector<double> out(1000);

  thrust::transform(in.begin(), in.end(), out.begin(), myfunctor());

where myfunctor() is given by

#include <boost/math/special_functions/ellint_1.hpp>
.
.
.
struct myfunctor {
  __host__ __device__
  double operator()(double k) {
    return boost::math::ellint_1(sqrt(k));
  }
};

I keep getting warning: calling a __host__ function from a __host__ __device__ function is not allowed right at the line where ellint_1 is called in the functor.

Am I doing something wrong or is boost.math not suited for GPGPU use (because from what I've read, i definitely thought it was)?

Any function called inside __device__ qualified functions must also be a __device__ qualified function. And boost::math::ellint_1() does not have such qualifier.

See CUDA Programming Guide B.1. - Function Execution Space Specifiers https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#function-declaration-specifiers

And boost::math is unrelated to boost::compute, with the latter focusing on generic STL-like algorithms and containers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM