Skip to content

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 through LoopKernel, which is also the oracle every kernel is checked against (tests/unit/parallel/). Kernels: symbol.kernels (Demap, Rotate, Gather), code.kernels (BlockDecode, LdpcDecode, BchDecode, Permute of an interleaver, Identity of a code a frame switches off, XorMask), sync.kernels (PilotLine), link.kernels (HeaderDecode of a framed header); the protocol is rpps.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 fork where available, else spawn (scripts need a __main__ guard); each builds its region from a picklable RegionSteps.
  • On dvbs2/normal the output equals the serial runner's bit for bit, for any block cut, worker count and batch size. Measure with python tools/parallel_bench.py 64 4.
  • A parallel region's kernels decode inside: each frame result is its message ("frame", crc_ok False 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:device pair around each run of kernels that need numpy (Kernel.where == "host": the decoders, a LoopKernel). Every crossing is a kernel, so BatchPlan.describe() shows the cost; nothing converts implicitly. Constants go to a device once (Kernel.const). bad, why, notes and code_failed stay 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) through rpps.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. On dvbs2/normal the 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 Scheduler puts 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, with Scheduler(eager=False) so batches fill.
  • Checked without a GPU. tests/support/fakedevice.py is 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 with tools/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 capacity (batches in flight before the scheduler waits)

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 worker: build per-thread operators, load a bitstream, compile a kernel graph

submit

Start a batch (a list of frames) and return a Future of its list of Results

close

Release threads, processes, devices

prepare
prepare(worker)

Get ready to run worker: build per-thread operators, load a bitstream, compile a kernel graph

Source code in src/rpps/parallel/executor.py
def prepare(self, worker):
    """Get ready to run `worker`: build per-thread operators, load a bitstream, compile a kernel graph"""
    self.worker = worker
submit
submit(batch) -> Future

Start a batch (a list of frames) and return a Future of its list of Results

Source code in src/rpps/parallel/executor.py
def submit(self, batch) -> Future:
    """Start a batch (a list of frames) and return a Future of its list of Results"""
    raise NotImplementedError
close
close()

Release threads, processes, devices

Source code in src/rpps/parallel/executor.py
def close(self):
    """Release threads, processes, devices"""

InlineExecutor

Bases: Executor

Run each batch right here, in order. Identical to calling the worker

ThreadExecutor

