@@ -54,8 +54,11 @@ function plan_r2r end
54
54
55
55
# # FFT: Implement fft by calling fftw.
56
56
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 ()
59
62
60
63
# # Direction of FFT
61
64
@@ -140,32 +143,32 @@ alignment_of(A::FakeArray) = Int32(0)
140
143
@exclusive function export_wisdom (fname:: AbstractString )
141
144
f = ccall (:fopen , Ptr{Cvoid}, (Cstring,Cstring), fname, :w )
142
145
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)
144
147
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)
146
149
ccall (:fclose , Cvoid, (Ptr{Cvoid},), f)
147
150
end
148
151
149
152
@exclusive function import_wisdom (fname:: AbstractString )
150
153
f = ccall (:fopen , Ptr{Cvoid}, (Cstring,Cstring), fname, :r )
151
154
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
154
157
error (" failed to import wisdom from $fname " )
155
158
end
156
159
ccall (:fclose , Cvoid, (Ptr{Cvoid},), f)
157
160
end
158
161
159
162
@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
162
165
error (" failed to import system wisdom" )
163
166
end
164
167
end
165
168
166
169
@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, ())
169
172
end
170
173
171
174
# Threads
@@ -175,15 +178,15 @@ function _set_num_threads(num_threads::Integer)
175
178
@static if fftw_provider == " mkl"
176
179
_last_num_threads[] = num_threads
177
180
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)
180
183
end
181
184
182
185
@exclusive set_num_threads (num_threads:: Integer ) = _set_num_threads (num_threads)
183
186
184
187
function get_num_threads ()
185
188
@static if fftw_provider == " fftw"
186
- ccall ((:fftw_planner_nthreads ,libfftw3 () ), Cint, ())
189
+ ccall ((:fftw_planner_nthreads ,libfftw3), Cint, ())
187
190
else
188
191
_last_num_threads[]
189
192
end
@@ -210,9 +213,9 @@ const NO_TIMELIMIT = -1.0 # from fftw3.h
210
213
211
214
# only call these when fftwlock is held:
212
215
unsafe_set_timelimit (precision:: fftwTypeDouble ,seconds) =
213
- ccall ((:fftw_set_timelimit ,libfftw3 () ), Cvoid, (Float64,), seconds)
216
+ ccall ((:fftw_set_timelimit ,libfftw3), Cvoid, (Float64,), seconds)
214
217
unsafe_set_timelimit (precision:: fftwTypeSingle ,seconds) =
215
- ccall ((:fftwf_set_timelimit ,libfftw3f () ), Cvoid, (Float64,), seconds)
218
+ ccall ((:fftwf_set_timelimit ,libfftw3f), Cvoid, (Float64,), seconds)
216
219
@exclusive set_timelimit (precision, seconds) = unsafe_set_timelimit (precision, seconds)
217
220
218
221
# Array alignment mod 16:
@@ -233,9 +236,9 @@ unsafe_set_timelimit(precision::fftwTypeSingle,seconds) =
233
236
convert (Int32, convert (Int64, pointer (A)) % 16 )
234
237
else
235
238
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)
237
240
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)
239
242
end
240
243
241
244
# FFTWPlan (low-level)
@@ -319,9 +322,9 @@ unsafe_convert(::Type{PlanPtr}, p::FFTWPlan) = p.plan
319
322
320
323
# these functions should only be called while the fftwlock is held
321
324
unsafe_destroy_plan (@nospecialize (plan:: FFTWPlan{<:fftwDouble} )) =
322
- ccall ((:fftw_destroy_plan ,libfftw3 () ), Cvoid, (PlanPtr,), plan)
325
+ ccall ((:fftw_destroy_plan ,libfftw3), Cvoid, (PlanPtr,), plan)
323
326
unsafe_destroy_plan (@nospecialize (plan:: FFTWPlan{<:fftwSingle} )) =
324
- ccall ((:fftwf_destroy_plan ,libfftw3f () ), Cvoid, (PlanPtr,), plan)
327
+ ccall ((:fftwf_destroy_plan ,libfftw3f), Cvoid, (PlanPtr,), plan)
325
328
326
329
const deferred_destroy_lock = ReentrantLock () # lock protecting the deferred_destroy_plans list
327
330
const deferred_destroy_plans = FFTWPlan[]
@@ -382,19 +385,19 @@ end
382
385
# ################################################################################################
383
386
384
387
cost (plan:: FFTWPlan{<:fftwDouble} ) =
385
- ccall ((:fftw_cost ,libfftw3 () ), Float64, (PlanPtr,), plan)
388
+ ccall ((:fftw_cost ,libfftw3), Float64, (PlanPtr,), plan)
386
389
cost (plan:: FFTWPlan{<:fftwSingle} ) =
387
- ccall ((:fftwf_cost ,libfftw3f () ), Float64, (PlanPtr,), plan)
390
+ ccall ((:fftwf_cost ,libfftw3f), Float64, (PlanPtr,), plan)
388
391
389
392
@exclusive function arithmetic_ops (plan:: FFTWPlan{<:fftwDouble} )
390
393
add, mul, fma = Ref (0.0 ), Ref (0.0 ), Ref (0.0 )
391
- ccall ((:fftw_flops ,libfftw3 () ), Cvoid,
394
+ ccall ((:fftw_flops ,libfftw3), Cvoid,
392
395
(PlanPtr,Ref{Float64},Ref{Float64},Ref{Float64}), plan, add, mul, fma)
393
396
return (round (Int64, add[]), round (Int64, mul[]), round (Int64, fma[]))
394
397
end
395
398
@exclusive function arithmetic_ops (plan:: FFTWPlan{<:fftwSingle} )
396
399
add, mul, fma = Ref (0.0 ), Ref (0.0 ), Ref (0.0 )
397
- ccall ((:fftwf_flops ,libfftw3f () ), Cvoid,
400
+ ccall ((:fftwf_flops ,libfftw3f), Cvoid,
398
401
(PlanPtr,Ref{Float64},Ref{Float64},Ref{Float64}), plan, add, mul, fma)
399
402
return (round (Int64, add[]), round (Int64, mul[]), round (Int64, fma[]))
400
403
end
@@ -425,9 +428,9 @@ const has_sprint_plan = version >= v"3.3.4" && fftw_provider == "fftw"
425
428
426
429
@static if has_sprint_plan
427
430
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)
429
432
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)
431
434
function sprint_plan (plan:: FFTWPlan )
432
435
p = sprint_plan_ (plan)
433
436
str = unsafe_string (p)
@@ -509,49 +512,49 @@ _colmajorstrides(p) = ()
509
512
# Execute
510
513
511
514
unsafe_execute! (plan:: FFTWPlan{<:fftwDouble} ) =
512
- ccall ((:fftw_execute ,libfftw3 () ), Cvoid, (PlanPtr,), plan)
515
+ ccall ((:fftw_execute ,libfftw3), Cvoid, (PlanPtr,), plan)
513
516
514
517
unsafe_execute! (plan:: FFTWPlan{<:fftwSingle} ) =
515
- ccall ((:fftwf_execute ,libfftw3f () ), Cvoid, (PlanPtr,), plan)
518
+ ccall ((:fftwf_execute ,libfftw3f), Cvoid, (PlanPtr,), plan)
516
519
517
520
unsafe_execute! (plan:: cFFTWPlan{T} ,
518
521
X:: StridedArray{T} , Y:: StridedArray{T} ) where {T<: fftwDouble } =
519
- ccall ((:fftw_execute_dft ,libfftw3 () ), Cvoid,
522
+ ccall ((:fftw_execute_dft ,libfftw3), Cvoid,
520
523
(PlanPtr,Ptr{T},Ptr{T}), plan, X, Y)
521
524
522
525
unsafe_execute! (plan:: cFFTWPlan{T} ,
523
526
X:: StridedArray{T} , Y:: StridedArray{T} ) where {T<: fftwSingle } =
524
- ccall ((:fftwf_execute_dft ,libfftw3f () ), Cvoid,
527
+ ccall ((:fftwf_execute_dft ,libfftw3f), Cvoid,
525
528
(PlanPtr,Ptr{T},Ptr{T}), plan, X, Y)
526
529
527
530
unsafe_execute! (plan:: rFFTWPlan{Float64,FORWARD} ,
528
531
X:: StridedArray{Float64} , Y:: StridedArray{Complex{Float64}} ) =
529
- ccall ((:fftw_execute_dft_r2c ,libfftw3 () ), Cvoid,
532
+ ccall ((:fftw_execute_dft_r2c ,libfftw3), Cvoid,
530
533
(PlanPtr,Ptr{Float64},Ptr{Complex{Float64}}), plan, X, Y)
531
534
532
535
unsafe_execute! (plan:: rFFTWPlan{Float32,FORWARD} ,
533
536
X:: StridedArray{Float32} , Y:: StridedArray{Complex{Float32}} ) =
534
- ccall ((:fftwf_execute_dft_r2c ,libfftw3f () ), Cvoid,
537
+ ccall ((:fftwf_execute_dft_r2c ,libfftw3f), Cvoid,
535
538
(PlanPtr,Ptr{Float32},Ptr{Complex{Float32}}), plan, X, Y)
536
539
537
540
unsafe_execute! (plan:: rFFTWPlan{Complex{Float64},BACKWARD} ,
538
541
X:: StridedArray{Complex{Float64}} , Y:: StridedArray{Float64} ) =
539
- ccall ((:fftw_execute_dft_c2r ,libfftw3 () ), Cvoid,
542
+ ccall ((:fftw_execute_dft_c2r ,libfftw3), Cvoid,
540
543
(PlanPtr,Ptr{Complex{Float64}},Ptr{Float64}), plan, X, Y)
541
544
542
545
unsafe_execute! (plan:: rFFTWPlan{Complex{Float32},BACKWARD} ,
543
546
X:: StridedArray{Complex{Float32}} , Y:: StridedArray{Float32} ) =
544
- ccall ((:fftwf_execute_dft_c2r ,libfftw3f () ), Cvoid,
547
+ ccall ((:fftwf_execute_dft_c2r ,libfftw3f), Cvoid,
545
548
(PlanPtr,Ptr{Complex{Float32}},Ptr{Float32}), plan, X, Y)
546
549
547
550
unsafe_execute! (plan:: r2rFFTWPlan{T} ,
548
551
X:: StridedArray{T} , Y:: StridedArray{T} ) where {T<: fftwDouble } =
549
- ccall ((:fftw_execute_r2r ,libfftw3 () ), Cvoid,
552
+ ccall ((:fftw_execute_r2r ,libfftw3), Cvoid,
550
553
(PlanPtr,Ptr{T},Ptr{T}), plan, X, Y)
551
554
552
555
unsafe_execute! (plan:: r2rFFTWPlan{T} ,
553
556
X:: StridedArray{T} , Y:: StridedArray{T} ) where {T<: fftwSingle } =
554
- ccall ((:fftwf_execute_r2r ,libfftw3f () ), Cvoid,
557
+ ccall ((:fftwf_execute_r2r ,libfftw3f), Cvoid,
555
558
(PlanPtr,Ptr{T},Ptr{T}), plan, X, Y)
556
559
557
560
# NOTE ON GC (garbage collection):
@@ -648,7 +651,7 @@ for (Tr,Tc,fftw,lib) in ((:Float64,:(Complex{Float64}),"fftw",:libfftw3),
648
651
unsafe_set_timelimit ($ Tr, timelimit)
649
652
R = isa (region, Tuple) ? region : copy (region)
650
653
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),
652
655
PlanPtr,
653
656
(Int32, Ptr{Int}, Int32, Ptr{Int},
654
657
Ptr{$ Tc}, Ptr{$ Tc}, Int32, UInt32),
@@ -668,7 +671,7 @@ for (Tr,Tc,fftw,lib) in ((:Float64,:(Complex{Float64}),"fftw",:libfftw3),
668
671
regionshft = _circshiftmin1 (region) # FFTW halves last dim
669
672
unsafe_set_timelimit ($ Tr, timelimit)
670
673
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),
672
675
PlanPtr,
673
676
(Int32, Ptr{Int}, Int32, Ptr{Int},
674
677
Ptr{$ Tr}, Ptr{$ Tc}, UInt32),
@@ -688,7 +691,7 @@ for (Tr,Tc,fftw,lib) in ((:Float64,:(Complex{Float64}),"fftw",:libfftw3),
688
691
regionshft = _circshiftmin1 (region) # FFTW halves last dim
689
692
unsafe_set_timelimit ($ Tr, timelimit)
690
693
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),
692
695
PlanPtr,
693
696
(Int32, Ptr{Int}, Int32, Ptr{Int},
694
697
Ptr{$ Tc}, Ptr{$ Tr}, UInt32),
@@ -710,7 +713,7 @@ for (Tr,Tc,fftw,lib) in ((:Float64,:(Complex{Float64}),"fftw",:libfftw3),
710
713
knd = fix_kinds (region, kinds)
711
714
unsafe_set_timelimit ($ Tr, timelimit)
712
715
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),
714
717
PlanPtr,
715
718
(Int32, Ptr{Int}, Int32, Ptr{Int},
716
719
Ptr{$ Tr}, Ptr{$ Tr}, Ptr{Int32}, UInt32),
@@ -738,7 +741,7 @@ for (Tr,Tc,fftw,lib) in ((:Float64,:(Complex{Float64}),"fftw",:libfftw3),
738
741
howmany[2 : 3 , :] .*= 2
739
742
end
740
743
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),
742
745
PlanPtr,
743
746
(Int32, Ptr{Int}, Int32, Ptr{Int},
744
747
Ptr{$ Tc}, Ptr{$ Tc}, Ptr{Int32}, UInt32),
0 commit comments