Skip to content

Commit 2d0ae0b

Browse files
[CI][Bench] Refactor bench workflow
1 parent 24dddd1 commit 2d0ae0b

File tree

2 files changed

+127
-97
lines changed

2 files changed

+127
-97
lines changed

.github/workflows/sycl-linux-run-tests.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,5 +378,4 @@ jobs:
378378
dry_run: ${{ inputs.benchmark_dry_run }}
379379
exit_on_failure: ${{ inputs.benchmark_exit_on_failure }}
380380
build_ref: ${{ inputs.repo_ref }}
381-
env:
382-
RUNNER_TAG: ${{ inputs.runner }}
381+
runner: ${{ inputs.runner }}

devops/actions/run-tests/benchmark/action.yml

Lines changed: 126 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@ name: 'Run benchmarks'
22

33
# This action assumes the following prerequisites:
44
#
5-
# - SYCL is accessible in the system (nightly image provides it within /opt/sycl),
6-
# or SYCL is placed in ./toolchain (TODO: change this??). The second option has higher priority.
7-
# - /devops has been checked out in ./devops.
8-
# - env.GITHUB_TOKEN was properly set, because according to Github, that's
9-
# apparently the recommended way to pass a secret into a github action:
10-
11-
# https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#accessing-your-secrets
12-
#
13-
# - env.RUNNER_TAG set to the runner tag used to run this workflow: Currently,
14-
# only specific runners are fully supported.
5+
# - SYCL is placed in dir pointed by 'inputs.sycl_dir', if not, it has to be accessible
6+
# in the system (e.g. nightly image provides it within /opt/sycl, but it might be a little older).
7+
# - /devops dir has been checked out in ./devops.
158

169
inputs:
1710
target_devices:
@@ -37,59 +30,130 @@ inputs:
3730
exit_on_failure:
3831
type: string
3932
required: False
33+
# Path to SYCL installation directory
34+
sycl_dir:
35+
type: string
36+
required: False
37+
default: "./toolchain"
38+
# Only specific runners are supported
39+
runner:
40+
type: string
41+
required: True
4042

