Skip to main content

Module simd

Module simd 

Source
Expand description

SIMD-accelerated kernels for the pipeline’s two hot CPU loops: per-pixel image normalization and per-timestep CTC argmax decode. (Conv/matmul work lives in ONNX Runtime.)

Each kernel ships as a scalar reference (*_scalar, always compiled) and a SIMD path (*_simd, behind the simd feature) built on wide and runtime-dispatched via multiversion, so one binary selects AVX2/SSE/NEON at runtime without target-cpu=native. Entry points pick the SIMD path when the feature is on, else the scalar one.

The SIMD paths are bit-identical to the scalar reference: same value * alpha + beta form (plain multiply-add, not FMA, which rounds differently) and same “last index wins on ties” argmax. Parity tests at the bottom of the module enforce this, so toggling simd never changes output.

Functions§

argmax
Returns the (index, value) of the maximum element of row.
normalize_chw_into
Writes a normalized image in CHW (channel-major) layout into out.
normalize_crnn_chw_into
Fills a CRNN CHW input tensor from a resized RGB crop.
normalize_hwc_into
Writes a normalized image in HWC (interleaved) layout into out.
scale_clamp_bgr_planes_to_rgb
Converts a BGR-ordered CHW float plane-triple into an interleaved RGB u8 image, computing (v * scale).clamp(0.0, 255.0) as u8 per element.