M
ma740988
Assume I have a vendor file called ' vendor.h'. Within the file
there's two methods memalign and cforward. It is my understanding that
the memalign function is a wrapper around malloc. cforward is just a
vendor function for doing forward FFT's. At issue CSL_COMPLEX is
'cumbersome' to work with. As a result I created a wrapper. So now -
given the pseudo code.
#include <iostream>
#include <complex>
#include <vector>
// in vendor file - vendor.h
struct CSL_COMPLEX {
float r;
float i ;
};
void *memalign(size_t blocksize, size_t bytes)
{
return ( malloc ( blocksize * bytes ) ) ; // not sure if I have this
right but .. for test purposes
}
void cforward (
CSL_COMPLEX* ptr_input,
CSL_COMPLEX* ptr_ouput,
int num_sample
)
{}
// end vendor.h
typedef std::vector < std::complex < float > > CFLOAT_VEC ;
struct wrapper {
int previous ;
CSL_COMPLEX *ptr_mem_f ;
wrapper ( )
: previous ( INT_MAX )
, ptr_mem_f ( 0 )
{}
void execute_f ( CFLOAT_VEC& vec )
{
CFLOAT_VEC::size_type const current_sz = vec.size() ;
if ( !current_sz )
return ;
if ( previous != current_sz )
{
std::cout << current_sz << std::endl;
ptr_mem_f =
( CSL_COMPLEX *) memalign ( 32, 2 * current_sz * sizeof (
CSL_COMPLEX ) ) ;
}
// copy contents from vec to ptr_mem_f
for ( int idx ( 0 ); idx < current_sz; ++idx ) {
ptr_mem_f [ idx ].r = vec[ idx ].real() ;
ptr_mem_f [ idx ].i = vec[ idx ].imag() ;
}
// - at this point we run the forward FFT run the forward fft
//
cforward ( ptr_mem_f, ptr_mem_f, current_sz ) ; // for inplace
operations input and output is the same
// now copy back to vec ..
for ( int idx ( 0 ); idx < current_sz; ++idx ) {
std::complex < float > temp (
ptr_mem_f [ idx ].r,
ptr_mem_f [ idx ].i
);
vec[ idx ] = temp ;
}
previous = current_sz;
}
};
int main()
{
CFLOAT_VEC fv ( 5 );
for ( CFLOAT_VEC::size_type jdx ( 0 ); jdx < fv.size(); ++jdx )
fv [ jdx ] = std::complex < float > ( jdx , jdx ) ;
wrapper w_obj;
w_obj.execute_f ( fv ) ;
}
The fundamental issue today surrounds the copy from vec to ptr_mem_f
and ptr_mem_f to vec - literally - kills my timing. Besides my current
approach, I'm unsure how to put a decent wrapper around the basket
case of a function - cforward? Ideas welcomed, thanks in advance
there's two methods memalign and cforward. It is my understanding that
the memalign function is a wrapper around malloc. cforward is just a
vendor function for doing forward FFT's. At issue CSL_COMPLEX is
'cumbersome' to work with. As a result I created a wrapper. So now -
given the pseudo code.
#include <iostream>
#include <complex>
#include <vector>
// in vendor file - vendor.h
struct CSL_COMPLEX {
float r;
float i ;
};
void *memalign(size_t blocksize, size_t bytes)
{
return ( malloc ( blocksize * bytes ) ) ; // not sure if I have this
right but .. for test purposes
}
void cforward (
CSL_COMPLEX* ptr_input,
CSL_COMPLEX* ptr_ouput,
int num_sample
)
{}
// end vendor.h
typedef std::vector < std::complex < float > > CFLOAT_VEC ;
struct wrapper {
int previous ;
CSL_COMPLEX *ptr_mem_f ;
wrapper ( )
: previous ( INT_MAX )
, ptr_mem_f ( 0 )
{}
void execute_f ( CFLOAT_VEC& vec )
{
CFLOAT_VEC::size_type const current_sz = vec.size() ;
if ( !current_sz )
return ;
if ( previous != current_sz )
{
std::cout << current_sz << std::endl;
ptr_mem_f =
( CSL_COMPLEX *) memalign ( 32, 2 * current_sz * sizeof (
CSL_COMPLEX ) ) ;
}
// copy contents from vec to ptr_mem_f
for ( int idx ( 0 ); idx < current_sz; ++idx ) {
ptr_mem_f [ idx ].r = vec[ idx ].real() ;
ptr_mem_f [ idx ].i = vec[ idx ].imag() ;
}
// - at this point we run the forward FFT run the forward fft
//
cforward ( ptr_mem_f, ptr_mem_f, current_sz ) ; // for inplace
operations input and output is the same
// now copy back to vec ..
for ( int idx ( 0 ); idx < current_sz; ++idx ) {
std::complex < float > temp (
ptr_mem_f [ idx ].r,
ptr_mem_f [ idx ].i
);
vec[ idx ] = temp ;
}
previous = current_sz;
}
};
int main()
{
CFLOAT_VEC fv ( 5 );
for ( CFLOAT_VEC::size_type jdx ( 0 ); jdx < fv.size(); ++jdx )
fv [ jdx ] = std::complex < float > ( jdx , jdx ) ;
wrapper w_obj;
w_obj.execute_f ( fv ) ;
}
The fundamental issue today surrounds the copy from vec to ptr_mem_f
and ptr_mem_f to vec - literally - kills my timing. Besides my current
approach, I'm unsure how to put a decent wrapper around the basket
case of a function - cforward? Ideas welcomed, thanks in advance