Skip to main content

Machine capability detection and compute normalization

Project description

coren

Compute and resource normalization.

Measures what your machine can do. Built for irohds -- to tell you whether a computation is faster to run locally or fetch from the network.

Any two machines looking at the same function can independently agree on how much work it requires (an almost deterministic op count). Each machine knows its own capabilities (benchmarked once at startup). The verdict is local arithmetic: compare estimated compute time against estimated fetch time.

Integration into irohds, a decentralized memoization system for scientific computing, was the initial reason for making this package. It is also useful as a standalone tool for roofline analysis, ETL buffer sizing, and build parallelism decisions.

Install

uv add coren

Or from source:

uv run maturin develop --features python

Usage

from coren import FnCost, MachCap

# Describe the work (deterministic, same on every machine)
cost = FnCost.sort(1_000_000, 64, 64_000_000)

# Measure this machine (benchmarks run once, cached)
cap = MachCap.read()

# Get the answer
v = cap.verdict(cost)
print(v)  # "compute (saves 0.712s)" or "fetch (saves 2.3s)"

if v.should_fetch():
    download_result()
else:
    compute_locally()

How it works

Two layers:

FnCost describes a function's resource requirements in absolute physical units. Four integers: ops (total arithmetic operations), mem_bytes (memory traffic), peak_mem (peak RAM footprint), result_bytes (output size). These are properties of the algorithm and its inputs. Bitwise identical on every machine.

MachCap describes what this machine can do. Measured via micro-benchmarks (FMA throughput, STREAM triad, disk sequential I/O) and OS queries (NIC link speed, battery state, core count, RAM). Produces a roofline model: peak ops/s and memory bandwidth.

The verdict compares estimated compute time (from the roofline model) against estimated fetch time (result_bytes / NIC bandwidth). The score is the difference in seconds: positive means fetch is faster, negative means compute is faster. Infinity means one option is impossible (no RAM, or no network).

FnCost constructors

FnCost.new(ops, mem_bytes, peak_mem, result_bytes)   raw values
FnCost.scan(n_bytes, result_bytes)                   linear scan
FnCost.sort(n, item_bytes, result_bytes)             merge sort
FnCost.hash(n_bytes)                                 crypto hash
FnCost.matmul(m, n, k, result_bytes)                 dense GEMM
FnCost.etl(rows, row_bytes, ops_per_row, result_bytes)  row processing
FnCost.copy(size)                                    file copy (ops=0)

Combinators

a.then(b)    # sequential: ops sum, peak_mem = max, result = b's output
a + b        # same as then
a.par(b)     # parallel: ops = max, peak_mem sums, result sums
a.repeat(k)  # k iterations, peak_mem unchanged

Normalizing wall-clock measurements

When a function is executed and you only know the wall-clock time (not the algorithmic complexity), MachCap.normalize() converts the measurement into a FnCost suitable for local verdict computation.

WARNING: normalize() output is NOT deterministic across machines. Different machines produce different ops/mem_bytes values for the same function. Do NOT use normalize()-produced FnCost as cache keys, content addresses, or any identifier that must match across peers. For cache keys, use the static constructors (sort, hash, matmul, etc.) or FnCost.new() with values derived from the function's definition and parameters.

cost = cap.normalize(compute_ns=15_000_000_000, peak_mem=4_000_000_000, result_bytes=500_000_000)
# cost is a safe overestimate, suitable for verdict() but NOT for cache keys

CLI

$ coren
coren  [desktop]
  cores                    8p / 16l
  frequency                3600 MHz

  roofline (measured)
    peak (all cores)       89.2 GFLOPS
    mem bandwidth          38.1 GB/s
    disk bandwidth         1.52 GB/s
    ridge point            2.34 ops/byte

  verdicts (what should this machine do?)
    task                       ops         Q         R    score       neck action
    sort 1M x 64B          200.0M     1.2GB    10.0MB   -0.712   memory compute
    matmul 1k^3              2.0G    22.9MB    10.0MB   -0.779  compute compute

$ coren --json   # machine-readable output

Rust

use coren::{FnCost, MachCap};

let cost = FnCost::sort(1_000_000, 64, 64_000_000);
let cap = MachCap::read(".");
let v = cap.verdict(&cost);

if v.should_fetch() {
    // download from peer
} else {
    // compute locally
}

License

MIT OR Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coren-0.1.2.tar.gz (23.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

coren-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (405.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

coren-0.1.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (379.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

coren-0.1.2-cp313-cp313-macosx_11_0_arm64.whl (295.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

Details for the file coren-0.1.2.tar.gz.

File metadata

  • Download URL: coren-0.1.2.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for coren-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4fa9edc321068954e3420e731a64d96b560a865e4d76fecf11b81dabbdb015aa
MD5 2bba2505bdc83fb02d01fb4f273e004e
BLAKE2b-256 e56e58fb4027f246fb8d17fc3ca8b11e454b59e00874d82a1ae69536a4f4511e

See more details on using hashes here.

File details

Details for the file coren-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for coren-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 75bff13397e13b0856b4c321279dca5a6927f8877d46eb88f30a75b45f7fe4b1
MD5 3ea384bff7c8c73a5edc51149c63dd04
BLAKE2b-256 8e9b3dd5d898a9357e4675397cd681a81ce7e13811f85ff392b0f7c963bbfe06

See more details on using hashes here.

File details

Details for the file coren-0.1.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for coren-0.1.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a49b120328dedcd11fce2f3f4fd7ae87a8fe0ecb8c2ddda218a9bc3d666e6fb8
MD5 fd4a8c673a1f1c5a6fc9c29f50229356
BLAKE2b-256 783b2a560f2bf85142cc401cd5eecb1b8ccf6ef8fac977588abc14e1487090e9

See more details on using hashes here.

File details

Details for the file coren-0.1.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for coren-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ca02462683e3eb195f263481de2dc3133d456ae169e19fadb56adfa84f99df68
MD5 b782a5a0775b2506db078de1db4ac9f4
BLAKE2b-256 4604a4ce0be576007ca93ec07d64ed82466eecce1081266f62e833372fa1146c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page