From bfe3ab4e045063175b5fbff411430913b15919dd Mon Sep 17 00:00:00 2001 From: Jago Stong-Wright Date: Mon, 25 Sep 2023 18:37:58 +0100 Subject: [PATCH] attempted to fix, doesn't run (seg faults) --- src/AppleAccelerate.jl | 2 ++ src/DSP.jl | 74 ++++++++++++++++++++---------------------- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/AppleAccelerate.jl b/src/AppleAccelerate.jl index 1681629..8ce6c80 100644 --- a/src/AppleAccelerate.jl +++ b/src/AppleAccelerate.jl @@ -3,6 +3,8 @@ module AppleAccelerate using LinearAlgebra, Libdl #using LAPACK_jll, LAPACK32_jll # Needed if use_external_lapack == true +import Base: log2, round + # For now, only use BLAS from Accelerate (that is to say, vecLib) global const libacc = "/System/Library/Frameworks/Accelerate.framework/Accelerate" global const libacc_info_plist = "/System/Library/Frameworks/Accelerate.framework/Versions/Current/Resources/Info.plist" diff --git a/src/DSP.jl b/src/DSP.jl index 2da55cc..4bdc658 100644 --- a/src/DSP.jl +++ b/src/DSP.jl @@ -372,42 +372,38 @@ function plan_destroy(setup::DFTSetup) end -# const FFT_FORWARD = +1 -# const FFT_INVERSE = -1 -# const SIGNAL_STRIDE = 1 -# -# typealias vDSP_Stride Clong -# typealias vDSP_Length Culong -# typealias FFTDirection Cint -# -# immutable DSPDoubleSplitComplex -# realp::Ptr{Float64} -# imagp::Ptr{Float64} -# end -# -# DSPDoubleSplitComplex(realp::Vector{Float64},imagp::Vector{Float64})=DSPDoubleSplitComplex(pointer(realp),pointer(imagp)) -# -# -# function plan_fft(n,radix::Integer=2) -# @assert isinteger(log2(n)) -# logn=round(Int,log2(n)) -# ccall(("vDSP_create_fftsetupD",libacc),Ptr{Cvoid},(Cuint,Cint),logn,radix) -# end -# -# function newfft(r::Vector{Complex128},plan) -# n=length(r) -# @assert isinteger(log2(n)) -# logn=round(Int,log2(n)) -# -# realp,imagp=real(r),imag(r) # keep references to avoid garbage collection -# vals=DSPDoubleSplitComplex(realp,imagp) -# retr,reti=Array{Float64}(undef,n),Array{Float64}(undef,n) # keep references to avoid garbage collection -# ret=DSPDoubleSplitComplex(retr,reti) -# -# -# ccall(("vDSP_fft_zopD",libacc),Cvoid, -# (Ptr{Cvoid},DSPDoubleSplitComplex,vDSP_Stride, DSPDoubleSplitComplex,vDSP_Stride, vDSP_Length,FFTDirection), -# plan, vals, SIGNAL_STRIDE, ret, SIGNAL_STRIDE,logn, FFT_FORWARD) -# -# retr+im*reti -# End +const FFT_FORWARD = 1 +const FFT_INVERSE = -1 +const SIGNAL_STRIDE = 1 + +struct DSPDoubleSplitComplex + realp::Ptr{Float64} + imagp::Ptr{Float64} +end + +DSPDoubleSplitComplex(realp::Vector{Float64}, imagp::Vector{Float64}) = DSPDoubleSplitComplex(pointer(realp), pointer(imagp)) + +function plan_fft(n, radix::Integer = 2) + logn = log2(n) + @assert isinteger(logn) + logn = round(Int, logn) + ccall(("vDSP_create_fftsetupD", libacc), Ptr{Cvoid}, (Cuint, Cint), logn, radix) +end + +function newfft(r, plan) + n = length(r) + @assert isinteger(log2(n)) + logn = round(Int, log2(n)) + + realp, imagp = real(r), imag(r) # keep references to avoid garbage collection + vals = DSPDoubleSplitComplex(realp, imagp) + retr, reti = Array{Float64}(undef, n), Array{Float64}(undef, n) # keep references to avoid garbage collection + ret = DSPDoubleSplitComplex(retr, reti) + + + ccall(("vDSP_fft_zopD",libacc), Cvoid, + (Ptr{Cvoid}, DSPDoubleSplitComplex, Cint, DSPDoubleSplitComplex, Cint, Cint, Cint), + plan, vals, SIGNAL_STRIDE, ret, SIGNAL_STRIDE, logn, FFT_FORWARD) + + return retr + im*reti +end