Cuda 同时使用CUB和推力进行并行和扫描

Cuda 同时使用CUB和推力进行并行和扫描,cuda,thrust,cub,Cuda,Thrust,Cub,我正在尝试对测试向量进行并行和扫描。为此,我同时使用了推力库和CUB库 struct CustomSum { template <typename T> CUB_RUNTIME_FUNCTION __forceinline__ T operator()(const T &a, const T &b) const { return a + b; } }; // 2d array stored

我正在尝试对测试向量进行并行和扫描。为此,我同时使用了推力库和CUB库

struct CustomSum
{
    template <typename T>
    CUB_RUNTIME_FUNCTION __forceinline__
        T operator()(const T &a, const T &b) const {
            return a + b;
        }
};
    // 2d array stored in row-major order [(0,0), (0,1), (0,2), ... ]
    thrust::host_vector<int> hVec_I1(SIZE_IMG, 1);
    thrust::host_vector<int> hVec_I2(SIZE_IMG, 1);
    thrust::host_vector<int> h_out(SIZE_IMG, 1);

    CustomSum sum_op;
    // Innitialize vector with synthetic image:
    initialize(N, N, hVec_I1, hVec_I2);

    // Compute Integral Image M1 and M2
    thrust::device_vector<int> dVec_M1 = hVec_I1;
    thrust::device_vector<int> dVec_M2 = hVec_I2;
    thrust::device_vector<int> d_o = h_out;

    //thrust::device_ptr<double> d_in = dVec_M1.data();
    //thrust::device_ptr<double> d_out1 = d_out.data();
    int* d_in = thrust::raw_pointer_cast(&dVec_M1[0]);
    int *d_out = thrust::raw_pointer_cast(&d_o[0]);
    //d_in = thrust::raw_pointer_cast(dVec_M2.data());

    //thrust::device_vector<int> d_out;
    //int *d_out = thrust::raw_pointer_cast(dVec_M1.data());
    void *d_temp_storage = NULL;
    size_t temp_storage_bytes = 0;

    // Run inclusive prefix sum-scan
    cub::DeviceScan::InclusiveScan(d_temp_storage, temp_storage_bytes, d_in, d_out, sum_op, SIZE_IMG);
    // Allocate temporary storage for inclusive prefix scan
    cudaMalloc(&d_temp_storage, temp_storage_bytes);
    // Run inclusive prefix sum-scan
    cub::DeviceScan::InclusiveScan(d_temp_storage, temp_storage_bytes, d_in, d_out, sum_op, SIZE_IMG);
struct CustomSum
{
模板
CUB_运行时_函数_forceinline__
T运算符()(常数T&a,常数T&b)常数{
返回a+b;
}
};
//按行大顺序存储的二维数组[(0,0),(0,1),(0,2),…]
推力:主机向量hVec I1(大小IMG,1);
推力:主机向量hVec I2(大小IMG,1);
推力:主机向量输出(大小IMG,1);
自定义总和运算;
//使用合成图像初始化矢量:
初始化(N,N,hVec_I1,hVec_I2);
//计算积分图像M1和M2
推力:装置矢量dVec\U M1=hVec\U I1;
推力:装置矢量dVec\U M2=hVec\U I2;
推力::设备向量d_o=h_out;
//推力:device_ptr d_in=dVec_M1.data();
//推力::device_ptr d_out1=d_out.data();
int*d_in=推力::原始指针投射(&dVec_M1[0]);
int*d_out=推力::原始指针\u投射(&d_o[0]);
//d_in=推力::原始指针(dVec_M2.data());
//推力::装置矢量d输出;
//int*d_out=推力::原始指针(dVec_M1.data());
void*d_temp_storage=NULL;
大小\u t温度\u存储\u字节=0;
//运行包含前缀和扫描
cub::DeviceScan::InclusiveScan(数据临时存储、临时存储字节、数据输入、数据输出、总和运算、大小IMG);
//为包含性前缀扫描分配临时存储
cudaMalloc(&d_临时存储,临时存储字节);
//运行包含前缀和扫描
cub::DeviceScan::InclusiveScan(数据临时存储、临时存储字节、数据输入、数据输出、总和运算、大小IMG);
我得到的错误是

Error   43  error : calling a __host__ function("CustomSum::operator ()<int> ") from a __device__ function("cub::TilePrefixCallbackOp<int, CustomSum, cub::ScanTileState<int, (bool)1> > ::operator ()") is not allowed c:\users\asu_cuda_laptop\documents\visual studio 2013\projects\stats_kernel\cub\agent\single_pass_scan_operators.cuh    747 1   stats_kernel
错误43错误:不允许从设备函数(“cub::TilePrefixCallbackOp::operator()”)调用主机函数(“CustomSum::operator()”)。c:\users\asu\cuda\u laptop\documents\visualstudio 2013\projects\stats\u kernel\cub\agent\single\u pass\u scan\u operators.cuh 747 1 stats\u kernel
我无法正确解释错误,我确信我处理原始指针的方式存在问题。感谢您的帮助


相关链接:

尝试将
CustomSum::operator()
定义为
\uuuu设备
函数。有关中的
\uuuuuuuuuuuuu主机\uuuuuuu
vs
\uuuuuuuuuu设备\uuuuuuuuuu
函数的详细信息。

如果正确的编译轨迹为used@talonmies所以如果Gaara添加了“设备”,但仍然不起作用,我们至少可以排除CUB_RUNTIME_函数被错误定义的可能性。我不认为
CUB_RUNTIME_函数
的主要目的是为函数的一般用例提供
\uuuuuu主机\uuuuuuu设备\uuuuuuuuu
装饰,而这些通常情况下必须如此装饰,但其目的是在CDP设置中可从设备代码中额外调用的函数上提供
\uuuu device\uuuu
标记。很明显,这需要显式修饰函子。因此,我相信这个答案是正确的。即使是OP的帖子中提供的
CustomSum
也显示了显式修饰,所以OP为什么会放弃这种修饰是一个谜。你能编辑你的问题以包含你用于此代码的编译命令吗?