@@ -55,8 +55,11 @@ function plan_r2r end
5555
5656# # FFT: Implement fft by calling fftw.
5757
58- const version = VersionNumber (split (unsafe_string (cglobal (
59- (:fftw_version ,libfftw3 ()), UInt8)), [' -' , ' ' ])[2 ])
58+ # TODO : this is dangerous since it captures runtime data from the compile machine
59+ # n.b. write this as a function to avoid Julia bugs with the runtime cglobal implementation
60+ get_version () = VersionNumber (split (unsafe_string (cglobal (
61+ (:fftw_version ,libfftw3_no_init), UInt8)), [' -' , ' ' ])[2 ])
62+ const version = get_version ()
6063
6164# # Direction of FFT
6265
@@ -141,32 +144,32 @@ alignment_of(A::FakeArray) = Int32(0)
141144@exclusive function export_wisdom (fname:: AbstractString )
142145 f = ccall (:fopen , Ptr{Cvoid}, (Cstring,Cstring), fname, :w )
143146 systemerror (" could not open wisdom file $fname for writing" , f == C_NULL )
144- ccall ((:fftw_export_wisdom_to_file ,libfftw3 () ), Cvoid, (Ptr{Cvoid},), f)
147+ ccall ((:fftw_export_wisdom_to_file ,libfftw3), Cvoid, (Ptr{Cvoid},), f)
145148 ccall (:fputs , Int32, (Ptr{UInt8},Ptr{Cvoid}), " " ^ 256 , f) # no NUL, hence no Cstring
146- ccall ((:fftwf_export_wisdom_to_file ,libfftw3f () ), Cvoid, (Ptr{Cvoid},), f)
149+ ccall ((:fftwf_export_wisdom_to_file ,libfftw3f), Cvoid, (Ptr{Cvoid},), f)
147150 ccall (:fclose , Cvoid, (Ptr{Cvoid},), f)
148151end
149152
150153@exclusive function import_wisdom (fname:: AbstractString )
151154 f = ccall (:fopen , Ptr{Cvoid}, (Cstring,Cstring), fname, :r )
152155 systemerror (" could not open wisdom file $fname for reading" , f == C_NULL )
153- if ccall ((:fftw_import_wisdom_from_file ,libfftw3 () ),Int32,(Ptr{Cvoid},),f)== 0 ||
154- ccall ((:fftwf_import_wisdom_from_file ,libfftw3f () ),Int32,(Ptr{Cvoid},),f)== 0
156+ if ccall ((:fftw_import_wisdom_from_file ,libfftw3),Int32,(Ptr{Cvoid},),f)== 0 ||
157+ ccall ((:fftwf_import_wisdom_from_file ,libfftw3f),Int32,(Ptr{Cvoid},),f)== 0
155158 error (" failed to import wisdom from $fname " )
156159 end
157160 ccall (:fclose , Cvoid, (Ptr{Cvoid},), f)
158161end
159162
160163@exclusive function import_system_wisdom ()
161- if ccall ((:fftw_import_system_wisdom ,libfftw3 () ), Int32, ()) == 0 ||
162- ccall ((:fftwf_import_system_wisdom ,libfftw3f () ), Int32, ()) == 0
164+ if ccall ((:fftw_import_system_wisdom ,libfftw3), Int32, ()) == 0 ||
165+ ccall ((:fftwf_import_system_wisdom ,libfftw3f), Int32, ()) == 0
163166 error (" failed to import system wisdom" )
164167 end
165168end
166169
167170@exclusive function forget_wisdom ()
168- ccall ((:fftw_forget_wisdom ,libfftw3 () ), Cvoid, ())
169- ccall ((:fftwf_forget_wisdom ,libfftw3f () ), Cvoid, ())
171+ ccall ((:fftw_forget_wisdom ,libfftw3), Cvoid, ())
172+ ccall ((:fftwf_forget_wisdom ,libfftw3f), Cvoid, ())
170173end
171174
172175# Threads
@@ -176,15 +179,15 @@ function _set_num_threads(num_threads::Integer)
176179 @static if fftw_provider == " mkl"
177180 _last_num_threads[] = num_threads
178181 end
179- ccall ((:fftw_plan_with_nthreads ,libfftw3 () ), Cvoid, (Int32,), num_threads)
180- ccall ((:fftwf_plan_with_nthreads ,libfftw3f () ), Cvoid, (Int32,), num_threads)
182+ ccall ((:fftw_plan_with_nthreads ,libfftw3), Cvoid, (Int32,), num_threads)
183+ ccall ((:fftwf_plan_with_nthreads ,libfftw3f), Cvoid, (Int32,), num_threads)
181184end
182185
183186@exclusive set_num_threads (num_threads:: Integer ) = _set_num_threads (num_threads)
184187
185188function get_num_threads ()
186189 @static if fftw_provider == " fftw"
187- ccall ((:fftw_planner_nthreads ,libfftw3 () ), Cint, ())
190+ ccall ((:fftw_planner_nthreads ,libfftw3), Cint, ())
188191 else
189192 _last_num_threads[]
190193 end
@@ -211,9 +214,9 @@ const NO_TIMELIMIT = -1.0 # from fftw3.h
211214
212215# only call these when fftwlock is held:
213216unsafe_set_timelimit (precision:: fftwTypeDouble ,seconds) =
214- ccall ((:fftw_set_timelimit ,libfftw3 () ), Cvoid, (Float64,), seconds)
217+ ccall ((:fftw_set_timelimit ,libfftw3), Cvoid, (Float64,), seconds)
215218unsafe_set_timelimit (precision:: fftwTypeSingle ,seconds) =
216- ccall ((:fftwf_set_timelimit ,libfftw3f () ), Cvoid, (Float64,), seconds)
219+ ccall ((:fftwf_set_timelimit ,libfftw3f), Cvoid, (Float64,), seconds)
217220@exclusive set_timelimit (precision, seconds) = unsafe_set_timelimit (precision, seconds)
218221
219222# Array alignment mod 16:
@@ -234,9 +237,9 @@ unsafe_set_timelimit(precision::fftwTypeSingle,seconds) =
234237 convert (Int32, convert (Int64, pointer (A)) % 16 )
235238else
236239 alignment_of (A:: StridedArray{T} ) where {T<: fftwDouble } =
237- ccall ((:fftw_alignment_of , libfftw3 () ), Int32, (Ptr{T},), A)
240+ ccall ((:fftw_alignment_of , libfftw3), Int32, (Ptr{T},), A)
238241 alignment_of (A:: StridedArray{T} ) where {T<: fftwSingle } =
239- ccall ((:fftwf_alignment_of , libfftw3f () ), Int32, (Ptr{T},), A)
242+ ccall ((:fftwf_alignment_of , libfftw3f), Int32, (Ptr{T},), A)
240243end
241244
242245# FFTWPlan (low-level)
@@ -320,9 +323,9 @@ unsafe_convert(::Type{PlanPtr}, p::FFTWPlan) = p.plan
320323
321324# these functions should only be called while the fftwlock is held
322325unsafe_destroy_plan (@nospecialize (plan:: FFTWPlan{<:fftwDouble} )) =
323- ccall ((:fftw_destroy_plan ,libfftw3 () ), Cvoid, (PlanPtr,), plan)
326+ ccall ((:fftw_destroy_plan ,libfftw3), Cvoid, (PlanPtr,), plan)
324327unsafe_destroy_plan (@nospecialize (plan:: FFTWPlan{<:fftwSingle} )) =
325- ccall ((:fftwf_destroy_plan ,libfftw3f () ), Cvoid, (PlanPtr,), plan)
328+ ccall ((:fftwf_destroy_plan ,libfftw3f), Cvoid, (PlanPtr,), plan)
326329
327330const deferred_destroy_lock = ReentrantLock () # lock protecting the deferred_destroy_plans list
328331const deferred_destroy_plans = FFTWPlan[]
@@ -383,19 +386,19 @@ end
383386# ################################################################################################
384387
385388cost (plan:: FFTWPlan{<:fftwDouble} ) =
386- ccall ((:fftw_cost ,libfftw3 () ), Float64, (PlanPtr,), plan)
389+ ccall ((:fftw_cost ,libfftw3), Float64, (PlanPtr,), plan)
387390cost (plan:: FFTWPlan{<:fftwSingle} ) =
388- ccall ((:fftwf_cost ,libfftw3f () ), Float64, (PlanPtr,), plan)
391+ ccall ((:fftwf_cost ,libfftw3f), Float64, (PlanPtr,), plan)
389392
390393@exclusive function arithmetic_ops (plan:: FFTWPlan{<:fftwDouble} )
391394 add, mul, fma = Ref (0.0 ), Ref (0.0 ), Ref (0.0 )
392- ccall ((:fftw_flops ,libfftw3 () ), Cvoid,
395+ ccall ((:fftw_flops ,libfftw3), Cvoid,
393396 (PlanPtr,Ref{Float64},Ref{Float64},Ref{Float64}), plan, add, mul, fma)
394397 return (round (Int64, add[]), round (Int64, mul[]), round (Int64, fma[]))
395398end
396399@exclusive function arithmetic_ops (plan:: FFTWPlan{<:fftwSingle} )
397400 add, mul, fma = Ref (0.0 ), Ref (0.0 ), Ref (0.0 )
398- ccall ((:fftwf_flops ,libfftw3f () ), Cvoid,
401+ ccall ((:fftwf_flops ,libfftw3f), Cvoid,
399402 (PlanPtr,Ref{Float64},Ref{Float64},Ref{Float64}), plan, add, mul, fma)
400403 return (round (Int64, add[]), round (Int64, mul[]), round (Int64, fma[]))
401404end
@@ -426,9 +429,9 @@ const has_sprint_plan = version >= v"3.3.4" && fftw_provider == "fftw"
426429
427430@static if has_sprint_plan
428431 sprint_plan_ (plan:: FFTWPlan{<:fftwDouble} ) =
429- ccall ((:fftw_sprint_plan ,libfftw3 () ), Ptr{UInt8}, (PlanPtr,), plan)
432+ ccall ((:fftw_sprint_plan ,libfftw3), Ptr{UInt8}, (PlanPtr,), plan)
430433 sprint_plan_ (plan:: FFTWPlan{<:fftwSingle} ) =
431- ccall ((:fftwf_sprint_plan ,libfftw3f () ), Ptr{UInt8}, (PlanPtr,), plan)
434+ ccall ((:fftwf_sprint_plan ,libfftw3f), Ptr{UInt8}, (PlanPtr,), plan)
432435 function sprint_plan (plan:: FFTWPlan )
433436 p = sprint_plan_ (plan)
434437 str = unsafe_string (p)
@@ -510,49 +513,49 @@ _colmajorstrides(p) = ()
510513# Execute
511514
512515unsafe_execute! (plan:: FFTWPlan{<:fftwDouble} ) =
513- ccall ((:fftw_execute ,libfftw3 () ), Cvoid, (PlanPtr,), plan)
516+ ccall ((:fftw_execute ,libfftw3), Cvoid, (PlanPtr,), plan)
514517
515518unsafe_execute! (plan:: FFTWPlan{<:fftwSingle} ) =
516- ccall ((:fftwf_execute ,libfftw3f () ), Cvoid, (PlanPtr,), plan)
519+ ccall ((:fftwf_execute ,libfftw3f), Cvoid, (PlanPtr,), plan)
517520
518521unsafe_execute! (plan:: cFFTWPlan{T} ,
519522 X:: StridedArray{T} , Y:: StridedArray{T} ) where {T<: fftwDouble } =
520- ccall ((:fftw_execute_dft ,libfftw3 () ), Cvoid,
523+ ccall ((:fftw_execute_dft ,libfftw3), Cvoid,
521524 (PlanPtr,Ptr{T},Ptr{T}), plan, X, Y)
522525
523526unsafe_execute! (plan:: cFFTWPlan{T} ,
524527 X:: StridedArray{T} , Y:: StridedArray{T} ) where {T<: fftwSingle } =
525- ccall ((:fftwf_execute_dft ,libfftw3f () ), Cvoid,
528+ ccall ((:fftwf_execute_dft ,libfftw3f), Cvoid,
526529 (PlanPtr,Ptr{T},Ptr{T}), plan, X, Y)
527530
528531unsafe_execute! (plan:: rFFTWPlan{Float64,FORWARD} ,
529532 X:: StridedArray{Float64} , Y:: StridedArray{Complex{Float64}} ) =
530- ccall ((:fftw_execute_dft_r2c ,libfftw3 () ), Cvoid,
533+ ccall ((:fftw_execute_dft_r2c ,libfftw3), Cvoid,
531534 (PlanPtr,Ptr{Float64},Ptr{Complex{Float64}}), plan, X, Y)
532535
533536unsafe_execute! (plan:: rFFTWPlan{Float32,FORWARD} ,
534537 X:: StridedArray{Float32} , Y:: StridedArray{Complex{Float32}} ) =
535- ccall ((:fftwf_execute_dft_r2c ,libfftw3f () ), Cvoid,
538+ ccall ((:fftwf_execute_dft_r2c ,libfftw3f), Cvoid,
536539 (PlanPtr,Ptr{Float32},Ptr{Complex{Float32}}), plan, X, Y)
537540
538541unsafe_execute! (plan:: rFFTWPlan{Complex{Float64},BACKWARD} ,
539542 X:: StridedArray{Complex{Float64}} , Y:: StridedArray{Float64} ) =
540- ccall ((:fftw_execute_dft_c2r ,libfftw3 () ), Cvoid,
543+ ccall ((:fftw_execute_dft_c2r ,libfftw3), Cvoid,
541544 (PlanPtr,Ptr{Complex{Float64}},Ptr{Float64}), plan, X, Y)
542545
543546unsafe_execute! (plan:: rFFTWPlan{Complex{Float32},BACKWARD} ,
544547 X:: StridedArray{Complex{Float32}} , Y:: StridedArray{Float32} ) =
545- ccall ((:fftwf_execute_dft_c2r ,libfftw3f () ), Cvoid,
548+ ccall ((:fftwf_execute_dft_c2r ,libfftw3f), Cvoid,
546549 (PlanPtr,Ptr{Complex{Float32}},Ptr{Float32}), plan, X, Y)
547550
548551unsafe_execute! (plan:: r2rFFTWPlan{T} ,
549552 X:: StridedArray{T} , Y:: StridedArray{T} ) where {T<: fftwDouble } =
550- ccall ((:fftw_execute_r2r ,libfftw3 () ), Cvoid,
553+ ccall ((:fftw_execute_r2r ,libfftw3), Cvoid,
551554 (PlanPtr,Ptr{T},Ptr{T}), plan, X, Y)
552555
553556unsafe_execute! (plan:: r2rFFTWPlan{T} ,
554557 X:: StridedArray{T} , Y:: StridedArray{T} ) where {T<: fftwSingle } =
555- ccall ((:fftwf_execute_r2r ,libfftw3f () ), Cvoid,
558+ ccall ((:fftwf_execute_r2r ,libfftw3f), Cvoid,
556559 (PlanPtr,Ptr{T},Ptr{T}), plan, X, Y)
557560
558561# NOTE ON GC (garbage collection):
@@ -649,7 +652,7 @@ for (Tr,Tc,fftw,lib) in ((:Float64,:(Complex{Float64}),"fftw",:libfftw3),
649652 unsafe_set_timelimit ($ Tr, timelimit)
650653 R = isa (region, Tuple) ? region : copy (region)
651654 dims, howmany = dims_howmany (X, Y, size (X), R)
652- plan = ccall (($ (string (fftw," _plan_guru64_dft" )),$ lib () ),
655+ plan = ccall (($ (string (fftw," _plan_guru64_dft" )),$ lib),
653656 PlanPtr,
654657 (Int32, Ptr{Int}, Int32, Ptr{Int},
655658 Ptr{$ Tc}, Ptr{$ Tc}, Int32, UInt32),
@@ -669,7 +672,7 @@ for (Tr,Tc,fftw,lib) in ((:Float64,:(Complex{Float64}),"fftw",:libfftw3),
669672 regionshft = _circshiftmin1 (region) # FFTW halves last dim
670673 unsafe_set_timelimit ($ Tr, timelimit)
671674 dims, howmany = dims_howmany (X, Y, size (X), regionshft)
672- plan = ccall (($ (string (fftw," _plan_guru64_dft_r2c" )),$ lib () ),
675+ plan = ccall (($ (string (fftw," _plan_guru64_dft_r2c" )),$ lib),
673676 PlanPtr,
674677 (Int32, Ptr{Int}, Int32, Ptr{Int},
675678 Ptr{$ Tr}, Ptr{$ Tc}, UInt32),
@@ -689,7 +692,7 @@ for (Tr,Tc,fftw,lib) in ((:Float64,:(Complex{Float64}),"fftw",:libfftw3),
689692 regionshft = _circshiftmin1 (region) # FFTW halves last dim
690693 unsafe_set_timelimit ($ Tr, timelimit)
691694 dims, howmany = dims_howmany (X, Y, size (Y), regionshft)
692- plan = ccall (($ (string (fftw," _plan_guru64_dft_c2r" )),$ lib () ),
695+ plan = ccall (($ (string (fftw," _plan_guru64_dft_c2r" )),$ lib),
693696 PlanPtr,
694697 (Int32, Ptr{Int}, Int32, Ptr{Int},
695698 Ptr{$ Tc}, Ptr{$ Tr}, UInt32),
@@ -711,7 +714,7 @@ for (Tr,Tc,fftw,lib) in ((:Float64,:(Complex{Float64}),"fftw",:libfftw3),
711714 knd = fix_kinds (region, kinds)
712715 unsafe_set_timelimit ($ Tr, timelimit)
713716 dims, howmany = dims_howmany (X, Y, size (X), region)
714- plan = ccall (($ (string (fftw," _plan_guru64_r2r" )),$ lib () ),
717+ plan = ccall (($ (string (fftw," _plan_guru64_r2r" )),$ lib),
715718 PlanPtr,
716719 (Int32, Ptr{Int}, Int32, Ptr{Int},
717720 Ptr{$ Tr}, Ptr{$ Tr}, Ptr{Int32}, UInt32),
@@ -739,7 +742,7 @@ for (Tr,Tc,fftw,lib) in ((:Float64,:(Complex{Float64}),"fftw",:libfftw3),
739742 howmany[2 : 3 , :] .*= 2
740743 end
741744 howmany = [howmany [2 ,1 ,1 ]] # append loop over real/imag parts
742- plan = ccall (($ (string (fftw," _plan_guru64_r2r" )),$ lib () ),
745+ plan = ccall (($ (string (fftw," _plan_guru64_r2r" )),$ lib),
743746 PlanPtr,
744747 (Int32, Ptr{Int}, Int32, Ptr{Int},
745748 Ptr{$ Tc}, Ptr{$ Tc}, Ptr{Int32}, UInt32),
0 commit comments