Skip to content

Commit

Permalink
Merge pull request #219 from anarkiwi/view
Browse files Browse the repository at this point in the history
vkfft comparison test.
  • Loading branch information
anarkiwi authored Feb 17, 2024
2 parents a700c69 + c37dee6 commit be93d6f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 250 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ jobs:
fetch-depth: 0
- name: build_test
run: |
sudo apt-get -y update && sudo add-apt-repository ppa:gnuradio/gnuradio-releases && bin/apt_get.sh && bin/install-volk.sh v3.1.0 && bin/build_test.sh && bin/test_grc310.sh
sudo apt-get -y update && sudo add-apt-repository ppa:gnuradio/gnuradio-releases && bin/apt_get.sh && bin/install-volk.sh v3.1.0 && TEST_VKFFT=0 bin/build_test.sh && bin/test_grc310.sh
13 changes: 6 additions & 7 deletions lib/vkfft_short_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,11 @@ vkfft_short_impl::vkfft_short_impl(std::size_t fft_batch_size, std::size_t nfft,
}

void vkfft_short_impl::init_converter_() {
uhd::convert::id_type id;
id.input_format = "sc16_chdr";
id.num_inputs = 1;
id.output_format = "fc32";
id.num_outputs = 1;
_converter = uhd::convert::get_converter(id, 0)();
_id.input_format = "sc16_chdr";
_id.num_inputs = 1;
_id.output_format = "fc32";
_id.num_outputs = 1;
_converter = uhd::convert::get_converter(_id, 0)();
_converter->set_scalar(1 / 32767.);
}

Expand All @@ -254,7 +253,7 @@ int vkfft_short_impl::work(int noutput_items,

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

Expand Down
1 change: 1 addition & 0 deletions lib/vkfft_short_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class vkfft_short_impl : public vkfft_short, base_impl {
boost::scoped_array<gr_complex> input_buffer_;
uhd::convert::converter::sptr _converter;
void init_converter_();
uhd::convert::id_type _id;

public:
vkfft_short_impl(std::size_t fft_batch_size, std::size_t nfft, bool shift);
Expand Down
1 change: 0 additions & 1 deletion python/iqtlabs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ add_custom_target(
)
if(VKFFT)
GR_ADD_TEST(qa_vkfft ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_vkfft.py)
GR_ADD_TEST(qa_vkfft_short ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_vkfft_short.py)
endif()
GR_ADD_TEST(qa_tuneable_test_source ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_tuneable_test_source.py)
GR_ADD_TEST(qa_retune_fft ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_retune_fft.py)
Expand Down
1 change: 0 additions & 1 deletion python/iqtlabs/qa_iq_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,5 @@ def test_instance(self):
last_rx_freq = rx_freq



if __name__ == "__main__":
gr_unittest.run(qa_iq_inference)
43 changes: 32 additions & 11 deletions python/iqtlabs/qa_vkfft.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,37 +208,49 @@
from gnuradio import blocks, fft, iqtlabs, gr, gr_unittest


def run_fft(fft_block, points, fft_roll, input_items):
def run_fft(fft_block, short, points, fft_roll, input_items):
tb = gr.top_block()
src1 = blocks.vector_source_c(input_items, vlen=points)
dst1 = blocks.vector_sink_c(vlen=points)
tb = gr.top_block()
tb.connect(src1, fft_block)
tb.connect(fft_block, dst1)
if short:
v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, points)
cis = blocks.complex_to_interleaved_short(False, 32767)
s2v = blocks.stream_to_vector(gr.sizeof_short, points * 2)
test_blocks = [src1, v2s, cis, s2v, fft_block, dst1]
else:
test_blocks = [src1, fft_block, dst1]
for i, b in enumerate(test_blocks, start=0):
if i:
tb.connect(test_blocks[i - 1], b)
tb.run()
data = dst1.data()
tb.stop()
tb.wait()
data = dst1.data()
del tb
return data


class qa_vkfft(gr_unittest.TestCase):
def test_instance(self):
def round_complex(self, l, n=3):
return [complex(round(x.real, n), round(x.imag, n)) for x in l]

def run_comparison(self, vkfft_block, short):
for fft_roll in (True, False):
fft_batch_size = 1
points = 8

batch_input_items = []
for i in range(1, fft_batch_size + 1):
batch_input_items.append(
1j * np.arange(points)
1j * np.arange(start=0, stop=(points * 0.1), step=0.1)
) # pytype: disable=wrong-arg-types

sw_data = []
for i in range(1, fft_batch_size + 1):
sw_data.extend(
run_fft(
fft.fft_vcc(points, True, [], fft_roll, 1),
0,
points,
fft_roll,
batch_input_items[i - 1],
Expand All @@ -249,16 +261,25 @@ def test_instance(self):
for i in range(1, fft_batch_size + 1):
vkfft_data.extend(
run_fft(
iqtlabs.vkfft(fft_batch_size, points, fft_roll),
vkfft_block(fft_batch_size, points, fft_roll),
short,
points,
fft_roll,
batch_input_items[i - 1],
)
)

if os.getenv("TEST_VKFFT", 0):
self.assertEqual(vkfft_data, sw_data)
self.assertEqual(
self.round_complex(vkfft_data), self.round_complex(sw_data)
)

def test_vkfft(self):
self.run_comparison(iqtlabs.vkfft, False)

def test_short_vkfft(self):
self.run_comparison(iqtlabs.vkfft_short, True)


if __name__ == "__main__":
gr_unittest.run(qa_vkfft)
if os.getenv("TEST_VKFFT", 0):
gr_unittest.run(qa_vkfft)
229 changes: 0 additions & 229 deletions python/iqtlabs/qa_vkfft_short.py

This file was deleted.

0 comments on commit be93d6f

Please sign in to comment.