简体   繁体   English

如何在Thrust在GPU上使用的仿函数中使用boost.compute函数?

[英]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. 我正在尝试在推力算法中使用boost.math提供的特殊功能。

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 其中myfunctor()

#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. 我不断收到warning: calling a __host__ function from a __host__ __device__ function is not allowed在函子中调用ellint_1的行上, warning: calling a __host__ function from a __host__ __device__ function is not allowed

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)? 我是在做错什么还是boost.math不适合GPGPU使用(因为我读过的书,我绝对认为是这样)?

Any function called inside __device__ qualified functions must also be a __device__ qualified function. __device__限定函数内部调用的任何函数也必须是__device__限定函数。 And boost::math::ellint_1() does not have such qualifier. 并且boost::math::ellint_1()没有这种限定符。

See CUDA Programming Guide B.1. 请参阅CUDA编程指南B.1。 - Function Execution Space Specifiers https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#function-declaration-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. boost :: math与boost :: compute无关,后者主要关注类STL的通用算法和容器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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