Some Issue about using cufft in class's methods

Brief Description
I have defined a cufftHandle attribute in a class, and then I’m trying to use cufftPlan1d(&plan, 512, CUFFT_C2C, 1) on this attribute within one of the class’s methods. However, this results in an error, which says “malloc(): invalid size (unsorted)”. However, when I use the same code in the main function, it works without errors. Can anyone help me understand why this is happening?

Details

  • I have defined a class with a cufftHandle attribute, let’s call it plan.
  • In one of the class methods, I’m trying to use cufftPlan1d on plan with certain parameters.
  • This code works without errors when placed in the main function.
  • However, when I try to use it within the class method, I encounter an error. The error message is: [malloc(): invalid size (unsorted)].

Relations
On Jetson Orin NX, Jetpack 5.1.1, CUDA 11.4.

One possibility is that you are passing the cufftHandle to the class method that provisions it via cufftPlan1d by-value. That generally won’t work. This is an elementary programming error associated with C or C++ that has nothing to do with CUDA.

This is just a guess, since you’ve not provided any code, and details you have omitted matter, such as exactly how you are passing the plan to each method.

I think there might be a misunderstanding. I haven’t been passing cufftHandle type parameters to this class; the class itself contains attributes of cufftHandle type.

a minimal example (bad version):

class fft_related_work{
    private:
    cufftHandle plan;

    public:
    void init(uint32_t length);
};

void fft_related_work::init(uint32_t length){
    cufftPlan1d(&plan, length, CUFFT_C2C, 1);
}

// get error if run this code
fft_related_work work;
work.init(512);

The program encounters the error at cufftPlan1d(&plan, length, CUFFT_C2C, 1); On the same machine and environment, it will work if I change the code as below:(good version)

int main(){
    cufftHandle plan;
    // no error in this example
    cufftPlan1d(&plan, length, CUFFT_C2C, 1);
    return 0;
}