-
Notifications
You must be signed in to change notification settings - Fork 42
378 lines (359 loc) · 16.1 KB
/
benchmarks.yml
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
name: Benchmarks
on:
pull_request:
types: [opened, reopened, synchronize, labeled, unlabeled ]
workflow_dispatch:
jobs:
libor:
# if: contains(github.event.pull_request.labels.*.name, 'benchmarks') || github.event_name == 'workflow_dispatch'
name: Libor Swaption Sample
runs-on: ubuntu-latest
container:
image: ghcr.io/foonathan/gcc:12
outputs:
libor: ${{ steps.libor-results.outputs.result }}
steps:
- name: Hardware characteristics
run: |
echo "----------------- CPU ----------------"
lscpu
echo "------------------ Mem ---------------"
lsmem
- uses: actions/checkout@v4
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: benchmark-libor
- name: configure
run: |
mkdir build
cd build
cmake .. -GNinja \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER=g++ \
-DXAD_NO_THREADLOCAL=ON \
-DXAD_SIMD_OPTION=AVX2 \
-DXAD_USE_STRONG_INLINE=ON
- name: build
run: |
cd build
cmake --build .
- name: Run Test
run: |
cd build
ctest --no-compress-output --output-on-failure --parallel $(($(nproc) + 2))
# if we are on main branch & triggered by workflow-dispatch, push artefact
- name: Push Reference
uses: actions/upload-artifact@v4
if: github.event_name == 'workflow_dispatch'
with:
name: libor_exe
path: build/samples/LiborSwaptionPricer/LiborSwaptionPricer
if-no-files-found: error
retention-days: 90
overwrite: true
# if we are in a pull request, pull the uploaded artifact from earlier and run
- name: Pull Reference
if: github.event_name == 'pull_request'
run: |
mkdir -p build/samples/LiborSwaptionPricer/ref
cd build/samples/LiborSwaptionPricer/ref
curl -L "https://xadhackathon.s3.eu-west-1.amazonaws.com/libor_exe.zip" --output artifact.zip
unzip artifact.zip
chmod +x LiborSwaptionPricer
- name: Run Reference
if: github.event_name == 'pull_request'
run: |
set -e
cd build/samples/LiborSwaptionPricer/ref
ls -l
file ./LiborSwaptionPricer
chmod +x ./LiborSwaptionPricer
rm -f ../reference.log || true
# warmup run
./LiborSwaptionPricer 50000
for i in $(seq 1 ${{ vars.REPETITIONS }}) ; do \
./LiborSwaptionPricer 50000 | tee -a ../reference.log ; \
done
- name: Run Benchmark
if: github.event_name == 'pull_request'
run: |
set -e
cd build/samples/LiborSwaptionPricer
rm -f output.log || true
# warmup run
./LiborSwaptionPricer 50000
for i in $(seq 1 ${{ vars.REPETITIONS }}) ; do \
./LiborSwaptionPricer 50000 | tee -a output.log ; \
done
- name: Prepare results
if: github.event_name == 'pull_request'
id: libor-results
run: |
set -e
apt-get update && apt-get install -y bc datamash
echo "Min Max Mean StdDev Median TrimMean GeoMean HarmMean"
echo "*Output*"
awk '$2 == "AAD" { print $4 }' build/samples/LiborSwaptionPricer/output.log | datamash min 1 max 1 mean 1 sstdev 1 median 1 trimmean 1 geomean 1 harmmean 1
OUT_TIME=$(awk '$2 == "AAD" { print $4 }' build/samples/LiborSwaptionPricer/output.log | datamash median 1)
echo "*Reference*"
awk '$2 == "AAD" { print $4 }' build/samples/LiborSwaptionPricer/reference.log | datamash min 1 max 1 mean 1 sstdev 1 median 1 trimmean 1 geomean 1 harmmean 1
REF_TIME=$(awk '$2 == "AAD" { print $4 }' build/samples/LiborSwaptionPricer/reference.log | datamash median 1)
DIFFERENCE=$(echo "scale=9; $REF_TIME - $OUT_TIME" | bc | awk '{printf "%.3f\n", $1}')
echo "Difference: $DIFFERENCE"
PERCENTAGE=$(echo "scale=9; (($REF_TIME - $OUT_TIME) / $REF_TIME) * 100.0" | bc | awk '{printf "%.3f\n", $1}')
echo "Percentage: $PERCENTAGE"
echo "result=| ${REF_TIME}s | ${OUT_TIME}s | ${PERCENTAGE}% |" >> "$GITHUB_OUTPUT"
quantlib:
name: QuantLib Samples
runs-on: ubuntu-latest
container: ghcr.io/lballabio/quantlib-devenv:noble-1.85.0
outputs:
test: ${{ steps.test-results.outputs.result }}
bermudan: ${{ steps.bermudan-results.outputs.result }}
steps:
- name: Hardware characteristics
run: |
echo "----------------- CPU ----------------"
lscpu
echo "------------------ Mem ---------------"
lsmem
- uses: actions/checkout@v4
with:
path: xad
- uses: actions/checkout@v4
with:
repository: lballabio/QuantLib
ref: v1.35
path: QuantLib
- uses: actions/checkout@v4
with:
path: QuantLib-Risks-Cpp
repository: auto-differentiation/QuantLib-Risks-Cpp
ref: a1fcf4f0fab0a464710c249aa76871421675babd
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: benchmark-quantlib
- name: Setup
run: |
apt-get update \
&& apt-get install -y ninja-build bc datamash unzip
- name: Configure
run: |
cd QuantLib
mkdir build
cd build
cmake -G Ninja -DBOOST_ROOT=/usr \
-DCMAKE_CXX_STANDARD=17 \
-DQLRISKS_DISABLE_AAD=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DQL_EXTERNAL_SUBDIRECTORIES="$(pwd)/../../xad;$(pwd)/../../QuantLib-Risks-Cpp" \
-DQL_EXTRA_LINK_LIBRARIES=QuantLib-Risks \
-DQL_NULL_AS_FUNCTIONS=ON \
-DXAD_NO_THREADLOCAL=ON \
-DXAD_SIMD_OPTION=AVX2 \
..
- name: Compile
run: |
cd QuantLib/build
cmake --build .
- name: Test QuantLib
if: github.event_name == 'pull_request'
run: |
cd QuantLib/build
./test-suite/quantlib-test-suite --log_level=message
- name: Test QuantLib-Risks
if: github.event_name == 'pull_request'
run: |
cd QuantLib/build
./QuantLib-Risks-Cpp/test-suite/quantlib-risks-test-suite --log_level=message
# if we are on main branch & triggered by workflow-dispatch, push artefact
- name: Prepare Pushes
run: |
cd QuantLib/build/ql/
cp -a libQuantLib.so* ../test-suite/
cp -a libQuantLib.so* ../QuantLib-Risks-Cpp/Examples/AdjointBermudanSwaption
- name: Push Reference Test-suite
uses: actions/upload-artifact@v4
if: github.event_name == 'workflow_dispatch'
with:
name: ql_test_exe
path: QuantLib/build/test-suite/*uant*ib*
if-no-files-found: error
retention-days: 90
overwrite: true
- name: Push Reference AdjointBermudan
uses: actions/upload-artifact@v4
if: github.event_name == 'workflow_dispatch'
with:
name: ql_bermudan_exe
path: QuantLib/build/QuantLib-Risks-Cpp/Examples/AdjointBermudanSwaption/*
if-no-files-found: error
retention-days: 90
overwrite: true
# if we are in a pull request, pull the uploaded artifact from earlier and run
- name: Pull Reference Test-suite
if: github.event_name == 'pull_request'
run: |
mkdir -p QuantLib/build/test-suite/ref
cd QuantLib/build/test-suite/ref
wget "https://xadhackathon.s3.eu-west-1.amazonaws.com/test-suite.zip" --output-document artifact.zip
unzip artifact.zip
chmod +x quantlib-test-suite
- name: Pull Reference AdjointBermudan
if: github.event_name == 'pull_request'
run: |
mkdir -p QuantLib/build/QuantLib-Risks-Cpp/Examples/AdjointBermudanSwaption/ref
cd QuantLib/build/QuantLib-Risks-Cpp/Examples/AdjointBermudanSwaption/ref
wget "https://xadhackathon.s3.eu-west-1.amazonaws.com/swaption.zip" --output-document artifact.zip
unzip artifact.zip
chmod +x AdjointBermudanSwaption
- name: Run Reference Test-suite
if: github.event_name == 'pull_request'
run: |
set -e
cd QuantLib/build/test-suite/ref
ls -l
file ./quantlib-test-suite
chmod +x ./quantlib-test-suite
export LD_LIBRARY_PATH=.
# warmup run
./quantlib-test-suite --log_level=test_suite --run_test="QuantLibTests/*/testPathwiseGreeks" | grep -v "is skipped because"
rm -f ../reference.log || true
for i in $(seq 1 ${{ vars.REPETITIONS }}) ; do \
./quantlib-test-suite --log_level=test_suite --run_test="QuantLibTests/*/testPathwiseGreeks" | grep -v "is skipped because" | tee -a ../reference.log ; \
done
- name: Run Benchmark Test-suite
if: github.event_name == 'pull_request'
run: |
set -e
cd QuantLib/build/test-suite
rm -f output.log || true
# warmup run
./quantlib-test-suite --log_level=test_suite --run_test="QuantLibTests/*/testPathwiseGreeks" | grep -v "is skipped because"
for i in $(seq 1 ${{ vars.REPETITIONS }}) ; do \
./quantlib-test-suite --log_level=test_suite --run_test="QuantLibTests/*/testPathwiseGreeks" | grep -v "is skipped because" | tee -a output.log ; \
done
- name: Prepare results Tests-suite
if: github.event_name == 'pull_request'
id: test-results
run: |
set -e
ls -l QuantLib/build/test-suite/
echo "Min Max Mean StdDev Median TrimMean GeoMean HarmMean"
echo "*Output*"
sed -e 's/us$//g' -e 's/ms$/000/g' QuantLib/build/test-suite/output.log | awk ' $0 ~ /Leaving test case.*testPathwiseGreeks/ { print $NF }' | datamash min 1 max 1 mean 1 sstdev 1 median 1 trimmean 1 geomean 1 harmmean 1
OUT_TIME=$(sed -e 's/us$//g' -e 's/ms$/000/g' QuantLib/build/test-suite/output.log | awk ' $0 ~ /Leaving test case.*testPathwiseGreeks/ { print $NF }' | datamash median 1)
echo "*Reference*"
sed -e 's/us$//g' -e 's/ms$/000/g' QuantLib/build/test-suite/reference.log | awk ' $0 ~ /Leaving test case.*testPathwiseGreeks/ { print $NF }' | datamash min 1 max 1 mean 1 sstdev 1 median 1 trimmean 1 geomean 1 harmmean 1
REF_TIME=$(sed -e 's/us$//g' -e 's/ms$/000/g' QuantLib/build/test-suite/reference.log | awk ' $0 ~ /Leaving test case.*testPathwiseGreeks/ { print $NF }' | datamash median 1)
DIFFERENCE=$(echo "scale=9; $REF_TIME - $OUT_TIME" | bc | awk '{printf "%.3f\n", $1}')
echo "Difference: $DIFFERENCE"
PERCENTAGE=$(echo "scale=9; (($REF_TIME - $OUT_TIME) / $REF_TIME) * 100.0" | bc | awk '{printf "%.3f\n", $1}')
echo "Percentage: $PERCENTAGE"
echo "result=| ${REF_TIME}ms | ${OUT_TIME}ms | ${PERCENTAGE}% |" >> "$GITHUB_OUTPUT"
- name: Run Reference AdjointBermudan
if: github.event_name == 'pull_request'
run: |
set -e
cd QuantLib/build/QuantLib-Risks-Cpp/Examples/AdjointBermudanSwaption/ref
ls -l
file ./AdjointBermudanSwaption
chmod +x ./AdjointBermudanSwaption
rm -f ../reference.log || true
# warmup run
export LD_LIBRARY_PATH=.
./AdjointBermudanSwaption 200
for i in $(seq 1 ${{ vars.REPETITIONS }}) ; do \
./AdjointBermudanSwaption 200 | tee -a ../reference.log ; \
done
ls -l ..
- name: Run Benchmark AdjointBermudan
if: github.event_name == 'pull_request'
run: |
set -e
cd QuantLib/build/QuantLib-Risks-Cpp/Examples/AdjointBermudanSwaption
rm -f output.log || true
# warmup run
./AdjointBermudanSwaption 200
for i in $(seq 1 ${{ vars.REPETITIONS }}) ; do \
./AdjointBermudanSwaption 200 | tee -a output.log ; \
done
ls -l .
- name: Prepare results Bermudan
if: github.event_name == 'pull_request'
id: bermudan-results
run: |
set -e
ls -l QuantLib/build/QuantLib-Risks-Cpp/Examples/AdjointBermudanSwaption/
echo "Min Max Mean StdDev Median TrimMean GeoMean HarmMean"
echo "*Output*"
awk '$1 == "For" && $7 == "average" { print $8 }' QuantLib/build/QuantLib-Risks-Cpp/Examples/AdjointBermudanSwaption/output.log | datamash min 1 max 1 mean 1 sstdev 1 median 1 trimmean 1 geomean 1 harmmean 1
OUT_TIME=$(awk '$1 == "For" && $7 == "average" { print $8 }' QuantLib/build/QuantLib-Risks-Cpp/Examples/AdjointBermudanSwaption/output.log | datamash median 1)
echo "*Reference*"
awk '$1 == "For" && $7 == "average" { print $8 }' QuantLib/build/QuantLib-Risks-Cpp/Examples/AdjointBermudanSwaption/reference.log | datamash min 1 max 1 mean 1 sstdev 1 median 1 trimmean 1 geomean 1 harmmean 1
REF_TIME=$(awk '$1 == "For" && $7 == "average" { print $8 }' QuantLib/build/QuantLib-Risks-Cpp/Examples/AdjointBermudanSwaption/reference.log | datamash median 1)
DIFFERENCE=$(echo "scale=9; $REF_TIME - $OUT_TIME" | bc | awk '{printf "%.3f\n", $1}')
echo "Difference: $DIFFERENCE"
PERCENTAGE=$(echo "scale=9; (($REF_TIME - $OUT_TIME) / $REF_TIME) * 100.0" | bc | awk '{printf "%.3f\n", $1}')
echo "Percentage: $PERCENTAGE"
echo "result=| ${REF_TIME}ms | ${OUT_TIME}ms | ${PERCENTAGE}% |" >> "$GITHUB_OUTPUT"
update-runid:
name: Update Run-id
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
needs:
- quantlib
- libor
steps:
- uses: actions/checkout@v4
- name: Set runid variable
run: |
gh variable list
gh variable set REFERENCE_RUN_ID --body "${{ github.run_id }}"
gh variable list
env:
GH_TOKEN: ${{ secrets.WORKFLOW_READ_TOKEN }}
collect:
name: Collect Results
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
needs:
- quantlib
- libor
env:
LIBOR: ${{ needs.libor.outputs.libor }}
TESTSUITE: ${{ needs.quantlib.outputs.test }}
BERMUDAN: ${{ needs.quantlib.outputs.bermudan }}
steps:
- name: Collect results into markdown
run: |
echo "## Performance Results" > results.md
echo "" >> results.md
echo "Median of the ${{ vars.REPETITIONS }} executions, with pre-built reference and this PR's version." >> results.md
echo "" >> results.md
echo "| Application | Reference | Result | Improvement |" >> results.md
echo "|-------------|----------:|-------:|------------:|" >> results.md
echo "| [LIBOR Swaption (50K paths)](https://github.com/auto-differentiation/xad/tree/main/samples/LiborSwaptionPricer) $LIBOR" >> results.md
echo "| [Bermudan Swaption (200 repetitions)](https://github.com/auto-differentiation/QuantLib-Risks-Cpp/blob/main/Examples/AdjointBermudanSwaption/AdjointBermudanSwaptionXAD.cpp) $BERMUDAN" >> results.md
echo "| [testPathwiseGreeks](https://github.com/lballabio/QuantLib/blob/v1.35/test-suite/marketmodel.cpp#L2090) $TESTSUITE" >> results.md
- name: Find Comment
uses: peter-evans/find-comment@v3
if: github.event_name == 'pull_request'
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Performance Results
- name: Post or update PR comment
id: pr-comment
if: github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-path: results.md
edit-mode: replace