cast to cuda complex ? Use crealf?

Hello ,

I am using the fftwf_complex data type in my codes.

Now, I have a kernel where I want to do:

for ( int i = 0; i < N; i++ )
{
		crealf(  ouMean[ GlobalIdx ] ) = sqrtf(  crealf( Data ) *  crealf( Data ) + cimagf( Data ) *  cimagf( Data ) -  crealf ( ouMean[ GlobalIdx ] ) ) / (i + 1);
}

And I am receiving:

argument of type "const complex_float_t *" is incompatible with parameter of type "float __complex__"
expression must be a modifiable lvalue
no suitable conversion function from "cuFloatComplex" to "float __complex__" exists

If I use:

cuCrealf(  ouMean[ GlobalIdx ] ) = sqrtf(  cuCrealf( Data ) *  cuCrealf( Data ) + cuCimagf( Data ) *  cuCimagf( Data ) -  cuCrealf ( ouMean[ GlobalIdx ] ) ) / (i + 1);

I receive:

no suitable constructor exists to convert from "const complex_float_t *const" to  "float2"
expression must be a modifiable lvalue

How can I overcome this problem?

Thanks!

You can use

ouMean[ GlobalIdx ] = make_cuFloatComplex( sqrtf(...), 0 )

or (since cuFloatComplex is just a float2 and has member variables .x (real) and .y (imag) )

ouMean[ GlobalIdx ].x = sqrtf(...)

OK,

Thanks , it works like this.

But I can’t uderstand , since I am using fftw3.h, it supposes to work like:

ouMean[ GlobalIdx ][ 0 ]

for the real part and

ouMean[ GlobalIdx ][ 1 ]

for the imag part.

But it gives me : e

xpression must have pointer-to-object type

Hmm… I figured that the reason it doesn’t work is because I have also the complex header,

#include <complex.h>
#include <fftw3.h>

because I am using it in a lot of other files in the same program.

Is there a way to overcome this problem?
( I want to use the above headers for other files of my program )