name: backend-pplnn

on:
  push:
    paths-ignore:
      - "demo/**"
      - "tools/**"

  pull_request:
    paths-ignore:
      - "demo/**"
      - "tools/**"
      - "docs/**"

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build_pplnn_cuda:
    runs-on: [self-hosted, linux-3090]
    container:
      image: openmmlab/mmdeploy:ubuntu20.04-cuda11.3
      options: "--gpus=all --ipc=host"
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          submodules: 'recursive'
      - name: Install dependencies
        run: |
          apt update && apt install unzip wget
          python3 -V
          python3 -m pip install openmim numpy
          python3 -m pip install -r requirements.txt
          python3 -m mim install $(cat requirements/codebases.txt | grep mmpretrain)
          python3 -m pip list
      - name: Build SDK
        run: |
          bash .github/scripts/linux/build.sh "cuda" "pplnn" \
              -Dpplcv_DIR=${pplcv_DIR} \
              -Dpplnn_DIR=${pplnn_DIR}
          ls build/lib
      - name: Install mmdeploy with pplnn
        id: badge_status
        run: |
          rm -rf .eggs && python3 -m pip install -e .
          export LD_LIBRARY_PATH="/root/workspace/mmdeploy/build/lib:${LD_LIBRARY_PATH}"
          python3 tools/check_env.py
          python3 -c 'import mmdeploy.apis.pplnn as pplnn_api; assert pplnn_api.is_available()'
      - name: create badge
        if: always()
        uses: RubbaBoy/BYOB@v1.2.1
        with:
          NAME: build_pplnn_cuda
          LABEL: 'build'
          STATUS: ${{ steps.badge_status.conclusion == 'success' && 'passing' || 'failing' }}
          COLOR: ${{ steps.badge_status.conclusion == 'success' && 'green' || 'red' }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


  build_pplnn_cpu:
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          submodules: 'recursive'
      - name: Install mmdeploy with pplnn
        id: badge_status
        run: |
          python -m pip install torch==1.8.2 torchvision==0.9.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu
          python -m pip install mmcv-lite protobuf==3.20.2
          python tools/scripts/build_ubuntu_x64_pplnn.py 8
          python -c 'import mmdeploy.apis.pplnn as pplnn_api; assert pplnn_api.is_available()'
      - name: create badge
        if: always()
        uses: RubbaBoy/BYOB@v1.2.1
        with:
          NAME: build_pplnn_cpu
          LABEL: 'build'
          STATUS: ${{ steps.badge_status.conclusion == 'success' && 'passing' || 'failing' }}
          COLOR: ${{ steps.badge_status.conclusion == 'success' && 'blue' || 'red' }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
