ParetoStackpareto-stackdocshpc-labs

Optimizations

The automatic transforms ParetoStack 0.4.5 can apply. Each one is verified against your program's outputs before it is kept: identical output, or the accuracy contract you declare for the ones marked "contract". Contract. The rule a changed program's output must meet before its speed-up counts. The default is identical output (byte for byte). Where small differences are expected (rounding, fixed-point arithmetic, an FFT), the contract is a tolerance you declare: a numeric error, PSNR or SSIM for images, or a task metric. A change that does not meet its contract is rejected, whatever its speed. "Engine" is the lowest engine version (the Use optimizers up to setting) that offers it; the default is the newest. This page says what each transform does for you; how it decides and what it checks stays in the tool.

L1: loops and lookups

Bind module attribute lookups before loops (Python)

py:bind_attr · engine V3 · output: identical

Looks up a module function once, outside the loop.

Bind builtins / module functions to locals in loops (Python)

py:bind_global · engine V3 · output: identical

Reuses frequently called built-in and module functions inside loops.

Bind list.append before loops (Python)

py:bind_method · engine V3 · output: identical

Reuses a method of a list that the loop fills.

Inline tiny pure functions in loops (Python)

py:inline · engine V3 · output: identical

Removes the cost of calling very small functions in loops.

Hoist loop-invariant arithmetic (Python)

py:hoist · engine V3 · output: identical

Computes arithmetic that does not change in a loop once, before the loop.

A string grown piece by piece in a loop is joined once (Python)

py:str_build · engine V3 · output: identical

Regular expressions with a constant pattern are compiled once (Python)

py:re_hoist · engine V3 · output: identical

Vectorize element-wise loops over NumPy float64 arrays (Python)

py:vectorize · engine V3 · output: identical

Replaces element-by-element loops over NumPy arrays with array operations.

Parallelize independent loops over pure functions (Python)

py:parallelize · engine V3 · output: identical

Runs independent iterations of a loop on several cores. Opt-in.

OpenCV: build a factory once (kernels, matrices, detectors, classifiers) instead of on every pass of a loop (Python, V10)

py:cv_hoist · engine V10 · output: identical

Builds OpenCV helper objects that a loop recreates on every pass only once.

OpenCV: the same computation on the same image, once instead of on every pass of a loop (Python, V10)

py:cv_cse · engine V10 · output: identical

Avoids repeating the same OpenCV computation on the same image.

Parallelize independent element-wise loops with OpenMP (C/C++)

cpp:parallelize · engine V3 · output: identical

Runs independent iterations of a loop on several cores. Opt-in.

Unroll independent element-wise loops by 4 (C/C++, L1)

cpp:unroll · engine V3 · output: identical

L2: data layout

Membership tests against a fixed list use a set (Python)

py:set_member · engine V3 · output: identical

Uses a faster lookup structure for repeated membership tests.

Software-pipeline independent element-wise loops (C/C++, L2)

cpp:swp · engine V3 · output: identical

Loop interchange to unit stride (C/C++)

cpp:interchange · engine V3 · output: identical

Reorders loops for better memory access.

Tile transposition-like loop nests (C/C++)

cpp:tile · engine V3 · output: identical

Processes data in blocks for better use of the cache.

Tiled i-k-j matrix multiply (C/C++)

cpp:matmul · engine V3 · output: identical

Reorders a matrix multiply for better cache use; the result stays bit-identical.

LIB: library swaps

Library swap: naive matrix multiply to NumPy matmul / BLAS (Python)

py:lib_matmul · engine V4 · output: within a declared contract

Replaces a hand-written matrix multiply with the tuned library routine. Rounding differs at round-off level.

OpenCV: a hand-written per-pixel loop becomes the OpenCV function that does it (Python, V10)

py:cv_loops · engine V10 · output: identical

Replaces a hand-written per-pixel loop with the equivalent OpenCV call.

OpenCV: per-pixel loops whose OpenCV equivalent rounds differently (Python, V10)

py:cv_approx · engine V10 · output: within a declared contract

The same, where OpenCV rounds slightly differently from the hand-written loop.

GPU offload: naive matrix multiply to a CuPy matmul on the GPU (Python, V10)

py:gpu_matmul · engine V10 · output: within a declared contract

Runs large matrix products on the GPU when that pays off; otherwise the original code runs.

GPU offload: a @ b / np.dot / np.matmul on big 2-D float arrays go through CuPy (Python, V10)

py:gpu_dot · engine V10 · output: within a declared contract

Runs large matrix products on the GPU when that pays off; otherwise the original code runs.

L3: algorithmic

FFT convolution for large operands (Python, L3)

py:fft_convolve · engine V4 · output: within a declared contract

Uses a faster algorithm for large convolutions. Rounding differs slightly.

Separable filters as two 1-D passes (Python, L3)

py:separable_filter · engine V4 · output: within a declared contract

Splits suitable 2-D filters into two cheaper 1-D passes. Rounding differs slightly.

Window sums via a summed-area table (Python, L3)

py:integral_image · engine V4 · output: within a declared contract

Computes window sums faster by reusing partial sums.

Database: a query per item becomes one batched query (Python, DB)

py:db_batch · engine V3 · output: identical

Database: rows fetched only to be summed / counted / maxed are aggregated by the database (Python, DB)

py:db_aggregate · engine V3 · output: identical

Fixed-point arithmetic for uint8 / int16 / uint16 array maths (Python, L3)

py:fixed_point · engine V4 · output: within a declared contract

Uses integer arithmetic for image maths. The output can differ slightly, within the accuracy you accept.

Fixed-point arithmetic for uint8 / int16 / uint16 loops (C/C++, L3)

cpp:fixed_point · engine V4 · output: within a declared contract

Uses integer arithmetic for image maths. The output can differ slightly, within the accuracy you accept.

Window sums via a summed-area table (C/C++, L3)

cpp:integral_image · engine V4 · output: within a declared contract

Computes window sums faster by reusing partial sums.

Separable 2-D convolution as two 1-D passes (C/C++, L3)

cpp:separable_filter · engine V4 · output: within a declared contract

Splits suitable 2-D filters into two cheaper 1-D passes. Rounding differs slightly.

FFT convolution for long 1-D loops (C/C++, L3)

cpp:fft_convolve · engine V4 · output: within a declared contract

Uses a faster algorithm for large convolutions. Rounding differs slightly.

Fixed-point arithmetic for byte / 16-bit image loops (Java, L3)

java:fixed_point · engine V4 · output: within a declared contract

Uses integer arithmetic for image maths. The output can differ slightly, within the accuracy you accept.

Window sums via a summed-area table (Java, L3)

java:integral_image · engine V4 · output: within a declared contract

Computes window sums faster by reusing partial sums.

Separable 2-D convolution as two 1-D passes (Java, L3)

java:separable_filter · engine V4 · output: within a declared contract

Splits suitable 2-D filters into two cheaper 1-D passes. Rounding differs slightly.

FFT convolution for long 1-D loops (Java, L3)

java:fft_convolve · engine V4 · output: within a declared contract

Uses a faster algorithm for large convolutions. Rounding differs slightly.

L4: cross-language port

Port pure-numeric functions to C (Python, L4)

py:port_c · engine V9 · output: identical when it applies

Moves pure-numeric functions to C and keeps the original function as the fallback.