Parallel
rpps.parallel ¶
Parallel processing of frames: a profile's frame-parallel region
Real time needs more than one core, and later a GPU or FPGA. Once frame sync has found a frame and its header has set
the parameters, the rest is per-frame work with no state across frames. A profile marks where that region starts
("parallel": "<step id>"); rpps.profile.parallel refuses a region with stream-scoped steps (SCOPE = STREAM), a
publishing header or a late change.
The unit is the batch, not the thread: N frames through one program pays on every target.
profile.rx(parallel=rp.parallel.Parallel("thread", workers=4)) -> ParallelRunner
front the ordinary Runner, stopped at the region; the changes it resolved cut the input at frame starts
Scheduler frames -> batches of one key -> Executor (inline, threads by rows, processes, later GPU / FPGA) -> results in order
BatchPlan per key (the header's parameters, the frame's shape): the region's kernels, shapes checked, describe()
Kernel a pure function over [N, L] arrays, run(xp, batch); LoopKernel runs frame by frame through the operators
- An operator gives its kernel with
op.kernel(params, how); a step without one runs throughLoopKernel, which is also the oracle every kernel is checked against (tests/unit/parallel/). Kernels:symbol.kernels(Demap,Rotate,Gather),code.kernels(BlockDecode,LdpcDecode,BchDecode,Permuteof an interleaver,Identityof a code a frame switches off,XorMask),sync.kernels(PilotLine),link.kernels(HeaderDecodeof a framed header); the protocol isrpps.base.kernel. - Kernels belong to generic operators, never a protocol; they use only what numpy and cupy share (
xp), hold their constants, keep shapes fixed per key, and mark a failed row instead of raising.BatchPlan.describe()is data, what a device library or HLS generator would build from. - Processes use
forkwhere available, elsespawn(scripts need a__main__guard); each builds its region from a picklableRegionSteps. - On
dvbs2/normalthe output equals the serial runner's bit for bit, for any block cut, worker count and batch size. Measure withpython tools/parallel_bench.py 64 4. - A parallel region's kernels decode inside: each frame result is its message (
"frame",crc_okFalse when dropped), without the header fields a serial runner gives.
Devices (GPUs)¶
Vendor neutral: CUDA and ROCm/HIP alike, through CuPy (built for either, one API); nothing here names a vendor, and no
kernel branches on one. rpps._accel.device() gives (xp, "cuda" | "hip") or (numpy, None);
Parallel("thread", xp=xp) runs the region's plans on it (inline or thread executors only: a device does not cross a
fork).
- Hand-off. A batch is stacked on the host and the plan moves it: one upload at its start, one download at its end,
and a
to:host/to:devicepair around each run of kernels that need numpy (Kernel.where == "host": the decoders, aLoopKernel). Every crossing is a kernel, soBatchPlan.describe()shows the cost; nothing converts implicitly. Constants go to a device once (Kernel.const).bad,why,notesandcode_failedstay on the host. - Instructions, each with the numpy run as its oracle: (1) array code over
xp, which most kernels are and which runs on CuPy unchanged; (2) hand-written device kernels for what array code does badly, in a portable subset of CUDA C that HIP compiles as it is (no warp intrinsics, no wavefront width assumed), compiled at run time by CuPy (NVRTC or hiprtc) throughrpps.base.kernel.device_functions: the layered min-sum LDPC decoder (rpps.code.kernels.LdpcDecode, a launch per layer over every check and codeword, codewords the fastest axis so accesses are contiguous, the batch compacted as codewords converge), BCH syndromes (BchDecode: only the words with errors go to the host to be located, their bits flipped on the device) and the soft demapper (Demap, a thread a symbol); (3)describe(), the export for an FPGA or HLS flow. A header's fields are read on the host from its few bits (HeaderDecode); its payload is cut on the device. Ondvbs2/normalthe whole region stays on a device: one upload, one download. - Getting results back. The download at the plan's end gives numpy; results are built on the host and the
Schedulerputs them in order, as for any executor. A dedicated device executor (later) overlaps the next batch's upload with this one's work on device streams, withScheduler(eager=False)so batches fill. - Checked without a GPU.
tests/support/fakedevice.pyis numpy behind an array type that refuses what CuPy refuses (no implicit conversion, no numpy array mixed in); every kernel and the DVB-S2 region run on it in the suite. - Batches pay on a device. A layer launch needs thousands of (check, codeword) threads to fill a GPU, so a device
wins from about 16 frames a batch (
Parallel(max_batch=)) and is even at one; measure withtools/device_bench.py. On an AMD Radeon 860M (an integrated GPU) against 16 CPU threads with the C++ kernels, 16-64 frames a batch, the machine otherwise idle: LDPC 1.9-2.4x, BCH 2.0-3.6x (clean words; 1.0-1.5x with five errors a word), demap 4.2-8.6x; the DVB-S2 region 2.1x, and the receiver end to end (four workers) 1.1x, the serial front now most of its time. - The front on a device (
"device": true): frame sync,timing: mat(16% faster end to end on the 860M), Oerder & Meyr and MPower (1.3x slower: each window waits on the device). Per-sample loops stay on the CPU.
Modules:
| Name | Description |
|---|---|
executor |
Executors: where a parallel region runs (rpps.parallel) |
frame |
The unit of parallel work: one frame in, one result out (rpps.parallel) |
kernel |
Running a step on a batch when its operators give no kernel (the protocol is rpps.base.kernel; rpps.parallel) |
plan |
Batch plans: a region's kernels for one set of parameters (rpps.parallel) |
runner |
The parallel runner: a serial front, then a region that runs frame by frame (rpps.parallel) |
scheduler |
Scheduler: frames in, batches out to an executor, results back in order (rpps.parallel) |
worker |
The worker of a parallel region: batches of frames through a plan (rpps.parallel) |
executor ¶
Executors: where a parallel region runs (rpps.parallel)
An executor takes batches of frames that share a key and gives back their results. The work itself is a worker: a
callable worker(frames) -> [Result] (one result per frame, same order), built by the region once per executor, so every
backend runs the same thing:
InlineExecutor the caller's thread, one batch at a time: the reference, and what tests compare against
ThreadExecutor a pool of threads; pays off where the worker releases the GIL (numpy, the rpps._native kernels)
ProcessExecutor a pool of processes, each with its own copy of the worker: what stays Python scales too
A process pool, a GPU or an FPGA are further executors with the same four methods: only what worker is (a compiled kernel
group, a bitstream and its DMA) and how batches get there changes. A worker never raises for one bad frame: it returns
Result.dropped; an exception is a bug and comes out at result().
Classes:
| Name | Description |
|---|---|
Executor |
Runs batches of frames. Subclasses set |
InlineExecutor |
Run each batch right here, in order. Identical to calling the worker |
ThreadExecutor |
A pool of threads; a batch is split across them (min_rows: frames a run needs at least). workers: threads (0: RPPS_THREADS, |
ProcessExecutor |
A pool of worker processes, each with its own copy of the worker (built there from its recipe, so it takes whatever a |
Functions:
| Name | Description |
|---|---|
make |
An executor by name: "inline", "thread" (workers=...). An Executor instance goes through |
Executor ¶
Runs batches of frames. Subclasses set capacity (batches in flight before the scheduler waits)
Methods:
| Name | Description |
|---|---|
prepare |
Get ready to run |
submit |
Start a batch (a list of frames) and return a Future of its list of Results |
close |
Release threads, processes, devices |
InlineExecutor ¶
ThreadExecutor ¶
Bases: Executor
A pool of threads; a batch is split across them (min_rows: frames a run needs at least). workers: threads (0: RPPS_THREADS, else the CPU count)
Methods:
| Name | Description |
|---|---|
prepare |
worker: a callable, or one with |
submit |
One batch is split into up to |
Source code in src/rpps/parallel/executor.py
prepare ¶
worker: a callable, or one with per_thread() that makes another: every thread then has its own operators (an
operator keeps state while it runs). They are made here, so the first frames don't pay for building them
Source code in src/rpps/parallel/executor.py
submit ¶
One batch is split into up to workers runs of consecutive frames (of one key, so each is a batch of its own):
what a kernel does to a batch is large array work that releases the GIL, so the runs go on together
Source code in src/rpps/parallel/executor.py
ProcessExecutor ¶
Bases: Executor
A pool of worker processes, each with its own copy of the worker (built there from its recipe, so it takes whatever a
worker pickles to: a PlanWorker, a module level function). Frames and results cross as pickles; a batch is split across
the processes by rows, as in ThreadExecutor. No GIL is shared, so what stays Python in a region scales; the native kernels
each get cores / workers threads.
workers: processes (0: RPPS_THREADS, else the CPU count). start_method: "fork" where there is one (cheap, and the parent's
config paths come along), else "spawn" (a script then needs its if __name__ == "__main__" guard)
Source code in src/rpps/parallel/executor.py
make ¶
An executor by name: "inline", "thread" (workers=...). An Executor instance goes through
Source code in src/rpps/parallel/executor.py
frame ¶
The unit of parallel work: one frame in, one result out (rpps.parallel)
A Frame holds everything needed to process it, and nothing shared: no Stream, no Meta, no ctx. It can be pickled, put in
shared memory or sent to a device. params are the controlled parameters the serial front already resolved for it
({step id: {parameter: value}}), so a worker never reads a header or a table.
Classes:
| Name | Description |
|---|---|
Frame |
One frame of a parallel region's input |
Result |
What a frame gave. status DROPPED: the frame could not be processed (a gap of |
Frame
dataclass
¶
Frame(seq: int, data: ndarray, params: dict = dict(), pos: int = 0, pos_out: int = 0, n_out: int = 0, tags: tuple = ())
One frame of a parallel region's input
seq: its order (0, 1, 2 ... per stream); results come out in this order. pos: absolute position of its first item in the region's input; n_out: items it will give, and pos_out where, both worked out by the front from the step maps, so output positions do not depend on completion order. tags: what the data is (CAT, DT, REP of rpps.Data), to put it back together.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
What frames must share to run as one batch: their parameters (a MODCOD, a pilot flag) and shape |
key
property
¶
What frames must share to run as one batch: their parameters (a MODCOD, a pilot flag) and shape
Result
dataclass
¶
Result(seq: int, data: ndarray, pos_out: int = 0, n_out: int = 0, status: str = OK, reports: list = list(), tags: tuple = (), pos: int = 0, spent: dict = dict())
What a frame gave. status DROPPED: the frame could not be processed (a gap of n_out items at pos_out), why in
reports, which go to the stream's control reports in order. pos: where the frame started, in the region's input
(its message is placed from there). spent: {kernel: seconds} this frame's share of its batch's time (the region's load)
kernel ¶
Running a step on a batch when its operators give no kernel (the protocol is rpps.base.kernel; rpps.parallel)
A region frame is whole, so what an operator does to it is a function of the frame and of the parameters controls gave it: no
state across calls. A Kernel is that function over a batch of frames, one frame per row of an [N, L] array:
batch = kernel.run(xp, batch)
xp is the array module (numpy; cupy on a GPU), so a kernel is written once. A kernel is immutable once built and holds its
constants (a keystream, a permutation, a code's graph), made once for its parameters, so they can live on a device and be
exported (describe). Rows that cannot be processed are marked in batch.bad (with a reason) and carry zeros on: the shape of
a batch never changes with the data.
An operator gives one with op.kernel(params, how) (params: its controlled parameters; how: / decode, * encode, + stage;
returns None for what it has no kernel for). A step whose operators do not is run by LoopKernel: the existing
per-frame operator, through Data. That path is also the oracle every kernel is compared with.
Classes:
| Name | Description |
|---|---|
LoopKernel |
A step run one frame at a time through its operators ( |
Functions:
| Name | Description |
|---|---|
kernel_of |
The kernel of a step with these controlled parameters: the operator's own ( |
LoopKernel ¶
Bases: Kernel
A step run one frame at a time through its operators (Data, a fresh stream per frame): correct for any operator, and
the reference the batch kernels are checked against. live: the controlled parameters applied to each frame as its start
Source code in src/rpps/parallel/kernel.py
kernel_of ¶
The kernel of a step with these controlled parameters: the operator's own (op.kernel(params, how)) when the step is one
operator that has one, else a LoopKernel
Source code in src/rpps/parallel/kernel.py
plan ¶
Batch plans: a region's kernels for one set of parameters (rpps.parallel)
A BatchPlan is what a worker compiles for a Frame.key (the parameters the front resolved, and the frame's shape) and runs
on every batch with that key. It chains the region's kernels, checks the lengths between them where they are known, keeps the
time each spent, and describes itself in a form a device backend can build (describe).
On an array module other than numpy (a device), the plan uploads a batch once at its start and downloads it once at its end,
and puts a ToHost / ToDevice pair around each run of kernels that need numpy (Kernel.where == "host"): every crossing is a
kernel of its own, in describe(), and nothing moves implicitly.
Classes:
| Name | Description |
|---|---|
BatchPlan |
|
Functions:
| Name | Description |
|---|---|
placed |
|
compile |
The plan of |
BatchPlan ¶
Methods:
| Name | Description |
|---|---|
describe |
[{kernel, in, out, consts}] from a frame of |
Source code in src/rpps/parallel/plan.py
describe ¶
[{kernel, in, out, consts}] from a frame of n_in items; a length a kernel can't tell before running is None
Source code in src/rpps/parallel/plan.py
placed ¶
kernels with the transfers a device needs: in from the host, out to it, and around every host kernel (none on numpy)
Source code in src/rpps/parallel/plan.py
compile ¶
The plan of steps (built steps, in order) for params ({step id: {parameter: value}}). A parameter a step takes live
is applied to every frame as its start; one it takes by restart builds the step again with it (what a header did to
a runner). xp: the array module the plan runs on (numpy when None): a device's gets its transfers (placed)
Source code in src/rpps/parallel/plan.py
runner ¶
The parallel runner: a serial front, then a region that runs frame by frame (rpps.parallel)
rx = profile.rx(parallel=rp.parallel.Parallel("thread", workers=8))
out = rx(block) # as any runner; the output is the same, a frame later
The front (the steps before the profile's parallel marker) is an ordinary Runner: timing, carrier, frame sync, the
header, and the control path, which resolves the parameters of each frame. What reaches the region is cut at the frame
starts those changes mark; each frame goes out as a Frame with its parameters, a Scheduler batches them to an
Executor, and the results come back in order.
PlanWorker (rpps.parallel.worker) runs the region on a batch of frames through a BatchPlan of kernels, from a fresh
state per frame. A frame's output is as long as the region makes it; one that cannot be decoded is dropped and reported.
Output positions count from 0 and add up frame by frame (the serial runner starts at the first frame's position scaled by
its ratio; not done here yet), and a dropped frame gives no items and no gap. Latency is a frame, declared in
stream.est["parallel"].
Classes:
| Name | Description |
|---|---|
Parallel |
How a parallel region runs: executor ("inline", "thread", or an Executor), its keyword arguments, and batching: |
ParallelRunner |
A Runner whose slots from |
Parallel
dataclass
¶
How a parallel region runs: executor ("inline", "thread", or an Executor), its keyword arguments, and batching: frames that arrive in one call (up to max_batch, of one key) run as one batch. xp: the array module the kernels run on (None: numpy; a device's, such as CuPy, with the inline or thread executor: a device does not cross a fork)
Source code in src/rpps/parallel/runner.py
ParallelRunner ¶
Bases: Runner
A Runner whose slots from region_slot on run frame by frame on an executor. Same contract as Runner
Source code in src/rpps/parallel/runner.py
scheduler ¶
Scheduler: frames in, batches out to an executor, results back in order (rpps.parallel)
sch = Scheduler(executor, worker, max_batch=16)
for frame in frames:
for result in sch.push(frame): # whatever is ready, in `seq` order
...
for result in sch.flush(): # the end of the stream: everything still in flight
...
Frames batch by Frame.key (same parameters and shape), up to max_batch; see eager. At most executor.capacity batches are in flight:
a push that would exceed it waits for the oldest, so a slow back stalls the front instead of growing memory. Results are
released in seq order only, so a frame that finishes early waits for those before it; a gap (a dropped frame) is a Result
with status DROPPED, which keeps its place and its output position.
Classes:
| Name | Description |
|---|---|
Scheduler |
|
Scheduler ¶
Methods:
| Name | Description |
|---|---|
push |
Take a frame (they come in |
kick |
Run what is waiting now, whatever its size (the frames that are here, all pushed): a caller that pushes a group of |
flush |
The stream ends: run what is waiting and give every result left, in order |
Attributes:
| Name | Type | Description |
|---|---|---|
pending |
Frames pushed and not yet released |
Source code in src/rpps/parallel/scheduler.py
push ¶
Take a frame (they come in seq order); give back the results that are ready, in order
Source code in src/rpps/parallel/scheduler.py
kick ¶
Run what is waiting now, whatever its size (the frames that are here, all pushed): a caller that pushes a group of
frames and then waits for results calls this, so batches form from the group without waiting for max_batch.
Gives back the results that are ready, in order
Source code in src/rpps/parallel/scheduler.py
flush ¶
The stream ends: run what is waiting and give every result left, in order
worker ¶
The worker of a parallel region: batches of frames through a plan (rpps.parallel)
worker(frames) -> [Result] frames share a key; one plan per key, compiled on first use and kept
The region's operators are built once per worker (building takes a moment) and shared by its plans: a LoopKernel applies its
parameters to every frame as a frame start, so frames of different keys can follow one another. A worker is used by one
thread at a time (per_thread makes another).
xp is the array module the plans run on (numpy; a device's, such as CuPy for CUDA or ROCm). The batch is stacked on the host and
the plan moves it (one upload, one download, rpps.parallel.plan.placed), so the results are numpy whatever xp is. A worker
sent to another process goes as its recipe, on numpy (a device does not cross a fork).
Classes:
| Name | Description |
|---|---|
RegionSteps |
The built steps of a profile's parallel region, as a picklable recipe (a worker in another process builds its own) |
RegionSteps ¶
The built steps of a profile's parallel region, as a picklable recipe (a worker in another process builds its own)