# Generates a Docker container with an installed GenTen built with gcc
# compilers and CUDA parallelism.
#
# This is intended to be run from the top-level genten source tree

# Base image
FROM nvidia/cuda:11.7.1-devel-ubuntu22.04
#FROM nvidia/cuda:11.0.3-devel-ubuntu20.04
MAINTAINER Eric Phipps <etphipp@sandia.gov>

# Change to bash so we have, e.g., -o pipefail
SHELL ["/bin/bash", "-c"]

# Install GenTen dependencies
RUN \
  apt-get update --yes && \
  apt-get dist-upgrade --yes && \
  apt-get install --yes \
    cmake \
    gfortran \
    libblas-dev \
    liblapack-dev \
    libboost-iostreams-dev \
    && \
  rm -rf /var/lib/apt/lists/*

# Install useful utilities
RUN \
  apt-get update --yes && \
  apt-get install --yes \
    vim \
    && \
    rm -rf /var/lib/apt/lists/*

# Add genten src
RUN mkdir -p /src
COPY . /src/genten

ARG ARCH=BDW
ARG GPU=VOLTA70

# Setup environment
ENV \
  GENTEN_ARCH=${ARCH} \
  GENTEN_GPU=${GPU} \
  GENTEN_SRC_PATH=/src/genten \
  GENTEN_INSTALL_PATH=/usr

# Build and install genten
RUN \
  set -o pipefail && \
  mkdir -p /build/genten  && \
  cd /build/genten && \
  /src/genten/scripts/gitlab_cuda/do_configure.sh 2>&1 | tee cmake_output.txt && \
  make -j8 install 2>&1 | tee make_output.txt
