HBAG-SpMM-Adaptive v0.3.0
SpMM (Sparse x Dense) CSR con schedule OpenMP adaptativo . con un schedule que reacciona a la irregularidad de densidad por fila. Bit-exact paralelo al kernel clasico.
Que trae v0.3.0:
spmm_hbag_core_omp64_adaptive: 4 modos (0dynamic,2static,3balanced, otros = guided).- Modo balanced (3): particion EXACTA por nnz acumulado, no es heuristica.
- Bindings Python:
spmm_hbag/spmm_hbag_omp/spmm_hbag_native(int64) +spmm_hbag_adaptive.bench.c: 7 kernels,--self-test,--csv, flags--rows/--cols/--k/--density/--trials/--threads/--seed.make testcorre bench + pytest; CI en.github/workflows/test.yml.
No hay binario cerrado dentro del ZIP. La .so que usa la libreria
de Python se compila localmente al instalar; setup.py ejecuta nm -D
sobre hbag/libhbag.so y exige que exporte los 4 simbolos que
hbag/__init__.py requiere. Si tu toolchain no los soporta, la build
aborta con RuntimeError.
Quick start
make all # bench + cache_probe + libhbag.so
make test # test-c (./bench --self-test) + pytest
pip install -e . --no-build-isolation
python3 -c 'import hbag; print(hbag.__version__)' # 0.3.0
Uso como libreria:
import hbag, numpy as np
from scipy.sparse import random
A = random(2048, 2048, density=0.02, format='csr', dtype=np.float32)
B = np.random.rand(2048, 128).astype(np.float32)
C = hbag.spmm_hbag(A, B) # single-thread core
C_omp = hbag.spmm_hbag_omp(A, B) # OpenMP 32-bit
C_64 = hbag.spmm_hbag_native(A, B) # indices int64
C_ad, state = hbag.spmm_hbag_adaptive(A, B, return_state=True)
print(state.schedule_mode, state.chunk, state.TERM_U, state.nnz_cv)
Parámetros SOL-ART (qué mide cada uno)
spmm_hbag_adaptive(..., return_state=True) devuelve un GovernanceState
calculado sobre la matriz de salida C. Los nombres se conservan tal cual
están en el motor; la línea de cada uno dice en llano qué mide.
Estabilidad de la varianza de C. Vale 1 cuando los valores de C casi no se dispersan y baja cuando se dispersan mucho:
C_Coherencia=1 / (1 + var(C))
Estabilidad de la media de C. Vale 1 cuando la media de C está en cero y baja cuando se aleja de cero:
B_Balance=exp(-|mean(C)|)
Suavidad local de C. Vale 1 cuando posiciones vecinas tienen valores casi iguales y baja con saltos bruscos (se mide sobre las primeras 100 000 posiciones):
G_Gradiente=1 / (1 + mean|diff(C)|)
Cercanía a la escala de referencia. Vale 1 cuando el máximo de |C| está en V_xi (14.9 por defecto) y baja cuando se aleja en cualquier dirección:
A_Azar=exp(-|max|C| - V_xi| / V_xi)
Índice global de homeostasis. Es la suma ponderada de los cuatro anteriores; si es ≥ 0.5, Homeostasis es True:
TERM_U=0.60·C_Coherencia + 0.30·B_Balance + 0.05·G_Gradiente + 0.05·A_Azar
Irregularidad del trabajo, no de los valores: desviación estándar dividida por la media de nnz por fila. Vale 0 cuando todas las filas tienen el mismo número de nnz:
nnz_cv=std(nnz por fila) / mean(nnz por fila)
El schedule se decide con TERM_U y nnz_cv (ver SOLARTEngine.decide_schedule):
TERM_U ≥ 0.75 y CV < 0.35 → static; TERM_U ≥ 0.55 y CV < 0.80 → guided;
CV ≥ 1.0 → balanced (partición exacta por nnz); el resto → dynamic.
Comandos del Makefile (todos verificados, exit 0)
| Comando | Que hace |
|---|---|
make help |
Lista los targets |
make all |
Compila bench + cache_probe + hbag/libhbag.so |
make bench |
Solo ./bench |
make cache_probe |
Solo ./cache_probe (cachegrind helper) |
make shared |
Alias de make hbag/libhbag.so |
make hbag/libhbag.so |
Solo la .so + verificacion nm -D |
make libhbag.so |
.so legacy en la raiz |
make run |
./bench --csv /tmp/bench_results.csv |
make run-all |
bench 1/2/4 hilos, 3 CSV en /tmp |
make test-c |
./bench --self-test |
make test-py |
pytest tests/ -v |
make test |
test-c + test-py |
make install |
pip install -e . --no-build-isolation |
make clean |
Borra binarios, .so, __pycache__ |
make distclean |
Borra tambien CSV en /tmp |
Uso del benchmark ./bench
./bench sweep default (4 configs), tabla texto
./bench --self-test exit 2 si algun bit-exact falla
./bench --csv [FILE] CSV (stdout si FILE se omite)
./bench --rows N --cols N --k K --density D una sola config arbitraria
[--seed S] [--trials T] [--threads T]
./bench --threads T fija omp_set_num_threads(T); 0 = entorno
./bench --list imprime el sweep y sale
./bench -h | --help ayuda
Columnas del CSV (orden estricto):
config,label,N,K,density,nnz,threads,kernel,t_ms,max_err,status
t_ms= mejor de N corridas (--trials), con 2 warmups no contados.speedup=t(spmm_csr_std) / t(kernel)(solo en tabla texto).max_err= error absoluto maximo frente aspmm_csr_std.status=OKsimax_err < 1.0Y los 3 modos adaptativos son bit-exact contraspmm_hbag_core_omp64.
Los 3 modos de spmm_hbag_core_omp64_adaptive (dyn / static / balanced)
deben producir el mismo C bit-a-bit que spmm_hbag_core_omp64;
--self-test lo verifica y aborta (exit 2) si no se cumple.
Ejemplos:
./bench --csv results.csv
./bench --csv # CSV a stdout
./bench --rows 8192 --cols 8192 --k 256 --density 0.005 --trials 3 --csv big.csv
for t in 1 2 4; do OMP_NUM_THREADS=$t ./bench --csv bench_t${t}.csv --threads $t; done
./bench --self-test # smoke test bit-exact
./bench --list # muestra el sweep por defecto
./bench --help
Suite de pruebas (pytest)
pip install -e . --no-build-isolation
pip install pytest
make test-py
Archivos:
tests/test_correctness.py-- correctness numerico + smoke-tests C/Python.tests/test_adaptive.py-- comportamiento del schedule SOL-ART.
Cobertura:
- Cada
spmm_hbag_*vsscipy.sparse.csr.dot(B)en multiples K no multiplos de 8. - Reproducibilidad de las columnas deterministas del CSV (
N,K,density,nnz,threads,kernel,max_err,status);t_msse excluye porque es tiempo de pared (~3% jitter). - Existencia y exportacion de los 4 simbolos en
hbag/libhbag.sovianm -D. --self-testpasa end-to-end.make test-cymake test-pypasan.
Estructura del repositorio
hbag-spmm-adaptive/
├── .github/workflows/test.yml
├── .gitignore
├── BENCHMARKS.md
├── LICENSE
├── Makefile
├── README.md
├── pyproject.toml
├── setup.py
├── hbag/__init__.py
├── src/
│ ├── bench.c
│ ├── spmm.c
│ └── spmm.h
├── tests/
│ ├── test_adaptive.py
│ └── test_correctness.py
└── tools/
├── adaptive_homeostasis_demo.py
├── cache_probe.c
├── large_scale_mkl_check.py
└── multi_env_check.py
Verificar el mecanismo de cache (reproducible)
make cache_probe
valgrind --tool=cachegrind --cachegrind-out-file=out.csr ./cache_probe csr
valgrind --tool=cachegrind --cachegrind-out-file=out.hbag ./cache_probe hbag
cg_annotate out.csr | head -25
cg_annotate out.hbag | head -25
Limitaciones conocidas
- AVX2 + OpenMP requeridos para variantes multi-hilo.
- Python: indices
int32por defecto enspmm_hbag/spmm_hbag_omp. - Para mas de 2.1 mil millones NNZ usa
spmm_hbag_native(int64). - "Speedup adaptativo" no se reporta como constante: depende del patron de carga.
Licencia
Apache License 2.0 -- ver LICENSE.
Metadata
Release files for hbag 0.3.0
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 |
|---|---|---|---|---|
| hbag-0.3.0.tar.gz | 29.3 kB | With provenance | Details for hbag-0.3.0.tar.gz |
Release files / hbag-0.3.0.tar.gz
| Download URL | hbag-0.3.0.tar.gz |
|---|---|
| Size | 29.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
73dca0f9af69b287bd82987fd92376b57016cdb1c4a7cac397e48ed16c15d4fa
|
|
BLAKE2b-256 checksum How to use checksums |
50beba6fe4d2d1f1961ecfb99c7e6896bc4fffb10f5385275639faf247e0ed93
|
| 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 25, 2026.
Transparency logSecurity for hbag 0.3.0
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
1 file in this release has been uploaded with provenance metadata.
Attestation for hbag-0.3.0.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 25, 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.