简体   繁体   English

Fortran中使用PlanMany的cuFFT双精度误差

[英]Double precision error of cuFFT with PlanMany in Fortran

Following the ( answer of JackOLantern ) I'm trying to compute a batch 1D FFTs using cufftPlanMany.按照( JackOLantern 的回答),我正在尝试使用 cufftPlanMany 计算一批一维 FFT。

The code below perform nwfs=23 times the 1D FFT forward and the 1D FFT backward of an n=256 complex array.下面的代码对n=256复数数组执行nwfs=23次 1D FFT 前向和 1D FFT 后向。 It's to train me to handle the routine cufftPlanMany.就是训练我处理常规的 cufftPlanMany。 As a second step, the nwfs arrays will be differents .At the end, I check the errors of each arrays.第二步, nwfs数组会有所不同。最后,我检查每个数组的错误。

Because of the data are allocate as: cinput_d(n,nwfs) I use th function like this: cufftPlanMany(planmany, 1, fftsize, inembed, nwfs,1, onembed, nwfs,1, CUFFT_C2C, nwfs)由于数据分配为: cinput_d(n,nwfs)我使用这样的函数: cufftPlanMany(planmany, 1, fftsize, inembed, nwfs,1, onembed, nwfs,1, CUFFT_C2C, nwfs)

where :在哪里 :

  • rank = 1
  • fftsize = {n} same dim for each FFT fftsize = {n}每个 FFT 的fftsize = {n}相同
  • inembed = onembed = {0} ignored inembed = onembed = {0}忽略
  • istride = ostride = nwfs distance between two successive input and output istride = ostride = nwfs两个连续输入和输出之间的距离
  • idist = odist = 1 distance between two signals idist = odist = 1两个信号之间的距离
  • batch = nwfs number of fft to be done batch = nwfs要完成的 fft 数
program fft use cudafor use precision_m use cufft_m implicit none integer, allocatable:: kx(:) complex(fp_kind), allocatable:: matrix(:) complex(fp_kind), allocatable, pinned :: cinput(:,:),coutput(:,:) complex(fp_kind), allocatable, device :: cinput_d(:,:),coutput_d(:,:) integer:: i,j,k,n,nwfs integer, allocatable :: fftsize(:),inembed(:),onembed(:) type(c_ptr):: plan,planmany real(fp_kind):: twopi=8._fp_kind*atan(1._fp_kind),h integer::clock_start,clock_end,clock_rate,istat real :: elapsed_time character*1:: a real(fp_kind):: w,x,y,z integer:: nerrors n=256 nwfs=23 h=twopi/real(n,fp_kind) ! allocate arrays on the host allocate (cinput(n,nwfs),coutput(n,nwfs)) allocate (kx(n),matrix(n)) allocate (fftsize(nwfs),inembed(nwfs),onembed(nwfs)) ! allocate arrays on the device allocate (cinput_d(n,nwfs),coutput_d(n,nwfs)) fftsize(:) = n inembed(:) = 0 onembed(:) = 0 !initialize arrays on host kx =(/ ((i-0.5)*0.1953125, i=1,n/2), ((-n+i-0.5)*0.1953125, i=n/2+1,n) /) matrix = (/ ... /) !write(*,*) cinput !copy arrays to device do i =1,nwfs cinput(:,i)=matrix(:) end do cinput_d=cinput ! Initialize the plan for complex to complex transform if (fp_kind== singlePrecision) call cufftPlan1D(plan,n,CUFFT_C2C,1) if (fp_kind== doublePrecision) call cufftPlan1D(plan,n,CUFFT_Z2Z,1) if (fp_kind== doublePrecision) call cufftPlanMany(planmany, 1, fftsize, inembed, & nwfs,1, & onembed, & nwfs,1, & CUFFT_Z2Z, nwfs) if (fp_kind== singlePrecision) call cufftPlanMany(planmany, 1, fftsize, inembed, & nwfs,1, & onembed, & nwfs,1, & CUFFT_C2C, nwfs) !c_null_ptr fftsize,inembed,onembed ! cufftPlanMany(plan, rank, n, inembed, istride, idist, & ! onembed, ostride, odist, & ! type, batch) !subroutine cufftPlan1d(plan, nx, type, batch) call SYSTEM_CLOCK(COUNT_RATE=clock_rate) istat=cudaThreadSynchronize() call SYSTEM_CLOCK(count=clock_start) ! Forward transform out of place call cufftExec(planmany,cinput_d,coutput_d,CUFFT_FORWARD) !$cuf kernel do <<<*,*>>> do i=1,n do j =1,n coutput_d(i,j) = coutput_d(i,j)/real(n,fp_kind)!sqrt(twopi*real(n,fp_kind))*sqrt(2.*pi)/sqrt(real(maxn)) end do end do call cufftExec(planmany,coutput_d,coutput_d,CUFFT_INVERSE) istat=cudaThreadSynchronize() call SYSTEM_CLOCK(count=clock_end) ! Copy results back to host coutput=coutput_d do i=1,n ! write(*,'(i2,1x,2(f8.4),1x,2(f8.4),2x,e13.7)') i,cinput(i),coutput(i),abs(coutput(i)-cinput(i)) end do nerrors=0 do i=1,n !write(*,'(i2,5(1x,2(f8.4),1x,2(f8.4),2x,3(e13.7,2x)))') i,cinput(i,1),coutput(i,1),abs(coutput(i,1)-cinput(i,1)),abs(coutput(i,6)-cinput(i,6)),abs(coutput(i,nwfs)-cinput(i,nwfs)) do j=1,nwfs if (abs(coutput(i,j)-cinput(i,j))>1.d-5) then write(*,'(i3,i3,1x,e13.7,2x,4(f8.4))') i,j,abs(coutput(i,j)-cinput(i,j)),cinput(i,j),coutput(i,j) nerrors = nerrors + 1 end if end do end do elapsed_time = REAL(clock_end-clock_start)/REAL(clock_rate) write(*,*) 'elapsed_time :',elapsed_time,clock_start,clock_end,clock_rate if (nerrors .eq. 0) then print *, "Test Passed" else print *, "Test Failed" endif !release memory on the host and on the device deallocate (cinput,coutput,kx,cinput_d,coutput_d) ! Destroy the plans call cufftDestroy(plan) end program fft

Is somebody can tell me why the following "many-FFT" sometimes failed in double precision but never in single precision ?有人能告诉我为什么下面的“多 FFT”有时在双精度中失败,但在单精度中从未失败?

Single precision: "Test Passed" ALWAYS !单精度:“测试通过”总是! Double precision: "Test Failed" Sometimes !双精度:“测试失败”有时!

Indeed, I checked the Device to Host data transfer.事实上,我检查了设备到主机的数据传输。 That doesn't seem to be it.似乎不是这样。

Thanks for any help.谢谢你的帮助。

Thanks to talonmies.多亏了塔隆米。 It was the WDDM Timeout Detection & Recovery limit.这是 WDDM 超时检测和恢复限制。

See the link, to change the TDR请参阅链接以更改 TDR

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM