Skip to content

About

Workflow for continous benchmarking on HPC cluster from GitHub

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

43 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

HPC CB workflow

This reusable GitHub workflow runs a GitLab pipeline for a selected commit and reports the result back to GitHub. It mirrors the commit, triggers the pipeline, monitors it, collects artifacts and optionally publishes benchmarks with github-action-benchmark. The caller supplies its events, GitLab pipeline and cluster configuration.

flowchart LR
    Trigger["Push, schedule, dispatch or PR command"] --> Start
    subgraph GitHub["GitHub, hpc-pipeline.yml"]
        Start["Start"] --> Monitor["Monitor, check runs"]
        Monitor --> Collect["Collect, artifacts and PR comment"]
        Collect --> Benchmark["Benchmark, github-action-benchmark with history and Pages"]
    end
    subgraph GitLab["GitLab, reached with github2lab_action"]
        Pipeline["Pipeline of the mirrored commit"] --> Jobs["Jobs on the cluster runners"]
    end
    Start -- "mirror and trigger" --> Pipeline
    Pipeline -- "job status" --> Monitor
    Jobs -- "artifacts" --> Collect
Loading

GitLab operations use pc2/github2lab_action, all action references are pinned to commit hashes.

Setup

  1. Create a GitLab project with runners matching the job tags in the caller's .gitlab-ci.yml.
  2. Create a project access token with the read_api and write_repository scopes. It must be allowed to force push the mirrored branches, the default branch and hpc-pr-*, so allow force push for the default branch if it is protected. Disable pull mirroring for them.
  3. Create a pipeline trigger token under Settings, CI/CD, Pipeline trigger tokens. Cluster authorization may require a trigger token owned by a cluster user.
  4. Configure the caller's GitHub repository under Settings, Secrets and variables, Actions.
Setting Type Value
GITLAB_TOKEN Secret. The project access token.
GITLAB_TRIGGER_TOKEN Secret. The pipeline trigger token.
GITLAB_HOSTNAME Variable. The hostname without a protocol prefix.
GITLAB_PROJECT_ID Variable. The numeric GitLab project ID.

Usage

Caller workflow

The manual example and benchmark example are complete callers. Callers pin this workflow to a reviewed commit, since it runs with their secrets and write permissions. The examples in this repository cannot name their own commit, so they use the placeholder REVIEWED_COMMIT, replace it with the full hash of that commit.

The four dispatch inputs are required, continuation dispatches the caller with context_run_id and the PR command dispatches it with pull_request, source_sha and command_comment. The workflow reads them from the dispatch, so the caller only declares them.

The Actions form lists inputs in declaration order, so declare the caller's own options first. GitLab reads .gitlab-ci.yml from the mirrored commit, so it lives in the caller repository.

on:
  push:
    branches: [main]
  workflow_dispatch:
    inputs:
      pull_request:
        type: string
        default: ''
      source_sha:
        type: string
        default: ''
      context_run_id:
        type: string
        default: ''
      command_comment:
        type: string
        default: ''

permissions:
  contents: write
  checks: write
  actions: write
  pull-requests: write
  pages: write
  id-token: write

jobs:
  hpc:
    uses: pc2/hpc-cb-workflow/.github/workflows/hpc-pipeline.yml@REVIEWED_COMMIT
    with:
      gitlab_hostname: ${{ vars.GITLAB_HOSTNAME }}
      gitlab_project_id: ${{ vars.GITLAB_PROJECT_ID }}
    secrets:
      GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
      GITLAB_TRIGGER_TOKEN: ${{ secrets.GITLAB_TRIGGER_TOKEN }}

Pipeline rule

The GitLab pipeline must accept only triggers for the mirrored commit, otherwise jobs for another branch head can start. The workflow passes the selected commit as EXPECTED_COMMIT_SHA, the rule compares it with the commit GitLab runs.

Two pushes to the default branch within seconds mirror different commits to the same GitLab branch, the rule then fails the older run instead of testing the wrong commit.

workflow:
  rules:
    - if: >-
        $CI_PIPELINE_SOURCE == "trigger" &&
        $EXPECTED_COMMIT_SHA == $CI_COMMIT_SHA

Inputs and outputs

Input Meaning
gitlab_hostname The GitLab hostname without a protocol prefix.
gitlab_project_id The numeric GitLab project ID.
pipeline_variables Additional pipeline variables, one KEY=VALUE per line, each key once.
variable_patterns Allowed values, one NAME=REGEX per line for variables in pipeline_variables, matching the whole value.
context_run_id The original GitHub run, used to resume monitoring.
pull_request An optional open PR that contains the selected commit.
source_sha A reviewed commit of the PR, verified against pull_request.
command_comment The PR comment that authorized the run, set by the PR command.
benchmark Benchmark publication configuration as JSON, see below.
benchmark_file The path of a YAML file with the benchmark configuration, used instead of benchmark.
expected_pipeline_status The required terminal status, success by default, failed for deliberate failure tests.
max_wait_minutes Minutes one run monitors before continuing in another run, at most 330.
collect_timeout_minutes Minutes for collecting the artifacts after the pipeline finished, 60 by default, at most 360.

The pipeline_status output exposes the verified GitLab status after collection.

How it runs

Start

Start force pushes the selected commit to the same branch on GitLab and triggers one pipeline. Only the first attempt of a new run may start a pipeline, reruns reuse the saved context artifact.

The start job warns when the caller or its context_run_id input is missing on the default branch, continuation would fail there. Forks without gitlab_project_id skip the run, unsupported events such as pull_request fail with a message.

Monitoring

Wait verifies the pipeline identity and mirrors job results as check runs named HPC #<pipeline> / <job>, the pipeline ID separates pipelines of the same commit. The pipeline check HPC #<pipeline> holds the job table and sorts before its job checks. Jobs of child pipelines in the same project appear as <trigger job>/<job>.

GitLab outages up to thirty minutes are retried, an outage reaching max_wait_minutes hands over to the next run.

A pipeline blocked by a manual job ends the monitoring with status manual and fails the run. Optional manual jobs do not block.

Continuation

After max_wait_minutes the workflow dispatches the caller on the default branch again with context_run_id, so monitoring may outlast the six hour job limit. Continuation stops after seven days, the summary names the original run ID for a manual resume.

Collection

Collect uploads the GitLab artifacts with a thirty day retention and posts one PR comment per pipeline. A PR run that fails before collection comments with the failed step instead. Child pipeline archives are named <trigger job>_<job>.zip.

Collection fails when the pipeline fails or an artifact download fails, unless expected_pipeline_status requires the failure. Suites whose archive comes from a successful job are compared and recorded also when other jobs of the pipeline fail.

A pipeline without artifacts passes, the summary reports the number of collected archives. expire_in must outlast the queue time of the following jobs, since collection starts after the whole pipeline.

Security

Who may start a run

Only pushes to the default branch, manual dispatch and schedules run the workflow. The start job checks who started the run before anything is mirrored.

Trigger Required check
Push to the default branch or schedule. None, the code is reviewed.
Dispatch of the default branch without a PR. None, the code is reviewed.
Any other dispatch. The actor needs repository write access.
Dispatch by the PR command. The comment author needs repository write access, checked by the caller stub, the command and the start job, and the comment must name the selected commit.

Pass source_sha and pull_request to run a reviewed commit of an open PR, including a fork commit, from the caller on the default branch.

Repository writers are trusted to authorize cluster execution because their workflows can access the GitLab secrets. Users with write access can also run their own workflows on other branches, which receive the repository secrets, so grant write access only to trusted people.

What a run can access

PR runs use the GitLab branch hpc-pr-<number>-<sha>, these branches remain on GitLab until pruned. Jobs run with the CI account's filesystem and scheduler permissions, there is no sandbox. GitLab tokens reach only the steps that use them, collected archives are stored without extraction, the search for written suites reads only their file names.

Benchmarks

Configuration

Set benchmark_file to publish measurements with github-action-benchmark after a successful pipeline. The file lives in the caller repository, for example .github/hpc-benchmark.yml.

mode: history
branch: hpc-results
suites:
  - match: "* time"
    alert_threshold: 115%
    fail_threshold: 150%
  - match: "* efficiency"
    tool: customBiggerIsBetter

The configuration runs nothing, the jobs are defined in .gitlab-ci.yml and selected by the pipeline variables. The workflow reads the file from the commit of the caller workflow, not from the selected commit, so a PR cannot change its own thresholds. Small configurations can be passed inline as JSON with benchmark instead, with the same keys.

Suites written by the jobs

A GitLab job publishes a suite by writing its measurements to hpc-benchmarks/<suite name>.json in its artifacts, in one of the measurement formats.

benchmark:
  script:
    - mkdir -p hpc-benchmarks
    - ./benchmark > "hpc-benchmarks/$DEVICE time.json"
  artifacts:
    paths: [hpc-benchmarks/]

A suite with match is a rule, it sets the keys below for every written suite whose name fits the pattern, * stands for any text. The first fitting rule applies, a written suite without a rule fails the collection.

Only archives of successful jobs are searched, and only for files directly in hpc-benchmarks/ at the top of the archive. Rules apply only when the configuration has at least one, otherwise these files are ignored.

