Shared utilities for wgblas benchmark scripts — a JS module and a
parallel C header covering the same operations for the cuBLAS benchmarks.
JS — helpers.mjs
Used by every benchmarks/<routine>/wgblas/*.js (and the roofline probes)
for GPU clock warm-up, timing, result persistence and table formatting.
Every function is documented individually below:
warmClocks — full clocks before every measured configuration
A header-only C counterpart used by every benchmarks/<routine>/cuda/*.c.
All functions are static so each translation unit gets its own copy. It
also defines CUDA_CHECK / CUBLAS_CHECK, which print the failing
file:line and exit on any non-success status.
Function
Signature
What it does
warm_clocks
(cublasHandle_t handle) → void
Brings the GPU to full clocks before a measurement — the counterpart of warmClocks(), using cublasSscal bursts over a zeroed 64 MB buffer since these files define no kernels of their own
median
(float *arr, int n) → float
Returns the median of arr; copies before sorting so the original is unchanged
Writes benchmarks/results/<gpu>/cuda/<folder>/<file_name>.json in the same schema as saveResults(). Each record_field ({ name, type, values }, type FIELD_INT/FIELD_FLOAT/FIELD_STRING) is one swept key, written before the fixed compute_ms/compute_GFLOPs/compute_GBs fields, so any record shape needs no new function; pass gflops_vals = NULL to omit compute_GFLOPs
Thin wrappers over save_results for the record shapes older call sites use: {n}, {stride, n}, {pad, n} (_pad_ex adds GFLOP/s), {uplo, n}, {trans, n}, and a caller-named string (_flag) or float (_scalar) key with optional GFLOP/s. New benchmarks should call save_results directly
get_gpu_model
(char *dst, int maxlen) → void
Fills dst with the CUDA device name as a slug, so wgblas and cuBLAS results land in the same benchmarks/results/<gpu>/ folder
random_float_array
(int n, float low, float high) → float*
Heap-allocates n random floats in [low, high]; caller must free()
host_bytes_available
(void) → size_t
Available host RAM from /proc/meminfo, for benchmarks that stage large host copies (the f64 routines stage two); returns 0 if unknown, which callers treat as "don't skip"
The C slug in get_gpu_model maps each non-alphanumeric character to -
one at a time, while getGpuModel() collapses runs and trims the ends —
identical for every GPU benchmarked so far, but a name with consecutive or
edge punctuation would split into two folders (tracked in TODO.md).
Shared utilities for wgblas benchmark scripts — a JS module and a parallel C header covering the same operations for the cuBLAS benchmarks.
JS —
helpers.mjsUsed by every
benchmarks/<routine>/wgblas/*.js(and the roofline probes) for GPU clock warm-up, timing, result persistence and table formatting. Every function is documented individually below:C —
helpers.hA header-only C counterpart used by every
benchmarks/<routine>/cuda/*.c. All functions arestaticso each translation unit gets its own copy. It also definesCUDA_CHECK/CUBLAS_CHECK, which print the failing file:line and exit on any non-success status.warm_clocks(cublasHandle_t handle) → voidwarmClocks(), usingcublasSscalbursts over a zeroed 64 MB buffer since these files define no kernels of their ownmedian(float *arr, int n) → floatarr; copies before sorting so the original is unchangedsave_results(const char *gpu_model, const char *folder, const char *file_name, const record_field *fields, int n_fields, float *med_times, float *gbs_vals, float *gflops_vals, int n) → voidbenchmarks/results/<gpu>/cuda/<folder>/<file_name>.jsonin the same schema assaveResults(). Eachrecord_field({ name, type, values }, typeFIELD_INT/FIELD_FLOAT/FIELD_STRING) is one swept key, written before the fixedcompute_ms/compute_GFLOPs/compute_GBsfields, so any record shape needs no new function; passgflops_vals = NULLto omitcompute_GFLOPssave_results_ex,_stride,_pad,_pad_ex,_uplo,_trans,_flag,_scalarsave_resultsfor the record shapes older call sites use:{n},{stride, n},{pad, n}(_pad_exadds GFLOP/s),{uplo, n},{trans, n}, and a caller-named string (_flag) or float (_scalar) key with optional GFLOP/s. New benchmarks should callsave_resultsdirectlyget_gpu_model(char *dst, int maxlen) → voiddstwith the CUDA device name as a slug, so wgblas and cuBLAS results land in the samebenchmarks/results/<gpu>/folderrandom_float_array(int n, float low, float high) → float*nrandom floats in[low, high]; caller mustfree()host_bytes_available(void) → size_t/proc/meminfo, for benchmarks that stage large host copies (the f64 routines stage two); returns 0 if unknown, which callers treat as "don't skip"The C slug in
get_gpu_modelmaps each non-alphanumeric character to-one at a time, whilegetGpuModel()collapses runs and trims the ends — identical for every GPU benchmarked so far, but a name with consecutive or edge punctuation would split into two folders (tracked inTODO.md).