Debian Codegraph @

others/mbedtls/tf-psa-crypto/drivers/pqcp/mldsa-native/.github/workflows/bench_ec2_reusable.yml

raw symbols SCIP
1 # Copyright (c) The mlkem-native project authors
2 # Copyright (c) The mldsa-native project authors
3 # SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4
5 name: bench-ec2-reusable
6 on:
7 workflow_call:
8 inputs:
9 name:
10 type: string
11 description: Alternative name of instance
12 default: Graviton2
13 ec2_instance_type:
14 type: string
15 description: Type if EC2 instance to benchmark on
16 default: t4g.small
17 ec2_ami:
18 type: string
19 description: Textual description of AMI
20 default: ubuntu-latest (aarch64)
21 ec2_ami_id:
22 type: string
23 description: AMI ID
24 default: ami-0c4e709339fa8521a
25 cflags:
26 type: string
27 description: Custom CFLAGS for compilation
28 default: ""
29 archflags:
30 type: string
31 description: Custom ARCH flags for compilation
32 default: -mcpu=neoverse-n1 -march=armv8.2-a
33 ldflags:
34 type: string
35 description: Custom LDFLAGS for linking
36 default: ""
37 opt:
38 type: string
39 description: Runs with optimized code if enabled (opt, no_opt, all)
40 default: "opt"
41 perf:
42 type: string
43 description: Method by which clock cycles should be measured (PMU | PERF)
44 default: PERF
45 store_results:
46 type: boolean
47 description: Indicates if results should be pushed to github pages
48 default: false
49 verbose:
50 description: Determine for the log verbosity
51 type: boolean
52 default: false
53 bench_extra_args:
54 type: string
55 description: Additional command line to be appended to `bench` script
56 default: ''
57 compiler:
58 type: string
59 description: Compiler to use. When unset, default nix shell is used.
60 default: ''
61 additional_packages:
62 type: string
63 description: Additional packages to install when custom compiler is used.
64 default: ''
65 aws_region:
66 type: string
67 default: "us-east-1"
68 alert_threshold:
69 type: string
70 description: "Set alert threshold in percentage for benchmark result"
71 default: "103%"
72 env:
73 AWS_ROLE: arn:aws:iam::904233116199:role/mldsa-native-ci
74 AMI_UBUNTU_LATEST_X86_64: ami-084568db4383264d4
75 AMI_UBUNTU_LATEST_AARCH64: ami-0c4e709339fa8521a
76
77 permissions:
78 contents: read
79 pull-requests: read
80
81 jobs:
82 start-ec2-runner:
83 name: Start ${{ inputs.name }} (${{ inputs.ec2_instance_type }})
84 permissions:
85 contents: 'read'
86 id-token: 'write'
87 runs-on: ubuntu-latest
88 if: ${{ always() }} # The point is to make this step non-cancellable,
89 # avoiding race conditions where an instance is started,
90 # but isn't yet done registering as a runner and reporting back.
91 outputs:
92 label: ${{ steps.start-ec2-runner.outputs.label }}
93 ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }}
94 steps:
95 - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
96 - name: Determine AMI ID
97 id: det_ami_id
98 run: |
99 if [[ "${{ inputs.ec2_ami }}" == "ubuntu-latest (x86_64)" ]]; then
100 AMI_ID=${{ env.AMI_UBUNTU_LATEST_X86_64 }}
101 elif [[ "${{ inputs.ec2_ami }}" == "ubuntu-latest (aarch64)" ]]; then
102 AMI_ID=${{ env.AMI_UBUNTU_LATEST_AARCH64 }}
103 elif [[ "${{ inputs.ec2_ami }}" == "ubuntu-latest (custom AMI)" ]]; then
104 AMI_ID=${{ inputs.ec2_ami_id }}
105 fi
106 echo "Using AMI ID: $AMI_ID"
107 echo "AMI_ID=$AMI_ID" >> $GITHUB_OUTPUT
108 - name: Configure AWS credentials
109 uses: aws-actions/configure-aws-credentials@00943011d9042930efac3dcd3a170e4273319bc8 # v5.1.0
110 with:
111 role-to-assume: ${{ env.AWS_ROLE }}
112 aws-region: ${{ inputs.aws_region }}
113 - name: Start EC2 runner
114 id: start-ec2-runner
115 uses: machulav/ec2-github-runner@a6dbcefcf8a31a861f5e078bb153ed332130c512 # v2.4.3
116 with:
117 mode: start
118 github-token: ${{ secrets.AWS_GITHUB_TOKEN }}
119 ec2-image-id: ${{ steps.det_ami_id.outputs.AMI_ID }}
120 ec2-instance-type: ${{ inputs.ec2_instance_type }}
121 subnet-id: subnet-094d73eb42eb6bf5b
122 security-group-id: sg-0282706dbc92a1579
123 bench_nix:
124 name: Bench (nix)
125 permissions:
126 contents: write
127 pull-requests: write
128 runs-on: ${{ needs.start-ec2-runner.outputs.label }}
129 needs: start-ec2-runner # required to start the main job when the runner is ready
130 if: ${{ inputs.compiler == '' }}
131 steps:
132 - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
133 - uses: ./.github/actions/bench
134 if: ${{ inputs.opt == 'all' || inputs.opt == 'opt' }}
135 with:
136 nix-verbose: ${{ inputs.verbose }}
137 name: ${{ inputs.name }}
138 cflags: ${{ inputs.cflags }}
139 archflags: ${{ inputs.archflags }}
140 ldflags: ${{ inputs.ldflags }}
141 opt: true
142 perf: ${{ inputs.perf }}
143 store_results: ${{ inputs.store_results }}
144 bench_extra_args: ${{ inputs.bench_extra_args }}
145 gh_token: ${{ secrets.AWS_GITHUB_TOKEN }}
146 - uses: ./.github/actions/bench
147 if: ${{ inputs.opt == 'all' || inputs.opt == 'no_opt' }}
148 with:
149 nix-verbose: ${{ inputs.verbose }}
150 name: ${{ inputs.name }} (no-opt)
151 cflags: ${{ inputs.cflags }}
152 archflags: ${{ inputs.archflags }}
153 ldflags: ${{ inputs.ldflags }}
154 opt: false
155 perf: ${{ inputs.perf }}
156 store_results: ${{ inputs.store_results }}
157 bench_extra_args: ${{ inputs.bench_extra_args }}
158 gh_token: ${{ secrets.AWS_GITHUB_TOKEN }}
159 alert_threshold: ${{ inputs.alert_threshold }}
160 bench_custom:
161 name: Bench (custom compiler)
162 permissions:
163 contents: write
164 pull-requests: write
165 runs-on: ${{ needs.start-ec2-runner.outputs.label }}
166 needs: start-ec2-runner # required to start the main job when the runner is ready
167 if: ${{ inputs.compiler != '' }}
168 steps:
169 - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
170 - uses: ./.github/actions/setup-apt
171 with:
172 packages: ${{ inputs.additional_packages }}
173 - name: Set compiler
174 run: |
175 echo "CC=${{ inputs.compiler }}" >> "$GITHUB_ENV"
176 - uses: ./.github/actions/bench
177 if: ${{ inputs.opt == 'all' || inputs.opt == 'opt' }}
178 with:
179 nix-shell: 'ci-bench'
180 custom-shell: 'bash'
181 nix-cache: false
182 nix-verbose: ${{ inputs.verbose }}
183 name: ${{ inputs.name }} (${{ inputs.compiler }})
184 cflags: ${{ inputs.cflags }}
185 archflags: ${{ inputs.archflags }}
186 ldflags: ${{ inputs.ldflags }}
187 opt: true
188 perf: ${{ inputs.perf }}
189 store_results: ${{ inputs.store_results }}
190 bench_extra_args: ${{ inputs.bench_extra_args }}
191 gh_token: ${{ secrets.AWS_GITHUB_TOKEN }}
192 - uses: ./.github/actions/bench
193 if: ${{ inputs.opt == 'all' || inputs.opt == 'no_opt' }}
194 with:
195 nix-shell: 'ci-bench'
196 custom-shell: 'bash'
197 nix-cache: false
198 nix-verbose: ${{ inputs.verbose }}
199 name: ${{ inputs.name }} (${{ inputs.compiler }}) (no-opt)
200 cflags: ${{ inputs.cflags }}
201 archflags: ${{ inputs.archflags }}
202 ldflags: ${{ inputs.ldflags }}
203 opt: false
204 perf: ${{ inputs.perf }}
205 store_results: ${{ inputs.store_results }}
206 bench_extra_args: ${{ inputs.bench_extra_args }}
207 gh_token: ${{ secrets.AWS_GITHUB_TOKEN }}
208 alert_threshold: ${{ inputs.alert_threshold }}
209 stop-ec2-runner:
210 name: Stop ${{ inputs.name }} (${{ inputs.ec2_instance_type }})
211 permissions:
212 contents: 'read'
213 id-token: 'write'
214 needs:
215 - start-ec2-runner
216 - bench_nix # required to wait when the main job is done
217 - bench_custom # required to wait when the main job is done
218 runs-on: ubuntu-latest
219 if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs
220 steps:
221 - name: Configure AWS credentials
222 uses: aws-actions/configure-aws-credentials@00943011d9042930efac3dcd3a170e4273319bc8 # v5.1.0
223 with:
224 role-to-assume: ${{ env.AWS_ROLE }}
225 aws-region: ${{ inputs.aws_region }}
226 - name: Stop EC2 runner
227 uses: machulav/ec2-github-runner@a6dbcefcf8a31a861f5e078bb153ed332130c512 # v2.4.3
228 with:
229 mode: stop
230 github-token: ${{ secrets.AWS_GITHUB_TOKEN }}
231 label: ${{ needs.start-ec2-runner.outputs.label }}
232 ec2-instance-id: ${{ needs.start-ec2-runner.outputs.ec2-instance-id }}