Skip to content

Commit

Permalink
Merge pull request #184 from anarkiwi/tidy
Browse files Browse the repository at this point in the history
tidy up vkfft blocks API to accept batch size directly.
  • Loading branch information
anarkiwi committed Jan 16, 2024
2 parents f64ec33 + c0a2000 commit 4184051
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 57 deletions.
16 changes: 9 additions & 7 deletions grc/iqtlabs_vkfft.block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,29 @@ documentation: |-
vector of complex, representing FFT output.
parameters:
vlen: length of FFT vector, as a multiple of nfft to achieve batching.
fft_batch_size: how many FFT windows in the input vector.
nfft: number of FFT points.
shift: if true, move DC component to center of output
(see gnuradio fft shift parameter).
templates:
imports: from gnuradio import iqtlabs
make: iqtlabs.vkfft(${vlen}, ${nfft}, ${shift})
make: iqtlabs.vkfft(${fft_batch_size}, ${nfft}, ${shift})

cpp_templates:
includes: ['#include <gnuradio/iqtlabs/vkfft.h>']
declarations: 'gr::iqtlabs::vkfft::sptr ${id};'
make: 'this->${id} = gr::iqtlabs::vkfft::make(${vlen}, ${nfft}, ${bool});'
make: >
this->${id} = gr::iqtlabs::vkfft::make(
${fft_batch_size}, ${nfft}, ${bool});
link: ['libgnuradio-iqtlabs.so']

asserts:
- ${ vlen >= nfft }
- ${ fft_batch_size > 0 }
- ${ nfft > 0 }

parameters:
- id: vlen
- id: fft_batch_size
dtype: int
- id: nfft
dtype: int
Expand All @@ -43,12 +45,12 @@ inputs:
- label: input
domain: stream
dtype: complex
vlen: ${ vlen }
vlen: ${ fft_batch_size * nfft }

outputs:
- label: output
domain: stream
dtype: complex
vlen: ${ vlen }
vlen: ${ fft_batch_size * nfft }

file_format: 1
24 changes: 13 additions & 11 deletions grc/iqtlabs_vkfft_short.block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,37 @@ label: vkfft_short
category: '[iqtlabs]'
flags: [python, cpp]
documentation: |-
This block uses VkFFT to do FFT offload via Vulkan (short dtype version)
This block uses VkFFT to do FFT offload via Vulkan (short version).
input:
vector of short, representing I/Q samples.
vector of complex, representing I/Q samples.
output:
vector of complex, representing FFT output.
parameters:
vlen: length of FFT vector, as a multiple of nfft to achieve batching.
fft_batch_size: how many FFT windows in the input vector.
nfft: number of FFT points.
shift: if true, move DC component to center of output
(see gnuradio fft shift parameter).
templates:
imports: from gnuradio import iqtlabs
make: iqtlabs.vkfft(${vlen}, ${nfft}, ${shift})
make: iqtlabs.vkfft_short(${fft_batch_size}, ${nfft}, ${shift})

cpp_templates:
includes: ['#include <gnuradio/iqtlabs/vkfft.h>']
declarations: 'gr::iqtlabs::vkfft::sptr ${id};'
make: 'this->${id} = gr::iqtlabs::vkfft::make(${vlen}, ${nfft}, ${bool});'
includes: ['#include <gnuradio/iqtlabs/vkfft_short.h>']
declarations: 'gr::iqtlabs::vkfft_short::sptr ${id};'
make: >
this->${id} = gr::iqtlabs::vkfft_short::make(
${fft_batch_size}, ${nfft}, ${bool});
link: ['libgnuradio-iqtlabs.so']

asserts:
- ${ vlen >= nfft }
- ${ fft_batch_size > 0 }
- ${ nfft > 0 }

parameters:
- id: vlen
- id: fft_batch_size
dtype: int
- id: nfft
dtype: int
Expand All @@ -43,12 +45,12 @@ inputs:
- label: input
domain: stream
dtype: short
vlen: ${ vlen }
vlen: ${ fft_batch_size * nfft * 2}

outputs:
- label: output
domain: stream
dtype: complex
vlen: ${ vlen }
vlen: ${ fft_batch_size * nfft }

