我正在尝试对测试向量进行并行求和扫描。为此,我同时使用 Thrust 和 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);
我得到的错误是
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
我无法正确解释该错误,并且我确信我处理原始指针的方式存在问题。任何帮助表示赞赏。