Repository navigation
299 lines (275 loc) · 12.3 KB
/
Copy pathbenchmark.yml
File metadata and controls
299 lines (275 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
name: Benchmark
on:
issue_comment:
types: [created]
workflow_dispatch:
inputs:
warmup:
description: "Warmup iterations"
default: "5"
iterations:
description: "Timed iterations"
default: "20"
sizes:
description: "Comma-separated square GEMM sizes (M=N=K)"
default: "256,512,1024,2048,4096"
permissions:
contents: read
pull-requests: write
issues: write
env:
BUILD_TYPE: Release
BENCH_WARMUP: ${{ github.event.inputs.warmup || '5' }}
BENCH_ITERS: ${{ github.event.inputs.iterations || '20' }}
BENCH_SIZES: ${{ github.event.inputs.sizes || '256,512,1024,2048,4096' }}
DEPS_CACHE: /tmp/sofieblas-cmake-deps
jobs:
parse-command:
name: Parse trigger
runs-on: ubuntu-latest
if: |
github.event_name == 'workflow_dispatch' ||
(
github.event_name == 'issue_comment' &&
github.event.issue.pull_request != null &&
contains(fromJSON('["sanjibansg","lmoneta"]'), github.event.comment.user.login) &&
startsWith(github.event.comment.body, '/runbenchmark')
)
outputs:
runner_label: ${{ steps.parse.outputs.runner_label }}
valid: ${{ steps.parse.outputs.valid }}
flavor: ${{ steps.parse.outputs.flavor }}
valid_flavors: ${{ steps.parse.outputs.valid_flavors }}
backend: ${{ steps.parse.outputs.backend }}
steps:
- name: React to trigger comment
if: github.event_name == 'issue_comment'
uses: actions/github-script@v7
with:
script: |
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: 'eyes'
});
- name: Parse runner flavor
id: parse
uses: actions/github-script@v7
with:
script: |
// default flavor keyed by name -> { self-hosted runner label, GPU backend }
const flavors = {
l40s: { runner: 'ml4ep-l40s', backend: 'cuda' },
h100: { runner: 'ml4ep-h100', backend: 'cuda' },
'h100-47gb': { runner: 'ml4ep-h100-47gb', backend: 'cuda' },
w7900: { runner: 'ml4ep-w7900', backend: 'hip' },
mi300x: { runner: 'ml4ep-mi300x', backend: 'hip' },
};
let flavor = 'l40s';
let valid = true;
if (context.eventName === 'issue_comment') {
const m = context.payload.comment.body.trim().match(/^\/runbenchmark(?:\s+(\S+))?/i);
if (m && m[1]) {
flavor = m[1].toLowerCase();
valid = Object.prototype.hasOwnProperty.call(flavors, flavor);
}
}
core.setOutput('flavor', flavor);
core.setOutput('valid', String(valid));
core.setOutput('runner_label', valid ? flavors[flavor].runner : '');
core.setOutput('backend', valid ? flavors[flavor].backend : '');
core.setOutput('valid_flavors', Object.keys(flavors).join(', '));
- name: Post run link
if: github.event_name == 'issue_comment'
uses: actions/github-script@v7
with:
script: |
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
body: `\`/runbenchmark\` (${{ steps.parse.outputs.flavor }}): triggered - [view run](${runUrl})`
});
benchmark:
name: Benchmark Comparison
needs: parse-command
if: needs.parse-command.outputs.valid == 'true'
concurrency:
group: benchmark-${{ needs.parse-command.outputs.flavor }}-${{ github.event.issue.number || github.ref }}
cancel-in-progress: true
runs-on: ${{ needs.parse-command.outputs.runner_label }}
container: registry.cern.ch/ngt/lxplus-like:9
timeout-minutes: 60
steps:
- name: GPU check (NVIDIA)
if: needs.parse-command.outputs.backend == 'cuda'
run: nvidia-smi
- name: GPU check (AMD)
if: needs.parse-command.outputs.backend == 'hip'
run: rocm-smi
- name: Resolve PR info
id: pr
if: github.event_name == 'issue_comment'
uses: actions/github-script@v7
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.issue.number
});
core.setOutput('number', pr.data.number);
core.setOutput('merge_ref', `refs/pull/${pr.data.number}/merge`);
core.setOutput('base_ref', pr.data.base.ref);
- name: Checkout PR branch
uses: actions/checkout@v4
with:
path: sofieblas-pr
ref: ${{ github.event_name == 'issue_comment' && steps.pr.outputs.merge_ref || github.ref }}
- name: Checkout base branch
if: github.event_name == 'issue_comment'
uses: actions/checkout@v4
with:
ref: ${{ steps.pr.outputs.base_ref }}
path: sofieblas-main
- name: Cache FetchContent dependencies
uses: actions/cache@v4
with:
path: ${{ env.DEPS_CACHE }}
key: cmake-deps-bench-${{ needs.parse-command.outputs.backend }}-${{ hashFiles('sofieblas-pr/cmake/SofieBLASBackends.cmake') }}
restore-keys: cmake-deps-bench-${{ needs.parse-command.outputs.backend }}-
- name: Configure PR build
env:
BACKEND: ${{ needs.parse-command.outputs.backend }}
run: |
cmake -B sofieblas-pr/build -S sofieblas-pr \
-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \
-DSOFIEBLAS_BUILD_BENCHMARKS=ON \
-DCMAKE_CUDA_ARCHITECTURES=native \
-DCMAKE_HIP_ARCHITECTURES=native \
"-DSOFIEBLAS_ENABLE_CUDA=$([ "$BACKEND" = "cuda" ] && echo ON || echo OFF)" \
"-DSOFIEBLAS_ENABLE_HIP=$([ "$BACKEND" = "hip" ] && echo ON || echo OFF)" \
"-DFETCHCONTENT_BASE_DIR=${{ env.DEPS_CACHE }}"
- name: Build PR benchmark
run: cmake --build sofieblas-pr/build --target "bench_${{ needs.parse-command.outputs.backend }}" -j"$(nproc)"
- name: Run PR benchmark
working-directory: sofieblas-pr/build/benchmark
run: |
"./bench_${{ needs.parse-command.outputs.backend }}" \
-w "${{ env.BENCH_WARMUP }}" \
-n "${{ env.BENCH_ITERS }}" \
--sizes "${{ env.BENCH_SIZES }}" \
| tee benchmark_pr.txt
- name: Check whether base branch supports the benchmark harness
id: base_support
if: github.event_name == 'issue_comment'
run: |
if grep -q "SOFIEBLAS_BUILD_BENCHMARKS" sofieblas-main/CMakeLists.txt 2>/dev/null; then
echo "supported=true" >> "$GITHUB_OUTPUT"
else
echo "supported=false" >> "$GITHUB_OUTPUT"
echo "::warning::${{ steps.pr.outputs.base_ref }} does not define the SOFIEBLAS_BUILD_BENCHMARKS option yet - skipping the base-branch comparison."
fi
- name: Configure base build
if: github.event_name == 'issue_comment' && steps.base_support.outputs.supported == 'true'
env:
BACKEND: ${{ needs.parse-command.outputs.backend }}
run: |
cmake -B sofieblas-main/build -S sofieblas-main \
-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \
-DSOFIEBLAS_BUILD_BENCHMARKS=ON \
-DCMAKE_CUDA_ARCHITECTURES=native \
-DCMAKE_HIP_ARCHITECTURES=native \
"-DSOFIEBLAS_ENABLE_CUDA=$([ "$BACKEND" = "cuda" ] && echo ON || echo OFF)" \
"-DSOFIEBLAS_ENABLE_HIP=$([ "$BACKEND" = "hip" ] && echo ON || echo OFF)" \
"-DFETCHCONTENT_BASE_DIR=${{ env.DEPS_CACHE }}"
- name: Build base benchmark
if: github.event_name == 'issue_comment' && steps.base_support.outputs.supported == 'true'
run: cmake --build sofieblas-main/build --target "bench_${{ needs.parse-command.outputs.backend }}" -j"$(nproc)"
- name: Run base benchmark
if: github.event_name == 'issue_comment' && steps.base_support.outputs.supported == 'true'
working-directory: sofieblas-main/build/benchmark
run: |
"./bench_${{ needs.parse-command.outputs.backend }}" \
-w "${{ env.BENCH_WARMUP }}" \
-n "${{ env.BENCH_ITERS }}" \
--sizes "${{ env.BENCH_SIZES }}" \
| tee benchmark_main.txt
- name: Build comparison summary
id: summary
if: always()
run: |
{
echo "summary<<BENCH_EOF"
echo "### Benchmark results (${{ needs.parse-command.outputs.flavor }})"
echo ""
if [ "${{ github.event_name }}" = "issue_comment" ] && [ "${{ steps.base_support.outputs.supported }}" = "true" ]; then
echo "Comparing against \`${{ steps.pr.outputs.base_ref }}\`"
elif [ "${{ github.event_name }}" = "issue_comment" ]; then
echo "_\`${{ steps.pr.outputs.base_ref }}\` does not yet support the benchmark harness - showing PR results only._"
fi
echo ""
echo '```'
echo "── PR ──────────────────────────────────────────────────────────────"
cat sofieblas-pr/build/benchmark/benchmark_pr.txt 2>/dev/null || echo "(no results)"
if [ -f sofieblas-main/build/benchmark/benchmark_main.txt ]; then
echo ""
echo "── ${{ steps.pr.outputs.base_ref }} ──────────────────────────────────────────────"
cat sofieblas-main/build/benchmark/benchmark_main.txt
fi
echo '```'
echo "BENCH_EOF"
} >> "$GITHUB_OUTPUT"
- name: Post results as PR comment
if: always() && github.event_name == 'issue_comment'
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ steps.pr.outputs.number }}
header: benchmark
message: ${{ steps.summary.outputs.summary }}
- name: Write job summary
if: always()
run: echo "${{ steps.summary.outputs.summary }}" >> "$GITHUB_STEP_SUMMARY"
- name: Notify benchmark completion
if: always() && github.event_name == 'issue_comment'
uses: actions/github-script@v7
with:
script: |
const status = '${{ job.status }}' === 'success' ? '✅ completed' : '❌ failed';
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
body: `\`/runbenchmark\` (${{ needs.parse-command.outputs.flavor }}): Benchmark ${status} - [view results](${runUrl})`
});
- name: Upload benchmark results
if: always()
uses: actions/upload-artifact@v4
with:
name: benchmark-results-${{ github.run_id }}
path: |
sofieblas-pr/build/benchmark/benchmark_pr.txt
sofieblas-main/build/benchmark/benchmark_main.txt
if-no-files-found: ignore
report-invalid-flavor:
name: Report invalid runner flavor
needs: parse-command
runs-on: ubuntu-latest
if: >-
always() && github.event_name == 'issue_comment' &&
needs.parse-command.result == 'success' &&
needs.parse-command.outputs.valid == 'false'
steps:
- uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
body: `\`/runbenchmark\`: unknown runner flavor \`${{ needs.parse-command.outputs.flavor }}\`. ` +
`Valid options: ${{ needs.parse-command.outputs.valid_flavors }} (or omit for the default, l40s).`
});