因为我需要使用CUDA对大型数字数组进行排序,所以我开始使用了thrust。到目前为止一切正常...但是当我想调用一个包含数据的thrust::host_vector的"手写"内核时怎么办?
我的做法是(缺少backcopy):
int CUDA_CountAndAdd_Kernel(thrust::host_vector<float> *samples, thrust::host_vector<int> *counts, int n) {
thrust::device_ptr<float> dSamples = thrust::device_malloc<float>(n);
thrust::copy(samples->begin(), samples->end(), dSamples);
thrust::device_ptr<int> dCounts = thrust::device_malloc<int>(n);
thrust::copy(counts->begin(), counts->end(), dCounts);
float *dSamples_raw = thrust::raw_pointer_cast(dSamples);
int *dCounts_raw = thrust::raw_pointer_cast(dCounts);
CUDA_CountAndAdd_Kernel<<<1, n>>>(dSamples_raw, dCounts_raw);
thrust::device_free(dCounts);
thrust::device_free(dSamples);
}
内核看起来像这样:
__global__ void CUDA_CountAndAdd_Kernel_Device(float *samples, int *counts)
但是编译失败并显示以下错误:
错误:类型为“float **”的参数与类型为“thrust::host_vector> *”的参数不兼容
什么?!我以为我正在提供浮点和整数的原始指针?还是我漏了什么?