The suite names come from the selected commit, the thresholds and the tool from the caller commit. A PR run fails for a suite without a recorded baseline, so a renamed suite cannot pass unnoticed, a suite that is no longer written is not compared. At most 100 written suites are supported.

Suites named in the configuration

A suite with name, archive and file selects one file inside one collected archive, for jobs that cannot write to hpc-benchmarks/. archive is the GitLab job name with .zip, where : is dropped and a space becomes _, so the matrix job bench: [gpu] is collected as bench_[gpu].zip.

suites:
  - name: "{device} {julia}"
    archive: bench-{device}{julia}.zip
    file: results/benchmark.json
    matrix:
      device: [cpu, gpu]
      julia: ["1.10", "1.13"]

A suite with a matrix becomes one suite per combination of its values, {name} in the other keys is replaced by the value of that name. Matrix values are quoted strings, YAML would read an unquoted 1.10 as the number 1.1. Quote values that start with a placeholder, and use every placeholder in name, since suite names must be unique.

Both kinds of suites can be mixed in one configuration.

Keys

Key Meaning
mode history records on the branch, pages also deploys it with GitHub Pages, compare only checks.
branch The history branch, hpc-results by default, created on the first recording run.
match The name pattern of a rule for suites written by the jobs.
name The stable suite name, letters, digits, spaces, dots, underscores and hyphens, use separate suites for different hardware, versions or thread counts.
archive The GitLab job artifact archive of a named suite.
file The measurement file inside the archive of a named suite.
tool customSmallerIsBetter by default, customBiggerIsBetter or julia.
directory The dashboard directory on the branch, bench by default.
alert_threshold The warning ratio, 115% by default, at least 100%.
fail_threshold The failing ratio, 150% by default, at least the warning ratio.
matrix Optional lists of values by placeholder name for a named suite.

Measurement files

A measurement file must have a format of github-action-benchmark, selected by tool. The workflow supports the two custom formats and julia.

The custom formats contain a JSON array with one object per metric.

[
  {"name": "solve/threads=8", "unit": "s", "value": 0.0018},
  {"name": "solve/threads=24", "unit": "s", "value": 0.0007}
]

name and unit are nonempty texts and name is unique in the file, value is a finite number that is not negative. With customSmallerIsBetter, the default, a larger value is a regression, with customBiggerIsBetter a smaller one. The optional keys range and extra of the action are passed on.

The julia format reads the estimates exported by BenchmarkTools.save. A file may hold at most twenty megabytes.

Comparison

The action compares against the latest recorded result of the suite from a different commit, it does not rerun the baseline. New measurements extend a suite, measurements missing from the baseline or changed units fail the comparison.

Each measurement is marked ok, warning or failure by the thresholds, warnings keep the result successful and appear in the check title. The comparison appears in the job summary, a HPC benchmark / <suite> check and the PR comment.

Recording

Run Behavior
Default branch Compares and records, with compare it only compares.
PR Compares without recording.
Other branch Fails unless mode is compare.
Retry Reuses the ledger stored with the history or the thirty day comparison artifact, and appends no measurement.

A run on the default branch must record the first baseline before PR or compare runs can succeed. GitHub keeps one pending report per history branch, so avoid callers that record to the same branch at the same time.

GitHub Pages

For pages, select GitHub Actions as the source under Settings, Pages, the dashboard is served below the directory, for example /bench/. This mode replaces whatever the repository publishes on Pages. For an existing documentation site, use history and copy the directory from the branch into the documentation build.

PR command

Reviewed PRs run with a comment /hpc <commit> [<commit> ...].

Enabling the command

Copy the command example into the caller repository, set workflow to the caller's file name and replace REVIEWED_COMMIT with the same commit as in the caller. GitHub starts comment workflows only in the commented repository, so this stub listens there and calls the command in this repository.

Commits and authorization

Each commit requires its full 40 character hexadecimal hash and must belong to the PR. The full hash binds approval to the reviewed commit even if the PR changes before dispatch.

The comment author needs repository write access, which is checked three times. The authorize job of the stub checks it in the caller repository, before the command of this repository is called, so the check holds for every version of this workflow. The command checks it again and dispatches the caller once per commit, and the start job checks it a third time.

A comment of a user without write access fails in the authorize job and gets no reply.

Only named commits run, so a push after the review cannot reach the cluster. Earlier commits of the PR can run as well, for example to locate a benchmark regression. Review each earlier commit on its own before naming it, a later commit can hide what an earlier one changes. If any hash is incomplete or names a commit outside the PR, nothing is dispatched.

The same run can be dispatched by hand with pull_request and source_sha.

Feedback

A reaction on the comment acknowledges it.

