Hello all,
I have implemented a reduction with complex numbers using CUDA Thrust but would now like to implement a version using CUDA CUB library. I am using CUDA 11.4 and have the following code in file myReductions.cu:
#include <iostream>
#include <cub/cub.cuh>
#include <cuComplex.h>
struct ComplexProdFloat {
__device__ __forceinline__
cuComplex operator()(cuComplex &a, cuComplex &b) {
cuComplex tmp;
tmp.x = a.x * b.x - a.y * b.y;
tmp.y = a.x * b.y + a.y * b.x;
a.x = tmp.x;
a.y = tmp.y;
return a;
}
};
// PARAM: a is HOST-side allocated array
// PARAM: N is length of a array
cuComplex reduceCUB(cuComplex *a, const size_t N) {
ComplexProdFloat prod;
cuComplex init;
void *d_temp_storage = NULL;
size_t temp_storage_bytes = 0;
init.x = init.y = 1;
cuComplex *d_a, d_prod;
CUDA_CHECK(cudaMalloc(reinterpret_cast<void **>(&d_a), sizeof(cuComplex) * N));
CUDA_CHECK(cudaMalloc(reinterpret_cast<void **>(&d_prod), sizeof(cuComplex)));
CUDA_CHECK(cudaMemcpy(d_a, a, N * sizeof(cuComplex), cudaMemcpyHostToDevice));
// This is where the error occurs when compiling
cub::DeviceReduce::Reduce(d_temp_storage, temp_storage_bytes, d_a, d_test, N, prod, init);
CUDA_CHECK(cudaMalloc(reinterpret_cast<void **>(&d_temp_storage), temp_storage_bytes));
...
CUDA_CHECK(cudaFree(reinterpret_cast<void *>(&d_temp_storage)));
return h_sum;
The above code is just a snippet of the full code but exposes the point at which the compilation fails. This failure occurs at the line containing cub::DeviceReduce::Reduce(d_temp_storage, temp_storage_bytes, d_a, d_test, N, prod, init);
The error that is output when compiling follows:
/usr/local/cuda/bin/…/targets/x86_64-linux/include/cub/device/dispatch/dispatch_reduce.cuh(325): error: class “std::iterator_traits” has no member “value_type”
detected during:
processing of template argument list for “cub::DispatchReduce” based on template arguments <cuComplex *, cuComplex, OffsetT, ComplexProdFloat>
/usr/local/cuda/bin/…/targets/x86_64-linux/include/cub/device/device_reduce.cuh(162):
…
I am hoping this is simple overlook on my part regarding the use of CUB, but am unsure. Can anyone assist by providing some hints/help?
Thanks
P.S. I am using C++ 17