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

name: CI Linux

on:
  push:
  workflow_dispatch:

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

permissions: read-all

jobs:

### BUILD JOBS ###

  build-arch-clang:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: archlinux:latest
      cmd: |
        export CC=clang
        export CXX=clang++
        scripts/build/linux.sh -G Ninja -DBUILD_GLFW=OFF

  build-arch-clang-extras:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: archlinux:latest
      cmd: |
        export CC=clang
        export CXX=clang++
        scripts/build/linux.sh -G Ninja -DBUILD_GLFW=OFF -DBUILD_OSPRAY_CI_EXTRAS=ON -DBUILD_OSPRAY_MODULE_MPI=ON -DBUILD_OSPRAY_MODULE_MULTIDEVICE=ON

  build-arch-gcc:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: archlinux:latest
      cmd: |
        scripts/build/linux.sh -G Ninja -DBUILD_GLFW=OFF

  build-ubuntu2404-gcc-extras:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: ubuntu:24.04
      cmd: |
        scripts/build/linux.sh -G Ninja -DBUILD_GLFW=OFF -DBUILD_OSPRAY_CI_EXTRAS=ON

  build-rocky8-gcc:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: rockylinux:8
      cmd: |
        scripts/build/linux.sh -DBUILD_EMBREE_FROM_SOURCE=ON -DBUILD_OPENVKL_FROM_SOURCE=ON -DBUILD_OIDN=OFF -DBUILD_ISA_AVX512=OFF -DTBB_VERSION=2021.9.0
      artifact-out: build-rocky8-gcc
      artifact-path: build/install/ospray build/CMakeCache.txt build/*/build/CMakeCache.txt

  build-rocky8-icx:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: rockylinux:8
      cmd: |
        module load cmake
        module load intel/2022.1
        export CC=icx
        export CXX=icpx
        export CXXFLAGS="-fhonor-infinities -fhonor-nans"
        export CFLAGS=$CXXFLAGS
        export LDFLAGS="-static-intel"
        scripts/build/linux.sh -DBUILD_EMBREE_FROM_SOURCE=ON -DBUILD_OPENVKL_FROM_SOURCE=ON -DBUILD_OIDN=OFF -DTBB_VERSION=2021.9.0
      artifact-out: build-rocky8-icx
      artifact-path: build/install/ospray build/CMakeCache.txt build/*/build/CMakeCache.txt

  build-rocky8-mpi-impi:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: rockylinux:8
      cmd: |
        module load cmake
        module load impi/2021.6
        scripts/build/linux.sh -DBUILD_EMBREE_FROM_SOURCE=ON -DBUILD_OPENVKL_FROM_SOURCE=ON -DBUILD_OIDN=OFF -DBUILD_OSPRAY_MODULE_MPI=ON -DBUILD_ISA_AVX512=OFF -DTBB_VERSION=2021.9.0

  build-rocky8-mpi-mpich:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: rockylinux:8
      cmd: |
        module load cmake
        module load mpi/mpich-x86_64
        scripts/build/linux.sh -DBUILD_EMBREE_FROM_SOURCE=ON -DBUILD_OPENVKL_FROM_SOURCE=ON -DBUILD_OIDN=OFF -DBUILD_OSPRAY_MODULE_MPI=ON -DBUILD_ISA_AVX512=OFF -DTBB_VERSION=2021.9.0
      artifact-out: build-rocky8-mpi-mpich
      artifact-path: build/install/ospray build/CMakeCache.txt build/*/build/CMakeCache.txt

  build-rocky8-mpi-openmpi:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: rockylinux:8
      cmd: |
        module load cmake
        module load mpi/openmpi-x86_64
        scripts/build/linux.sh -DBUILD_EMBREE_FROM_SOURCE=ON -DBUILD_OPENVKL_FROM_SOURCE=ON -DBUILD_OIDN=OFF -DBUILD_OSPRAY_MODULE_MPI=ON -DBUILD_ISA_AVX512=OFF -DTBB_VERSION=2021.9.0

  build-centos8:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: centos:8
      cmd: |
        scripts/build/linux.sh -G Ninja
      artifact-out: build-centos8
      artifact-path: build/install/ospray build/CMakeCache.txt build/*/build/CMakeCache.txt

  build-centos8-mpi-mpich:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: centos:8
      cmd: |
        module load mpi/mpich-x86_64
        scripts/build/linux.sh -DBUILD_OSPRAY_MODULE_MPI=ON

  build-centos8-mpi-openmpi:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: centos:8
      cmd: |
        module load mpi/openmpi-x86_64
        scripts/build/linux.sh -DBUILD_OSPRAY_MODULE_MPI=ON

  build-rocky8-oidn-mpi:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: rockylinux:8
      cmd: |
        module load cmake/3.15.2
        module load mpi/mpich-x86_64
        scripts/build/linux.sh -DBUILD_OSPRAY_MODULE_MPI=ON
      artifact-out: build-rocky8-oidn-mpi
      artifact-path: build/install/ospray build/CMakeCache.txt build/*/build/CMakeCache.txt

  build-linux-debug:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: archlinux:latest
      cmd: |
        export CC=clang
        export CXX=clang++
        export CFLAGS=-fsanitize=address
        export CXXFLAGS=-fsanitize=address
        export LDFLAGS=-fsanitize=address
        scripts/build/linux.sh -G Ninja -DBUILD_GLFW=OFF -DCMAKE_BUILD_TYPE=Debug -DBUILD_OSPRAY_MODULE_MPI=ON
      artifact-out: build-linux-debug
      artifact-path: build/install/ospray build/CMakeCache.txt build/*/build/CMakeCache.txt build/install/embree

  build-ubuntu2404-gcc:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: ubuntu:24.04
      cmd: |
        scripts/build/linux.sh -G Ninja -DBUILD_GLFW=OFF
      artifact-out: build-ubuntu2404-gcc
      artifact-path: build/install/ospray build/CMakeCache.txt build/*/build/CMakeCache.txt

  build-ubuntu2004-gcc:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: ubuntu:20.04
      cmd: |
        scripts/build/linux.sh -G Ninja -DBUILD_GLFW=OFF -DBUILD_OSPRAY_MODULE_MULTIDEVICE=ON
      artifact-out: build-ubuntu2004-gcc
      artifact-path: build/install/ospray build/CMakeCache.txt build/*/build/CMakeCache.txt

  build-ubuntu2204-oidn-mpi:
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: ubuntu:22.04
      cmd: |
        scripts/build/linux.sh -DBUILD_OSPRAY_MODULE_MPI=ON
      artifact-out: build-ubuntu2204-oidn-mpi
      artifact-path: build/install/ospray build/CMakeCache.txt build/*/build/CMakeCache.txt

  build-ubuntu2204-arm:
    secrets: inherit
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/perf.yml@main
    with:
      runs-on: '[ "Linux", "ARM64" ]'
      cmd: |
        scripts/build/linux.sh -DBUILD_GLFW=OFF -DBUILD_TBB_FROM_SOURCE=ON -DBUILD_EMBREE_FROM_SOURCE=ON -DBUILD_OPENVKL_FROM_SOURCE=ON -DBUILD_OIDN_FROM_SOURCE=ON
      artifact-out: build-ubuntu2204-arm
      artifact-path: build/install/ospray build/CMakeCache.txt build/*/build/CMakeCache.txt

