Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 14 additions & 34 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
name: Run benchmarks

on:
pull_request:
types: [labeled]
workflow_dispatch:

permissions:
pull-requests: write
env:
CARGO_TERM_COLOR: always

jobs:
benchmark:
if: github.event.label.name == 'benchmark'
name: Run criterion benchmarks
runs-on: ubuntu-latest
steps:
Expand All @@ -22,41 +20,23 @@ jobs:
- name: Get data
uses: ./.github/actions/cache-data

- name: Cache Criterion baseline
- name: Cache Criterion results
uses: actions/cache@v4
with:
path: target/criterion
key: criterion-benchmark-${{ runner.os }}-${{ github.ref }}
key: ${{ runner.os }}-criterion-${{ github.ref_name }}
restore-keys: |
criterion-benchmark-${{ runner.os }}-refs/heads/main
${{ runner.os }}-criterion-main
${{ runner.os }}-criterion-

- name: Run benchmarks and save clean output
id: bench
- name: Run benchmarks
run: |
export NEOPDF_DATA_PATH=${PWD}/neopdf-data
# TODO: remove the version specification
cargo bench -p neopdf -- --nocapture | awk '/^test result: ok\./ {p=1; next} p' | tee benchmark_results.txt
cargo bench -p neopdf@0.3.0-alpha4

- name: Post benchmark results as a PR comment
uses: actions/github-script@v7
- name: Upload benchmark reports
if: always()
uses: actions/upload-artifact@v4
with:
script: |
const fs = require('fs');
const output = fs.readFileSync('benchmark_results.txt', 'utf8').trim();

if (output) {
const body = '## 🚀 Benchmark Results 🚀\n\n' +
'Here are the results from the benchmark run.\n\n' +
'```\n' +
output + '\n' +
'```';

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
} else {
console.log("Benchmark output was empty.");
}
name: criterion-reports-${{ github.sha }}
path: target/criterion/
3 changes: 2 additions & 1 deletion .github/workflows/run-pyapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:
cd neopdf_pyapi
python3 -m venv --system-site-packages myenv
. myenv/bin/activate
pip install maturin
# maturin-1.12.5 fails with: `--include-debuginfo cannot be used with --strip`
pip install maturin==1.12.4
maturin develop --extras test
export NEOPDF_DATA_PATH=/usr/share/LHAPDF
pytest --verbose
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/run-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
cd neopdf_pyapi
python -m venv env
. env/bin/activate
pip install maturin
# maturin-1.12.5 fails with: `--include-debuginfo cannot be used with --strip`
pip install maturin==1.12.4
maturin develop --extras test
pytest -m multipleversions benches/test_versions.py
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `LogFourCubic` and `LogFiveCubic` interpolation strategies for 4D and 5D data.
- Added new methods to the Fortran and C/C++ APIs to write and compress grids
with `xi` and `delta` dependence.
- Added `load_by_lhaid` method to load PDF set using LHAPDF IDs.

### Changed

Expand Down
81 changes: 80 additions & 1 deletion neopdf/benches/bench_pdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,91 @@ fn xfxq2_members(c: &mut Criterion) {
});
}

fn xfxq2_allpids_cheby(c: &mut Criterion) {
let pdf = PDF::load("MAP22_grids_FF_Km_N3LL.neopdf.lz4", 0);
let ids: Vec<i32> = (-4..=4).filter(|&x| x != 0).collect();
let point = [1e-2, 5e-1, 10.0];
let mut out = vec![0.0; ids.len()];

let mut group = c.benchmark_group("xfxq2_allpids_cheby");

group.bench_function("fast_path", |b| {
b.iter(|| {
pdf.xfxq2_allpids(
std::hint::black_box(&ids),
std::hint::black_box(&point),
std::hint::black_box(&mut out),
)
})
});

group.bench_function("slow_path_loop", |b| {
b.iter(|| {
for (i, &pid) in ids.iter().enumerate() {
out[i] = pdf.xfxq2(std::hint::black_box(pid), std::hint::black_box(&point));
}
})
});

group.finish();
}

fn xfxq2s_cheby(c: &mut Criterion) {
let pdf = PDF::load("MAP22_grids_FF_Km_N3LL.neopdf.lz4", 0);
let ids: Vec<i32> = (-4..=4).filter(|&x| x != 0).collect();
let pts = [
[1e-4, 1e-2, 2.0],
[1e-3, 1e-2, 2.0],
[1e-2, 1e-2, 2.0],
[1e-1, 1e-2, 2.0],
[1e-4, 1e-1, 10.0],
[1e-3, 1e-1, 10.0],
[1e-2, 1e-1, 10.0],
[1e-1, 1e-1, 10.0],
[1e-4, 0.5, 100.0],
[1e-3, 0.5, 100.0],
[1e-2, 0.5, 100.0],
[1e-1, 0.5, 100.0],
[1e-4, 0.9, 1000.0],
[1e-3, 0.9, 1000.0],
[1e-2, 0.9, 1000.0],
[1e-1, 0.9, 1000.0],
];
let pts_slices: Vec<&[f64]> = pts.iter().map(|p| &p[..]).collect();

let mut group = c.benchmark_group("xfxq2_matrix_cheby");

group.bench_function("flavor_batched_xfxq2s", |b| {
b.iter(|| {
pdf.xfxq2s(
std::hint::black_box(ids.clone()),
std::hint::black_box(&pts_slices),
)
})
});

group.bench_function("point_batched_loop", |b| {
b.iter(|| {
for &pid in &ids {
let _ = pdf.xfxq2_cheby_batch(
std::hint::black_box(pid),
std::hint::black_box(&pts_slices),
);
}
})
});

group.finish();
}

criterion_group!(
benches,
xfxq2,
xfxq2s,
xfxq2_members,
xfxq2_cheby,
xfxq2_cheby_batch
xfxq2_cheby_batch,
xfxq2_allpids_cheby,
xfxq2s_cheby
);
criterion_main!(benches);
Loading