Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7074477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:03:45+00:00 2026-05-28T06:03:45+00:00

I have difficulties to use complex numbers in cuda,pycuda. I have this in C:

  • 0

I have difficulties to use complex numbers in cuda,pycuda.

I have this in C:

#include <complex>
typedef std::complex<double> cmplx;
....
cmplx j(0.,1.);   

Also,in the same code:

#include <boost/python.hpp>
#include <boost/array.hpp>
...
typedef std::vector< boost::array<std::complex<double>,3 > > ComplexFieldType;
typedef std::vector< boost::array<double,3> > RealFieldType;
...
__global__ void compute(RealFieldType const & Rs,ComplexFieldType const & M,..)
...

    

How can i convert this to use it with pycuda?
I tried sth like this (according to the book ‘cuda by an example’):

struct cuComplex {
    float real;
    float imag;
    cuComplex(float a,float b): real(a),imag(b){} 
    cuComplex operator *(const cuComplex& a) {
    return cuComplex(real*a.real -imag*a.imag ,imag*a.real +real*a.imag);
    }
cuComplex operator +(const cuComplex& a) {
    return cuComplex(real+a.real ,imag+a.imag);
    };  

cuComplex j(0.,1.);    //instead of  cmplx j(0.,1.);  

 __global__ void compute(float *Rs,cuComplex * M,..)  //instead of RealFieldType const & Rs,ComplexFieldType const & M
....
    

Some of the errors i take are:

data member initializer is not allowed

this declaration has no storage class or type specifier

Thank you!

——————–-EDIT-———————————————

I did the following using #include <pycuda-complex.hpp> (relative to the above) :

pycuda::complex<float> cmplx;

cmplx j(0.,1.);

and as for typedef std::vector< boost::array<std::complex<double>,3 > > ComplexFieldType;

and ComplexFieldType const & M ,inside the global function,
i tried just "float *M " or "cmplx *M".

Until now , i am getting error :

variable "cmplx" is not a type name

If i use pycuda::complex cmplx; ,then i get:

identifier "cmplx" is undefined

name followed by "::" must be a class or namespace name

Also:

expression must have pointer-to-object type (but maybe this is from another part of code)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:03:46+00:00Added an answer on May 28, 2026 at 6:03 am

    It really isn’t clear what you are actually trying to do (if you actually know yourself), and the question is getting progressively more confused as the edits and comments roll on. But to expand Andreas’s answer a little, here is a simple, compilable piece of CUDA code which uses the pycuda native complex type correctly:

    #include <pycuda-complex.hpp>
    
    template<typename T>
    __global__ void kernel(const T * x, const T *y, T *z)
    {
        int tid = threadIdx.x + blockDim.x * blockIdx.x;
    
        z[tid] = x[tid] + y[tid];
    }
    
    
    typedef pycuda::complex<float> scmplx;
    typedef pycuda::complex<double> dcmplx;
    
    template void kernel<float>(const float *, const float *, float *);
    template void kernel<double>(const double *, const double *, double *);
    template void kernel<scmplx>(const scmplx *, const scmplx *, scmplx *);
    template void kernel<dcmplx>(const dcmplx *, const dcmplx *, dcmplx *);
    

    This gives you single and double real and complex versions of the trivial kernel and compiles with nvcc something like this:

    $ nvcc -arch=sm_20 -Xptxas="-v" -I$HOME/pycuda-2011.1.2/src/cuda -c scmplx.cu 
    ptxas info    : Compiling entry function '_Z6kernelIN6pycuda7complexIdEEEvPKT_S5_PS3_' for 'sm_20'
    ptxas info    : Used 12 registers, 44 bytes cmem[0], 168 bytes cmem[2], 4 bytes cmem[16]
    ptxas info    : Compiling entry function '_Z6kernelIN6pycuda7complexIfEEEvPKT_S5_PS3_' for 'sm_20'
    ptxas info    : Used 8 registers, 44 bytes cmem[0], 168 bytes cmem[2]
    ptxas info    : Compiling entry function '_Z6kernelIdEvPKT_S2_PS0_' for 'sm_20'
    ptxas info    : Used 8 registers, 44 bytes cmem[0], 168 bytes cmem[2]
    ptxas info    : Compiling entry function '_Z6kernelIfEvPKT_S2_PS0_' for 'sm_20'
    ptxas info    : Used 4 registers, 44 bytes cmem[0], 168 bytes cmem[2]
    

    Perhaps this goes someway to answering your question….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some difficulties with Ajax.BeginForm I have something like this in a view
Since I have been running in a lot of difficulties when trying to use
I have difficulties with how to use RLE on sequences of symbols. For example,
I'm having real difficulties optimising a MySQL query. I have to use the existing
I have encountered some difficulties while training my nn. When I use, lets say,
I would like to use the universal code and have ran into difficulties getting
I sometimes have difficulties with other people who wish to solve a problem when
I am reading the book: Intel Threading Building Blocks. I often have difficulties understanding
I have some difficulties in my project. I got the RGB values from a
I have some difficulties for using Ruby block, passing in a method. As in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.