Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fix the error that occurred in not defining the cuFFT library in Google colab #518

Open
Moein151 opened this issue Aug 16, 2024 · 0 comments

Comments

@Moein151
Copy link

Moein151 commented Aug 16, 2024

Hi, I am a beginner in CUDA programming and I need to use the cuFFT library for my research in Google colab. But by executing the code, the commands of the cuFFT library are justified with an error.

The Code is:

%%cuda
#include <stdio.h>
#include <stdlib.h>
#include <cuda.h>
#include <cufft.h>
void generate_fake_samples(int N, float **out)
{
    int i;
    float *result = (float *)malloc(sizeof(float) * N);


    for (i = 0; i < N; i++)
    {
        result[i] = cos(i);
    }

    *out = result;
}
void real_to_complex(float *r, cufftComplex **complx, int N)
{
    int i;
    (*complx) = (cufftComplex *)malloc(sizeof(cufftComplex) * N);

    for (i = 0; i < N; i++)
    {
        (*complx)[i].x = r[i];
        (*complx)[i].y = 0;
    }
}

int main(int argc, char **argv)
{
    int i,a=1,b=3 ;
    int N = 2048;
    float *samples;
    cufftHandle plan = 0;
    cufftComplex *dComplexSamples, *complexSamples, *complexFreq;


    // Input Generation
    generate_fake_samples(N, &samples);
    printf("Initial Samples:\n");
    for (i = 0; i < 30; i++)
    {
        printf("  %2.4f\n", samples[i]);
    }
    printf("  ...\n");


    real_to_complex(samples, &complexSamples, N);


    complexFreq = (cufftComplex *)malloc(sizeof(cufftComplex) * N);

    cufftCreate(&plan);
    cufftPlan1d(&plan, N, CUFFT_C2C, 1);

    printf("%d\n",a+b);
    return 0;
}

The error I am getting is: /usr/bin/ld: /tmp/tmpxft_00000272_00000000-11_single_file.o: in function main':
tmpxft_00000272_00000000-6_single_file.cudafe1.cpp:(.text+0x20e): undefined reference to cufftCreate' /usr/bin/ld: tmpxft_00000272_00000000-6_single_file.cudafe1.cpp:(.text+0x227): undefined reference to cufftPlan1d'
collect2: error: ld returned 1 exit status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant