Questions
Questions copied to clipboard
How to fix the error that occurred in not defining the cuFFT library in Google colab
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