# Ad-hoc build that runs in the ECP Hardware, concretely in OLCF Ascent.
.ascent_gcc_cuda:
  variables:
    CCACHE_BASEDIR:       "/gpfs/wolf/"
    CCACHE_DIR:           "/gpfs/wolf/proj-shared/csc331/vtk-m/ci/ccache/"
    # -isystem= is not affected by CCACHE_BASEDIR, thus we must ignore it
    CCACHE_IGNOREOPTIONS: "-isystem=*"
    CCACHE_NOHASHDIR:     "true"

    CC:                   "gcc"
    CXX:                  "g++"
    CMAKE_BUILD_TYPE:     "RelWithDebInfo"
    CMAKE_GENERATOR:      "Ninja"
    CUDAHOSTCXX:          "g++"
    CUSTOM_CI_BUILDS_DIR: "/gpfs/wolf/proj-shared/csc331/vtk-m/ci/runtime"

    VTKM_SETTINGS: cuda+ascent+ccache
    JOB_MODULES: >-
      git-lfs
      zstd
      cuda/11.4.2
      gcc/10.2.0
      ninja
      spectrum-mpi
      lsf-tools
      cmake
  interruptible: true

.setup_env_ecpci: &setup_env_ecpci |
  module purge
  module load ${JOB_MODULES}
  module list
  export PATH="/gpfs/wolf/proj-shared/csc331/vtk-m/ci/utils:$PATH"

build:ascent_gcc_cuda:
  stage: build
  tags: [olcf, ascent, nobatch]
  extends:
    - .ascent_gcc_cuda
    - .run_ascent_ci
  before_script:
    - *setup_env_ecpci
    - ccache -z
    - git remote add lfs https://gitlab.kitware.com/vtk/vtk-m.git
    - git fetch lfs
    - git-lfs install
    - git-lfs pull lfs
  script:
    - CTEST_MAX_PARALLELISM=32 cmake -V -P .gitlab/ci/config/gitlab_ci_setup.cmake
    - ctest -VV -S .gitlab/ci/ctest_configure.cmake
  artifacts:
    expire_in: 24 hours
    when: always
    paths:
      - build/
  timeout: 10 minutes

test:ascent_gcc_cuda:
  stage: test
  tags: [olcf, ascent, batch]
  extends:
    - .ascent_gcc_cuda
    - .run_ascent_ci
    - .cmake_test_artifacts
  needs:
    - build:ascent_gcc_cuda
  dependencies:
    - build:ascent_gcc_cuda
  variables:
    SCHEDULER_PARAMETERS: -P CSC331 -W 2:00 -nnodes 1 -alloc_flags gpudefault
    # We need this to skip ctest_submit from being run inside a jsrun job
    GITLAB_CI_EMULATION: 1
  before_script:
    - *setup_env_ecpci
  script:
    - jsrun -n1 -a1 -g1 -c42 ctest -VV -S .gitlab/ci/ctest_build.cmake
    - CTEST_MAX_PARALLELISM=4  jsrun -n1 -a1 -g1 -c8  ctest -VV -S .gitlab/ci/ctest_test.cmake
  after_script:
    - *setup_env_ecpci
    - ccache -s
    - ctest -VV -S .gitlab/ci/ctest_submit_build.cmake
    - ctest -VV -S .gitlab/ci/ctest_submit_test.cmake
  timeout: 120 minutes