ThreadExecutor(workers=0, capacity=None, min_rows=1)

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 per_thread() that makes another: every thread then has its own operators (an

submit

One batch is split into up to workers runs of consecutive frames (of one key, so each is a batch of its own):

Source code in src/rpps/parallel/executor.py
def __init__(self, workers=0, capacity=None, min_rows=1):
    n = workers or int(os.environ.get("RPPS_THREADS", 0)) or os.cpu_count() or 1
    self.workers, self.min_rows = n, max(1, int(min_rows))
    self.capacity = capacity or 2*n
    self._pool = ThreadPoolExecutor(n, thread_name_prefix="rpps-frame")
prepare
prepare(worker)

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
def prepare(self, worker):
    """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"""
    self.worker = worker
    make = getattr(worker, "per_thread", None)
    self._idle = queue.SimpleQueue()
    for _ in range(self.workers):
        self._idle.put(make() if make is not None else worker)
submit
submit(batch)

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
def submit(self, batch):
    """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"""
    n = min(self.workers, max(1, len(batch)//self.min_rows))
    size = -(-len(batch)//n)
    parts = [batch[i:i + size] for i in range(0, len(batch), size)]
    futs = [self._pool.submit(self._one, part) for part in parts]
    return futs[0] if len(futs) == 1 else _Joined(futs)

ProcessExecutor

ProcessExecutor(workers=0, capacity=None, min_rows=1, start_method=None)

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
def __init__(self, workers=0, capacity=None, min_rows=1, start_method=None):
    n = workers or int(os.environ.get("RPPS_THREADS", 0)) or os.cpu_count() or 1
    self.workers, self.min_rows = n, max(1, int(min_rows))
    self.capacity = capacity or 2*n
    self.start_method = start_method
    self._pool = None

make

make(executor='inline', **kw)

An executor by name: "inline", "thread" (workers=...). An Executor instance goes through

Source code in src/rpps/parallel/executor.py
def make(executor="inline", **kw):
    """An executor by name: "inline", "thread" (workers=...). An Executor instance goes through"""
    if isinstance(executor, Executor):
        return executor
    kinds = {"inline": InlineExecutor, "thread": ThreadExecutor, "process": ProcessExecutor}
    if executor not in kinds:
        from ..errors import ConfigError
        raise ConfigError(f"no executor {executor!r}, have {sorted(kinds)}")
    return kinds[executor](**kw)

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 n_out items at pos_out), why in

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
key

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 (Data, a fresh stream per frame): correct for any operator, and

Functions:

Name Description
kernel_of

The kernel of a step with these controlled parameters: the operator's own (op.kernel(params, how)) when the step is one

LoopKernel

LoopKernel(step, live, direction='rx')

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
def __init__(self, step, live, direction="rx"):
    self.step, self.live, self.direction = step, live, direction
    self.name = f"loop:{step.id}"

kernel_of

kernel_of(step, live, direction='rx')

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
def kernel_of(step, live, direction="rx"):
    """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`"""
    ops = step.rx if direction == "rx" else step.tx
    if len(ops) == 1 and hasattr(ops[0][1], "kernel"):
        how, op = ops[0]
        k = op.kernel(live, how)
        if k is not None:
            return k
    return LoopKernel(step, live, direction)

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

kernels with the transfers a device needs: in from the host, out to it, and around every host kernel (none on numpy)

compile

The plan of steps (built steps, in order) for params ({step id: {parameter: value}}). A parameter a step takes live

BatchPlan

BatchPlan(kernels, key=None)

Methods:

Name Description
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
def __init__(self, kernels, key=None):
    self.kernels, self.key = list(kernels), key
    self.spent = {k.name: 0.0 for k in self.kernels}
    self.batches = 0
describe
describe(n_in)

[{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
def describe(self, n_in):
    """[{kernel, in, out, consts}] from a frame of `n_in` items; a length a kernel can't tell before running is None"""
    out, n = [], n_in
    for k in self.kernels:
        d = k.describe(n)
        out.append(d)
        n = d["out"]
    return out

placed

placed(kernels, xp)

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
def placed(kernels, xp):
    """`kernels` with the transfers a device needs: in from the host, out to it, and around every host kernel (none on numpy)"""
    import numpy as np
    if xp is np:
        return list(kernels)
    out, dev = [], False
    for k in kernels:
        want = k.where != "host"
        if want != dev:
            out.append(ToDevice() if want else ToHost())
            dev = want
        out.append(k)
    if dev:
        out.append(ToHost())
    return out

compile

compile(steps, params, direction='rx', key=None, xp=None)

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
def compile(steps, params, direction="rx", key=None, xp=None):
    """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`)"""
    kernels = []
    for st in steps:
        p = params.get(st.id, {})
        live = {k: v for k, v in p.items() if st.controls.get(k) == _ctl.LIVE}
        restart = {k: v for k, v in p.items() if st.controls.get(k) == _ctl.RESTART}
        if restart:
            new = st.rebuild(restart)
            new.takes, new.gives = st.takes, st.gives
            st = new
        for k in p:
            if k not in st.controls:
                raise ConfigError(f"step {st.id!r} cannot be controlled on {k!r} (it takes {sorted(st.controls)})")
        kernels.append(kernel_of(st, live, direction))
    return BatchPlan(kernels if xp is None else placed(kernels, xp), key)

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 region_slot on run frame by frame on an executor. Same contract as Runner

Parallel dataclass

Parallel(executor='inline', max_batch=16, xp=None, **kw)

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
def __init__(self, executor="inline", max_batch=16, xp=None, **kw):
    self.executor, self.max_batch, self.kw, self.xp = executor, max_batch, kw, xp
    if xp is not None and (executor == "process" or type(executor).__name__ == "ProcessExecutor"):
        raise ValueError("a device array module runs in this process: use the inline or thread executor")

ParallelRunner

ParallelRunner(slots, name, entries, direction, make_steps, region_first, parallel, profile=None)

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
def __init__(self, slots, name, entries, direction, make_steps, region_first, parallel, profile=None):
    super().__init__(slots, name, entries, direction, profile)
    if direction != "rx":
        raise ValueError("a parallel region is a receive-side thing")
    self.stop = next(i for i, s in enumerate(self.slots) if s.step.id == region_first)
    self.sched = Scheduler(parallel.executor, PlanWorker(make_steps, direction, parallel.xp if parallel.xp is not None else np), parallel.max_batch, False,
                           **(parallel.kw or {}))
    self._pend, self._pend_pos, self._cur = [], None, {}
    self._fseq, self._out_next, self._tags = 0, None, None
    self.frames = 0
    self._spent = {} # {kernel: seconds} the region's workers spent

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

Scheduler(executor='inline', worker=None, max_batch=16, eager=True, **kw)

Methods:

Name Description
push

Take a frame (they come in seq order); give back the results that are ready, in order

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
def __init__(self, executor="inline", worker=None, max_batch=16, eager=True, **kw):
    self.executor = make(executor, **kw)
    self.executor.prepare(worker)
    self.max_batch, self.eager = max(1, int(max_batch)), eager
    self._open = OrderedDict() # key -> frames waiting for a batch
    self._flying = deque()     # (batch, future), oldest first
    self._ready = {}           # seq -> Result, finished but not yet in order
    self._next = 0             # the seq to release next
    self._seen = 0             # frames pushed
    self.max_flying = 0
pending property
pending

Frames pushed and not yet released

push
push(frame)

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
def push(self, frame):
    """Take a frame (they come in `seq` order); give back the results that are ready, in order"""
    if frame.seq != self._seen:
        raise ValueError(f"frames come in order: expected seq {self._seen}, got {frame.seq}")
    self._seen += 1
    q = self._open.setdefault(frame.key, [])
    q.append(frame)
    if len(q) >= self.max_batch:
        self._submit(self._open.pop(frame.key))
    # Idle capacity is not left waiting for a full batch: batches only grow while every slot is busy, so a trickle of
    # frames is not held back (`eager=False` waits for max_batch or the flush instead, for a device that wants full batches)
    while self.eager and self._open and len(self._flying) < self.executor.capacity:
        self._submit(self._open.pop(next(iter(self._open))))
    return self._release()
kick
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
def kick(self):
    """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"""
    for key in list(self._open):
        self._submit(self._open.pop(key))
    return self._release()
flush
flush()

The stream ends: run what is waiting and give every result left, in order

Source code in src/rpps/parallel/scheduler.py
def flush(self):
    """The stream ends: run what is waiting and give every result left, in order"""
    for key in list(self._open):
        self._submit(self._open.pop(key))
    while self._flying:
        self._wait()
    return self._release()

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

RegionSteps(name, obj, sync, params, first)

The built steps of a profile's parallel region, as a picklable recipe (a worker in another process builds its own)

Source code in src/rpps/parallel/worker.py
def __init__(self, name, obj, sync, params, first):
    self.name, self.obj, self.sync, self.params, self.first = name, obj, sync, params, first