Skip to content

Commit e4a5eb2

Browse files
committed
Merge main into add-tle_gpu_alloc
2 parents e3d9178 + 553537f commit e4a5eb2

1,537 files changed

Lines changed: 140990 additions & 49907 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
<!-- PR Title
2-
[component] brief description
3-
component options:
4-
- BUILD
5-
- CI/CD
6-
- DOC
7-
- FRONTEND
8-
- BACKEND
9-
- AUTOTUNER
10-
- CACHE
11-
- LAYOUTS
12-
- PIPELINE
13-
- PROTON
14-
- TEST
15-
- OTHER
1+
<!-- PR Title Format:
2+
[TLE][BUILD][TEST][CI/CD][DOC][PROTON][BACKEND][FLIR] Brief description
3+
[LANGUAGE][AUTOTUNER][LAYOUT][PIPELINE][WarpSpecialization] Brief description
4+
Do not set the following title tags: [FEATURE][BUG][FixBug][Refine] ...
165
-->

.github/actions/check-backend-changed/action.yml

Lines changed: 108 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
# Copyright 2025- FlagOS Contributors
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in all
11+
# copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
121
name: 'Check if backend-relevant files changed'
222
description: 'Determine whether the CI for a given backend should run or be skipped'
323
inputs:
@@ -26,7 +46,9 @@ runs:
2646
2747
# Check if the workflow is triggered by a Pull Request event
2848
if [ "${{ github.event_name }}" == "pull_request" ]; then
29-
FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
49+
# Use three-dot syntax to compare the merge base (common ancestor) with the HEAD commit
50+
# This ensures we only detect files changed in this PR, excluding changes already merged to base branch
51+
FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }}...${{ github.sha }})
3052
else
3153
# Handle 'push' events (or other events where 'base_ref' isn't applicable)
3254
# Check if the 'before' SHA is all zeros, which indicates a newly created/pushed branch
@@ -41,46 +63,95 @@ runs:
4163
fi
4264
fi
4365
44-
SHOULD_SKIP=true
45-
# If no changes were made, we need to run the CI process to avoid any misjudgments.
46-
if [ -z "$FILES" ]; then
47-
echo "No files changed, running CI by default"
48-
SHOULD_SKIP=false
49-
else
50-
while IFS= read -r file; do
51-
# Skip empty lines
52-
if [ -z "$file" ]; then
53-
continue
54-
fi
55-
# Current workflow file changed → always run
56-
if [[ "$file" == "$CURRENT_WORKFLOW" ]]; then
57-
echo "'$file' -> This workflow file changed, need to run"
58-
SHOULD_SKIP=false
59-
break
60-
fi
61-
# Check if the file is a documentation file (same logic as check-docs-only)
62-
if [[ ! "$file" =~ CMakeLists\.txt$ ]] && [[ "$file" =~ (\.(md|yml|txt|png|jpg|jpeg|gif|svg|ico|webp)$|CODEOWNERS$) ]]; then
63-
echo "'$file' -> Doc file, not relevant to CI decision"
64-
continue
66+
NEED_CI_TEST=(
67+
"bin"
68+
"cmake"
69+
"include"
70+
"lib"
71+
"python"
72+
"scripts"
73+
"test"
74+
"unittest"
75+
"utils"
76+
"third_party/proton"
77+
"third_party/tle"
78+
"third_party/f2reduce"
79+
"CMakeLists.txt"
80+
"Makefile"
81+
"MANIFEST.in"
82+
"pyproject.toml"
83+
"setup.py"
84+
".github/actions"
85+
".github/workflows/code-format-check.yml"
86+
)
87+
88+
# ============================================================
89+
# Function: Check if file should trigger CI test
90+
# ============================================================
91+
need_ci_test() {
92+
local file="$1"
93+
for item in "${NEED_CI_TEST[@]}"; do
94+
# Check if it's a directory (ends with / or no extension)
95+
# or check if file matches exactly or is under the directory
96+
if [[ "$file" == "$item" ]] || [[ "$file" == "$item/"* ]]; then
97+
return 0
6598
fi
66-
# It is a code file. Check whether it lives inside third_party/
67-
if [[ "$file" == third_party/* ]]; then
68-
if [[ "$file" == third_party/${BACKEND}/* ]]; then
69-
echo "'$file' -> Backend '$BACKEND' file changed, need to run"
70-
SHOULD_SKIP=false
71-
break
72-
else
73-
echo "'$file' -> Other backend file, not relevant to '$BACKEND'"
74-
continue
75-
fi
76-
else
77-
# Core code file (outside third_party/) — affects all backends
78-
echo "'$file' -> Core code file changed, need to run"
99+
done
100+
return 1
101+
}
102+
103+
104+
# ================================================================
105+
# MAIN LOGIC: Determine whether to run CI
106+
# ================================================================
107+
# CI will run if ANY changed file matches one of these three rules:
108+
# 1. The current workflow file itself
109+
# 2. The NEED_CI_TEST white list above
110+
# 3. third_party/${BACKEND}/ directory
111+
#
112+
# Otherwise, CI will be skipped.
113+
#
114+
# Documentation files (markdown, images, text files, etc.) are automatically
115+
# skipped and do NOT trigger CI, unless they are CMakeLists.txt.
116+
# ================================================================
117+
SHOULD_SKIP=true
118+
119+
while IFS= read -r file; do
120+
# Skip empty lines
121+
if [ -z "$file" ]; then
122+
continue
123+
fi
124+
125+
# Skip documentation files
126+
if [[ ! "$file" =~ CMakeLists\.txt$ ]] && [[ "$file" =~ (\.(md|txt|png|jpg|jpeg|gif|svg|ico|webp)$|CODEOWNERS$) ]]; then
127+
echo "'$file' -> Doc file, not relevant to CI decision"
128+
continue
129+
fi
130+
131+
# Current workflow file changed → always run
132+
if [[ "$file" == "$CURRENT_WORKFLOW" ]]; then
133+
echo "'$file' -> This workflow file changed, need to run"
134+
SHOULD_SKIP=false
135+
break
136+
fi
137+
138+
# Files/directories in NEED_CI_TEST → run CI
139+
if need_ci_test "$file"; then
140+
echo "'$file' -> In NEED_CI_TEST list, need to run"
141+
SHOULD_SKIP=false
142+
break
143+
fi
144+
145+
# It is a code file. Check whether it lives inside third_party/ or .github/workflows/benchmark/
146+
if [[ "$file" == third_party/* ]] || [[ "$file" == .github/workflows/benchmark/* ]]; then
147+
if [[ "$file" == third_party/${BACKEND}/* ]] || [[ "$file" == .github/workflows/benchmark/${BACKEND}/* ]]; then
148+
echo "'$file' -> Backend '$BACKEND' file changed, need to run"
79149
SHOULD_SKIP=false
80150
break
81151
fi
82-
done <<< "$FILES"
83-
fi
152+
fi
153+
done <<< "$FILES"
154+
84155
echo "should_skip=$SHOULD_SKIP" >> $GITHUB_OUTPUT
85156
if [ "$SHOULD_SKIP" == "true" ]; then
86157
echo "✅ No relevant files changed for backend '$BACKEND'. Will skip CI."

.github/actions/check-docs-only/action.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
# Copyright 2025- FlagOS Contributors
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in all
11+
# copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
121
name: 'Check if only docs changed'
222
description: 'Check if only documentation files were modified'
323
outputs:
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright 2025- FlagOS Contributors
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in all
11+
# copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
name: 'Cleanup FlagTree Environment'
22+
description: 'Purge previous FlagTree installations to ensure a fresh build'
23+
24+
runs:
25+
using: 'composite'
26+
steps:
27+
- name: Purge previous FlagTree installations
28+
shell: bash
29+
run: |
30+
set -x
31+
echo "Starting environment cleanup..."
32+
33+
SITE_PACKAGES=$(python3 -c "import sysconfig; print(sysconfig.get_path('purelib'))")
34+
35+
# 1. Normalize the path to resolve symlinks and eliminate '..'
36+
SITE_PACKAGES=$(realpath -m "$SITE_PACKAGES" 2>/dev/null || readlink -f "$SITE_PACKAGES" 2>/dev/null || echo "$SITE_PACKAGES")
37+
38+
# 2. Reject if the path still contains '..' after normalization
39+
if [[ "$SITE_PACKAGES" == *".."* ]]; then
40+
echo "Error: Path contains '..' after normalization. Aborting."
41+
exit 1
42+
fi
43+
44+
# 3. Ensure it is a real, existing directory
45+
if [[ ! -d "$SITE_PACKAGES" ]]; then
46+
echo "Error: Directory '$SITE_PACKAGES' does not exist. Aborting."
47+
exit 1
48+
fi
49+
50+
# 4. Ensure it is an absolute path located in a standard Python directory
51+
# Check if it contains 'site-packages' or 'dist-packages' as the directory name
52+
if [[ ! "$SITE_PACKAGES" =~ ^/.*/python[^/]*/(site|dist)-packages/?$ ]]; then
53+
echo "Error: '$SITE_PACKAGES' is not a recognized Python package directory. Aborting."
54+
exit 1
55+
fi
56+
57+
# 5. Reject overly broad or critical system directories
58+
if [[ "$SITE_PACKAGES" == "/" ]] ||
59+
[[ "$SITE_PACKAGES" == "/root" ]] ||
60+
[[ "$SITE_PACKAGES" == "/home" ]] ||
61+
[[ "$SITE_PACKAGES" == "/usr" ]] ||
62+
[[ "$SITE_PACKAGES" == "/usr/lib" ]]; then
63+
echo "Error: Path '$SITE_PACKAGES' is too broad. Aborting."
64+
exit 1
65+
fi
66+
67+
# 1. Attempt to gracefully uninstall via pip
68+
python3 -m pip uninstall -y flagtree --break-system-packages || true
69+
70+
# 2. Remove temporary directories left by interrupted pip processes
71+
rm -rf "$SITE_PACKAGES"/~* || true
72+
73+
# 3. Force remove any remaining metadata and code directories
74+
rm -rf "$SITE_PACKAGES"/flagtree*dist-info || true
75+
rm -rf "$SITE_PACKAGES"/triton || true
76+
77+
echo "Environment cleanup completed."
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright 2025- FlagOS Contributors
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in all
11+
# copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
name: 'Clear Cache if Labeled'
22+
description: 'Check if PR has specific backend ClearCache label and clear cache if present'
23+
24+
inputs:
25+
github-token:
26+
description: 'GitHub token for API access'
27+
required: true
28+
backend:
29+
description: 'The backend name to check for (e.g., mthreads)'
30+
required: true
31+
32+
runs:
33+
using: 'composite'
34+
steps:
35+
- name: Check specific ClearCache label
36+
id: check
37+
uses: actions/github-script@v6
38+
with:
39+
github-token: ${{ inputs.github-token }}
40+
script: |
41+
const backend = '${{ inputs.backend }}';
42+
const expectedLabel = `ClearCache:${backend}`;
43+
44+
if (context.eventName !== 'pull_request' && context.eventName !== 'pull_request_target') {
45+
console.log('ℹ️ Not a PR event, skipping label check');
46+
core.setOutput('has_clear_cache_label', 'false');
47+
return;
48+
}
49+
50+
if (!context.payload || !context.payload.pull_request) {
51+
console.log('⚠️ No pull_request payload found, skipping label check');
52+
core.setOutput('has_clear_cache_label', 'false');
53+
return;
54+
}
55+
56+
const prNumber = context.payload.pull_request.number;
57+
try {
58+
const { data: prData } = await github.rest.pulls.get({
59+
owner: context.repo.owner,
60+
repo: context.repo.repo,
61+
pull_number: prNumber
62+
});
63+
64+
const labels = (prData.labels || []).map(label => label.name);
65+
console.log(`Current PR labels:`, labels.join(', ') || '(no labels)');
66+
67+
const hasClearCache = labels.includes(expectedLabel);
68+
console.log(`🔍 Has "${expectedLabel}" label:`, hasClearCache ? '✅ YES' : '❌ NO');
69+
70+
core.setOutput('has_clear_cache_label', hasClearCache ? 'true' : 'false');
71+
} catch (err) {
72+
console.log('❌ Error checking PR labels:', err.message || err);
73+
core.setOutput('has_clear_cache_label', 'false');
74+
}
75+
76+
- name: Clear cache if label present
77+
id: cleanup
78+
if: steps.check.outputs.has_clear_cache_label == 'true'
79+
shell: bash
80+
run: |
81+
echo "========================================="
82+
echo "🧹 Clearing cache for ${{ inputs.backend }} backend."
83+
echo "========================================="
84+
85+
echo "-> Clearing cache..."
86+
echo "-> Remove ~/.triton/cache"
87+
rm -rf ~/.triton/cache || true
88+
echo "-> Remove ~/.flaggems"
89+
rm -rf ~/.flaggems || true
90+
echo "-> Clear cache done"

0 commit comments

Comments
 (0)