name: SNL-CI

on:
  pull_request:
    paths-ignore:
    - '**/*.md'
    types: [ opened, reopened, synchronize ]

permissions:
  contents: none

# Cancels any in progress 'workflow' associated with this PR
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  CUDA_12_2_CPP20:
    name: SNL_CUDA_NVCC_12_2_CPP20
    runs-on: [snl-kk-env-cuda-12.2.0-gcc-11.3.0-latest]
    continue-on-error: true

    strategy:
      matrix:
        view_legacy: [ON, OFF]

    steps:
      - name: checkout_kokkos
        uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
        with:
          repository: kokkos/kokkos
          path: kokkos

      - name: configure_kokkos
        run: |
          nvidia-smi
          cd kokkos
          cmake -B build \
            -DCMAKE_CXX_STANDARD=20 \
            -DKokkos_ENABLE_CUDA=ON \
            -DKokkos_ARCH_HOPPER90=ON \
            -DKokkos_ARCH_NATIVE=ON \
            -DCMAKE_CXX_EXTENSIONS=OFF \
            -DCMAKE_CXX_FLAGS="-Werror" \
            -DBUILD_SHARED_LIBS=OFF \
            -DKokkos_ENABLE_COMPILER_WARNINGS=ON \
            -DKokkos_ENABLE_DEPRECATED_CODE_4=OFF \
            -DKokkos_ENABLE_IMPL_VIEW_LEGACY=${{ matrix.view_legacy }} \
            -DKokkos_ENABLE_TESTS=ON \
            -DKokkos_ENABLE_EXAMPLES=ON \
            -DKokkos_ENABLE_BENCHMARKS=ON \
            -DKokkos_ENABLE_BENCHMARKS_HEAVY=${{ matrix.view_legacy == 'ON' && 'OFF' || 'ON' }} \
            ./

      - name: build_and_install_kokkos
        working-directory: kokkos
        run: |
          cmake --build build -j36
          cmake --install build --prefix install

      - name: test_kokkos
        working-directory: kokkos/build
        run: ctest --output-on-failure --timeout 3600

  HIP_6_2_1_CPP23:
    name: SNL_HIP_ROCM_6_2_1_CPP23
    runs-on: [rocm-6.2.1_openblas-0.3.28_zen3_gfx90a-latest-latest]
    continue-on-error: true

    strategy:
      matrix:
        view_legacy: [ON, OFF]

    steps:
      - name: checkout_kokkos
        uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
        with:
          repository: kokkos/kokkos
          path: kokkos

      - name: configure_kokkos
        run: |
          cd kokkos
          cmake -S . -B build \
            -DCMAKE_CXX_COMPILER=hipcc \
            -DCMAKE_CXX_STANDARD=23 \
            -DKokkos_ENABLE_HIP=ON \
            -DKokkos_ARCH_AMD_GFX90A=ON \
            -DKokkos_ARCH_NATIVE=ON \
            -DCMAKE_CXX_EXTENSIONS=OFF \
            -DCMAKE_CXX_FLAGS="-Werror -Wno-unused-command-line-argument" \
            -DBUILD_SHARED_LIBS=OFF \
            -DKokkos_ENABLE_COMPILER_WARNINGS=ON \
            -DKokkos_ENABLE_DEPRECATED_CODE_4=OFF \
            -DKokkos_ENABLE_IMPL_VIEW_LEGACY=${{ matrix.view_legacy }} \
            -DKokkos_ENABLE_TESTS=ON \
            -DKokkos_ENABLE_EXAMPLES=ON \
            -DKokkos_ENABLE_BENCHMARKS=ON

      - name: build_and_install_kokkos
        working-directory: kokkos
        run: |
          cmake --build build --parallel $(nproc)
          cmake --install build --prefix install

      - name: test_kokkos
        working-directory: kokkos/build
        run: ctest --output-on-failure --timeout 3600

  HIP_6_2_1:
    name: SNL_HIP_ROCM_6_2_1
    runs-on: [rocm-6.2.1_openblas-0.3.28_zen3_gfx90a-latest-latest]
    continue-on-error: true

    steps:
      - name: checkout_kokkos
        uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
        with:
          repository: kokkos/kokkos
          path: kokkos

      - name: configure_kokkos
        run: |
          cd kokkos
          cmake -S . -B build \
            -DCMAKE_CXX_COMPILER=hipcc \
            -DCMAKE_CXX_STANDARD=20 \
            -DKokkos_ENABLE_HIP=ON \
            -DKokkos_ARCH_AMD_GFX90A=ON \
            -DKokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE=ON \
            -DKokkos_ARCH_NATIVE=ON \
            -DCMAKE_CXX_EXTENSIONS=OFF \
            -DCMAKE_CXX_FLAGS="-Werror -Wno-unused-command-line-argument" \
            -DBUILD_SHARED_LIBS=OFF \
            -DKokkos_ENABLE_COMPILER_WARNINGS=ON \
            -DKokkos_ENABLE_DEPRECATED_CODE_4=OFF \
            -DKokkos_ENABLE_TESTS=ON \
            -DKokkos_ENABLE_EXAMPLES=ON \
            -DKokkos_ENABLE_BENCHMARKS=ON

      - name: build_and_install_kokkos
        working-directory: kokkos
        run: |
          cmake --build build --parallel $(nproc)
          cmake --install build --prefix install

      - name: test_kokkos
        working-directory: kokkos/build
        run: ctest --output-on-failure --timeout 3600

  INTEL_2024_2_1_SPR:
    name: SNL_OPENMP_SERIAL_INTEL_2024_2_1
    runs-on: [inteloneapi-basekit-2024.2.1-0-devel-ubuntu22.04-latest-spr]
    continue-on-error: true

    strategy:
      matrix:
        view_legacy: [ON, OFF]

    steps:
      - name: checkout_kokkos
        uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
        with:
          repository: kokkos/kokkos
          path: kokkos

      - name: configure_kokkos
        run: |
          cd kokkos
          cmake -S . -B build \
            -DCMAKE_CXX_COMPILER=icpx \
            -DCMAKE_CXX_STANDARD=20 \
            -DCMAKE_CXX_FLAGS='-Werror -fp-model=precise -Wno-pass-failed' \
            -DKokkos_ENABLE_OPENMP=ON \
            -DKokkos_ENABLE_SERIAL=ON \
            -DKokkos_ARCH_SPR=ON \
            -DKokkos_ENABLE_COMPILER_WARNINGS=ON \
            -DKokkos_ENABLE_DEPRECATED_CODE_4=OFF \
            -DKokkos_ENABLE_IMPL_VIEW_LEGACY=${{ matrix.view_legacy }} \
            -DKokkos_ENABLE_TESTS=ON \
            -DKokkos_ENABLE_EXAMPLES=ON \
            -DKokkos_ENABLE_BENCHMARKS=ON \
            -DKokkos_ENABLE_BENCHMARKS_HEAVY=${{ matrix.view_legacy == 'ON' && 'OFF' || 'ON' }}

      - name: build_and_install_kokkos
        working-directory: kokkos
        run: |
          cmake --build build --parallel $(nproc)
          cmake --install build --prefix install

      - name: test_kokkos
        working-directory: kokkos/build
        run: ctest --output-on-failure --timeout 3600

  INTEL_2024_2_1_PVC:
    name: SNL_SYCL_INTEL_2024_2_1
    runs-on: [inteloneapi-basekit-2024.2.1-0-devel-ubuntu22.04-latest-pv]
    continue-on-error: true

    strategy:
      matrix:
        view_legacy: [ON, OFF]

    steps:
      - name: checkout_kokkos
        uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
        with:
          repository: kokkos/kokkos
          path: kokkos

      - name: configure_kokkos
        run: |
          cd kokkos
          cmake -S . -B build \
            -DCMAKE_CXX_COMPILER=icpx \
            -DCMAKE_CXX_STANDARD=20 \
            -DCMAKE_BUILD_TYPE=Release \
            -DCMAKE_CXX_FLAGS='-Werror -fp-model=precise -fsycl-device-code-split=per_kernel -Wno-zero-length-array -Wno-pass-failed' \
            -DKokkos_ENABLE_SYCL=ON \
            -DKokkos_ARCH_INTEL_PVC=ON \
            -DKokkos_ENABLE_COMPILER_WARNINGS=ON \
            -DKokkos_ENABLE_DEPRECATED_CODE_4=OFF \
            -DKokkos_ENABLE_IMPL_VIEW_LEGACY=${{ matrix.view_legacy }} \
            -DKokkos_ENABLE_TESTS=ON \
            -DKokkos_ENABLE_EXAMPLES=ON \
            -DKokkos_ENABLE_BENCHMARKS=ON

      - name: build_and_install_kokkos
        working-directory: kokkos
        run: |
          cmake --build build --parallel $(nproc)
          cmake --install build --prefix install

      - name: test_kokkos
        working-directory: kokkos/build
        run: ONEAPI_DEVICE_SELECTOR=level_zero:gpu ctest --output-on-failure --timeout 3600

