DSPRelated.com
Forums

Saving Variables as .const

Started by B S July 28, 2011
B.S.

Real easy to save/restore those constants.

once the original 'W' values are created,
stop the program
copy 'W' to a file using CCS

exit the program
edit your program to have a 'w_original' that is the same as 'W'
code w_original as
static const int w_original[] {

};

then very early in your program code
memcpy( W, w_original, sizeof(W) );

-or-
for even faster startup code
int W[] {

};
however, the program will have to be re-started for each run, not just call the
function.

R. Williams

---------- Original Message -----------
From: B S
To: Richard Williams , "c..."

Sent: Fri, 5 Aug 2011 02:39:22 -0700 (PDT)
Subject: Re: [c6x] Saving Variables as .const

> R. Williams,
>
> Yes that's obvious but I am wondering why it says in the example code
> to save those constants to avoid their calculation every time. If
> these constants has to be calculated every time then I can't get the
> profiling given on the same wiki page..
>
> I will try to see what can be done but I am sorry to bother you.
> BAS
>
> ________________________________
> From: Richard Williams
> To: B S ; c...
> Sent: Friday, August 5, 2011 3:55 AM
> Subject: Re: [c6x] Saving Variables as .const
>
>  
>
> B.S.
>
> It should be obvious that a second run using a modified W array
> (twiddle array) will result in a different out put.
>
> R. Williams
>
> ---------- Original Message -----------
> From: B S
> To: Richard Williams , c...
> Sent: Thu, 4 Aug 2011 04:48:54 -0700 (PDT)
> Subject: Re: [c6x] Saving Variables as .const
>
> > R. Williams,
> >
> > W, A and B are defined as global variables. Yes, W is changing by
> > calling FFT_Split().
> >
> > BAS
> >
> > ________________________________
> > From: Richard Williams
> > To: B S ; c...
> > Sent: Tue, August 2, 2011 3:58:07 PM
> > Subject: Re: [c6x] Saving Variables as .const
> >
> > B.S.
> >
> > A couple of questions that are not answered by your code example///
> >
> > 1) Where is 'w' located? defined?
> > 2) Where is 'A' and 'B' located? defined?
> >
> > In general, flag, 'w', 'A", and 'B' need to be file static variables
> > for your plan to work.
> > Also, 'N' cannot be changing between successive passes.
> > Are any of the 'w', 'A', 'B' being modified by the calls to
> > DSPF_sp_fftSPxSP() or FFT_Split()? a little experimentation and using
> > printf() to debug the problem will clarify why re-using the same
> > arrays is not working well.
> >
> > R. Williams
> >
> > ---------- Original Message -----------
> > From: B S
> > To: Richard Williams , c...
> > Sent: Tue, 2 Aug 2011 05:28:58 -0700 (PDT)
> > Subject: Re: [c6x] Saving Variables as .const
> >
> > > R. Williams,
> > >
> > > In main.c, I am enabling HWI and Timer and rest of the FFT calculation
> > > is being done in ISR. I tried to put twiddle and some constants inside
> > > a loop to calculate them only once but it doesn't give accurate FFT
> > > result. I am using example C code given at the following page.
> > >
> > >
> http://processors.wiki.ti.com/index.php/Efficient_FFT_Computation_of_Real_Input#Computing_a_Length_N.2F2_Complex_FFT_from_a_Length_N_Real_Input_Sequence
> >
> > >
> > > Copy of example code.
> > > tw_gen (w, N / 2);
> > > split_gen (A, B, N / 2);
> > >
> > > // Once w(twiddles), A, B Tables are generated they can be saved
> > > as .const // and need not be generated every time.. twiddle > > > (float *) w;
> > >
> > > // Forward FFT Calculation using N/2 complex FFT..
> > > DSPF_sp_fftSPxSP (N / 2, pRFFT_In, twiddle, pTemp, brev, rad, 0, N
> > > / 2);
> > >
> > > // FFT Split call to get complex FFT out of length N..
> > > FFT_Split (N / 2, pTemp, A, B, pRFFT_Out);
> > >
> > > Modified code by me;
> > >
> > > if (flag == 0)
> > > {
> > > tw_gen (w, N / 2);
> > > split_gen (A, B, N / 2);
> > > twiddle = (float *) w;
> > > flag++;
> > > }
> > >
> > > DSPF_sp_fftSPxSP (N / 2, pRFFT_In, twiddle, pTemp, brev, rad, 0, N / 2)
> > > ; FFT_Split (N / 2, pTemp, A, B, pRFFT_Out);
> > >
> > > Thanks for your help.
> > >
> > > BAS
> > >
> > > ________________________________
> > > From: Richard Williams
> > > To: B S ; c...
> > > Sent: Fri, July 29, 2011 3:24:03 AM
> > > Subject: Re: [c6x] Saving Variables as .const
> > >
> > > B.S.
> > >
> > > I would suggest making the twiddle, etc to be static variables, using the
> > > 'static' modifier
> > > Then modify your code to calculate them once, perhaps during
> > > initialization, then never calculate them again during that execution
> > > of the program.
> > >
> > > Or calculate them, print them using one small program.
> > > Then type them into a 'const' table in the program your going to use
> > > for the FFT operations.
> > >
> > > R. Williams
> > >
> > > ---------- Original Message -----------
> > > From: B S
> > > To: c...
> > > Sent: Thu, 28 Jul 2011 03:48:17 -0700 (PDT)
> > > Subject: [c6x] Saving Variables as .const
> > >
> > > > Hi,
> > > >
> > > > I am running an efficient FFT algorithm on DSK 6713 where twiddle, and
> > > > some variables are generating again and again in the main and taking
> > > > so much time which in result affecting the real time processing. How
> > > > can I save them as .const to avoid their calculation every time ?
> > > >
> > > > Thanks for your help.
> > > >
> > > > BAS
> > > ------- End of Original Message -------
> > ------- End of Original Message -------
> ------- End of Original Message -------
------- End of Original Message -------

