3
으로 손으로 쓰는 CUDA 커널을 호출하면 추력을 사용하게되었습니다. 지금까지는 그렇게 좋았지 만, 데이터를 포함하는 thrust :: host_vector가있는 "필기"커널을 호출하고 싶을 때 어떻게해야할까요?CUDA로 숫자의 큰 배열을 정렬해야하므로 추력
내 방식이되었다 (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)
그러나 컴파일 실패 :
error: argument of type "float **" is incompatible with parameter of type "thrust::host_vector> *"
허! 내가 float 및 int 원시 포인터를주는 줄 알았는데? 아니면 뭔가 빠졌나요?
D' oh! - 오류는 구현 자체가 아니라 혼자서 항상 발생합니다. –