## Copyright 2023 Intel Corporation
## SPDX-License-Identifier: Apache-2.0

name: CI GPU ICX Linux Workflow
on:
  push:
  workflow_dispatch:

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

jobs:

  build-gpu:
    secrets: inherit
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker_gpu.yml@main
    with:
      submodules: true
      image: ubuntu:22.04
      artifact-out: build-gpu
      artifact-path: ./build/install ./build/openvkl/build
      env-from-files: .github/deps/dpcpp-icx.env
      cmd: |
        module load cmake/3.25.3
        gitlab/build.sh -D BUILD_OPENVDB=OFF \
                        -D OPENVKL_EXTRA_OPTIONS="-DOPENVKL_ENABLE_DEVICE_GPU=ON \
                           -DOPENVKL_DEVICE_CPU_STRUCTURED_REGULAR=OFF \
                           -DOPENVKL_DEVICE_CPU_STRUCTURED_REGULAR_LEGACY=ON"

  build-gpu-rel-with-dbg-info:
    secrets: inherit
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker_gpu.yml@main
    with:
      submodules: true
      image: ubuntu:22.04
      env-from-files: .github/deps/dpcpp-icx.env
      cmd: |
        module load cmake/3.25.3
        gitlab/build.sh -D BUILD_OPENVDB=OFF \
                        -D OPENVKL_EXTRA_OPTIONS="-DOPENVKL_ENABLE_DEVICE_GPU=ON \
                           -DOPENVKL_DEVICE_CPU_STRUCTURED_REGULAR=OFF \
                           -DOPENVKL_DEVICE_CPU_STRUCTURED_REGULAR_LEGACY=ON \
                           -D CMAKE_BUILD_TYPE=RelWithDebInfo"

  build-gpu-debug:
    secrets: inherit
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker_gpu.yml@main
    with:
      submodules: true
      image: ubuntu:22.04
      env-from-files: .github/deps/dpcpp-icx.env
      cmd: |
        module load cmake/3.25.3
        gitlab/build.sh -D BUILD_OPENVDB=OFF \
                        -D OPENVKL_EXTRA_OPTIONS="-DOPENVKL_ENABLE_DEVICE_GPU=ON \
                           -DOPENVKL_DEVICE_CPU_STRUCTURED_REGULAR=OFF \
                           -DOPENVKL_DEVICE_CPU_STRUCTURED_REGULAR_LEGACY=ON \
                           -D CMAKE_BUILD_TYPE=Debug"

  test-build-from-install-dg2:
    needs: [ build-gpu ]
    secrets: inherit
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker_gpu.yml@main
    with:
      image: ubuntu:22.04
      runs-on: '[ "Linux", "docker", "dg2" ]'
      artifact-in: build-gpu
      env-from-files: .github/deps/dpcpp-icx.env .github/deps/gfx-linux-public.env
      options: --device=/dev/dri:/dev/dri
      cmd: |
        module load cmake/3.25.3
        export PATH=`pwd`/build/install/bin:`pwd`/build/install:$PATH
        gitlab/build-from-install.sh

  test-pvc:
    secrets: inherit
    needs: [ build-gpu ]
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker_gpu.yml@main
    with:
      submodules: true
      image: ubuntu:22.04
      runs-on: '[ "Linux", "docker", "pvc" ]'
      artifact-in: build-gpu
      env-from-files: .github/deps/dpcpp-icx.env .github/deps/gfx-linux-public.env .github/env/pvc-runtime-options.env
      options: --device=/dev/dri:/dev/dri
      cmd: |
        cd ./build/install/bin
        ./vklTutorialGPU
        ./vklTestsGPU --durations yes

  test-examples-pvc:
    secrets: inherit
    needs: [ build-gpu ]
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker_gpu.yml@main
    with:
      submodules: true
      image: ubuntu:22.04
      runs-on: '[ "Linux", "docker", "pvc" ]'
      artifact-in: build-gpu
      artifact-out: test-examples-pvc
      artifact-path: ./build/install/bin/*.pfm
      artifact-on-failure: true
      env-from-files: .github/deps/dpcpp-icx.env .github/deps/gfx-linux-public.env .github/env/pvc-runtime-options.env
      options: --device=/dev/dri:/dev/dri
      cmd: |
        cd ./build/install/bin
        python3 $GITHUB_WORKSPACE/.github/scripts/run-examples-tests.py $STORAGE_PATH/tools/img-diff/dist_linux/img_diff

  test-cpu:
    secrets: inherit
    needs: [ build-gpu ]
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker_gpu.yml@main
    with:
      submodules: true
      image: ubuntu:22.04
      runs-on: '[ "Linux", "docker", "build" ]'
      artifact-in: build-gpu
      env-from-files: .github/deps/dpcpp-icx.env
      cmd: |
        cd ./build/install/bin
        ./vklTutorialCPU
        ./vklTestsCPU --durations yes

  test-dg2:
    secrets: inherit
    needs: [ build-gpu ]
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker_gpu.yml@main
    with:
      submodules: true
      image: ubuntu:22.04
      runs-on: '[ "Linux", "docker", "dg2" ]'
      artifact-in: build-gpu
      env-from-files: .github/deps/dpcpp-icx.env .github/deps/gfx-linux-public.env
      options: --device=/dev/dri:/dev/dri
      cmd: |
        cd ./build/install/bin
        ./vklTutorialGPU
        ./vklTestsGPU --durations yes

  test-examples-dg2:
    secrets: inherit
    needs: [ build-gpu ]
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker_gpu.yml@main
    with:
      submodules: true
      image: ubuntu:22.04
      runs-on: '[ "Linux", "docker", "dg2" ]'
      artifact-in: build-gpu
      artifact-out: test-examples-dg2
      artifact-path: ./build/install/bin/*.pfm
      artifact-on-failure: true
      env-from-files: .github/deps/dpcpp-icx.env .github/deps/gfx-linux-public.env
      options: --device=/dev/dri:/dev/dri
      cmd: |
        cd ./build/install/bin
        python3 $GITHUB_WORKSPACE/.github/scripts/run-examples-tests.py $STORAGE_PATH/tools/img-diff/dist_linux/img_diff

  test-examples-big-volume-pvc:
    secrets: inherit
    needs: [ build-gpu ]
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker_gpu.yml@main
    with:
      submodules: true
      image: ubuntu:22.04
      runs-on: '[ "Linux", "docker", "pvc" ]'
      artifact-in: build-gpu
      artifact-out: test-examples-big-volume-pvc
      artifact-path: ./build/install/*.pfm
      artifact-on-failure: true
      env-from-files: .github/deps/dpcpp-icx.env .github/deps/gfx-linux-public.env  .github/env/pvc-runtime-options.env
      options: --device=/dev/dri:/dev/dri
      cmd: |
        cd ./build/install
        $GITHUB_WORKSPACE/.github/scripts/run-examples-big-volume-tests.sh