【问题标题】:Calling handwritten CUDA kernel with thrust用推力调用手写的 CUDA 内核
【发布时间】:2011-01-24 18:39:26
【问题描述】:

因为我需要使用 CUDA 对大量数字进行排序,所以我使用了推力。到目前为止,一切都很好......但是当我想调用一个“手写”内核时,有一个包含数据的推力::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 **”类型的参数是 与类型参数不兼容 "推力::host_vector> *"

嗯?!我以为我在给出浮点和整数原始指针?还是我错过了什么?

【问题讨论】:

    标签: c++ cuda thrust


    【解决方案1】:

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

    变化:

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

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

    看看会发生什么。

    【讨论】:

    • 天啊! - 错误总是在我自己身上,而不是在实现中。
    猜你喜欢
    • 2018-07-22
    • 1970-01-01
    • 2021-02-07
    • 1970-01-01
    • 2016-09-10
    • 2020-01-24
    • 2014-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多