_____________________________________
Thanks Richard.

BAS

________________________________
From: Richard Williams
To: B S ; "c..."
Sent: Saturday, August 6, 2011 2:29 AM
Subject: Re: [c6x] Saving Variables as .const
 

B.S.

Real easy to save/restore those constants.

once the original 'W' values are created,
stop the program
copy 'W' to a file using CCS

exit the program
edit your program to have a 'w_original' that is the same as 'W'
code w_original as
static const int w_original[] {

};

then very early in your program code
memcpy( W, w_original, sizeof(W) );

-or-
for even faster startup code
int W[] {

};
however, the program will have to be re-started for each run, not just call the
function.

R. Williams

---------- Original Message -----------
From: B S
To: Richard Williams , "c..."

Sent: Fri, 5 Aug 2011 02:39:22 -0700 (PDT)
Subject: Re: [c6x] Saving Variables as .const

> R. Williams,
>
> Yes that's obvious but I am wondering why it says in the example code
> to save those constants to avoid their calculation every time. If
> these constants has to be calculated every time then I can't get the
> profiling given on the same wiki page..
>
> I will try to see what can be done but I am sorry to bother you.
> BAS
>
> ________________________________
> From: Richard Williams
> To: B S ; c...
> Sent: Friday, August 5, 2011 3:55 AM
> Subject: Re: [c6x] Saving Variables as .const
>
>  
>
> B.S.
>
> It should be obvious that a second run using a modified W array
> (twiddle array) will result in a different out put.
>
> R. Williams
>
> ---------- Original Message -----------
> From: B S
> To: Richard Williams , c...
> Sent: Thu, 4 Aug 2011 04:48:54 -0700 (PDT)
> Subject: Re: [c6x] Saving Variables as .const
>
> > R. Williams,
> >
> > W, A and B are defined as global variables. Yes, W is changing by
> > calling FFT_Split().
> >
> > BAS
> >
> > ________________________________
> > From: Richard Williams
> > To: B S ; c...
> > Sent: Tue, August 2, 2011 3:58:07 PM
> > Subject: Re: [c6x] Saving Variables as .const
> >
> > B.S.
> >
> > A couple of questions that are not answered by your code example///
> >
> > 1) Where is 'w' located? defined?
> > 2) Where is 'A' and 'B' located? defined?
> >
> > In general, flag, 'w', 'A", and 'B' need to be file static variables
> > for your plan to work.
> > Also, 'N' cannot be changing between successive passes.
> > Are any of the 'w', 'A', 'B' being modified by the calls to
> > DSPF_sp_fftSPxSP() or FFT_Split()? a little experimentation and using
> > printf() to debug the problem will clarify why re-using the same
> > arrays is not working well.
> >
> > R. Williams
> >
> > ---------- Original Message -----------
> > From: B S
> > To: Richard Williams , c...
> > Sent: Tue, 2 Aug 2011 05:28:58 -0700 (PDT)
> > Subject: Re: [c6x] Saving Variables as .const
> >
> > > R. Williams,
> > >
> > > In main.c, I am enabling HWI and Timer and rest of the FFT calculation
> > > is being done in ISR. I tried to put twiddle and some constants inside
> > > a loop to calculate them only once but it doesn't give accurate FFT
> > > result. I am using example C code given at the following page.
> > >
> > >
> http://processors.wiki.ti.com/index.php/Efficient_FFT_Computation_of_Real_Input#Computing_a_Length_N.2F2_Complex_FFT_from_a_Length_N_Real_Input_Sequence
> >
> > >
> > > Copy of example code.
> > > tw_gen (w, N / 2);
> > > split_gen (A, B, N / 2);
> > >
> > > // Once w(twiddles), A, B Tables are generated they can be saved
> > > as .const // and need not be generated every time.. twiddle > > > (float *) w;
> > >
> > > // Forward FFT Calculation using N/2 complex FFT..
> > > DSPF_sp_fftSPxSP (N / 2, pRFFT_In, twiddle, pTemp, brev, rad, 0, N
> > > / 2);
> > >
> > > // FFT Split call to get complex FFT out of length N..
> > > FFT_Split (N / 2, pTemp, A, B, pRFFT_Out);
> > >
> > > Modified code by me;
> > >
> > > if (flag == 0)
> > > {
> > > tw_gen (w, N / 2);
> > > split_gen (A, B, N / 2);
> > > twiddle = (float *) w;
> > > flag++;
> > > }
> > >
> > > DSPF_sp_fftSPxSP (N / 2, pRFFT_In, twiddle, pTemp, brev, rad, 0, N / 2)
> > > ; FFT_Split (N / 2, pTemp, A, B, pRFFT_Out);
> > >
> > > Thanks for your help.
> > >
> > > BAS
> > >
> > > ________________________________
> > > From: Richard Williams
> > > To: B S ; c...
> > > Sent: Fri, July 29, 2011 3:24:03 AM
> > > Subject: Re: [c6x] Saving Variables as .const
> > >
> > > B.S.
> > >
> > > I would suggest making the twiddle, etc to be static variables, using the
> > > 'static' modifier
> > > Then modify your code to calculate them once, perhaps during
> > > initialization, then never calculate them again during that execution
> > > of the program.
> > >
> > > Or calculate them, print them using one small program.
> > > Then type them into a 'const' table in the program your going to use
> > > for the FFT operations.
> > >
> > > R. Williams
> > >
> > > ---------- Original Message -----------
> > > From: B S
> > > To: c...
> > > Sent: Thu, 28 Jul 2011 03:48:17 -0700 (PDT)
> > > Subject: [c6x] Saving Variables as .const
> > >
> > > > Hi,
> > > >
> > > > I am running an efficient FFT algorithm on DSK 6713 where twiddle, and
> > > > some variables are generating again and again in the main and taking
> > > > so much time which in result affecting the real time processing. How
> > > > can I save them as .const to avoid their calculation every time ?
> > > >
> > > > Thanks for your help.
> > > >
> > > > BAS
> > > ------- End of Original Message -------
> > ------- End of Original Message -------
> ------- End of Original Message -------
------- End of Original Message -------