PyCuda cuFloatComplex

Hello all,

I am trying to learn PyCuda, so this is likely a simple answer but I need to ask.

Say I have a device pointer to an array of type cuFloatComplex and I would like to copy that from device to host such that the results can be printed to standard output - what is the PyCuda way to do this? I assume that I would need to create a numpy array on host to store results but given that cuFloatComplex is not a Python type how can this be done?

Thanks in advance for any assistance.

The memory layout of CUDA’s complex types matches what is specified for C, C++, Fortran: the real part of each number is followed by its imaginary part. So when interfacing with those languages simple memcpy() like operations will work for copying data, and just passing a pointer for zero-copy interfaces.

In the PyCUDA documentation I find:

https://documen.tician.de/pycuda/array.html

Based on this, treating ‘cuFloatComplex’ as ‘float2’ in PyCUDA should do the trick. Accessing .x will give you the real part, accessing .y will give you the imaginary part.

Thanks for the information. I will give it a try.

Works perfectly. Thank you again @njuffa