RI Kernels
CPU and GPU kernels for radio interferometry, exposed to JAX as FFI custom calls with full support for automatic differentiation.
Installation
The CPU kernels and all of the Python code live in ri_kernels. The GPU kernels
ship as add-on packages, one per CUDA major version, selected with an extra:
pip install ri_kernels # CPU kernels only
pip install "ri_kernels[cuda12]" # + CUDA 12 kernels and jax[cuda12]
pip install "ri_kernels[cuda13]" # + CUDA 13 kernels and jax[cuda13]
Building from source
Requires CMake >= 3.20, a C++20 compiler, and network access at configure time (Google Highway is fetched by CMake).
pip install . # CPU only
RI_KERNELS_CUDA=1 pip install . # CPU + CUDA, needs nvcc
RI_KERNELS_ROCM=1 pip install . # CPU + ROCm, needs hipcc
Both libraries land in the ri_kernels package directory in that case, which is
also a location the loader searches. Note that pip install .[cuda12] is a
different thing: the extra resolves ri_kernels_cuda12 from the index, so it
needs a published release. To build the GPU kernels from the checkout, use
RI_KERNELS_CUDA=1.
Other CMake options of note: RI_KERNELS_CPU (default ON),
RI_KERNELS_MULTI_ARCH (dynamic SIMD dispatch, default ON — turn it off and
set arch flags via CMAKE_CXX_FLAGS for a single-target build),
RI_KERNELS_BUNDLED_HIGHWAY, CMAKE_CUDA_ARCHITECTURES, and
RI_KERNELS_STATIC_CUDART (default ON; set it to OFF when a package
manager should provide the shared CUDA runtime).
Tests
Tests can be run with
python -m pytest tests
RFI visibilities
RFIVisOp computes the per-baseline RFI visibility
vis[bl, f, t] = mean over (n_int_freq, n_int_time) of
sum over n_rfi of A[a1] conj(A[a2]) exp(i (φ[a1] - φ[a2]))
for amplitudes A shaped (n_ant, n_freq, n_time, n_rfi, n_int_freq, n_int_time) and phases φ in radians of the same shape, giving an output of
shape (n_baselines, n_freq, n_time). It is constructed from the baseline
layout and evaluated through eval:
from ri_kernels.jax_api import RFIVisOp
vis = RFIVisOp(n_ant, a1, a2).eval(rfi_amp_fine, rfi_phase)
The operator has native primal, JVP, and transpose kernels for CPU, CUDA, and ROCm, so both forward- and reverse-mode differentiation stay inside the kernels. Precision has to match across the inputs: complex64 with float32, or complex128 with float64. Both amplitudes and phases are differentiated.
Analytic RFI visibilities
RFIAnalyticVisOp integrates the time polynomial against phase moments, with
frequency quadrature unchanged. It stages amplitude coefficients per antenna
and cell, then contracts pairs of antenna tiles. The default time scratch axis
has three coefficients, independent of fringe winding.
from ri_kernels.jax_api import RFIAnalyticVisOp
vis = RFIAnalyticVisOp(n_ant, a1, a2).eval(
amp, phase, delay_us, w_freq, start_freq, g_time, start_time,
dnu_mhz, int_time, freq_mhz,
segments=2, terms=6, cubic_terms=3,
)
amp, complex(n_ant, n_rfi, n_freq, n_time): the signal on the data grid.phase, real(n_ant, n_rfi, n_freq, n_time): the phase at the channel and cell centre, reduced to one turn (in float64, before casting).delay_us, real(n_ant, n_rfi, n_time, n_path): the geometric delay in microseconds, with the sign that makes the phase2π f τ, and its firstn_path - 1time derivatives at the cell centre, relative to the array mean (a common term cancels in every baseline; the full delay's change across a cell is ~1e4 wavelengths, beyond float32).w_freq,start_freq: per channel, the weights that turn its stencil ofn_sfneighbouring channels into its fine channels, and the first channel of the stencil.g_time,start_time: per cell, monomial coefficients inx = 2*tau/int_time, astabascal.poly_interp.monomial_tablesproduces them, including the shifted edge stencils, and the first cell of the stencil. Each stencil must lie inside its axis and contain its cell.dnu_mhz: the fine offsets from the channel centre;freq_mhz: the channel centres. Both are in MHz; divideconfig.freqsin Hz by1e6. MHz × μs is cycles.int_time: a positive scalar in seconds.
Every real operand shares the precision of phase; the stencil starts are
int32. The constructor builds, per pair of 32-antenna tiles, the list of the
pairs the baselines cover there (tile_pair_list), which the staged GPU
kernels work through a tile pair per block; each (a1, a2) baseline may
appear at most once.
amp, phase and delay_us are differentiated; int_time and the tables
are constants whose gradients eval stops. Two JVP kernels carry the
tangents, one for the signal alone and a full one that takes the phase and
delay tangents as well; one transpose kernel serves both and always returns
the phase cotangent with the signal's. The phase enters every cell's weights as the one factor
exp(i (phase[a1] - phase[a2])), so the phase tangent turns the pair's
product by i (dV = i (dphase[a1] - dphase[a2]) V per source and fine
channel) and the cotangent is -Im(g V) on a1 and +Im(g V) on a2,
summed over the baseline's sources and fine channels; both cost one extra
contraction against weights the kernel has already formed.
The delay's four orders move the closed form's angles: the delay itself the
centre phase (by 2π dnu τ), the rate the winding a, the curvature b and
the jerk the cubic c. The weights integrate x^m exp(i (φ + a x + b x² + c x³)), so their derivatives in these are the weights of one, two and three
orders higher, turned by i; the curvature and cubic series are truncated, so
the kernels subtract what the truncation leaves out of their derivatives, and
the delay gradient is that of the visibility as computed. The delay cotangent
sums -s Im(g V') on a1 and +s Im(g V') on a2 over the sources, the
channels and the fine channels, with V' the pair's product against the
order's derivative weights and s what a unit of the order adds to its angle.
Orders above three, and the third with cubic_terms=0, get a zero gradient.
The three further weight orders make the delay derivative cost about half as
much again as the full pass without it, so the full JVP and the transpose form
it only when the delay tangent is not a symbolic zero. The transpose further
skips it when the delay tangent is a constant of the map being transposed,
and under jax.jit dead-code elimination switches it off when nothing reads
the delay cotangent (say, only the amplitude and phase gradients are kept).
The JVP rule binds the signal-only JVP whenever the phase and delay tangents are symbolic zeros, so a fixed orbit's forward mode computes no phase derivative; its VJP still computes the phase cotangent and drops it, but no delay cotangent unless the delay is differentiated. The compiled JVPs and transposes follow JAX's complex cotangent convention.
The moment branches, segmentation and cubic translation follow
tabascal.coarse_rfi_vis.analytic_rfi_vis. segments, terms, and
cubic_terms are static options: close over them or mark them static when
jitting. The defaults use two pieces, six curvature terms and three cubic
terms. segments=4, terms=16 selects the reference's conservative settings.
Zero cubic terms deliberately omits cubic phase; delay derivatives above
order three are always omitted. Coefficient counts 1–9, segments 1–1024,
curvature terms 1–32 and cubic terms 0–8 are supported. These limits bound
local storage; convergence still depends on the supplied delay and interval.
Every angle -- the centre phase, the winding and the segment translations -- is formed and reduced in double for both input precisions: a single-precision angle has no fractional turn left at the magnitudes the delay reaches. The moment recurrences that follow only multiply the coefficient buffers, so the CPU kernels keep them in double, where it is free, while the GPU kernels run them at the operator's own precision: a consumer card retires one double-precision instruction per sixty-four single-precision ones, and a complex64 weight costs well over an order of magnitude more in its double form there. Fresnel seeds stay in double either way, and use a small-argument series and rational auxiliary functions: a two-term asymptotic near 2.5 is insufficient for the higher moments. The common three-coefficient, six-term, three-cubic-term path has unrolled moment orders so its CUDA recurrence can stay in registers. Wider configurations use a bounded general implementation.
GPU scratch is bounded by the scratch_mb argument of eval (256 MiB by
default), with time chunks and, when necessary, frequency chunks. A smaller
budget means more chunks, and each chunk of a transpose passes over the whole
signal cotangent. The transpose reduces coefficient cotangents within each tile
in shared memory, writes separate partials for partner tiles, and gathers
through the interpolation stencils. Shared-memory atomics mean the last bits of
the GPU transpose can vary between runs.
After building on the GPU host, run:
python -m pytest tests/test_rfi_analytic_vis_op.py
python tests/benchmark_rfi_analytic_vis_op.py --antennas 256 512 --iterations 100
The analytic tests compare both precisions and the amplitude, phase and delay derivatives against a frozen float64 JAX reference. They cover zero winding, both recurrence branches, the Fresnel boundary, cubic translation, wider coefficient counts, sparse/reversed/autocorrelation baselines, partial antenna tiles and forced scratch splitting. The benchmark reports synchronised forward, JVP and VJP times, signal-only, with the phase and with the delay, after compilation and warmup. It uses synthetic inputs; repeat the scientific accuracy check and the 100-iteration optimisation with the production SKA-Low data. Inspect ptxas register/spill reports and Nsight local-memory traffic for the default specialisation before interpreting its speedup. CUDA compilation, device tests and performance need the GPU host; CPU tests do not establish those results.
Pure JAX references
RFIVisOpRef and RFIAnalyticVisOpRef compute the same visibilities as
RFIVisOp and RFIAnalyticVisOp in plain JAX, with the same constructor and
eval signature, so either can stand in for its kernel:
from ri_kernels.jax_api import RFIAnalyticVisOpRef
vis = RFIAnalyticVisOpRef(n_ant, a1, a2).eval(amp, phase, delay_us, ...)
JAX differentiates them directly and they need no FFI library, but they
materialise every baseline at once (the analytic one cell at a time), so they
are meant for checking the kernels and for small problems. The analytic
reference accepts scratch_mb and ignores it, and does not apply the kernels'
limits on coefficient counts and series lengths. The kernel tests check
against these references, and tests/test_*_ref.py check the references
themselves against a direct sum and brute-force quadrature.
Metadata
Release files for ri-kernels 0.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ri_kernels-0.2.5.tar.gz | 111.7 kB | With provenance | Details for ri_kernels-0.2.5.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ri_kernels-0.2.5-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl | Python 3 | none | Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 | Details for ri_kernels-0.2.5-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
| ri_kernels-0.2.5-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl | Python 3 | none | Linux glibc 2.24+ ARM64, Linux glibc 2.28+ ARM64 | Details for ri_kernels-0.2.5-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl |
| ri_kernels-0.2.5-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details for ri_kernels-0.2.5-py3-none-macosx_11_0_arm64.whl |
Total release size: 1.0 MB
Release files / ri_kernels-0.2.5.tar.gz
| Download URL | ri_kernels-0.2.5.tar.gz |
|---|---|
| Size | 111.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3931ae1325d5f633e3d7baa0ab54e748f0c39ca6e7fb1069451a7ab100629be1
|
|
BLAKE2b-256 checksum How to use checksums |
de194bb0578907b750f1081bfcc20521dfadd9e3b2d42d07576b3e123d5fcfbc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logRelease files / ri_kernels-0.2.5-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | ri_kernels-0.2.5-py3-none-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 390.4 kB |
| Tags | Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
ff4f9ced4e5e817fdbba1c2a0f3a7ca003c08826fb61db2aa9f638789903a517
|
|
BLAKE2b-256 checksum How to use checksums |
38944dae22fe06e65fd17e71bb7fe89ee856d189d064ecd969fb8c08b4a52b5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logRelease files / ri_kernels-0.2.5-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
| Download URL | ri_kernels-0.2.5-py3-none-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 300.4 kB |
| Tags | Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
3eb2039aa7c59d105b51b61138da0bf52840b649936a0d5e004b1a4091035974
|
|
BLAKE2b-256 checksum How to use checksums |
cbcec1e31956a75523802559ab0198c8131968d3b2c19ddcf8d4ded0ce0c8881
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logRelease files / ri_kernels-0.2.5-py3-none-macosx_11_0_arm64.whl
| Download URL | ri_kernels-0.2.5-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 217.6 kB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4cf917c1938d46c13f5568873115533216309db8f0b436e38407eeb8bde0d32e
|
|
BLAKE2b-256 checksum How to use checksums |
d27049689632bb738f5de3d958af3f25e3f121cf19e09d2d93985e83fd27c56f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logSecurity for ri-kernels 0.2.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 4 files in this release have been uploaded with provenance metadata.
Attestation for ri_kernels-0.2.5.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.