# FIXME_HPX: workaround for standard library calling OOM handler for failing nothrow new, remove once fixed
  HPX_GCC_15_1_1:
    name: SNL_HPX_GCC_15_1_1
    runs-on: [ci-containersfedora-latest-latest]
    continue-on-error: true

    steps:
      - name: checkout_kokkos
        uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
        with:
          repository: kokkos/kokkos
          path: kokkos

      - name: set_hpx_vars
        run: echo "HPX_HANDLE_FAILED_NEW=0" >> $GITHUB_ENV

      - name: configure_kokkos
        run: |
          cd kokkos
          cmake -B build \
            -DBUILD_SHARED_LIBS=ON \
            -DKokkos_ENABLE_HWLOC=ON \
            -DKokkos_ENABLE_HPX=ON \
            -DKokkos_ENABLE_TESTS=ON \
            -DKokkos_ENABLE_BENCHMARKS=ON \
            -DKokkos_ENABLE_BENCHMARKS_HEAVY=${{ matrix.view_legacy == 'ON' && 'OFF' || 'ON' }} \
            -DKokkos_ENABLE_EXAMPLES=ON \
            -DKokkos_ENABLE_DEPRECATED_CODE_4=ON \
            -DKokkos_ENABLE_COMPILER_WARNINGS=ON \
            -DCMAKE_CXX_FLAGS="-Werror" \
            -DCMAKE_CXX_STANDARD=23 \
            -DCMAKE_CXX_COMPILER=g++ \
            -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
            -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-warnings-as-errors=*" \
            -DCMAKE_BUILD_TYPE=RelWithDebInfo

      - name: build_and_install_kokkos
        working-directory: kokkos
        run: |
          ccache -z
          cmake --build build --parallel $(nproc)
          cmake --install build --prefix install
          ccache -s

      - name: test_kokkos
        working-directory: kokkos/build
        run: KOKKOS_NUM_THREADS=64 ctest --output-on-failure --timeout 3600
