Skip to content

Commit

Permalink
Implement pretune option to speed up AIR T.
Browse files Browse the repository at this point in the history
  • Loading branch information
anarkiwi committed Sep 21, 2023
1 parent 7e09c73 commit 65c98bf
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 21 deletions.
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 @@ def __init__(
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 @@ def __init__(
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 @@ def __init__(
self.wavelearner = wavelearner
self.iqtlabs = iqtlabs
self.samp_rate = samp_rate
self.retune_pre_fft = None

##################################################
# Blocks
Expand All @@ -87,12 +89,6 @@ def __init__(
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 @@ def __init__(
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 @@ def __init__(
(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"))
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_db_blocks(self, nfft, samp_rate, scaling):
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(
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
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 @@ def get_offload_fft_block(self, fft_batch_size, nfft, fft_block, fft_roll):
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 @@ def get_fft_blocks(
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

0 comments on commit 65c98bf

Please sign in to comment.