diff options
author | eb | 2008-04-22 22:24:16 +0000 |
---|---|---|
committer | eb | 2008-04-22 22:24:16 +0000 |
commit | b9ba2711addfc9057c136b520afc9e121ec19be9 (patch) | |
tree | 059e93ef559bb837c9ca46549688c86d2e153f1c /gcell/src/lib/wrapper | |
parent | 2ae538ed6a5d18615fb9eea280d861ed3a8600e5 (diff) | |
download | gnuradio-b9ba2711addfc9057c136b520afc9e121ec19be9.tar.gz gnuradio-b9ba2711addfc9057c136b520afc9e121ec19be9.tar.bz2 gnuradio-b9ba2711addfc9057c136b520afc9e121ec19be9.zip |
Merged eb/gcell -r8215:8243 into trunk. This adds gr-gcell, the GNU
Radio interface to the Cell Broadband Engine.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8244 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gcell/src/lib/wrapper')
-rw-r--r-- | gcell/src/lib/wrapper/gcp_fft_1d_r2.cc | 59 | ||||
-rw-r--r-- | gcell/src/lib/wrapper/gcp_fft_1d_r2.h | 19 | ||||
-rw-r--r-- | gcell/src/lib/wrapper/qa_gcp_fft_1d_r2.cc | 12 | ||||
-rw-r--r-- | gcell/src/lib/wrapper/spu/gcs_fft_1d_r2.c | 64 |
4 files changed, 107 insertions, 47 deletions
diff --git a/gcell/src/lib/wrapper/gcp_fft_1d_r2.cc b/gcell/src/lib/wrapper/gcp_fft_1d_r2.cc index f92ee42c8..07267e303 100644 --- a/gcell/src/lib/wrapper/gcp_fft_1d_r2.cc +++ b/gcell/src/lib/wrapper/gcp_fft_1d_r2.cc @@ -30,18 +30,19 @@ static void init_jd(gc_job_desc *jd, gc_proc_id_t proc_id, unsigned log2_fft_length, - bool forward, + bool shift, std::complex<float> *out, const std::complex<float> *in, - const std::complex<float> *W) + const std::complex<float> *twiddle, + const float *window) { jd->proc_id = proc_id; jd->input.nargs = 2; jd->output.nargs = 0; - jd->eaa.nargs = 3; + jd->eaa.nargs = 4; jd->input.arg[0].u32 = log2_fft_length; - jd->input.arg[1].u32 = forward; + jd->input.arg[1].u32 = shift; unsigned int fft_length = 1 << log2_fft_length; jd->eaa.arg[0].ea_addr = ptr_to_ea(out); @@ -52,19 +53,28 @@ init_jd(gc_job_desc *jd, jd->eaa.arg[1].direction = GCJD_DMA_GET; jd->eaa.arg[1].get_size = sizeof(std::complex<float>) * fft_length; - jd->eaa.arg[2].ea_addr = ptr_to_ea(const_cast<std::complex<float>*>(W)); + jd->eaa.arg[2].ea_addr = ptr_to_ea(const_cast<std::complex<float>*>(twiddle)); jd->eaa.arg[2].direction = GCJD_DMA_GET; jd->eaa.arg[2].get_size = sizeof(std::complex<float>) * fft_length / 4; -} + jd->eaa.arg[3].ea_addr = ptr_to_ea(const_cast<float*>(window)); + jd->eaa.arg[3].direction = GCJD_DMA_GET; + if (window == 0) + jd->eaa.arg[3].get_size = 0; + else + jd->eaa.arg[3].get_size = sizeof(float) * fft_length; +} -gc_job_desc * + +gc_job_desc_sptr gcp_fft_1d_r2_submit(gc_job_manager_sptr mgr, unsigned int log2_fft_length, bool forward, + bool shift, std::complex<float> *out, const std::complex<float> *in, - const std::complex<float> *W) + const std::complex<float> *twiddle, + const float *window) { unsigned int fft_length = 1 << log2_fft_length; if (fft_length > 4096) @@ -74,29 +84,36 @@ gcp_fft_1d_r2_submit(gc_job_manager_sptr mgr, throw gc_bad_align("out"); if ((intptr_t)in & 0xf) throw gc_bad_align("in"); - if ((intptr_t)W & 0xf) - throw gc_bad_align("W"); + if ((intptr_t)twiddle & 0xf) + throw gc_bad_align("twiddle"); + if ((intptr_t)window & 0xf) + throw gc_bad_align("window"); + + std::string proc_name; + if (forward) + proc_name = "fwd_fft_1d_r2"; + else + proc_name = "inv_fft_1d_r2"; - gc_proc_id_t fft_id = mgr->lookup_proc("fft_1d_r2"); - gc_job_desc *jd = mgr->alloc_job_desc(); - init_jd(jd, fft_id, log2_fft_length, forward, out, in, W); - if (!mgr->submit_job(jd)){ + gc_proc_id_t fft_id = mgr->lookup_proc(proc_name); + gc_job_desc_sptr jd = gc_job_manager::alloc_job_desc(mgr); + init_jd(jd.get(), fft_id, log2_fft_length, shift, out, in, twiddle, window); + if (!mgr->submit_job(jd.get())){ gc_job_status_t s = jd->status; - mgr->free_job_desc(jd); - throw gc_bad_submit("fft_1d_r2", s); + throw gc_bad_submit(proc_name, s); } return jd; } void -gcp_fft_1d_r2_twiddle(unsigned int log2_fft_length, std::complex<float> *W) +gcp_fft_1d_r2_twiddle(unsigned int log2_fft_length, std::complex<float> *twiddle) { unsigned int n = 1 << log2_fft_length; - W[0].real() = 1.0; - W[0].imag() = 0.0; + twiddle[0].real() = 1.0; + twiddle[0].imag() = 0.0; for (unsigned i=1; i < n/4; i++){ - W[i].real() = cos(i * 2*M_PI/n); - W[n/4 - i].imag() = -W[i].real(); + twiddle[i].real() = cos(i * 2*M_PI/n); + twiddle[n/4 - i].imag() = -twiddle[i].real(); } } diff --git a/gcell/src/lib/wrapper/gcp_fft_1d_r2.h b/gcell/src/lib/wrapper/gcp_fft_1d_r2.h index ed1d9e783..1207a5f36 100644 --- a/gcell/src/lib/wrapper/gcp_fft_1d_r2.h +++ b/gcell/src/lib/wrapper/gcp_fft_1d_r2.h @@ -25,25 +25,32 @@ #include <complex> /*! - * \brief Submit a job that computes the forward or reverse FFT. + * \brief Submit a job that computes the forward or inverse FFT. * * \param mgr is the job manager instance * \param log2_fft_length is the log2 of the fft_length (4 <= x <= 12). - * \param forward is true to compute the forward xform + * \param forward is true to compute the forward transform, else the inverse. + * \param shift indicates if an "fftshift" should be applied to the output data * \param out is the fft_length output from FFT (must be 16-byte aligned). * \param in is the fft_length input to FFT (must be 16-byte aligned). - * \param W is fft_length/4 twiddle factor input to FFT (must be 16-byte aligned). + * \param twiddle is fft_length/4 twiddle factor input to FFT (must be 16-byte aligned). + * \param window is the window to be applied to the input data. + * The window length must be either 0 or fft_length (must be 16-byte aligned). * - * Returns a job descriptor which should be passed to wait_job*. + * Returns a shared_ptr to a job descriptor which should be passed to wait_job*. * Throws an exception in the event of a problem. + * This uses the FFTW conventions for scaling. That is, neither the forward nor inverse + * are scaled by 1/fft_length. */ -gc_job_desc * +gc_job_desc_sptr gcp_fft_1d_r2_submit(gc_job_manager_sptr mgr, unsigned int log2_fft_length, bool forward, + bool shift, std::complex<float> *out, const std::complex<float> *in, - const std::complex<float> *W); + const std::complex<float> *twiddle, + const float *window); /*! * \brief Compute twiddle factors diff --git a/gcell/src/lib/wrapper/qa_gcp_fft_1d_r2.cc b/gcell/src/lib/wrapper/qa_gcp_fft_1d_r2.cc index b177edede..404f83657 100644 --- a/gcell/src/lib/wrapper/qa_gcp_fft_1d_r2.cc +++ b/gcell/src/lib/wrapper/qa_gcp_fft_1d_r2.cc @@ -80,7 +80,7 @@ qa_gcp_fft_1d_r2::t1() #endif } -// test reverse FFT +// test inverse FFT void qa_gcp_fft_1d_r2::t2() { @@ -101,11 +101,13 @@ qa_gcp_fft_1d_r2::t2() void qa_gcp_fft_1d_r2::t3() { + // FIXME Test fwd and inv with windowing option } void qa_gcp_fft_1d_r2::t4() { + // FIXME Test fwd and inv with shift option } static inline float @@ -178,14 +180,12 @@ qa_gcp_fft_1d_r2::test(gc_job_manager_sptr mgr, int log2_fft_size, bool forward) // ------------------------------------------------------------------------ // compute the answer on the cell - gc_job_desc *jd = gcp_fft_1d_r2_submit(mgr, log2_fft_size, forward, - cell_out, cell_in, cell_twiddle); - if (!mgr->wait_job(jd)){ + gc_job_desc_sptr jd = gcp_fft_1d_r2_submit(mgr, log2_fft_size, forward, false, + cell_out, cell_in, cell_twiddle, 0); + if (!mgr->wait_job(jd.get())){ fprintf(stderr, "wait_job failed: %s\n", gc_job_status_string(jd->status).c_str()); - mgr->free_job_desc(jd); CPPUNIT_ASSERT(0); } - mgr->free_job_desc(jd); // ------------------------------------------------------------------------ // compute the maximum of the relative error diff --git a/gcell/src/lib/wrapper/spu/gcs_fft_1d_r2.c b/gcell/src/lib/wrapper/spu/gcs_fft_1d_r2.c index bf4bdfd20..81e5dfd87 100644 --- a/gcell/src/lib/wrapper/spu/gcs_fft_1d_r2.c +++ b/gcell/src/lib/wrapper/spu/gcs_fft_1d_r2.c @@ -21,6 +21,7 @@ #include <gc_declare_proc.h> #include <libfft.h> +#include <assert.h> /* * v is really vector complex<float> @@ -35,24 +36,59 @@ conjugate_vector(vector float *v, int nelements) } static void -gcs_fft_1d_r2(const gc_job_direct_args_t *input, - gc_job_direct_args_t *output __attribute__((unused)), - const gc_job_ea_args_t *eaa) +gcs_fwd_fft_1d_r2(const gc_job_direct_args_t *input, + gc_job_direct_args_t *output __attribute__((unused)), + const gc_job_ea_args_t *eaa) { - vector float *out = (vector float *) eaa->arg[0].ls_addr; - vector float *in = (vector float *) eaa->arg[1].ls_addr; - vector float *W = (vector float *) eaa->arg[2].ls_addr; + vector float *out = (vector float *) eaa->arg[0].ls_addr; // complex + vector float *in = (vector float *) eaa->arg[1].ls_addr; // complex + vector float *twiddle = (vector float *) eaa->arg[2].ls_addr; // complex + vector float *window = (vector float *) eaa->arg[3].ls_addr; // float + int log2_fft_length = input->arg[0].u32; - int forward = input->arg[1].u32; // non-zero if forward xform + int shift = input->arg[1].u32; // non-zero if we should apply fftshift - if (forward){ - fft_1d_r2(out, in, W, log2_fft_length); + if (eaa->arg[3].get_size){ // apply window + // FIXME pointwise multiply in *= window + assert(0); } - else { - conjugate_vector(in, 1 << (log2_fft_length - 1)); - fft_1d_r2(out, in, W, log2_fft_length); - conjugate_vector(out, 1 << (log2_fft_length - 1)); + + fft_1d_r2(out, in, twiddle, log2_fft_length); + + if (shift){ + // FIXME apply "fftshift" to output data in-place + assert(0); } } -GC_DECLARE_PROC(gcs_fft_1d_r2, "fft_1d_r2"); +GC_DECLARE_PROC(gcs_fwd_fft_1d_r2, "fwd_fft_1d_r2"); + +static void +gcs_inv_fft_1d_r2(const gc_job_direct_args_t *input, + gc_job_direct_args_t *output __attribute__((unused)), + const gc_job_ea_args_t *eaa) +{ + vector float *out = (vector float *) eaa->arg[0].ls_addr; // complex + vector float *in = (vector float *) eaa->arg[1].ls_addr; // complex + vector float *twiddle = (vector float *) eaa->arg[2].ls_addr; // complex + vector float *window = (vector float *) eaa->arg[3].ls_addr; // float + + int log2_fft_length = input->arg[0].u32; + int shift = input->arg[1].u32; // non-zero if we should apply fftshift + + if (eaa->arg[3].get_size){ // apply window + // FIXME pointwise multiply in *= window + assert(0); + } + + if (shift){ + // FIXME apply "fftshift" to input data in-place + assert(0); + } + + conjugate_vector(in, 1 << (log2_fft_length - 1)); + fft_1d_r2(out, in, twiddle, log2_fft_length); + conjugate_vector(out, 1 << (log2_fft_length - 1)); +} + +GC_DECLARE_PROC(gcs_inv_fft_1d_r2, "inv_fft_1d_r2"); |