Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

Using FFTInitAlloc in C#

paul_brown
Beginner
586 Views

I'm currently writing an application in C# using the IPP libraries for FFT analysis. The application will be aquiring torque data at 40Hz and performing an FFT roughly every 2 seconds looking for vibration as indicated by certain cyclic frequencies, and will be expected to operate continuously for days at a time. I've downloaded the ms.net samples in order to use the wrappers in them, and I've looked through the posts in this forum for information. Using the information in thread 5481746 I can use FFTInitAlloc to create the specification structure by declaring them locally within the method, however I really only want to have to do this once, ie within a class constructor, or an intialization method, then have the FFT method run using the allocated specification structures. If I declare the IppsFFTSpec_R_64f structure as a member of the class and use new to initialize a memory allocation for it, then the following code

spec =

new IppsFFTSpec_R_64f();

ipp.IppsFFTSpec_R_64f* pFFTSpec = &spec;

sp.ippsFFTInitAlloc_R_64f(&pFFTSpec,lenFFTOrder,(

int)fft_order.IPP_FFT_DIV_FWD_BY_N, IppHintAlgorithm.ippAlgHintNone);

in the initialization method fails to compile with the error:

You can only take the address of an unfixed expression inside of a fixed statement initializer.

Ok, the obvious move is to fix the pointer declaration like so :

spec = new IppsFFTSpec_R_64f();

fixed(ipp.IppsFFTSpec_R_64f* pFFTSpec = &spec)

{

sp.ippsFFTInitAlloc_R_64f(&pFFTSpec,lenFFTOrder,(int)fft_order.IPP_FFT_DIV_FWD_BY_N, IppHintAlgorithm.ippAlgHintNone);

}

This however fails to compile with the error

Cannot take the address of the given expression

Can anyone suggest a way forward here, preferably one that doesn't involve performing the InitAlloc locally before each iteration of the FFT?

0 Kudos
2 Replies
borix
Beginner
586 Views

Paul,

you can and should do init fft once and call fft transform as many times as you need if you don't change theorder.

about initalloc func with spec param, hope the following example helps

using System;
using ipp;
unsafe public class one {
public static void Main() {
IppLibraryVersion lib = sp.ippsGetLibVersion();
Console.WriteLine(" {0} {1}", lib.Name, lib.Version );

float[] a = {1,2,3,4};
float[] b = {11,12,13,14};
float[] c = new float[4];

Ipp32fc v = new Ipp32fc(1,2);
fixed(float*pa=a){ sp.ippsAddC_32fc_I( v, pa, 2); }

fixed(float*pa=a,pb=b,pc = c){sp.ippsAdd_32f( pa, pb, pc, 4 );}
Console.WriteLine(" {0},{1},{2},{3} ",c[0],c[1],c[2],c[3]);

IppsFFTSpec_R_32f*p;
sp.ippsFFTInitAlloc_R_32f( &p, 2, 2, IppHintAlgorithm.ippAlgHintNone );
ulong start = sp.ippGetCpuClocks();
fixed(float*pa=a,pc=c){sp.ippsFFTFwd_RToPerm_32f( pa, pc, p, null );}
ulong stop = sp.ippGetCpuClocks();
sp.ippsFFTFree_R_32f( p );
Console.WriteLine(" {0},{1},{2},{3} ",c[0],c[1],c[2],c[3]);
Console.WriteLine( " cpu = {0} clocks = {1}", sp.ippGetCpuType(), stop-start );
}
}

0 Kudos
paul_brown
Beginner
586 Views

Borix,

Thanks for replying. I'm using the InitAlloc with the Spec param pretty much as you do in your example, and that works, but the problem I was trying to solve was how to delcare the InitAlloc prior to starting the worker thread which does the FFT, so I would only call InitAlloc once no matter how many thousands of times the FFT is run in my application. I have managed to get round the compiler errors however I think I'm then getting bitten by garbage collection moving the memory allocation around, and have gone back to using it as in your example.

0 Kudos
Reply