Reaction Meaning
πŸš€ The runs were started.
πŸ˜• The command is invalid.
πŸ‘Ž The commenter has no repository write access.

The reply names the authorized commits or the reasons for refusing. Results appear as check runs on each commit, one PR comment per pipeline and one HPC benchmark / <suite> check per suite. GitHub shows checks of earlier commits on the commit pages, not in the PR view.

Options

Options after the commits select what runs, /hpc <commit> suite=gpu applies to all named commits. Each option is a workflow_dispatch input of the caller with the same name, so the comment and the Actions form use the same names.

Options grant nothing beyond a manual dispatch, which repository writers can start anyway. The command refuses pull_request, source_sha, context_run_id and command_comment, values allow letters, digits and ._:/+-.

GitHub rejects inputs the caller does not declare, and the reply relays the rejection. Declare options as type: choice to restrict their values, and forward them explicitly as pipeline variables.

on:
  workflow_dispatch:
    inputs:
      suite:
        type: choice
        options: [all, cpu, gpu]
        default: all

jobs:
  hpc:
    with:
      pipeline_variables: SUITE=${{ inputs.suite || 'all' }}

GitLab rules such as if: $SUITE == "all" || $SUITE == "gpu" then select the jobs. Free text inputs, for example several suites joined by +, need a pattern, otherwise any value reaches GitLab.

      pipeline_variables: SUITES=${{ inputs.suites || 'all' }}
      variable_patterns: SUITES=(all|cpu|gpu)(\+(cpu|gpu))*

A value outside its pattern stops the run before anything is pushed to GitLab.

Selecting checks and benchmarks

Only suites of successful jobs start a benchmark job, so the jobs that ran decide what is measured. The benchmark example selects validation and benchmark jobs separately, each benchmark job writes its own suite.

variables:
  CHECKS: all
  BENCHMARKS: all

test-gpu:
  rules:
    - if: $CHECKS =~ /(^|\+)(all|gpu)(\+|$)/

bench-gpu:
  rules:
    - if: $BENCHMARKS =~ /(^|\+)(all|gpu)(\+|$)/
  script:
    - mkdir -p hpc-benchmarks
    - ./benchmark > "hpc-benchmarks/gpu benchmark.json"
  artifacts:
    paths: [hpc-benchmarks/]

A run with checks=none and benchmarks=gpu then measures only the GPU suite. For a named suite, collection notes a missing archive in its summary, and a missing file inside a collected archive fails the suite.

Continuation runs keep the variables and benchmark configuration of the original start.

Development

Unit tests

tests/ runs with mocked API responses and the pinned action revision, GITHUB2LAB_SOURCE selects a local action checkout. The reusable workflows embed the Python helpers from scripts/ between the lines # BEGIN EMBED <file> and # END EMBED <file>. Edit the helper, never the text between these lines, then run python scripts/embed_helpers.py and commit the workflows. The benchmark action checks run the pinned action against deterministic improvement, warning and failure measurements.

Integration suite

The integration suite runs against the configured GitLab project on pushes to main, weekly and on dispatch. Its pipeline needs a runner tagged otus-shell and a Slurm runner tagged otus-slurm, override the tags with INTEGRATION_RUNNER_TAG and BENCHMARK_RUNNER_TAG in the GitLab project variables.

The benchmark scenario measures a Julia dense linear solve on Slurm, BENCHMARK_SCHEDULER_PARAMETERS and BENCHMARK_JULIA_MODULE adjust the allocation and module.

The history workflow publishes the same measurement to Pages on pushes, weekly and on dispatch. A failing suite still records its point, Pages are redeployed from the branch regardless of the verdict.

Scenario Verified behavior
success Collection, check runs and the PR comment.
failure An expected pipeline failure with verified artifacts.
handover Continuation after one minute of monitoring.
handover_failure Continuation followed by an expected failure.
benchmark Dispatch only, the collected measurement JSON and Slurm allocation ID.

The continuation path runs from the default branch, merge changes to it before testing handover.

PR command test

The PR command test creates passing and failing draft PRs, posts /hpc <commit>, verifies continuation, reports and retries, then closes the PRs. It also verifies that an undeclared option is refused and that a declared option reaches the run.

It needs the following settings in this repository.

Setting Type Value
CB_TEST_TOKEN Actions secret. A fine grained token with the organization as resource owner, restricted to this repository, with pull requests read and write permission.
CB_TEST_ACTOR Actions variable. The GitHub username owning the token.

PRs created with the workflow token would need manual approval before their checks run, PRs created with the supplied token do not. The test account comments like any other user, so it needs repository write access.

About

Workflow for continous benchmarking on HPC cluster from GitHub

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages