From a4e5e60ae5aba213d01a0eb13c68db4debdeed7a Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Sat, 22 Jun 2024 21:16:28 +0000 Subject: [PATCH 1/4] Simplify retune_fft JSON output. --- docker/Dockerfile.base | 2 +- gamutrf/grpduzmq.py | 42 ++++++++++++++++++++++++++++++++++++++++++ gamutrf/grscan.py | 8 ++++---- torchserve-cuda.yml | 3 ++- torchserve.yml | 3 ++- 5 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 gamutrf/grpduzmq.py diff --git a/docker/Dockerfile.base b/docker/Dockerfile.base index e625e6f0..86bfe6cc 100644 --- a/docker/Dockerfile.base +++ b/docker/Dockerfile.base @@ -14,7 +14,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libvulkan-dev \ python3-numpy WORKDIR /root -RUN git clone https://github.com/iqtlabs/gr-iqtlabs -b 1.0.108 +RUN git clone https://github.com/iqtlabs/gr-iqtlabs -b 1.0.109 COPY --from=iqtlabs/gamutrf-vkfft:latest /root /root/gr-iqtlabs WORKDIR /root/gr-iqtlabs/build COPY --from=iqtlabs/gamutrf-sigmf:latest /usr/local /usr/local diff --git a/gamutrf/grpduzmq.py b/gamutrf/grpduzmq.py new file mode 100644 index 00000000..c22ca3c0 --- /dev/null +++ b/gamutrf/grpduzmq.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +import json +import sys +import time +import pmt +import zmq + +try: + from gnuradio import gr # pytype: disable=import-error +except ModuleNotFoundError as err: # pragma: no cover + print( + "Run from outside a supported environment, please run via Docker (https://github.com/IQTLabs/gamutRF#readme): %s" + % err + ) + sys.exit(1) + +DELIM = "\n" + + +class pduzmq(gr.basic_block): + def __init__( + self, + zmq_addr, + ): + gr.basic_block.__init__( + self, + name="pduzmq", + in_sig=None, + out_sig=None, + ) + self.zmq_context = zmq.Context() + self.zmq_pub = self.zmq_context.socket(zmq.PUB) + self.zmq_pub.setsockopt(zmq.SNDHWM, 100) + self.zmq_pub.setsockopt(zmq.SNDBUF, 65536) + self.zmq_pub.bind(zmq_addr) + self.message_port_register_in(pmt.intern("json")) + self.set_msg_handler(pmt.intern("json"), self.receive_pdu) + + def receive_pdu(self, pdu): + item = pmt.to_python(pmt.cdr(pdu)).tobytes().decode("utf8").strip() + self.zmq_pub.send_string(item + DELIM, flags=zmq.NOBLOCK) diff --git a/gamutrf/grscan.py b/gamutrf/grscan.py index 850a8151..5c39d411 100644 --- a/gamutrf/grscan.py +++ b/gamutrf/grscan.py @@ -25,6 +25,7 @@ from gamutrf.grsource import get_source from gamutrf.grinferenceoutput import inferenceoutput +from gamutrf.grpduzmq import pduzmq from gamutrf.utils import endianstr @@ -252,10 +253,8 @@ def __init__( ) self.fft_blocks.append(retune_fft) fft_zmq_addr = f"tcp://{logaddr}:{logport}" + pduzmq_block = pduzmq(fft_zmq_addr) logging.info("serving FFT on %s", fft_zmq_addr) - self.fft_blocks.append( - (zeromq.pub_sink(1, 1, fft_zmq_addr, 100, False, 65536, "")) - ) if fgaas_port: fgaas_zmq_addr = f"tcp://{fgaas_addr}:{fgaas_port}" @@ -390,13 +389,14 @@ def __init__( if not retune_fft_output_block: retune_fft_output_block = blocks.null_sink(gr.sizeof_float * nfft) - self.connect((retune_fft, 1), (retune_fft_output_block, 0)) + self.connect((retune_fft, 0), (retune_fft_output_block, 0)) 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.msg_connect((retune_fft, "json"), (pduzmq_block, "json")) self.connect_blocks(self.sources[0], self.sources[1:]) self.connect_blocks(self.sources[-1], self.fft_blocks) diff --git a/torchserve-cuda.yml b/torchserve-cuda.yml index afdc07ef..20072208 100644 --- a/torchserve-cuda.yml +++ b/torchserve-cuda.yml @@ -26,6 +26,7 @@ services: command: # can be multiple models # e.g. mini2_snr=mini2_snr.mar,another_mini2_snr=another_mini2_snr.mar - # As of torchserve v11, you will need to add setuptools==69.5.1 to your requirements.txt when generating a MAR file + # As of torchserve v11, you will need to add setuptools==69.5.1 + # to your requirements.txt when generating a MAR file # https://github.com/pytorch/serve/issues/3176 - --models torchsig_model=torchsig_model.mar diff --git a/torchserve.yml b/torchserve.yml index 47638b83..09b1a44c 100644 --- a/torchserve.yml +++ b/torchserve.yml @@ -18,6 +18,7 @@ services: - '/root/.cache/pip:/root/.cache/pip' command: # --models torchsig_model=torchsig_model.mar - # As of torchserve v11, you will need to add setuptools==69.5.1 to your requirements.txt when generating a MAR file + # As of torchserve v11, you will need to add setuptools==69.5.1 + # to your requirements.txt when generating a MAR file # https://github.com/pytorch/serve/issues/3176 - --models mini2_snr=mini2_snr.mar From 4976e64af71216749c9a1c6c4f9c9fd775b365cc Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Sun, 23 Jun 2024 02:39:34 +0000 Subject: [PATCH 2/4] import --- gamutrf/grpduzmq.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/gamutrf/grpduzmq.py b/gamutrf/grpduzmq.py index c22ca3c0..93383f88 100644 --- a/gamutrf/grpduzmq.py +++ b/gamutrf/grpduzmq.py @@ -1,8 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -import json import sys -import time import pmt import zmq From 080442d0a16509c4fac0c11c498617dda09ebda7 Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Sun, 23 Jun 2024 04:46:47 +0000 Subject: [PATCH 3/4] close. --- gamutrf/grpduzmq.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gamutrf/grpduzmq.py b/gamutrf/grpduzmq.py index 93383f88..ccba9997 100644 --- a/gamutrf/grpduzmq.py +++ b/gamutrf/grpduzmq.py @@ -35,6 +35,9 @@ def __init__( self.message_port_register_in(pmt.intern("json")) self.set_msg_handler(pmt.intern("json"), self.receive_pdu) + def stop(self): + self.zmq_pub.close() + def receive_pdu(self, pdu): item = pmt.to_python(pmt.cdr(pdu)).tobytes().decode("utf8").strip() self.zmq_pub.send_string(item + DELIM, flags=zmq.NOBLOCK) From 8e9f67d79afc557cda0fb1b2097bc1ab309c6d2a Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Sun, 23 Jun 2024 05:31:49 +0000 Subject: [PATCH 4/4] attribute --- gamutrf/grscan.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gamutrf/grscan.py b/gamutrf/grscan.py index 5c39d411..688b7727 100644 --- a/gamutrf/grscan.py +++ b/gamutrf/grscan.py @@ -253,7 +253,7 @@ def __init__( ) self.fft_blocks.append(retune_fft) fft_zmq_addr = f"tcp://{logaddr}:{logport}" - pduzmq_block = pduzmq(fft_zmq_addr) + self.pduzmq_block = pduzmq(fft_zmq_addr) logging.info("serving FFT on %s", fft_zmq_addr) if fgaas_port: @@ -396,7 +396,7 @@ def __init__( self.msg_connect((self.retune_pre_fft, "tune"), (retune_fft, "cmd")) else: self.msg_connect((retune_fft, "tune"), (self.sources[0], cmd_port)) - self.msg_connect((retune_fft, "json"), (pduzmq_block, "json")) + self.msg_connect((retune_fft, "json"), (self.pduzmq_block, "json")) self.connect_blocks(self.sources[0], self.sources[1:]) self.connect_blocks(self.sources[-1], self.fft_blocks)