استدعاء نواة كودا المكتوبة بخط اليد مع التوجه
سؤال
منذ أن كنت بحاجة إلى فرز صفائف كبيرة من الأرقام مع 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 **" غير متوافق مع معلمة النوع "Thrust :: Host_Vector> *"
هاه؟! اعتقدت أنني كنت أعطي تعويم و int raw رميات؟ أم هل فاتني شيء؟
المحلول
أنت تتصل بـ kernel باسم الوظيفة التي تكون عليها المكالمة ، وليس اسم kernel - وبالتالي عدم تطابق المعلمة.
يتغيرون:
CUDA_CountAndAdd_Kernel<<<1, n>>>(dSamples_raw, dCounts_raw);
ل
CUDA_CountAndAdd_Kernel_Device<<<1, n>>>(dSamples_raw, dCounts_raw);
وانظر ماذا يحدث.
لا تنتمي إلى StackOverflow