file_format: 1
2 changes: 1 addition & 1 deletion include/gnuradio/iqtlabs/vkfft.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class IQTLABS_API vkfft : virtual public gr::sync_block {
* class. iqtlabs::vkfft::make is the public interface for
* creating new instances.
*/
static sptr make(std::size_t vlen, std::size_t nfft, bool shift);
static sptr make(std::size_t fft_batch_size, std::size_t nfft, bool shift);
};

} // namespace iqtlabs
Expand Down
2 changes: 1 addition & 1 deletion include/gnuradio/iqtlabs/vkfft_short.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class IQTLABS_API vkfft_short : virtual public gr::sync_block {
* class. iqtlabs::vkfft_short::make is the public interface for
* creating new instances.
*/
static sptr make(std::size_t vlen, std::size_t nfft, bool shift);
static sptr make(std::size_t fft_batch_size, std::size_t nfft, bool shift);
};

} // namespace iqtlabs
Expand Down
21 changes: 12 additions & 9 deletions lib/vkfft_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,20 @@
namespace gr {
namespace iqtlabs {

vkfft::sptr vkfft::make(std::size_t vlen, std::size_t nfft, bool shift) {
return gnuradio::make_block_sptr<vkfft_impl>(vlen, nfft, shift);
vkfft::sptr vkfft::make(std::size_t fft_batch_size, std::size_t nfft,
bool shift) {
return gnuradio::make_block_sptr<vkfft_impl>(fft_batch_size, nfft, shift);
}

vkfft_impl::vkfft_impl(std::size_t vlen, std::size_t nfft, bool shift)
: vlen_(vlen),
vkfft_impl::vkfft_impl(std::size_t fft_batch_size, std::size_t nfft, bool shift)
: fft_batch_size_(fft_batch_size),
nfft_(nfft), gr::sync_block(
"vkfft",
gr::io_signature::make(1, 1, sizeof(gr_complex) * vlen),
gr::io_signature::make(1, 1,
sizeof(gr_complex) * vlen)) {
init_vkfft((vlen / nfft), nfft, sizeof(gr_complex), shift);
gr::io_signature::make(
1, 1, sizeof(gr_complex) * nfft * fft_batch_size),
gr::io_signature::make(
1, 1, sizeof(gr_complex) * nfft * fft_batch_size)) {
init_vkfft(fft_batch_size, nfft, sizeof(gr_complex), shift);
}

vkfft_impl::~vkfft_impl() { free_vkfft(); }
Expand All @@ -232,7 +234,8 @@ int vkfft_impl::work(int noutput_items, gr_vector_const_void_star &input_items,
gr_complex *const out = reinterpret_cast<gr_complex *const>(output_items[0]);
size_t buffer_index = 0;

for (int i = 0; i < noutput_items; ++i, buffer_index += vlen_) {
for (int i = 0; i < noutput_items;
++i, buffer_index += (fft_batch_size_ * nfft_)) {
vkfft_offload((char *)&in[buffer_index], (char *)&out[buffer_index]);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/vkfft_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ namespace iqtlabs {
class vkfft_impl : public vkfft, base_impl {
private:
std::size_t nfft_;
std::size_t vlen_;
std::size_t fft_batch_size_;

public:
vkfft_impl(std::size_t nfft, std::size_t batch, bool shift);
vkfft_impl(std::size_t fft_batch_size, std::size_t nfft, bool shift);
~vkfft_impl();

int work(int noutput_items, gr_vector_const_void_star &input_items,
Expand Down
33 changes: 19 additions & 14 deletions lib/vkfft_short_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,25 @@
namespace gr {
namespace iqtlabs {

vkfft_short::sptr vkfft_short::make(std::size_t vlen, std::size_t nfft,
bool shift) {
return gnuradio::make_block_sptr<vkfft_short_impl>(vlen, nfft, shift);
vkfft_short::sptr vkfft_short::make(std::size_t fft_batch_size,
std::size_t nfft, bool shift) {
return gnuradio::make_block_sptr<vkfft_short_impl>(fft_batch_size, nfft,
shift);
}

vkfft_short_impl::vkfft_short_impl(std::size_t vlen, std::size_t nfft,
vkfft_short_impl::vkfft_short_impl(std::size_t fft_batch_size, std::size_t nfft,
bool shift)
: vlen_(vlen),
nfft_(nfft), gr::sync_block("vkfft",
gr::io_signature::make(
1, 1, sizeof(std::int16_t) * 2 * vlen),
gr::io_signature::make(
1, 1, sizeof(gr_complex) * vlen)) {
: fft_batch_size_(fft_batch_size),
nfft_(nfft), gr::sync_block(
"vkfft_short",
gr::io_signature::make(1, 1,
sizeof(std::int16_t) * 2 * nfft *
fft_batch_size),
gr::io_signature::make(
1, 1, sizeof(gr_complex) * nfft * fft_batch_size)) {
init_converter_();
input_buffer_.reset(new gr_complex[vlen]);
init_vkfft((vlen / nfft), nfft, sizeof(gr_complex), shift);
input_buffer_.reset(new gr_complex[nfft * fft_batch_size]);
init_vkfft(fft_batch_size, nfft, sizeof(gr_complex), shift);
}

void vkfft_short_impl::init_converter_() {
Expand All @@ -248,8 +251,10 @@ int vkfft_short_impl::work(int noutput_items,
auto *buffer = input_buffer_.get();
size_t buffer_index = 0;

for (int i = 0; i < noutput_items; ++i, buffer_index += vlen_ * 2) {
_converter->conv(&in[buffer_index], &buffer[0], vlen_);
for (int i = 0; i < noutput_items;
++i, buffer_index += fft_batch_size_ * nfft_ * 2) {
_converter->conv(&in[buffer_index], &buffer[0],
fft_batch_size_ * nfft_ * 2);
vkfft_offload((char *)&buffer[0], (char *)&out[buffer_index]);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/vkfft_short_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,13 @@ namespace iqtlabs {
class vkfft_short_impl : public vkfft_short, base_impl {
private:
std::size_t nfft_;
std::size_t vlen_;
std::size_t fft_batch_size_;
boost::scoped_array<gr_complex> input_buffer_;
uhd::convert::converter::sptr _converter;
void init_converter_();

public:
vkfft_short_impl(std::size_t nfft, std::size_t batch, bool shift);
vkfft_short_impl(std::size_t fft_batch_size, std::size_t nfft, bool shift);
~vkfft_short_impl();

int work(int noutput_items, gr_vector_const_void_star &input_items,
Expand Down
2 changes: 1 addition & 1 deletion python/iqtlabs/bindings/docstrings/vkfft_pydoc_template.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Free Software Foundation, Inc.
* Copyright 2024 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Free Software Foundation, Inc.
* Copyright 2024 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
Expand Down
6 changes: 3 additions & 3 deletions python/iqtlabs/bindings/vkfft_python.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Free Software Foundation, Inc.
* Copyright 2024 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
Expand All @@ -14,7 +14,7 @@
/* BINDTOOL_GEN_AUTOMATIC(0) */
/* BINDTOOL_USE_PYGCCXML(0) */
/* BINDTOOL_HEADER_FILE(vkfft.h) */
/* BINDTOOL_HEADER_FILE_HASH(6cb25f3bb6a1c44ef9863a98b7e83c77) */
/* BINDTOOL_HEADER_FILE_HASH(573a4d7d80617702d8fa2355b3dc7749) */
/***********************************************************************************/

#include <pybind11/complex.h>
Expand All @@ -37,7 +37,7 @@ void bind_vkfft(py::module& m)
m, "vkfft", D(vkfft))

.def(py::init(&vkfft::make),
py::arg("vlen"),
py::arg("fft_batch_size"),
py::arg("nfft"),
py::arg("shift"),
D(vkfft, make))
Expand Down
6 changes: 3 additions & 3 deletions python/iqtlabs/bindings/vkfft_short_python.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Free Software Foundation, Inc.
* Copyright 2024 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
Expand All @@ -14,7 +14,7 @@
/* BINDTOOL_GEN_AUTOMATIC(0) */
/* BINDTOOL_USE_PYGCCXML(0) */
/* BINDTOOL_HEADER_FILE(vkfft_short.h) */
/* BINDTOOL_HEADER_FILE_HASH(a2d6de27d57f2204d29c673394da3b12) */
/* BINDTOOL_HEADER_FILE_HASH(138ecdd6b31957119102597250cdd57c) */
/***********************************************************************************/

#include <pybind11/complex.h>
Expand All @@ -40,7 +40,7 @@ void bind_vkfft_short(py::module& m)
std::shared_ptr<vkfft_short>>(m, "vkfft_short", D(vkfft_short))

.def(py::init(&vkfft_short::make),
py::arg("vlen"),
py::arg("fft_batch_size"),
py::arg("nfft"),
py::arg("shift"),
D(vkfft_short, make))
Expand Down
2 changes: 1 addition & 1 deletion python/iqtlabs/qa_vkfft.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def test_instance(self):
)

vkfft_data = run_fft(
iqtlabs.vkfft(fft_batch_size * points, points, fft_roll),
iqtlabs.vkfft(fft_batch_size, points, fft_roll),
points,
fft_roll,
batch_input_items,
Expand Down
2 changes: 1 addition & 1 deletion python/iqtlabs/qa_vkfft_short.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def test_instance(self):
# TODO: find workaround llvmpipe simulated gpu crashes under CI testing
# TODO: old UHD library vesion does not have automatic host-order.
try:
instance = vkfft_short(1024, 1, True)
instance = vkfft_short(1, 1024, True)
except RuntimeError as e:
print(e)

Expand Down

0 comments on commit 4184051

Please sign in to comment.