用推力调用手写的CUDA内核

时间:2010-03-07 21:28:35

标签: c++ cuda thrust

因为我需要用CUDA对大数字数组进行排序,所以我选择使用推力。到目前为止,这么好......但是当我想调用一个“手写”内核时,有一个包含数据的thrust :: host_vector?

我的方法是(缺少背板):

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&gt; *”

咦?我以为我给浮点数和int原始指针?或者我错过了什么?

1 个答案:

答案 0 :(得分:4)

您正在使用调用函数的名称调用内核,而不是内核的名称 - 因此参数不匹配。

变化:

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

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

看看会发生什么。

相关问题