# CUFFT on two GPUs (bug)

**URL:** <https://forums.developer.nvidia.com/t/cufft-on-two-gpus-bug/49769>\
**Category:** CUDA Programming and Performance\
**Created:** [May 6, 2017, 4:23pm UTC](https://forums.developer.nvidia.com/t/cufft-on-two-gpus-bug/49769 "2017-05-06T16:23:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob122](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Bob122](https://forums.developer.nvidia.com/u/Bob122)\
**Post date:** [May 6, 2017, 4:23pm UTC](https://forums.developer.nvidia.com/t/cufft-on-two-gpus-bug/49769/1 "2017-05-06T16:23:24Z")

</div>

Hi,

I am actually struggling to make cufft C2C work, and even if I am able to make FFTs from real to complex (R2C), when I try FFTs from complex to complex the result isn’t always the same (non deterministic).

To be more precise, sometimes the result is correct, and sometimes not!

What am I doing wrong?

Any help would be greatly appreciated,

Here is my code :

```auto
//...

int nGPUs = 2;
int whichGPUs[2];
whichGPUs[0] = 0;
whichGPUs[0] = 1;

cufftHandle plan_fft_F1_2_gpus;
result = cufftCreate(&plan_fft_F1_2_gpus);

result = cufftXtSetGPUs (plan_fft_F1_2_gpus, nGPUs, whichGPUs);

size_t F1_worksize[2];

if (cufftMakePlan1d(plan_fft_F1_2_gpus, apod_factor_F1*F1_NPoints, CUFFT_C2C, 
apod_factor_F2*F2_NPoints/2+1, F1_worksize)!=CUFFT_SUCCESS){
                        fprintf(stderr, "CUFFT error : Plan creation failed");
                }

cufftComplex *h_data_output_F1_F2; // the final result
cudaLibXtDesc *d_data_input_F1, *d_data_output_F1;

h_data_output_F1_F2 = (cufftComplex*) malloc(sizeof(cufftComplex)*
                        apod_factor_F1*F1_NPoints*((apod_factor_F2*F2_NPoints)/2+1));

//Malloc datas on GPU

if(cufftXtMalloc (plan_fft_F1_2_gpus, &d_data_input_F1, CUFFT_XT_FORMAT_INPLACE)
                           !=CUFFT_SUCCESS){
        fprintf(stderr, "CUFFT error1 : Malloc failed");
        return 1;
}

if(cufftXtMalloc (plan_fft_F1_2_gpus, &d_data_output_F1, CUFFT_XT_FORMAT_INPLACE)
                           !=CUFFT_SUCCESS) {
        fprintf(stderr, "CUFFT error2 : Malloc failed");
        return 1;
}

//F1_data_input comes from previously executed code (not displayed here) and contains the data

if (cufftXtMemcpy (plan_fft_F1_2_gpus, d_data_input_F1,
        F1_data_input, CUFFT_COPY_HOST_TO_DEVICE) != CUFFT_SUCCESS) {
                        fprintf(stderr, "CUFFT error : Memcopy failed");
                        return 1;
}

if(cufftXtExecDescriptorC2C(plan_fft_F1_2_gpus, d_data_input_F1,
                            d_data_output_F1, CUFFT_FORWARD)!= CUFFT_SUCCESS){
        fprintf(stderr, "Cuda error : failed to execute plan\n");
        return 1;
}

if (cudaDeviceSynchronize() != cudaSuccess){
        fprintf(stderr, "Cuda error: Failed to synchronize\n");
        return 1;
}

if (cufftXtMemcpy(plan_fft_F1_2_gpus, h_data_output_F1_F2, d_data_output_F1, 
CUFFT_COPY_DEVICE_TO_HOST)!=CUFFT_SUCCESS) {
        fprintf(stderr, "CUFFT error : Memcpy failed");
        return 1;
}

cufftDestroy(plan_fft_F1_2_gpus);
cufftXtFree(d_data_input_F1);
cufftXtFree(d_data_output_F1);

//...(Displaying the results in h_data_output_F1_F2 and more)...

```

---

<div class="post-metadata">

**Author:** ![Robert\_Crovella](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/robert_crovella/32/14043_2.png) [@Robert\_Crovella](https://forums.developer.nvidia.com/u/Robert_Crovella)\
**Post date:** [May 11, 2017, 12:41am UTC](https://forums.developer.nvidia.com/t/cufft-on-two-gpus-bug/49769/2 "2017-05-11T00:41:16Z")

</div>

cross posted (problem seems to be resolved?):

[url][http://stackoverflow.com/questions/43830132/cufft-xt-why-does-the-result-changes-each-time[/url]](http://stackoverflow.com/questions/43830132/cufft-xt-why-does-the-result-changes-each-time%5B/url%5D)
