From 342a935e41db906d8de4fb7d606a6abe430dba1f Mon Sep 17 00:00:00 2001
From: Proton <feisuzhu@163.com>
Date: Mon, 19 Dec 2022 15:22:10 +0800
Subject: [PATCH] [ci] Reenable AMDGPU CI, disable OpenGL tests in AMDGPU task
 (#6887)

---
 .github/workflows/scripts/common-utils.sh |  1 +
 .github/workflows/testing.yml             | 67 +++++++++++++++++++++++
 2 files changed, 68 insertions(+)

diff --git a/.github/workflows/scripts/common-utils.sh b/.github/workflows/scripts/common-utils.sh
index aa81fd9043d76..dea0b353e85ce 100644
--- a/.github/workflows/scripts/common-utils.sh
+++ b/.github/workflows/scripts/common-utils.sh
@@ -170,6 +170,7 @@ function ci-docker-run-amdgpu {
     ci-docker-run \
         --device=/dev/kfd \
         --device=/dev/dri \
+        --device=/dev/vga_arbiter \
         --group-add=video \
         -e DISPLAY=:$i \
         -e GPU_TEST=ON \
diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml
index 07253dea695b4..00691b8c09e12 100644
--- a/.github/workflows/testing.yml
+++ b/.github/workflows/testing.yml
@@ -268,6 +268,73 @@ jobs:
           path: taichi-release-tests/bad-compare/*
           retention-days: 7
 
+  build_and_test_amdgpu_linux:
+    name: Build and Test (AMDGPU)
+    needs: check_files
+    timeout-minutes: ${{ github.event.schedule != '0 18 * * *' && 90 || 120 }}
+    runs-on: [self-hosted, amdgpu]
+    steps:
+      - uses: actions/checkout@v3
+        with:
+          submodules: 'recursive'
+          fetch-depth: '0'
+
+      - name: Prepare Environment
+        run: |
+          . .github/workflows/scripts/common-utils.sh
+          prepare-build-cache
+          echo CI_DOCKER_RUN_EXTRA_ARGS="-v $(pwd):/home/dev/taichi" >> $GITHUB_ENV
+
+      - name: Build & Install
+        run: |
+          [[ ${{needs.check_files.outputs.run_job}} == false ]] && exit 0
+          . .github/workflows/scripts/common-utils.sh
+
+          ci-docker-run-amdgpu --name taichi-build \
+            registry.taichigraphics.com/taichidev-ubuntu18.04.amdgpu:v0.0.3 \
+            /home/dev/taichi/.github/workflows/scripts/unix-build.sh
+
+        env:
+          PY: py38
+          PROJECT_NAME: taichi
+          TAICHI_CMAKE_ARGS: >-
+            -DTI_WITH_CUDA:BOOL=OFF
+            -DTI_WITH_VULKAN:BOOL=OFF
+            -DTI_WITH_OPENGL:BOOL=OFF
+            -DTI_BUILD_TESTS:BOOL=ON
+
+      - name: Test
+        id: test
+        run: |
+          [[ ${{needs.check_files.outputs.run_job}} == false ]] && exit 0
+          . .github/workflows/scripts/common-utils.sh
+
+          ci-docker-run-amdgpu --name taichi-test \
+             registry.taichigraphics.com/taichidev-ubuntu18.04.amdgpu:v0.0.3 \
+             /home/dev/taichi/.github/workflows/scripts/unix_test.sh
+        env:
+          PY: py38
+          TI_WANTED_ARCHS: 'cpu,amdgpu'
+          TI_DEVICE_MEMORY_GB: '1'
+          TI_RUN_RELEASE_TESTS: '0'
+
+      - name: Save wheel if test failed
+        if: failure() && steps.test.conclusion == 'failure'
+        uses: actions/upload-artifact@v3
+        with:
+          name: broken-wheel
+          path: dist/*
+          retention-days: 7
+
+      - name: Save Bad Captures
+        if: failure() && steps.test.conclusion == 'failure'
+        uses: actions/upload-artifact@v3
+        with:
+          name: bad-captures
+          path: taichi-release-tests/bad-compare/*
+          retention-days: 7
+
+
   build_and_test_windows:
     name: Build and Test Windows
     needs: check_files