|
9 | 9 | default: '' |
10 | 10 | branches: |
11 | 11 | description: 'Space-separated list of branches to benchmark' |
12 | | - required: true |
13 | | - default: 'github_actions main' |
| 12 | + required: false |
| 13 | + default: 'main' |
14 | 14 | push: |
15 | 15 | branches: |
16 | 16 | - github_actions |
| 17 | + pull_request: |
| 18 | + branches: |
| 19 | + - main |
17 | 20 |
|
18 | 21 | jobs: |
| 22 | + # Job to generate the matrix configuration |
| 23 | + generate-matrix: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + outputs: |
| 26 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 27 | + steps: |
| 28 | + - name: Generate matrix |
| 29 | + id: set-matrix |
| 30 | + run: | |
| 31 | + # Print event information for debugging |
| 32 | + echo "Event name: ${{ github.event_name }}" |
| 33 | + echo "Branches input: '${{ github.event.inputs.branches }}'" |
| 34 | +
|
| 35 | + # Default branches based on event type |
| 36 | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 37 | + echo "Pull request detected. Using main and PR branch: ${{ github.head_ref }}" |
| 38 | + BRANCHES='["main", "${{ github.head_ref }}"]' |
| 39 | + elif [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ github.event.inputs.branches }}" ]]; then |
| 40 | + # Parse space-separated branches input into JSON array |
| 41 | + echo "Workflow dispatch with branches input detected" |
| 42 | + BRANCHES_INPUT="${{ github.event.inputs.branches }}" |
| 43 | + BRANCHES="[" |
| 44 | + for branch in $BRANCHES_INPUT; do |
| 45 | + if [[ "$BRANCHES" != "[" ]]; then |
| 46 | + BRANCHES="$BRANCHES, " |
| 47 | + fi |
| 48 | + BRANCHES="$BRANCHES\"$branch\"" |
| 49 | + echo "Adding branch to matrix: $branch" |
| 50 | + done |
| 51 | + BRANCHES="$BRANCHES]" |
| 52 | + else |
| 53 | + echo "Default event type. Using main and github_actions branches" |
| 54 | + BRANCHES='["main", "github_actions"]' |
| 55 | + fi |
| 56 | +
|
| 57 | + echo "Generated branches matrix: $BRANCHES" |
| 58 | + echo "matrix={\"jdk\":[24],\"isa\":[\"isa-avx512f\"],\"branch\":$BRANCHES}" >> $GITHUB_OUTPUT |
| 59 | +
|
19 | 60 | test-avx512: |
| 61 | + needs: generate-matrix |
20 | 62 | concurrency: |
21 | | - group: ${{ matrix.isa }}-${{ matrix.jdk }} |
| 63 | + group: ${{ matrix.isa }}-${{ matrix.jdk }}-${{ matrix.branch }} |
22 | 64 | cancel-in-progress: false |
23 | 65 | strategy: |
24 | | - matrix: |
25 | | - jdk: [ 24 ] |
26 | | - isa: [ isa-avx512f ] |
| 66 | + matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }} |
27 | 67 | runs-on: ${{ matrix.isa }} |
28 | 68 | steps: |
29 | 69 | - name: verify-avx512 |
@@ -64,100 +104,59 @@ jobs: |
64 | 104 | echo "version=$VERSION" >> $GITHUB_OUTPUT |
65 | 105 | echo "Current branch has version $VERSION" |
66 | 106 |
|
67 | | - # Save the current branch name and jvector-examples directory |
68 | | - - name: Save current branch and jvector-examples |
| 107 | + # Print debug information about the current job |
| 108 | + - name: Print job information |
69 | 109 | run: | |
70 | | - # Save current branch name |
71 | | - CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) |
72 | | - echo "CURRENT_BRANCH=$CURRENT_BRANCH" >> $GITHUB_ENV |
| 110 | + echo "Running benchmark for:" |
| 111 | + echo " - Branch: ${{ matrix.branch }}" |
| 112 | + echo " - JDK: ${{ matrix.jdk }}" |
| 113 | + echo " - ISA: ${{ matrix.isa }}" |
73 | 114 |
|
74 | | - # Create a backup of the jvector-examples directory |
75 | | - mkdir -p /tmp/jvector-backup |
76 | | - cp -r jvector-examples /tmp/jvector-backup/ |
| 115 | + # Checkout the branch specified in the matrix |
| 116 | + - name: Checkout branch |
| 117 | + run: | |
| 118 | + echo "Checking out branch: ${{ matrix.branch }}" |
| 119 | + git checkout ${{ matrix.branch }} || { echo "Failed to checkout branch ${{ matrix.branch }}"; exit 1; } |
| 120 | +
|
| 121 | + # Create a directory to store benchmark results |
| 122 | + - name: Create results directory |
| 123 | + run: mkdir -p benchmark_results |
77 | 124 |
|
78 | | - # Build the original branch to ensure jvector-examples is compiled |
79 | | - - name: Build original branch |
| 125 | + # Build the branch |
| 126 | + - name: Build branch |
80 | 127 | run: mvn -B -Punix-amd64-profile package --file pom.xml |
81 | 128 |
|
82 | | - # Parse the branches input and run benchmarks for each branch |
83 | | - - name: Run benchmarks for each branch |
| 129 | + # Run the benchmark if jvector-examples exists |
| 130 | + - name: Run benchmark |
84 | 131 | run: | |
85 | | - # Debug: Print the branches input |
86 | | - echo "Branches input: '${{ github.event.inputs.branches }}'" |
87 | | -
|
88 | | - # Get the list of branches to benchmark |
89 | | - # If the input is empty, use the default value from workflow definition |
90 | | - BRANCHES_INPUT="${{ github.event.inputs.branches }}" |
91 | | - if [ -z "$BRANCHES_INPUT" ]; then |
92 | | - echo "No branches specified, using default: 'github_actions main'" |
93 | | - BRANCHES_INPUT="github_actions main" |
| 132 | + # Check if jvector-examples directory and AutoBenchYAML class exist |
| 133 | + if [ ! -d "jvector-examples" ]; then |
| 134 | + echo "Warning: jvector-examples directory not found in branch ${{ matrix.branch }}. Skipping benchmark." |
| 135 | + exit 0 |
94 | 136 | fi |
95 | 137 |
|
96 | | - echo "Parsing branches from: '$BRANCHES_INPUT'" |
97 | | - IFS=' ' read -r -a BRANCHES <<< "$BRANCHES_INPUT" |
98 | | -
|
99 | | - # Debug: Print the parsed branches |
100 | | - echo "Parsed ${#BRANCHES[@]} branches: ${BRANCHES[*]}" |
101 | | -
|
102 | | - # Create a directory to store all benchmark results |
103 | | - mkdir -p benchmark_results |
104 | | -
|
105 | | - # If still no branches, add current branch |
106 | | - if [ ${#BRANCHES[@]} -eq 0 ]; then |
107 | | - echo "No branches parsed, adding current branch" |
108 | | - CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) |
109 | | - BRANCHES=("$CURRENT_BRANCH") |
110 | | - echo "Using current branch: $CURRENT_BRANCH" |
| 138 | + # Check if the jar with dependencies was built |
| 139 | + JAR_COUNT=$(ls jvector-examples/target/jvector-examples-*-jar-with-dependencies.jar 2>/dev/null | wc -l) |
| 140 | + if [ "$JAR_COUNT" -eq 0 ]; then |
| 141 | + echo "Warning: No jar with dependencies found in branch ${{ matrix.branch }}. Skipping benchmark." |
| 142 | + exit 0 |
111 | 143 | fi |
112 | 144 |
|
113 | | - # Loop through each branch |
114 | | - for branch in "${BRANCHES[@]}"; do |
115 | | - echo "Processing branch: $branch" |
116 | | -
|
117 | | - # Checkout the branch |
118 | | - git checkout $branch || { echo "Failed to checkout branch $branch"; continue; } |
119 | | -
|
120 | | - # Save the original jvector-examples directory from this branch if it exists |
121 | | - if [ -d "jvector-examples" ]; then |
122 | | - echo "Saving original jvector-examples from branch $branch" |
123 | | - mkdir -p /tmp/branch-backup |
124 | | - rm -rf /tmp/branch-backup/jvector-examples || true |
125 | | - cp -r jvector-examples /tmp/branch-backup/ |
126 | | - fi |
127 | | -
|
128 | | - # Replace jvector-examples with the one from the original branch |
129 | | - echo "Replacing jvector-examples with the one from the original branch" |
130 | | - rm -rf jvector-examples |
131 | | - cp -r /tmp/jvector-backup/jvector-examples . |
132 | | -
|
133 | | - # Build the branch with the injected jvector-examples |
134 | | - echo "Building branch $branch with injected jvector-examples" |
135 | | - mvn -B -Punix-amd64-profile package --file pom.xml |
136 | | -
|
137 | | - # Run the benchmark using the newly built jar with the branch's code and injected jvector-examples |
138 | | - echo "Running benchmark for branch $branch" |
139 | | - java ${{ matrix.jdk >= 20 && '--enable-native-access=ALL-UNNAMED --add-modules=jdk.incubator.vector' || '' }} \ |
140 | | - -jar jvector-examples/target/jvector-examples-*-jar-with-dependencies.jar \ |
141 | | - --config jvector-examples/yaml-configs/autoDefault.yml \ |
142 | | - --output ${branch}-bench-results |
143 | | -
|
144 | | - # Move the results to the benchmark_results directory |
145 | | - mv ${branch}-bench-results.csv benchmark_results/ |
146 | | - mv ${branch}-bench-results.json benchmark_results/ || true |
147 | | -
|
148 | | - # Restore the original jvector-examples directory for this branch |
149 | | - if [ -d "/tmp/branch-backup/jvector-examples" ]; then |
150 | | - echo "Restoring original jvector-examples for branch $branch" |
151 | | - rm -rf jvector-examples |
152 | | - cp -r /tmp/branch-backup/jvector-examples . |
153 | | - fi |
154 | | -
|
155 | | - echo "Completed benchmarks for branch: $branch" |
156 | | - done |
157 | | -
|
158 | | - # Return to the original branch |
159 | | - echo "Returning to original branch: $CURRENT_BRANCH" |
160 | | - git checkout $CURRENT_BRANCH || echo "Failed to return to original branch $CURRENT_BRANCH" |
| 145 | + # Run the benchmark |
| 146 | + echo "Running benchmark for branch ${{ matrix.branch }}" |
| 147 | + java ${{ matrix.jdk >= 20 && '--enable-native-access=ALL-UNNAMED --add-modules=jdk.incubator.vector' || '' }} \ |
| 148 | + -jar jvector-examples/target/jvector-examples-*-jar-with-dependencies.jar \ |
| 149 | + --config jvector-examples/yaml-configs/autoDefault.yml \ |
| 150 | + --output ${{ matrix.branch }}-bench-results || { |
| 151 | + echo "Warning: Benchmark failed for branch ${{ matrix.branch }}. This may be expected if the branch doesn't have the required code." |
| 152 | + exit 0 |
| 153 | + } |
| 154 | +
|
| 155 | + # Move the results to the benchmark_results directory |
| 156 | + mv ${{ matrix.branch }}-bench-results.csv benchmark_results/ || true |
| 157 | + mv ${{ matrix.branch }}-bench-results.json benchmark_results/ || true |
| 158 | +
|
| 159 | + echo "Completed benchmarks for branch: ${{ matrix.branch }}" |
161 | 160 |
|
162 | 161 | - name: Upload Individual Benchmark Results |
163 | 162 | uses: actions/upload-artifact@v4 |
|
0 commit comments