##=============================================================================
##
##  Copyright (c) Kitware, Inc.
##  All rights reserved.
##  See LICENSE.txt for details.
##
##  This software is distributed WITHOUT ANY WARRANTY; without even
##  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
##  PURPOSE.  See the above copyright notice for more information.
##
##=============================================================================

build:ubuntu2004_kokkos:
  tags:
    - build
    - vtkm
    - docker
    - linux-x86_64
  extends:
    - .ubuntu2004_kokkos
    - .cmake_build_linux
    - .run_automatically
  variables:
    CMAKE_BUILD_TYPE: RelWithDebInfo
    CMAKE_PREFIX_PATH: "/opt/anari"
    VTKM_SETTINGS: "kokkos+shared+64bit_floats+rendering+anari"

test:ubuntu2004_kokkos:
  tags:
    - test
    - vtkm
    - docker
    - linux-x86_64
  extends:
    - .ubuntu2004_kokkos
    - .cmake_test_linux
    - .run_automatically
  dependencies:
    - build:ubuntu2004_kokkos
  needs:
    - build:ubuntu2004_kokkos

build:ubuntu2004_hip_kokkos:
  tags:
    - vtkm
    - docker
    - linux-x86_64
    - radeon
  extends:
    - .ubuntu2004_hip_kokkos
    - .cmake_build_linux
    - .run_automatically
  variables:
    CMAKE_BUILD_TYPE:        "RelWithDebInfo"
    VTKM_SETTINGS:           "benchmarks+kokkos+hip+no_rendering+ccache"

    CMAKE_PREFIX_PATH:       "/opt/rocm/lib/cmake"
    LD_LIBRARY_PATH:         "/opt/rocm/lib"
    CMAKE_HIP_COMPILER:      "/opt/rocm/llvm/bin/clang++"
    Kokkos_CXX_COMPILER:     "/opt/rocm/llvm/bin/clang++"
    CMAKE_HIP_ARCHITECTURES: "gfx900"

    # -isystem= is not affected by CCACHE_BASEDIR, thus we must ignore it
    CCACHE_IGNOREOPTIONS:    "-isystem=*"
    CCACHE_BASEDIR:          "$CI_PROJECT_DIR"
    CCACHE_COMPILERCHECK:    "content"
    CCACHE_NOHASHDIR:        "true"
    CCACHE_RESHARE:          "true"
  after_script:
    - ccache -v -s
    - ccache -z

test:ubuntu2004_hip_kokkos:
  tags:
    - vtkm
    - docker
    - linux-x86_64
    - radeon
  extends:
    - .ubuntu2004_hip_kokkos
    - .cmake_test_linux
    - .run_upstream_branches
  variables:
    CTEST_MAX_PARALLELISM: 1
    TEST_EXCLUSIONS: "UnitTestWorkletParticleAdvection"
  dependencies:
    - build:ubuntu2004_hip_kokkos
  needs:
    - build:ubuntu2004_hip_kokkos
  timeout: 3 hours

# This is only for merge-requests
build:ascent:
  stage: build
  variables:
    BRANCH_NAME:     "mr${CI_MERGE_REQUEST_IID}-${CI_COMMIT_REF_NAME}"
    ASCENT_REST_URL: "https://code.ornl.gov/api/v4/projects/7035"
    ASCENT_GIT_URL:  "https://vbolea:${ECPTEST_TOKEN}@code.ornl.gov/ecpcitest/vtk-m.git"
  tags:
    - vtkm
    - docker
    - build
    - linux-x86_64
  extends:
    - .ubuntu2004
    - .run_only_merge_requests
  script:
    # A new commit is needed to symbolize a restart of a build from the same original commit
    - .gitlab/ci/config/ecpci-amend-commit.sh "NEW_COMMIT_SHA"
    - .gitlab/ci/config/ecpci-push-branch.sh "$ASCENT_GIT_URL" "$BRANCH_NAME"
    - timeout 130m .gitlab/ci/config/ecpci-wait-commit-status.sh "$ASCENT_REST_URL" "$(cat NEW_COMMIT_SHA)"
  after_script:
    - .gitlab/ci/config/ecpci-remove-branch.sh "$ASCENT_GIT_URL" "$BRANCH_NAME" || true
    - .gitlab/ci/config/ecpci-fetch-commit-trace.py "$ASCENT_REST_URL" "$(cat NEW_COMMIT_SHA)" "$ECPTEST_TOKEN"
  timeout: 150 minutes
  interruptible: true
