FROM nvidia/cuda:11.0-devel-ubuntu18.04
LABEL maintainer "Vicente Adolfo Bolea Sanchez<vicente.bolea@kitware.com>"

# Base dependencies for building VTK-m projects
RUN apt-get update && apt-get install -y --no-install-recommends \
      curl \
      g++ \
      git \
      git-lfs \
      ninja-build \
      && \
    rm -rf /var/lib/apt/lists/*

# Need to run git-lfs install manually on ubuntu based images when using the
# system packaged version
RUN git-lfs install

# kokkos backend requires cmake 3.18
RUN mkdir /opt/cmake/ && \
    curl -L https://github.com/Kitware/CMake/releases/download/v3.21.2/cmake-3.21.2-Linux-x86_64.sh > cmake-3.21.2-Linux-x86_64.sh && \
    sh cmake-3.21.2-Linux-x86_64.sh --prefix=/opt/cmake/ --exclude-subdir --skip-license && \
    rm cmake-3.21.2-Linux-x86_64.sh && \
    ln -s /opt/cmake/bin/ctest /opt/cmake/bin/ctest-latest

ENV PATH "/opt/cmake/bin:${PATH}"

# Build and install Kokkos
RUN mkdir -p /opt/kokkos/build && \
    cd /opt/kokkos/build && \
    curl -L https://github.com/kokkos/kokkos/archive/refs/tags/3.4.01.tar.gz > kokkos-3.4.01.tar.gz && \
    tar -xf kokkos-3.4.01.tar.gz && \
    mkdir bld && cd bld && \
    CXX=/opt/kokkos/build/kokkos-3.4.01/bin/nvcc_wrapper \
    cmake -B . -S ../kokkos-3.4.01 \
          -DCMAKE_BUILD_TYPE=Release \
          -DCMAKE_INSTALL_PREFIX=/opt/kokkos \
          -DCMAKE_CXX_FLAGS=-fPIC \
          -DCMAKE_CXX_STANDARD=14 \
          -DKokkos_ENABLE_CUDA=ON \
          -DKokkos_ENABLE_CUDA_CONSTEXPR=ON \
          -DKokkos_ENABLE_CUDA_LAMBDA=ON \
          -DKokkos_ENABLE_CUDA_LDG_INTRINSIC=ON \
          -DKokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE=OFF \
          -DKokkos_ENABLE_CUDA_UVM=ON \
          -DKokkos_ARCH_TURING75=ON && \
    cmake --build . -j 8 && \
    cmake --install .
