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