【问题标题】:How do I use boost.compute functions in a functor which will be used by Thrust on a GPU?如何在 GPU 上 Thrust 使用的仿函数中使用 boost.compute 函数?
【发布时间】:2019-09-21 03:11:19
【问题描述】:

我正在尝试在推力算法中使用 boost.math 提供的特殊函数。

基本上,我想做一个转换,像这样

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

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

myfunctor() 由下式给出

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

我不断在仿函数中调用ellint_1 的那一行得到warning: calling a __host__ function from a __host__ __device__ function is not allowed

是我做错了什么还是 boost.math 不适合 GPGPU 使用(因为从我所读的内容来看,我确实认为它是)?

【问题讨论】:

  • 我现在无法测试或检查,但问题可能出在sqrt
  • Boost.compute 是OpenCL 的助手。一个example 当 NVIDEA Thrust 是类似的助手但用于CUDA APIboost::math - 是一个 CPU 库。
  • 所以,我在设备代码中使用了 CPU 库。不知道我是怎么错过的。我只是搜索了可用于设备代码的此类特殊功能,但似乎找不到任何东西。你会碰巧知道什么吗?
  • 您似乎需要通过 OpenCL 或 CUDA 内核实现第一类 Legendre 完全椭圆积分。或者找到一个现有的 GPGPU 实现并使用它。

标签: c++ boost gpgpu thrust boost-compute


【解决方案1】:

__device__ 限定函数内调用的任何函数也必须是__device__ 限定函数。而boost::math::ellint_1() 没有这样的限定符。

请参阅 CUDA 编程指南 B.1。 - 函数执行空间说明符 https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#function-declaration-specifiers

并且 boost::math 与 boost::compute 无关,后者专注于通用的类似 STL 的算法和容器。

【讨论】:

    猜你喜欢
    • 2012-02-26
    • 2015-01-31
    • 1970-01-01
    • 2020-11-14
    • 1970-01-01
    • 2013-12-07
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    相关资源
    最近更新 更多