使用thrust调用手写的CUDA内核

3

因为我需要使用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> *”的参数不兼容

什么?!我以为我正在提供浮点和整数的原始指针?还是我漏了什么?

1个回答

4
你正在使用调用函数所在的名称来调用内核,而不是内核的名称-因此参数不匹配。
请更改为:
CUDA_CountAndAdd_Kernel<<<1, n>>>(dSamples_raw, dCounts_raw);

为了

CUDA_CountAndAdd_Kernel_Device<<<1, n>>>(dSamples_raw, dCounts_raw);

试试看会发生什么。


D'oh!- 错误总是出在我自己身上,而不是实现上。 - Sebastian Dressler

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接