### TEST JOBS ###

  test-rocky8-gcc-avx2:
    needs: build-rocky8-gcc
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    with:
      image: rockylinux:8
      cmd: |
        PATH="$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH" scripts/tests/run_tests.sh "$GITHUB_WORKSPACE" AVX2
      artifact-in: build-rocky8-gcc
      artifact-out: test-rocky8-gcc-avx2
      artifact-path: build_regression_tests/tests*.xml build_regression_tests/failed*
      artifact-on-failure: true

  test-rocky8-gcc-mpi-mpich-avx2:
    needs: build-rocky8-mpi-mpich
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    with:
      image: rockylinux:8
      cmd: |
        module load cmake
        module load mpi/mpich-x86_64
        PATH="$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH" scripts/tests/run_tests.sh "$GITHUB_WORKSPACE" AVX2 TEST_MPI
      artifact-in: build-rocky8-mpi-mpich
      artifact-out: test-rocky8-gcc-mpi-mpich-avx2
      artifact-path: build_regression_tests/tests*.xml build_regression_tests/failed*
      artifact-on-failure: true

  test-rocky8-icx-avx2:
    needs: build-rocky8-icx
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    with:
      image: rockylinux:8
      runs-on: '"avx2"'
      cmd: |
        PATH="$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH" scripts/tests/run_tests.sh "$GITHUB_WORKSPACE" AVX2
      artifact-in: build-rocky8-icx
      artifact-out: test-rocky8-icx-avx2
      artifact-path: build_regression_tests/tests*.xml build_regression_tests/failed*
      artifact-on-failure: true

  test-rocky8-icx-avx512skx:
    needs: build-rocky8-icx
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    with:
      image: rockylinux:8
      runs-on: '"avx512"'
      cmd: |
        PATH="$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH" scripts/tests/run_tests.sh "$GITHUB_WORKSPACE" AVX512SKX
      artifact-in: build-rocky8-icx
      artifact-out: test-rocky8-icx-avx512skx
      artifact-path: build_regression_tests/tests*.xml build_regression_tests/failed*
      artifact-on-failure: true

  test-centos8-avx512skx:
    needs: build-centos8
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    with:
      image: centos:8
      runs-on: '"avx512"'
      cmd: |
        PATH="$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH" scripts/tests/run_tests.sh "$GITHUB_WORKSPACE" AVX512SKX
      artifact-in: build-centos8
      artifact-out: test-centos8-avx512skx
      artifact-path: build_regression_tests/tests*.xml build_regression_tests/failed*
      artifact-on-failure: true

  test-rocky8-oidn-mpi-avx512skx:
    needs: build-rocky8-oidn-mpi
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    with:
      image: rockylinux:8
      runs-on: '"avx512"'
      cmd: |
        module load cmake/3.15.2
        module load mpi/mpich-x86_64
        export OIDN_DEFAULT_DEVICE=cpu
        PATH="$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH" scripts/tests/run_tests.sh "$GITHUB_WORKSPACE" AVX512SKX TEST_MPI
      artifact-in: build-rocky8-oidn-mpi
      artifact-out: test-rocky8-oidn-mpi-avx512skx
      artifact-path: build_regression_tests/tests*.xml build_regression_tests/failed*
      artifact-on-failure: true

  test-find-ospray:
    needs: build-centos8
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    with:
      image: centos:8
      cmd: |
        module load cmake
        mkdir buildtut
        cd buildtut
        cmake -D ospray_DIR=`echo $GITHUB_WORKSPACE/build/install/ospray/lib/cmake/ospray-*` ../apps/ospTutorial/ospTutorialFindospray
        cmake --build .
      artifact-in: build-centos8

  test-ubuntu2404-gcc-avx512skx:
    needs: build-ubuntu2404-gcc
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    with:
      image: ubuntu:24.04
      runs-on: '"avx512"'
      cmd: |
        PATH="$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH" scripts/tests/run_tests.sh "$GITHUB_WORKSPACE" AVX512SKX
      artifact-in: build-ubuntu2404-gcc
      artifact-out: test-ubuntu2404-gcc-avx512skx
      artifact-path: build_regression_tests/tests*.xml build_regression_tests/failed*
      artifact-on-failure: true

  test-ubuntu2004-gcc-avx2:
    needs: build-ubuntu2004-gcc
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    with:
      image: ubuntu:20.04
      runs-on: '"avx2"'
      cmd: |
        PATH="$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH" scripts/tests/run_tests.sh "$GITHUB_WORKSPACE" AVX2
      artifact-in: build-ubuntu2004-gcc
      artifact-out: test-ubuntu2004-gcc-avx2
      artifact-path: build_regression_tests/tests*.xml build_regression_tests/failed*
      artifact-on-failure: true

  test-ubuntu2004-gcc-avx512skx:
    needs: build-ubuntu2004-gcc
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    with:
      image: ubuntu:20.04
      runs-on: '"avx512"'
      cmd: |
        PATH="$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH" scripts/tests/run_tests.sh "$GITHUB_WORKSPACE" AVX512SKX TEST_MULTIDEVICE
      artifact-in: build-ubuntu2004-gcc
      artifact-out: test-ubuntu2004-gcc-avx512skx
      artifact-path: build_regression_tests/tests*.xml build_regression_tests/failed*
      artifact-on-failure: true

  test-ubuntu2204-oidn-mpi-avx2-dg2:
    needs: build-ubuntu2204-oidn-mpi
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    secrets: inherit
    with:
      image: ubuntu:22.04
      env-from-files: .github/workflows/dpcpp.env .github/workflows/gfx-ubuntu22.env
      submodules: true
      options: --device=/dev/dri:/dev/dri
      runs-on: '"dg2"'
      cmd: |
        export PATH="$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH"
        export OIDN_DEFAULT_DEVICE=sycl
        export OIDN_VERBOSE=2
        mkdir build_regression_tests
        cd build_regression_tests
        cmake -D OSPRAY_TEST_ISA=AVX2 $GITHUB_WORKSPACE/test_image_data
        cmake --build . --target ospray_test_data
        ospTestSuite --baseline-dir=regression_test_baseline --gtest_filter="DenoiserOp.DenoiserOp"
        OMPI_ALLOW_RUN_AS_ROOT=1 OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1 mpiexec -np 1 ospTestSuite --baseline-dir=regression_test_baseline --gtest_filter="DenoiserOp.DenoiserOp" --osp:load-modules=mpi_offload --osp:device=mpiOffload : -np 2 ospray_mpi_worker
      artifact-in: build-ubuntu2204-oidn-mpi

  test-ubuntu2204-arm:
    needs: build-ubuntu2204-arm
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/perf.yml@main
    with:
      runs-on: '[ "Linux", "ARM64" ]'
      cmd: |
        PATH="$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH" scripts/tests/run_tests.sh "$GITHUB_WORKSPACE" AVX512SKX
      artifact-in: build-ubuntu2204-arm
      artifact-out: test-ubuntu2204-arm
      artifact-path: build_regression_tests/tests*.xml build_regression_tests/failed*
      #artifact-on-failure: true

  test-tutorials:
    needs: build-centos8
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    with:
      image: centos:8
      cmd: scripts/tests/run_tutorials.sh
      artifact-in: build-centos8

  test-mpi-tutorials:
    needs: build-rocky8-oidn-mpi
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    with:
      image: rockylinux:8
      cmd: |
        module load cmake/3.15.2
        module load mpi/mpich-x86_64
        scripts/tests/run_tutorials.sh TEST_MPI
      artifact-in: build-rocky8-oidn-mpi

  sanitize-cpu:
    needs: build-linux-debug
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    with:
      image: archlinux:latest
      cmd: |
        export PATH=$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH
        export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build/install/embree/lib:$GITHUB_WORKSPACE/build/install/ospray/lib:$LD_LIBRARY_PATH
        export TBB_ENABLE_SANITIZERS=1
        scripts/tests/run_tests.sh $GITHUB_WORKSPACE AVX512SKX
      artifact-in: build-linux-debug

  sanitize-bench:
    needs: build-linux-debug
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    with:
      image: archlinux:latest
      cmd: |
        export PATH=$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH
        export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build/install/embree/lib:$GITHUB_WORKSPACE/build/install/ospray/lib:$LD_LIBRARY_PATH
        export TBB_ENABLE_SANITIZERS=1
        build/install/ospray/bin/ospBenchmark --benchmark_min_time=0s
      artifact-in: build-linux-debug

  sanitize-mpi:
    needs: build-linux-debug
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/docker.yml@main
    with:
      image: archlinux:latest
      cmd: |
        export PATH=$GITHUB_WORKSPACE/build/install/ospray/bin:$PATH
        export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build/install/embree/lib:$GITHUB_WORKSPACE/build/install/ospray/lib:$LD_LIBRARY_PATH
        export TBB_ENABLE_SANITIZERS=1
        OMPI_ALLOW_RUN_AS_ROOT=1 OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1 scripts/tests/run_tests.sh $GITHUB_WORKSPACE AVX512SKX SKIP_CPU TEST_MPI
      artifact-in: build-linux-debug
