Is there an API documentation for cuComplex?

I am trying to accelerate a program that renders Mandelbrot fractals, and while searching how to work with complex numbers inside the kernel, I coincidentally found this document, which has an example section, where a fractal is rendered with complex numbers, in the exact same way I want to do it. under section 4.2.2

There, this code snippet is provided:


Here, a strcuture called “cuComplex” is used, however, it isn’t mentioned, which header was used for it or which version the snippet featured. I also can’t find any official documentation for this structure when searching for it online or in the CUDA toolkit documentation. There is a “cuComplex.h” inside my environment (I use CUDA with Visual Studio 2022 on Windows 10), but it doesn’t seem to work the way it is shown in the snippet. To init a cuComplex, for example I have to do this:

cuComplex c(make_float2(0.0f, 0.0f));

And I can’t even write

a = a * a + c;

because, apparently, there is no operation defined for “*”

I looked at the file, where cuComplex is defined, and there are some functions that seem to multiply complex numbers, but the code and comments inside that file aren’t really readable for me. Also, I am confused why I can’t use this structure the way it is shown in the example snippet to begin with.

Is there an official documentation for this?

There is no documentation for cuComplex. It is a header file that is provided largely as a convenience - there isn’t anything specific to CUDA in it except that everything is decorated with __host__ __device__. Depending on your C++ knowledge level (and perhaps, complex math), you may be able to learn how to use it just by studying it. On a CUDA linux install, it is in the usual place for header files - /usr/local/cuda/include (cuComplex.h).

Otherwise, for the more general question about how to do convenient things with complex numbers in CUDA, you may be interested in this. You can do what you are describing with appropriate usage of thrust::complex, which is documented to some degree.

1 Like

Thank you for your response

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.