4143
runs:
4244
# composite actions don't make use of 'name', so copy-paste names as a comment in the first line of each step
4345
using: "composite"
4446
steps:
45-
- name: Check specified runner type / target backend
47+
- name: Check inputs and set up environment
4648
shell: bash
4749
env:
50+
# inputs are not directly used, as this allows code injection
4851
TARGET_DEVICE: ${{ inputs.target_devices }}
4952
PRESET: ${{ inputs.preset }}
53+
SYCL_DIR: ${{ inputs.sycl_dir }}
54+
RUNNER_TAG: ${{ inputs.runner }}
55+
# Will append "_<device>_<backend>" to that prefix, as the save name
56+
SAVE_PREFIX: ${{ inputs.save_name }}
5057
run: |
58+
# Check inputs and set up environment
59+
60+
# Ensure runner name has nothing injected
61+
if [ -z "$(printf '%s' "$RUNNER_NAME" | grep -oE '^[a-zA-Z0-9_-]+$')" ]; then
62+
echo "Bad runner name, please ensure runner name is [a-zA-Z0-9_-]."
63+
exit 1
64+
fi
65+
5166
# Check specified runner type / target backend
5267
case "$RUNNER_TAG" in
53-
'["PVC_PERF"]' ) ;;
54-
'["BMG_PERF"]' ) ;;
68+
'["PVC_PERF"]') MACHINE_TYPE="PVC" ;;
69+
'["BMG_PERF"]') MACHINE_TYPE="BMG" ;;
5570
*)
71+
# Best effort at matching if not known runners
72+
# TODO: should we drop it and just exit instead?
73+
MACHINE_TYPE="${RUNNER_TAG#[\"}"
74+
MACHINE_TYPE="${MACHINE_TYPE%_PERF=\"]}"
5675
echo "#"
5776
echo "# WARNING: Only specific tuned runners are fully supported."
5877
echo "# This workflow is not guaranteed to work with other runners."
5978
echo "#" ;;
6079
esac
6180
62-
# Ensure runner name has nothing injected
63-
# TODO: in terms of security, is this overkill?
64-
if [ -z "$(printf '%s' "$RUNNER_NAME" | grep -oE '^[a-zA-Z0-9_-]+$')" ]; then
65-
echo "Bad runner name, please ensure runner name is [a-zA-Z0-9_-]."
66-
exit 1
67-
fi
68-
69-
# input.target_devices is not directly used, as this allows code injection
7081
case "$TARGET_DEVICE" in
71-
level_zero:*) ;;
72-
level_zero_v2:*) ;;
82+
level_zero:*) SAVE_SUFFIX="L0" ;;
83+
level_zero_v2:*)
84+
SAVE_SUFFIX="L0v2"
85+
ONEAPI_DEVICE_SELECTOR="level_zero:gpu"
86+
export SYCL_UR_USE_LEVEL_ZERO_V2=1
87+
echo "SYCL_UR_USE_LEVEL_ZERO_V2=$SYCL_UR_USE_LEVEL_ZERO_V2" >> $GITHUB_ENV
88+
;;
89+
opencl:*) SAVE_SUFFIX="OCL" ;;
7390
*)
91+
SAVE_SUFFIX="${TARGET_DEVICE%%:*}"
7492
echo "#"
7593
echo "# WARNING: Only level_zero backend is fully supported."
7694
echo "# This workflow is not guaranteed to work with other backends."
7795
echo "#" ;;
7896
esac
79-
echo "ONEAPI_DEVICE_SELECTOR=$TARGET_DEVICE" >> $GITHUB_ENV
97+
98+
# Export variables with machine type, save name, device selector, etc.
99+
export ONEAPI_DEVICE_SELECTOR=$TARGET_DEVICE
100+
echo "ONEAPI_DEVICE_SELECTOR=$ONEAPI_DEVICE_SELECTOR" >> $GITHUB_ENV
101+
export SAVE_SUFFIX=$SAVE_SUFFIX
102+
echo "SAVE_SUFFIX=$SAVE_SUFFIX" >> $GITHUB_ENV
103+
export MACHINE_TYPE=$MACHINE_TYPE
104+
echo "MACHINE_TYPE=$MACHINE_TYPE" >> $GITHUB_ENV
105+
106+
export SAVE_NAME="${SAVE_PREFIX}_${MACHINE_TYPE}_${SAVE_SUFFIX}"
107+
echo "SAVE_NAME=$SAVE_NAME" >> $GITHUB_ENV
108+
export SAVE_TIMESTAMP="$(date -u +'%Y%m%d_%H%M%S')" # Timestamps are in UTC time
109+
echo "SAVE_TIMESTAMP=$SAVE_TIMESTAMP" >> $GITHUB_ENV
110+
111+
# By default, the benchmark scripts forceload level_zero
112+
FORCELOAD_ADAPTER="${ONEAPI_DEVICE_SELECTOR%%:*}"
113+
echo "Adapter: $FORCELOAD_ADAPTER"
114+
echo "FORCELOAD_ADAPTER=$FORCELOAD_ADAPTER" >> $GITHUB_ENV
80115
81116
# Make sure specified preset is a known value and is not malicious
82117
python3 ./devops/scripts/benchmarks/presets.py query "$PRESET"
83118
[ "$?" -ne 0 ] && exit 1 # Stop workflow if invalid preset
84119
echo "PRESET=$PRESET" >> $GITHUB_ENV
120+
121+
# Check if SYCL dir exists and has SYCL lib; set CMPLR_ROOT if so
122+
if [ -d "$SYCL_DIR" ] && [ -f "$SYCL_DIR/lib/libsycl.so" ]; then
123+
echo "Using SYCL from: $SYCL_DIR"
124+
export CMPLR_ROOT=$SYCL_DIR
125+
echo "CMPLR_ROOT=$CMPLR_ROOT" >> $GITHUB_ENV
126+
else
127+
echo "WARNING: SYCL directory '$SYCL_DIR' does not exist or is missing libsycl.so"
128+
echo "Checking if SYCL is installed in the system..."
129+
which sycl-ls
130+
sycl-ls
131+
export CMPLR_ROOT="$(dirname $(which sycl-ls))"
132+
echo "Using SYCL from: $CMPLR_ROOT"
133+
echo "CMPLR_ROOT=$CMPLR_ROOT" >> $GITHUB_ENV
134+
fi
85135
- name: Set NUMA node to run benchmarks on
86136
shell: bash
87137
run: |
88138
# Set CPU and GPU affinity for the first NUMA node; second node is used by UMF
89139
NUMA_NODE=0
90140
echo "ZE_AFFINITY_MASK=$NUMA_NODE" >> $GITHUB_ENV
91141
echo "NUMA_NODE=$NUMA_NODE" >> $GITHUB_ENV
142+
- name: Set env var for results branch
143+
shell: bash
144+
run: |
145+
# Set env var for results branch
92146
147+
# Set BENCHMARK_RESULTS_BRANCH globally for all subsequent steps.
148+
# This has to be done this way because of limits of composite actions.
149+
BENCHMARK_RESULTS_BRANCH="sycl-benchmark-ci-results"
150+
echo "BENCHMARK_RESULTS_BRANCH=$BENCHMARK_RESULTS_BRANCH" >> $GITHUB_ENV
151+
- name: Checkout results repo
152+
uses: actions/checkout@v5
153+
with:
154+
ref: ${{ env.BENCHMARK_RESULTS_BRANCH }}
155+
path: ./llvm-ci-perf-results
156+
persist-credentials: true
93157
# Compute-benchmarks relies on UR static libraries, cmake config files, etc.
94158
# DPC++ doesn't ship with these files. The easiest way of obtaining these
95159
# files is to build from scratch.
@@ -102,10 +166,10 @@ runs:
102166
# modified output the entire sycl build dir as an artifact, in which the
103167
# intermediate files required can be stitched together from the build files.
104168
# However, this is not exactly "clean" or "fun to maintain"...
105-
- name: Build Unified Runtime
169+
- name: Clone and build Unified Runtime
106170
shell: bash
107171
run: |
108-
# Build Unified Runtime
172+
# Clone and build Unified Runtime
109173
echo "::group::checkout_llvm_ur"
110174
111175
# Sparse-checkout UR at build ref:
@@ -137,13 +201,27 @@ runs:
137201
cd -
138202
139203
echo "::endgroup::"
140-
# Linux tools installed during docker creation may not match the self-hosted
141-
# kernel version, so we need to install the correct version here.
142-
- name: Install perf in version matching the host kernel
204+
- name: Install dependencies
143205
shell: bash
206+
env:
207+
RUNNER_TAG: ${{ inputs.runner }}
144208
run: |
145-
# Install perf in version matching the host kernel
146-
echo "::group::install_linux_tools"
209+
# Install dependencies
210+
211+
echo "::group::use_compute_runtime_tag_cache"
212+
213+
# Cache the compute_runtime version from dependencies.json, but perform a
214+
# check with L0 version before using it: This value is not guaranteed to
215+
# accurately reflect the current compute_runtime version used, as the
216+
# docker images are built nightly.
217+
export COMPUTE_RUNTIME_TAG_CACHE="$(cat ./devops/dependencies.json | jq -r .linux.compute_runtime.github_tag)"
218+
219+
echo "::endgroup::"
220+
echo "::group::install_perf"
221+
222+
# Install perf in version matching the host kernel.
223+
# Linux tools installed during docker creation may not match the self-hosted
224+
# kernel version, so we need to install the correct version here.
147225
if [ "$RUNNER_TAG" = '["BMG_PERF"]' ]; then
148226
echo "Adding repositories for Ubuntu 25.10 (Questing) on BMG_PERF runner"
149227
echo "deb http://archive.ubuntu.com/ubuntu/ questing main restricted universe multiverse" | sudo tee /etc/apt/sources.list.d/questing.list
@@ -152,30 +230,10 @@ runs:
152230
fi
153231
sudo apt-get update
154232
sudo apt-get install -y linux-tools-$(uname -r)
155-
echo "::endgroup::"
156-
- name: Set env var for results branch
157-
shell: bash
158-
run: |
159-
# Set env var for results branch
160-
# Set BENCHMARK_RESULTS_BRANCH globally for all subsequent steps.
161-
# This has to be done this way because of limits of composite actions.
162-
BENCHMARK_RESULTS_BRANCH="sycl-benchmark-ci-results"
163-
echo "BENCHMARK_RESULTS_BRANCH=$BENCHMARK_RESULTS_BRANCH" >> $GITHUB_ENV
164-
- name: Checkout results repo
165-
uses: actions/checkout@v5
166-
with:
167-
ref: ${{ env.BENCHMARK_RESULTS_BRANCH }}
168-
path: llvm-ci-perf-results
169-
- name: Build and run benchmarks
170-
env:
171-
# Need to append "_<device>_<backend>" to save name in order to follow
172-
# conventions:
173-
SAVE_PREFIX: ${{ inputs.save_name }}
174-
shell: bash
175-
run: |
176-
# Build and run benchmarks
177233
234+
echo "::endgroup::"
178235
echo "::group::install_python_deps"
236+
179237
echo "Installing python dependencies..."
180238
# Using --break-system-packages because:
181239
# - venv is not installed
@@ -186,58 +244,30 @@ runs:
186244
pip install --user --break-system-packages -r ./devops/scripts/benchmarks/requirements.txt
187245
188246
echo "::endgroup::"
189-
echo "::group::establish_parameters_and_vars"
190-
191-
export CMPLR_ROOT=./toolchain
192-
# By default, the benchmark scripts forceload level_zero
193-
FORCELOAD_ADAPTER="${ONEAPI_DEVICE_SELECTOR%%:*}"
194-
echo "Adapter: $FORCELOAD_ADAPTER"
195-
196-
case "$ONEAPI_DEVICE_SELECTOR" in
197-
level_zero:*) SAVE_SUFFIX="L0" ;;
198-
level_zero_v2:*)
199-
SAVE_SUFFIX="L0v2"
200-
export ONEAPI_DEVICE_SELECTOR="level_zero:gpu" # "level_zero_v2:gpu" not supported anymore
201-
export SYCL_UR_USE_LEVEL_ZERO_V2=1
202-
;;
203-
opencl:*) SAVE_SUFFIX="OCL" ;;
204-
*) SAVE_SUFFIX="${ONEAPI_DEVICE_SELECTOR%%:*}";;
205-
esac
206-
case "$RUNNER_TAG" in
207-
'["PVC_PERF"]') MACHINE_TYPE="PVC" ;;
208-
'["BMG_PERF"]') MACHINE_TYPE="BMG" ;;
209-
# Best effort at matching
210-
*)
211-
MACHINE_TYPE="${RUNNER_TAG#[\"}"
212-
MACHINE_TYPE="${MACHINE_TYPE%_PERF=\"]}"
213-
;;
214-
esac
215-
SAVE_NAME="${SAVE_PREFIX}_${MACHINE_TYPE}_${SAVE_SUFFIX}"
216-
echo "SAVE_NAME=$SAVE_NAME" >> $GITHUB_ENV
217-
SAVE_TIMESTAMP="$(date -u +'%Y%m%d_%H%M%S')" # Timestamps are in UTC time
218-
219-
# Cache the compute_runtime version from dependencies.json, but perform a
220-
# check with L0 version before using it: This value is not guaranteed to
221-
# accurately reflect the current compute_runtime version used, as the
222-
# docker images are built nightly.
223-
export COMPUTE_RUNTIME_TAG_CACHE="$(cat ./devops/dependencies.json | jq -r .linux.compute_runtime.github_tag)"
224-
225-
echo "::endgroup::"
226-
echo "::group::sycl_ls"
247+
- name: Run sycl-ls
248+
shell: bash
249+
run: |
250+
# Run sycl-ls
227251
sycl-ls --verbose
228-
echo "::endgroup::"
229-
echo "::group::run_benchmarks"
252+
- name: Build and run benchmarks
253+
shell: bash
254+
run: |
255+
# Build and run benchmarks
230256
257+
echo "::group::setup_workdir"
231258
WORKDIR="$(realpath ./llvm_test_workdir)"
232259
if [ -n "$WORKDIR" ] && [ -d "$WORKDIR" ] && [[ "$WORKDIR" == *llvm_test_workdir* ]]; then rm -rf "$WORKDIR" ; fi
233260
234261
# Clean up potentially existing, old summary files
235262
[ -f "github_summary_exe.md" ] && rm github_summary_exe.md
236263
[ -f "github_summary_reg.md" ] && rm github_summary_reg.md
237264
265+
echo "::endgroup::"
266+
echo "::group::run_benchmarks"
267+
238268
numactl --cpunodebind "$NUMA_NODE" --membind "$NUMA_NODE" \
239269
./devops/scripts/benchmarks/main.py "$WORKDIR" \
240-
--sycl "$(realpath ./toolchain)" \
270+
--sycl "$(realpath $CMPLR_ROOT)" \
241271
--ur "$(realpath ./ur/install)" \
242272
--adapter "$FORCELOAD_ADAPTER" \
243273
--save "$SAVE_NAME" \
@@ -253,6 +283,7 @@ runs:
253283
254284
echo "::endgroup::"
255285
echo "::group::compare_results"
286+
256287
python3 ./devops/scripts/benchmarks/compare.py to_hist \
257288
--avg-type EWMA \
258289
--cutoff "$(date -u -d '7 days ago' +'%Y%m%d_%H%M%S')" \
@@ -289,7 +320,7 @@ runs:
289320
cp "$diff" "../cached_changes/$diff"
290321
done
291322
- name: Push benchmarks results
292-
if: inputs.upload_results == 'true' && always()
323+
if: always() && inputs.upload_results == 'true'
293324
shell: bash
294325
run: |
295326
# Push benchmarks results

0 commit comments

Comments
 (0)