nvcc insists thrust::complex doesn't have real() or imag()

14 hours ago 3
ARTICLE AD BOX
#include <stdio.h> #include <thrust/complex.h> #include <thrust/device_vector.h> // #include <thrust/host_vector.h> int main(int argc, char *argv[]) { thrust::device_vector<thrust::complex<float>> data(1); // thrust::host_vector<thrust::complex<float>> data(1); data[0] = thrust::complex<float>(static_cast<float>(1.0), static_cast<float>(2.0)); data[0] *= static_cast<float>(5.0); printf("data[0] = %f %fi\n", data[0].real(), data[0].imag()); }

When I try to compile the above with nvcc, It says:

test.cu(14): error: class "thrust::THRUST_300104_SM_750_NS::device_reference<thrust::THRUST_300104_SM_750_NS::complex<float>>" has no member "real" printf("data[0] = %f %fi\n", data[0].real(), data[0].imag()); ^ test.cu(14): error: class "thrust::THRUST_300104_SM_750_NS::device_reference<thrust::THRUST_300104_SM_750_NS::complex<float>>" has no member "imag" printf("data[0] = %f %fi\n", data[0].real(), data[0].imag()); ^

When I comment out the "device_vector" lines and uncomment the equivalent "host_vector" lines below them, nvcc compiles it without any problems. What's going on?

I'm using CUDA toolkit 13.1.115. WSL, Ubuntu 24.04.

Read Entire Article