@@ -54,8 +54,11 @@ function plan_r2r end
5454
5555# # FFT: Implement fft by calling fftw.
5656
57- const version = VersionNumber (split (unsafe_string (cglobal (
58- (:fftw_version ,libfftw3 ()), UInt8)), [' -' , ' ' ])[2 ])
57+ # TODO : this is dangerous since it captures runtime data from the compile machine
58+ # n.b. write this as a function to avoid Julia bugs with the runtime cglobal implementation
59+ get_version () = VersionNumber (split (unsafe_string (cglobal (
60+ (:fftw_version ,libfftw3_no_init), UInt8)), [' -' , ' ' ])[2 ])
61+ const version = get_version ()
5962
6063# # Direction of FFT
6164
@@ -140,32 +143,32 @@ alignment_of(A::FakeArray) = Int32(0)
140143@exclusive function export_wisdom (fname:: AbstractString )
141144 f = ccall (:fopen , Ptr{Cvoid}, (Cstring,Cstring), fname, :w )
142145 systemerror (" could not open wisdom file $fname for writing" , f == C_NULL )
143- ccall ((:fftw_export_wisdom_to_file ,libfftw3 () ), Cvoid, (Ptr{Cvoid},), f)
146+ ccall ((:fftw_export_wisdom_to_file ,libfftw3), Cvoid, (Ptr{Cvoid},), f)
144147 ccall (:fputs , Int32, (Ptr{UInt8},Ptr{Cvoid}), " " ^ 256 , f) # no NUL, hence no Cstring
145- ccall ((:fftwf_export_wisdom_to_file ,libfftw3f () ), Cvoid, (Ptr{Cvoid},), f)
148+ ccall ((:fftwf_export_wisdom_to_file ,libfftw3f), Cvoid, (Ptr{Cvoid},), f)
146149 ccall (:fclose , Cvoid, (Ptr{Cvoid},), f)
147150end
148151
149152@exclusive function import_wisdom (fname:: AbstractString )
150153 f = ccall (:fopen , Ptr{Cvoid}, (Cstring,Cstring), fname, :r )
151154 systemerror (" could not open wisdom file $fname for reading" , f == C_NULL )
152- if ccall ((:fftw_import_wisdom_from_file ,libfftw3 () ),Int32,(Ptr{Cvoid},),f)== 0 ||
153- ccall ((:fftwf_import_wisdom_from_file ,libfftw3f () ),Int32,(Ptr{Cvoid},),f)== 0
155+ if ccall ((:fftw_import_wisdom_from_file ,libfftw3),Int32,(Ptr{Cvoid},),f)== 0 ||
156+ ccall ((:fftwf_import_wisdom_from_file ,libfftw3f),Int32,(Ptr{Cvoid},),f)== 0
154157 error (" failed to import wisdom from $fname " )
155158 end
156159 ccall (:fclose , Cvoid, (Ptr{Cvoid},), f)
157160end
158161
159162@exclusive function import_system_wisdom ()
160- if ccall ((:fftw_import_system_wisdom ,libfftw3 () ), Int32, ()) == 0 ||
161- ccall ((:fftwf_import_system_wisdom ,libfftw3f () ), Int32, ()) == 0
163+ if ccall ((:fftw_import_system_wisdom ,libfftw3), Int32, ()) == 0 ||
164+ ccall ((:fftwf_import_system_wisdom ,libfftw3f), Int32, ()) == 0
162165 error (" failed to import system wisdom" )
163166 end
164167end
165168
166169@exclusive function forget_wisdom ()
167- ccall ((:fftw_forget_wisdom ,libfftw3 () ), Cvoid, ())
168- ccall ((:fftwf_forget_wisdom ,libfftw3f () ), Cvoid, ())
170+ ccall ((:fftw_forget_wisdom ,libfftw3), Cvoid, ())
171+ ccall ((:fftwf_forget_wisdom ,libfftw3f), Cvoid, ())
169172end
170173
171174# Threads
@@ -175,15 +178,15 @@ function _set_num_threads(num_threads::Integer)
175178 @static if fftw_provider == " mkl"
176179 _last_num_threads[] = num_threads
177180 end
178- ccall ((:fftw_plan_with_nthreads ,libfftw3 () ), Cvoid, (Int32,), num_threads)
179- ccall ((:fftwf_plan_with_nthreads ,libfftw3f () ), Cvoid, (Int32,), num_threads)
181+ ccall ((:fftw_plan_with_nthreads ,libfftw3), Cvoid, (Int32,), num_threads)
182+ ccall ((:fftwf_plan_with_nthreads ,libfftw3f), Cvoid, (Int32,), num_threads)
180183end
181184
182185@exclusive set_num_threads (num_threads:: Integer ) = _set_num_threads (num_threads)
183186
184187function get_num_threads ()
185188 @static if fftw_provider == " fftw"
186- ccall ((:fftw_planner_nthreads ,libfftw3 () ), Cint, ())
189+ ccall ((:fftw_planner_nthreads ,libfftw3), Cint, ())
187190 else
188191 _last_num_threads[]
189192 end
@@ -210,9 +213,9 @@ const NO_TIMELIMIT = -1.0 # from fftw3.h
210213
211214# only call these when fftwlock is held:
212215unsafe_set_timelimit (precision:: fftwTypeDouble ,seconds) =
213- ccall ((:fftw_set_timelimit ,libfftw3 () ), Cvoid, (Float64,), seconds)
216+ ccall ((:fftw_set_timelimit ,libfftw3), Cvoid, (Float64,), seconds)
214217unsafe_set_timelimit (precision:: fftwTypeSingle ,seconds) =
215- ccall ((:fftwf_set_timelimit ,libfftw3f () ), Cvoid, (Float64,), seconds)
218+ ccall ((:fftwf_set_timelimit ,libfftw3f), Cvoid, (Float64,), seconds)
216219@exclusive set_timelimit (precision, seconds) = unsafe_set_timelimit (precision, seconds)
217220
218221# Array alignment mod 16:
@@ -233,9 +236,9 @@ unsafe_set_timelimit(precision::fftwTypeSingle,seconds) =
233236 convert (Int32, convert (Int64, pointer (A)) % 16 )
234237else
235238 alignment_of (A:: StridedArray{T} ) where {T<: fftwDouble } =
236- ccall ((:fftw_alignment_of , libfftw3 () ), Int32, (Ptr{T},), A)
239+ ccall ((:fftw_alignment_of , libfftw3), Int32, (Ptr{T},), A)
237240 alignment_of (A:: StridedArray{T} ) where {T<: fftwSingle } =
238- ccall ((:fftwf_alignment_of , libfftw3f () ), Int32, (Ptr{T},), A)
241+ ccall ((:fftwf_alignment_of , libfftw3f), Int32, (Ptr{T},), A)
239242end
240243
241244# FFTWPlan (low-level)
@@ -319,9 +322,9 @@ unsafe_convert(::Type{PlanPtr}, p::FFTWPlan) = p.plan
319322
320323# these functions should only be called while the fftwlock is held
321324unsafe_destroy_plan (@nospecialize (plan:: FFTWPlan{<:fftwDouble} )) =
322- ccall ((:fftw_destroy_plan ,libfftw3 () ), Cvoid, (PlanPtr,), plan)
325+ ccall ((:fftw_destroy_plan ,libfftw3), Cvoid, (PlanPtr,), plan)
323326unsafe_destroy_plan (@nospecialize (plan:: FFTWPlan{<:fftwSingle} )) =
324- ccall ((:fftwf_destroy_plan ,libfftw3f () ), Cvoid, (PlanPtr,), plan)
327+ ccall ((:fftwf_destroy_plan ,libfftw3f), Cvoid, (PlanPtr,), plan)
325328
326329const deferred_destroy_lock = ReentrantLock () # lock protecting the deferred_destroy_plans list
327330const deferred_destroy_plans = FFTWPlan[]
@@ -382,19 +385,19 @@ end
382385# ################################################################################################
383386
384387cost (plan:: FFTWPlan{<:fftwDouble} ) =
385- ccall ((:fftw_cost ,libfftw3 () ), Float64, (PlanPtr,), plan)
388+ ccall ((:fftw_cost ,libfftw3), Float64, (PlanPtr,), plan)
386389cost (plan:: FFTWPlan{<:fftwSingle} ) =
387- ccall ((:fftwf_cost ,libfftw3f () ), Float64, (PlanPtr,), plan)
390+ ccall ((:fftwf_cost ,libfftw3f), Float64, (PlanPtr,), plan)
388391
389392@exclusive function arithmetic_ops (plan:: FFTWPlan{<:fftwDouble} )
390393 add, mul, fma = Ref (0.0 ), Ref (0.0 ), Ref (0.0 )
391- ccall ((:fftw_flops ,libfftw3 () ), Cvoid,
394+ ccall ((:fftw_flops ,libfftw3), Cvoid,
392395 (PlanPtr,Ref{Float64},Ref{Float64},Ref{Float64}), plan, add, mul, fma)
393396 return (round (Int64, add[]), round (Int64, mul[]), round (Int64, fma[]))
394397end
395398@exclusive function arithmetic_ops (plan:: FFTWPlan{<:fftwSingle} )
396399 add, mul, fma = Ref (0.0 ), Ref (0.0 ), Ref (0.0 )
397- ccall ((:fftwf_flops ,libfftw3f () ), Cvoid,
400+ ccall ((:fftwf_flops ,libfftw3f), Cvoid,
398401 (PlanPtr,Ref{Float64},Ref{Float64},Ref{Float64}), plan, add, mul, fma)
399402 return (round (Int64, add[]), round (Int64, mul[]), round (Int64, fma[]))
400403end
@@ -425,9 +428,9 @@ const has_sprint_plan = version >= v"3.3.4" && fftw_provider == "fftw"
425428
426429@static if has_sprint_plan
427430 sprint_plan_ (plan:: FFTWPlan{<:fftwDouble} ) =
428- ccall ((:fftw_sprint_plan ,libfftw3 () ), Ptr{UInt8}, (PlanPtr,), plan)
431+ ccall ((:fftw_sprint_plan ,libfftw3), Ptr{UInt8}, (PlanPtr,), plan)
429432 sprint_plan_ (plan:: FFTWPlan{<:fftwSingle} ) =
430- ccall ((:fftwf_sprint_plan ,libfftw3f () ), Ptr{UInt8}, (PlanPtr,), plan)
433+ ccall ((:fftwf_sprint_plan ,libfftw3f), Ptr{UInt8}, (PlanPtr,), plan)
431434 function sprint_plan (plan:: FFTWPlan )
432435 p = sprint_plan_ (plan)
433436 str = unsafe_string (p)
@@ -509,49 +512,49 @@ _colmajorstrides(p) = ()
509512# Execute
510513
511514unsafe_execute! (plan:: FFTWPlan{<:fftwDouble} ) =
512- ccall ((:fftw_execute ,libfftw3 () ), Cvoid, (PlanPtr,), plan)
515+ ccall ((:fftw_execute ,libfftw3), Cvoid, (PlanPtr,), plan)
513516
514517unsafe_execute! (plan:: FFTWPlan{<:fftwSingle} ) =
515- ccall ((:fftwf_execute ,libfftw3f () ), Cvoid, (PlanPtr,), plan)
518+ ccall ((:fftwf_execute ,libfftw3f), Cvoid, (PlanPtr,), plan)
516519
517520unsafe_execute! (plan:: cFFTWPlan{T} ,
518521 X:: StridedArray{T} , Y:: StridedArray{T} ) where {T<: fftwDouble } =
519- ccall ((:fftw_execute_dft ,libfftw3 () ), Cvoid,
522+ ccall ((:fftw_execute_dft ,libfftw3), Cvoid,
520523 (PlanPtr,Ptr{T},Ptr{T}), plan, X, Y)
521524
522525unsafe_execute! (plan:: cFFTWPlan{T} ,
523526 X:: StridedArray{T} , Y:: StridedArray{T} ) where {T<: fftwSingle } =
524- ccall ((:fftwf_execute_dft ,libfftw3f () ), Cvoid,
527+ ccall ((:fftwf_execute_dft ,libfftw3f), Cvoid,
525528 (PlanPtr,Ptr{T},Ptr{T}), plan, X, Y)
526529
527530unsafe_execute! (plan:: rFFTWPlan{Float64,FORWARD} ,
528531 X:: StridedArray{Float64} , Y:: StridedArray{Complex{Float64}} ) =
529- ccall ((:fftw_execute_dft_r2c ,libfftw3 () ), Cvoid,
532+ ccall ((:fftw_execute_dft_r2c ,libfftw3), Cvoid,
530533 (PlanPtr,Ptr{Float64},Ptr{Complex{Float64}}), plan, X, Y)
531534
532535unsafe_execute! (plan:: rFFTWPlan{Float32,FORWARD} ,
533536 X:: StridedArray{Float32} , Y:: StridedArray{Complex{Float32}} ) =
534- ccall ((:fftwf_execute_dft_r2c ,libfftw3f () ), Cvoid,
537+ ccall ((:fftwf_execute_dft_r2c ,libfftw3f), Cvoid,
535538 (PlanPtr,Ptr{Float32},Ptr{Complex{Float32}}), plan, X, Y)
536539
537540unsafe_execute! (plan:: rFFTWPlan{Complex{Float64},BACKWARD} ,
538541 X:: StridedArray{Complex{Float64}} , Y:: StridedArray{Float64} ) =
539- ccall ((:fftw_execute_dft_c2r ,libfftw3 () ), Cvoid,
542+ ccall ((:fftw_execute_dft_c2r ,libfftw3), Cvoid,
540543 (PlanPtr,Ptr{Complex{Float64}},Ptr{Float64}), plan, X, Y)
541544
542545unsafe_execute! (plan:: rFFTWPlan{Complex{Float32},BACKWARD} ,
543546 X:: StridedArray{Complex{Float32}} , Y:: StridedArray{Float32} ) =
544- ccall ((:fftwf_execute_dft_c2r ,libfftw3f () ), Cvoid,
547+ ccall ((:fftwf_execute_dft_c2r ,libfftw3f), Cvoid,
545548 (PlanPtr,Ptr{Complex{Float32}},Ptr{Float32}), plan, X, Y)
546549
547550unsafe_execute! (plan:: r2rFFTWPlan{T} ,
548551 X:: StridedArray{T} , Y:: StridedArray{T} ) where {T<: fftwDouble } =
549- ccall ((:fftw_execute_r2r ,libfftw3 () ), Cvoid,
552+ ccall ((:fftw_execute_r2r ,libfftw3), Cvoid,
550553 (PlanPtr,Ptr{T},Ptr{T}), plan, X, Y)
551554
552555unsafe_execute! (plan:: r2rFFTWPlan{T} ,
553556 X:: StridedArray{T} , Y:: StridedArray{T} ) where {T<: fftwSingle } =
554- ccall ((:fftwf_execute_r2r ,libfftw3f () ), Cvoid,
557+ ccall ((:fftwf_execute_r2r ,libfftw3f), Cvoid,
555558 (PlanPtr,Ptr{T},Ptr{T}), plan, X, Y)
556559
557560# NOTE ON GC (garbage collection):
@@ -648,7 +651,7 @@ for (Tr,Tc,fftw,lib) in ((:Float64,:(Complex{Float64}),"fftw",:libfftw3),
648651 unsafe_set_timelimit ($ Tr, timelimit)
649652 R = isa (region, Tuple) ? region : copy (region)
650653 dims, howmany = dims_howmany (X, Y, size (X), R)
651- plan = ccall (($ (string (fftw," _plan_guru64_dft" )),$ lib () ),
654+ plan = ccall (($ (string (fftw," _plan_guru64_dft" )),$ lib),
652655 PlanPtr,
653656 (Int32, Ptr{Int}, Int32, Ptr{Int},
654657 Ptr{$ Tc}, Ptr{$ Tc}, Int32, UInt32),
@@ -668,7 +671,7 @@ for (Tr,Tc,fftw,lib) in ((:Float64,:(Complex{Float64}),"fftw",:libfftw3),
668671 regionshft = _circshiftmin1 (region) # FFTW halves last dim
669672 unsafe_set_timelimit ($ Tr, timelimit)
670673 dims, howmany = dims_howmany (X, Y, size (X), regionshft)
671- plan = ccall (($ (string (fftw," _plan_guru64_dft_r2c" )),$ lib () ),
674+ plan = ccall (($ (string (fftw," _plan_guru64_dft_r2c" )),$ lib),
672675 PlanPtr,
673676 (Int32, Ptr{Int}, Int32, Ptr{Int},
674677 Ptr{$ Tr}, Ptr{$ Tc}, UInt32),
@@ -688,7 +691,7 @@ for (Tr,Tc,fftw,lib) in ((:Float64,:(Complex{Float64}),"fftw",:libfftw3),
688691 regionshft = _circshiftmin1 (region) # FFTW halves last dim
689692 unsafe_set_timelimit ($ Tr, timelimit)
690693 dims, howmany = dims_howmany (X, Y, size (Y), regionshft)
691- plan = ccall (($ (string (fftw," _plan_guru64_dft_c2r" )),$ lib () ),
694+ plan = ccall (($ (string (fftw," _plan_guru64_dft_c2r" )),$ lib),
692695 PlanPtr,
693696 (Int32, Ptr{Int}, Int32, Ptr{Int},
694697 Ptr{$ Tc}, Ptr{$ Tr}, UInt32),
@@ -710,7 +713,7 @@ for (Tr,Tc,fftw,lib) in ((:Float64,:(Complex{Float64}),"fftw",:libfftw3),
710713 knd = fix_kinds (region, kinds)
711714 unsafe_set_timelimit ($ Tr, timelimit)
712715 dims, howmany = dims_howmany (X, Y, size (X), region)
713- plan = ccall (($ (string (fftw," _plan_guru64_r2r" )),$ lib () ),
716+ plan = ccall (($ (string (fftw," _plan_guru64_r2r" )),$ lib),
714717 PlanPtr,
715718 (Int32, Ptr{Int}, Int32, Ptr{Int},
716719 Ptr{$ Tr}, Ptr{$ Tr}, Ptr{Int32}, UInt32),
@@ -738,7 +741,7 @@ for (Tr,Tc,fftw,lib) in ((:Float64,:(Complex{Float64}),"fftw",:libfftw3),
738741 howmany[2 : 3 , :] .*= 2
739742 end
740743 howmany = [howmany [2 ,1 ,1 ]] # append loop over real/imag parts
741- plan = ccall (($ (string (fftw," _plan_guru64_r2r" )),$ lib () ),
744+ plan = ccall (($ (string (fftw," _plan_guru64_r2r" )),$ lib),
742745 PlanPtr,
743746 (Int32, Ptr{Int}, Int32, Ptr{Int},
744747 Ptr{$ Tc}, Ptr{$ Tc}, Ptr{Int32}, UInt32),
0 commit comments