diff --git a/.github/workflows/auto-update-translator-cid.yml b/.github/workflows/auto-update-translator-cid.yml new file mode 100644 index 0000000000..1dab04b9f4 --- /dev/null +++ b/.github/workflows/auto-update-translator-cid.yml @@ -0,0 +1,121 @@ + +name: Automate update Translator cid +on: + workflow_dispatch: + schedule: + - cron: '5 23 * * *' + +env: + PR_BRANCH: bot/update_translator_cid + +jobs: + update-config: + runs-on: + - glados + - spr + - runner-0.0.18 + defaults: + run: + shell: bash -noprofile --norc -eo pipefail -c "source /home/runner/intel/oneapi/setvars.sh > /dev/null; source {0}" + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # search the opened PR that has branch "bot/update_translator_cid", no new PR as long as the target PR is open + - name: Search the opened PR that has branch ${{ env.PR_BRANCH }} + env: + GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} + run: | + if gh pr list | grep "${PR_BRANCH}"; then + echo "Bot PR is still open" + echo "TARGET_PRID=$(gh pr list --search "head:${PR_BRANCH}" --json number --jq ".[].number")" >> $GITHUB_ENV + fi + + # if $TARGET_PRID is null, target PR is meged or closed or never been raised. In that case search for the latest valid translator cid + - name: Load pip cache + if: ${{ env.TARGET_PRID == null }} + uses: ./.github/actions/load + env: + CACHE_NUMBER: 1 + with: + path: $HOME/.cache/pip + key: pip-3.10-${{ hashFiles('python/pyproject.toml', 'python/setup.py') }}-${{ env.CACHE_NUMBER }} + + - name: Install Python 3.10 + if: ${{ env.TARGET_PRID == null }} + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Setup PyTorch with IPEX + if: ${{ env.TARGET_PRID == null }} + uses: ./.github/actions/setup-pytorch + with: + repository: Stonepia/pytorch + ref: "" + + - name: Setup IPEX + if: ${{ env.TARGET_PRID == null }} + uses: ./.github/actions/setup-ipex + + - name: Install test dependencies + if: ${{ env.TARGET_PRID == null }} + run: | + pip install pytest pytest-xdist pytest-rerunfailures pytest-select pytest-timeout expecttest + pip install git+https://github.com/kwasd/pytest-capturewarnings-ng.git@v1.2.0 + + - name: Get commit ID from Triton's spirv-llvm-translator.conf + if: ${{ env.TARGET_PRID == null }} + run: echo "CID_CURRENT=$(cat ./lib/Target/SPIRV/spirv-llvm-translator.conf)" >> $GITHUB_ENV + + - name: Checkout SPIRV-LLVM-Translator + if: ${{ env.TARGET_PRID == null }} + uses: actions/checkout@v4 + with: + repository: KhronosGroup/SPIRV-LLVM-Translator + ref: main + fetch-depth: 0 + path: external/SPIRV-LLVM-Translator + + - name: Get the latest commit ID from SPIRV-LLVM-Translator + if: ${{ env.TARGET_PRID == null }} + run: | + echo "CID_LATEST=$(git -C external/SPIRV-LLVM-Translator rev-parse HEAD)" >> $GITHUB_ENV + + # the latest valid cid has been weitten to spirv-llvm-translator.conf + - name: Search the latest valid Translator cid + if: ${{ env.TARGET_PRID == null }} + run: | + env + ./scripts/check_update_tranlator_cid.sh $CID_LATEST $CID_CURRENT + if git status --porcelain ./lib/Target/SPIRV/spirv-llvm-translator.conf | grep '^ M'; then + echo "MODIFIED=true" >> $GITHUB_ENV + echo "spirv-llvm-translator.conf has been modified" + fi + + # raise PR by bot + - name: Create PR if config is updated + if: ${{ env.TARGET_PRID == null && env.MODIFIED == 'true' }} + env: + GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + + if git show-ref --verify --quiet "refs/remotes/origin/${PR_BRANCH}"; then + echo "${PR_BRANCH} already exist, deleting..." + git push origin --delete "${PR_BRANCH}" + else + echo "${PR_BRANCH} not exist" + fi + + git checkout llvm-target # make sure checkout a new branch that is based on llvm-target + git checkout -b ${PR_BRANCH} + git branch --show-current # bot/update_translator_cid + git status + git add ./lib/Target/SPIRV/spirv-llvm-translator.conf + git commit -m "Update spirv-llvm-translator.conf" + git push origin ${PR_BRANCH} + pr_url=$(gh pr create --title "[github-bot] Update spirv-llvm-translator.conf" --body "Automated PR to update translator commit id." --reviewer whitneywhtsang --head ${PR_BRANCH} --base llvm-target) diff --git a/.github/workflows/update-spirv-llvm-translator.yml b/.github/workflows/update-spirv-llvm-translator.yml deleted file mode 100644 index 2c9521611d..0000000000 --- a/.github/workflows/update-spirv-llvm-translator.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: Get the latest commit from SPIRV-LLVM-Translator - -on: -# schedule: -# - cron: "0 0 * * *" - pull_request: - branches: - - lijunhui/translator_cid - push: - branches: - - lijunhui/translator_cid - -jobs: - update-translator-commit: - runs-on: - - glados - - spr - - runner-0.0.18 - defaults: - run: - shell: bash -noprofile --norc -eo pipefail -c "source /home/runner/intel/oneapi/setvars.sh > /dev/null; source {0}" - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Load pip cache - id: pip-cache - uses: ./.github/actions/load - env: - # Increase this value to reset cache - CACHE_NUMBER: 1 - with: - path: $HOME/.cache/pip - key: pip-3.10-${{ hashFiles('python/pyproject.toml', 'python/setup.py') }}-${{ env.CACHE_NUMBER }} - - - name: Install Python 3.10 - uses: actions/setup-python@v5 - with: - python-version: '3.10' - - - name: Setup PyTorch with IPEX - uses: ./.github/actions/setup-pytorch - with: - repository: Stonepia/pytorch - ref: "" - - - name: Setup IPEX - uses: ./.github/actions/setup-ipex - - - name: Install test dependencies - run: | - pip install pytest pytest-xdist pytest-rerunfailures pytest-select pytest-timeout expecttest - pip install git+https://github.com/kwasd/pytest-capturewarnings-ng.git@v1.2.0 - - - name: Get commit ID from Triton's spirv-llvm-translator.conf - id: translator-commit-in-triton - run: echo "cid_current=$(cat ./lib/Target/SPIRV/spirv-llvm-translator.conf)" >> $GITHUB_ENV - - - name: Checkout SPIRV-LLVM-Translator - uses: actions/checkout@v4 - with: - repository: KhronosGroup/SPIRV-LLVM-Translator - ref: main - fetch-depth: 0 - path: external/SPIRV-LLVM-Translator - - - name: Get the latest commit ID from SPIRV-LLVM-Translator - id: translator-latest-commit - run: | - echo "cid_latest=$(git -C external/SPIRV-LLVM-Translator rev-parse HEAD)" >> $GITHUB_ENV - - - name: Run check_update.sh - run: | - ./scripts/check_update_tranlator_cid.sh ${{ env.cid_latest }} ${{ env.cid_current }} diff --git a/scripts/check_update_tranlator_cid.sh b/scripts/check_update_tranlator_cid.sh index 9e6dd84608..0848d9dc3b 100755 --- a/scripts/check_update_tranlator_cid.sh +++ b/scripts/check_update_tranlator_cid.sh @@ -23,6 +23,7 @@ COMMIT_IDS=$(git -C $TRITON_PROJ/external/SPIRV-LLVM-Translator log --format="%H # check every commit ids cd $TRITON_PROJ +FOUND=false for cid in $COMMIT_IDS; do echo "$cid" > ./lib/Target/SPIRV/spirv-llvm-translator.conf if ! ./scripts/compile-triton.sh --clean; then @@ -34,8 +35,13 @@ for cid in $COMMIT_IDS; do if ./scripts/test-triton.sh --skip-deps; then echo "Tests passed for translator commit $cid" echo "A newer commit found: $cid" + FOUND=true break else echo "Tests failed for translator commit $cid" fi done + +if [ "$FOUND" = false ]; then + git restore ./lib/Target/SPIRV/spirv-llvm-translator.conf +fi