0

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)?

fiziks
  • 247
  • 2
  • 5
  • I can't test or check it right now but maybe the problem is `sqrt`. – t.niese May 02 '19 at 16:18
  • Boost.compute is a helper for [OpenCL](https://en.wikipedia.org/wiki/OpenCL). An [example](https://github.com/boostorg/compute/blob/master/example/simple_kernel.cpp) When the NVIDEA Thrust is similar helper but for [CUDA API](https://en.wikipedia.org/wiki/CUDA). And [boost::math](https://www.boost.org/doc/libs/1_70_0/libs/math/doc/html/index.html) - is a CPU library. – Victor Gubin May 02 '19 at 17:20
  • So, I was using a CPU library in my device code. Not sure how I missed that. I just did a search for such special functions available for device code, but I can't seem to find anything. Would you happen to know of anything? – fiziks May 02 '19 at 17:50
  • It seems like you would need to implement Legendre Complete Elliptic Integral of first kind by the OpenCL or CUDA kernel. Or find an existing GPGPU implementation, and use it. – Victor Gubin May 02 '19 at 18:06

1 Answers1

1

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.

Anthony
  • 51
  • 5