3

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>*」のパラメーターと互換性がありません

は?!私はfloatとintのrawポインターを与えていると思いましたか?または私は何かが欠けていますか?

4

1 に答える 1

4

カーネルの名前ではなく、呼び出し元の関数の名前でカーネルを呼び出しているため、パラメーターが一致していません。

変化する:

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

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

何が起こるか見てみましょう。

于 2010-03-08T01:31:54.680 に答える