Call CUDA Handwritten Core with Traction

since I needed to sort large arrays of numbers with CUDA, I came up with traction. So far so good ... but what when I want to name a "handwritten" kernel having thrust :: host_vector containing data?

My approach was (backcopy missing):

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);
}

The kernel looks like this:

__global__ void CUDA_CountAndAdd_Kernel_Device(float *samples, int *counts) 

But compilation fails:

error: argument of type "float **" equals incompatible with parameter of type "thrust :: host_vector> *"

Yes?! I thought I give float and int raw-pointers? Or am I missing something?

+3
source share
1 answer

​​ , , - , .

:

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

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

, .

+4

Source: https://habr.com/ru/post/1735825/


All Articles