Can CUDA kernel function perform complex operation?
It probably depends on how you define “complex operation”. For interpretations of the term that I can think of, the answer is “yes”.
For a simple case as follow：
typedef float2 Complex;
global void test1(Complex a, Complexb,int n)
int i = blockDim.x * blockIdx.x + threadIdx.x;
b[i] = a[i] + b[i];
it should be ok ?
but I found that it didn’t report errors and the add operator in the kernel function didn’t work
What happened when you tried it? I assume you got a compiler error. I get:
complex.cu(8): error: no operator "+" matches these operands operand types are: Complex + Complex
That is because CUDA does not offer support vector operations on float2 operands. Nor does if offer C+±style support for complex data types.
CUDA does offer a very limited support for operations on complex data types, via functions calls. Take a look at the CUDA header file cuComplex.h to see what is available.
CUDA development is largely driven by customer demand. If you think CUDA should offer full-fledged support for math on complex data types, consider filing an enhancement request via the bug reporting form linked from the registered developer website.
Meanwhile, you can build your own complex math operations, or try to find a open source implementation on the internet (you are unlikely to be the first CUDA user who needs some complex math in their code).
it didn’t report the errors when compiling and executing the program，but the result is incorrect
when I google “cuda complex arithmetic” I get a variety of interesting and explanatory hits, including worked examples.
I also used cufftComplex included by cufft lib
The support for complex arithmetic CUDA offers via cuComplex.h is sufficient for what the CUFFT and CUBLAS libraries need.
well，thanks for your answers， I will try what you say.