Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement pretune option to speed up AIR T. #876

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README-airt.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ $ pip3 install .
run gamutrf (may need to change sample rate depending on SDR - e.g. 125e6 or 100e6).

```
$ LD_PRELOAD=$HOME/.conda/envs/$CONDA_DEFAULT_ENV/lib/libgomp.so.1 gamutrf-scan --sdr=SoapyAIRT --freq-start=300e6 --freq-end=6e9 --tune-step-fft 256 --samp-rate=100e6 --nfft 256
$ LD_PRELOAD=$HOME/.conda/envs/$CONDA_DEFAULT_ENV/lib/libgomp.so.1 gamutrf-scan --sdr=SoapyAIRT --freq-start=300e6 --freq-end=6e9 --tune-step-fft 256 --samp-rate=100e6 --nfft 256 --pretune
```

gamutrf-scan will repeatedly print
Expand Down
98 changes: 85 additions & 13 deletions gamutrf/grscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
logaddr="0.0.0.0", # nosec
logport=8001,
nfft=1024,
pretune=False,
rotate_secs=0,
samp_rate=4.096e6,
sample_dir="",
Expand All @@ -56,7 +57,7 @@
tune_dwell_ms=0,
tuneoverlap=0.5,
tuning_ranges="",
use_vkfft=False,
vkfft=False,
wavelearner=None,
write_samples=0,
):
Expand All @@ -72,6 +73,7 @@
self.wavelearner = wavelearner
self.iqtlabs = iqtlabs
self.samp_rate = samp_rate
self.retune_pre_fft = None

##################################################
# Blocks
Expand All @@ -87,12 +89,6 @@
sdrargs=sdrargs,
)

fft_blocks = self.get_fft_blocks(
use_vkfft, fft_batch_size, nfft, dc_block_len, dc_block_long
)
self.fft_blocks = fft_blocks + self.get_db_blocks(nfft, samp_rate, scaling)
self.fft_to_inference_block = self.fft_blocks[-1]

self.samples_blocks = []
if write_samples:
Path(sample_dir).mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -134,6 +130,23 @@
f"requested retuning across {freq_range/1e6}MHz every {tune_step_fft} FFTs, dwell time {tune_dwell_ms}ms"
)

fft_blocks = self.get_fft_blocks(
vkfft,
fft_batch_size,
nfft,
dc_block_len,
dc_block_long,
freq_start,
freq_end,
tune_step_hz,
tune_step_fft,
skip_tune_step,
tuning_ranges,
pretune,
)
self.fft_blocks = fft_blocks + self.get_db_blocks(nfft, samp_rate, scaling)
self.fft_to_inference_block = self.fft_blocks[-1]

retune_fft = self.iqtlabs.retune_fft(
"rx_freq",
nfft,
Expand Down Expand Up @@ -243,7 +256,11 @@
(self.wavelearner_inference_block, 0), (self.yolo_bbox_block, 1)
)

self.msg_connect((retune_fft, "tune"), (self.sources[0], cmd_port))
if pretune:
self.msg_connect((self.retune_pre_fft, "tune"), (self.sources[0], cmd_port))
self.msg_connect((self.retune_pre_fft, "tune"), (retune_fft, "cmd"))

Check warning on line 261 in gamutrf/grscan.py

View check run for this annotation

Codecov / codecov/patch

gamutrf/grscan.py#L260-L261

Added lines #L260 - L261 were not covered by tests
else:
self.msg_connect((retune_fft, "tune"), (self.sources[0], cmd_port))
self.connect_blocks(self.sources[0], self.sources[1:])
self.connect_blocks(self.fft_to_inference_block, self.inference_blocks)
for pipeline_blocks in (
Expand Down Expand Up @@ -274,9 +291,40 @@
def get_window(self, nfft):
return window.hann(nfft)

def get_offload_fft_block(self, fft_batch_size, nfft, fft_block, fft_roll):
def get_offload_fft_block(
self,
fft_batch_size,
nfft,
fft_block,
fft_roll,
freq_start,
freq_end,
tune_step_hz,
tune_step_fft,
skip_tune_step,
tuning_ranges,
pretune,
):
if pretune:
self.retune_pre_fft = self.iqtlabs.retune_pre_fft(

Check warning on line 309 in gamutrf/grscan.py

View check run for this annotation

Codecov / codecov/patch

gamutrf/grscan.py#L309

Added line #L309 was not covered by tests
nfft,
fft_batch_size,
"rx_freq",
int(freq_start),
int(freq_end),
tune_step_hz,
tune_step_fft,
skip_tune_step,
tuning_ranges,
)
stream_to_vector = self.retune_pre_fft

Check warning on line 320 in gamutrf/grscan.py

View check run for this annotation

Codecov / codecov/patch

gamutrf/grscan.py#L320

Added line #L320 was not covered by tests
else:
stream_to_vector = blocks.stream_to_vector(
gr.sizeof_gr_complex, fft_batch_size * nfft
)

offload_blocks = [
blocks.stream_to_vector(gr.sizeof_gr_complex, fft_batch_size * nfft),
stream_to_vector,
blocks.multiply_const_vff(
[val for val in self.get_window(nfft) for _ in range(2)]
* fft_batch_size
Expand All @@ -289,7 +337,19 @@
return offload_blocks

def get_fft_blocks(
self, use_vkfft, fft_batch_size, nfft, dc_block_len, dc_block_long
self,
vkfft,
fft_batch_size,
nfft,
dc_block_len,
dc_block_long,
freq_start,
freq_end,
tune_step_hz,
tune_step_fft,
skip_tune_step,
tuning_ranges,
pretune,
):
fft_blocks = []
if dc_block_len:
Expand All @@ -299,11 +359,23 @@
if self.wavelearner:
fft_block = self.wavelearner.fft(int(fft_batch_size * nfft), (nfft), True)
fft_roll = True
elif use_vkfft:
elif vkfft:
fft_block = self.iqtlabs.vkfft(int(fft_batch_size * nfft), nfft, True)
if fft_block:
fft_blocks.extend(
self.get_offload_fft_block(fft_batch_size, nfft, fft_block, fft_roll)
self.get_offload_fft_block(
fft_batch_size,
nfft,
fft_block,
fft_roll,
freq_start,
freq_end,
tune_step_hz,
tune_step_fft,
skip_tune_step,
tuning_ranges,
pretune,
)
)
else:
fft_blocks.extend(
Expand Down
21 changes: 14 additions & 7 deletions gamutrf/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,27 @@ def argument_parser():
action=BooleanOptionalAction,
help="add sigmf meta file",
)
parser.add_argument(
"--use_vkfft",
dest="use_vkfft",
default=True,
action=BooleanOptionalAction,
help="use VkFFT (ignored if wavelearner available)",
)
parser.add_argument(
"--fft_batch_size",
dest="fft_batch_size",
type=int,
default=256,
help="offload FFT batch size",
)
parser.add_argument(
"--vkfft",
dest="vkfft",
default=True,
action=BooleanOptionalAction,
help="use VkFFT (ignored if wavelearner available)",
)
parser.add_argument(
"--pretune",
dest="pretune",
default=False,
action=BooleanOptionalAction,
help="use pretuning",
)
return parser


Expand Down
Loading