diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..999c00f459 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,59 @@ +name: TiledArray CI + +on: [push] + +env: + CMAKE_BUILD_PARALLEL_LEVEL : 2 + +jobs: + + MacOS-Build: + + strategy: + fail-fast: false + matrix: + os : [ macos-latest ] + cxx : [ clang++, /usr/local/bin/g++-10 ] + build_type : [ Release, Debug ] + prerequisites : [ gcc@10 boost eigen open-mpi ] + + name: "${{ matrix.os }}: ${{ matrix.cxx }} ${{ matrix.build_type }}" + runs-on: ${{ matrix.os }} + env: + CXX : ${{ matrix.cxx }} + BUILD_CONFIG : > + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -DTA_BUILD_UNITTEST=ON + -DMPIEXEC_PREFLAGS='--bind-to;none;--allow-run-as-root' + + steps: + - uses: actions/checkout@v2 + + - name: Host system info + shell: bash + run: cmake -P ${{github.workspace}}/ci/host_system_info.cmake + + - name: Install ${{matrix.prerequisites}} + run: brew install ${{matrix.prerequisites}} + + - name: "Configure build: ${{ env.BUILD_CONFIG }}" + shell: bash + run: | + set -x; + cmake -B${{github.workspace}}/build $BUILD_CONFIG + + - name: Build + working-directory: ${{github.workspace}}/build + shell: bash + run: | + cmake --build . --target tiledarray + cmake --build . --target examples + + - name: Test + working-directory: ${{github.workspace}}/build + shell: bash + #run: ctest -C $${{matrix.build_type}} + run: | + source ${{github.workspace}}/ci/openmpi.env + cmake --build . --target ta_test + cmake --build . --target check diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 104a5f6eeb..ee54cf681a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,35 +7,21 @@ default: variables: MAD_NUM_THREADS : 2 - TA_CI_TARGETS : "tiledarray examples ta_test check" - TA_CI_CONFIG : > - TA_BUILD_UNITTEST=TRUE - CMAKE_BUILD_TYPE=${BUILD_TYPE} - ${TA_PYTHON} - ${ENABLE_CUDA} - ${BLA_VENDOR} - ${ENABLE_SCALAPACK} + TA_TARGETS : "tiledarray examples ta_test check" + TA_CONFIG : > + TA_BUILD_UNITTEST=TRUE + CMAKE_BUILD_TYPE=${BUILD_TYPE} + ${TA_PYTHON} + ${ENABLE_CUDA} + ${BLA_VENDOR} + ${ENABLE_SCALAPACK} before_script: - - echo 'localhost slots=2' > /etc/openmpi/openmpi-default-hostfile + # NB: below tag parsing is not robust - echo "CI_RUNNER_TAGS=$CI_RUNNER_TAGS" - # NB: tag parsing below is not robust - CMAKE_BUILD_PARALLEL_LEVEL=$(echo $CI_RUNNER_TAGS | sed -n 's/CMAKE_BUILD_PARALLEL_LEVEL=\([0-9]\+\).*/\1/p') - export CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_BUILD_PARALLEL_LEVEL:=1} - echo "CMAKE_BUILD_PARALLEL_LEVEL=$CMAKE_BUILD_PARALLEL_LEVEL" - - |- - if [[ "$BLA_VENDOR" == "BLA_VENDOR=Intel10"* ]]; then - # apt-get install -yq intel-mkl-core-c-2020.4-304 - # source /opt/intel/compilers_and_libraries_2020.4.304/linux/mkl/bin/mklvars.sh intel64 - make -C /home/ValeevGroup install/intel-mkl - source /opt/intel/mkl/bin/mklvars.sh intel64 - echo "MKLROOT=$MKLROOT" - fi - - |- - if [[ "$ENABLE_CUDA" == "ENABLE_CUDA=ON" ]]; then - make -C /home/ValeevGroup install/cuda - export CUDACXX=/usr/local/cuda/bin/nvcc - fi ubuntu: stage: build @@ -46,17 +32,23 @@ ubuntu: TA_PYTHON : "TA_PYTHON=ON" ENABLE_SCALAPACK : "ENABLE_SCALAPACK=OFF" script: - - mkdir build - - cd build - # !!! Unset env vars that may conflict with build, eg FindBLAS uses $ENV{BLA_VENDOR} - - unset BUILD_TYPE TA_PYTHON BLA_VENDOR ENABLE_SCALAPACK ENABLE_CUDA - - ../bin/gitlab-ci.sh .. - ${TA_CI_TARGETS} - ${TA_CI_CONFIG} + - ./ci/.build-project + --build ./build + --metrics ./build/metrics.txt + ${TA_CONFIG} + ${TA_TARGETS} MPIEXEC_PREFLAGS='--bind-to;none;--allow-run-as-root' blacs_LIBRARIES=scalapack-openmpi scalapack_LIBRARIES=scalapack-openmpi #lapack_LIBRARIES=lapack + artifacts: + paths: + - build/metrics.txt + - build/CMakeCache.txt + - build/CMakeFiles/CMakeOutput.log + - build/CMakeFiles/CMakeError.log + reports: + metrics: build/metrics.txt parallel: matrix: - IMAGE : [ "ubuntu:18.04", "ubuntu:20.04" ] @@ -73,4 +65,4 @@ ubuntu: CXX: [ g++ ] BUILD_TYPE : [ "Release", "Debug" ] ENABLE_CUDA : [ "ENABLE_CUDA=ON" ] - TA_CI_TARGETS : [ "tiledarray examples" ] \ No newline at end of file + TA_TARGETS : [ "tiledarray examples" ] \ No newline at end of file diff --git a/bin/gitlab-ci.sh b/bin/gitlab-ci.sh deleted file mode 100755 index f83140682d..0000000000 --- a/bin/gitlab-ci.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -echo "$ $0 $@" - -if [ "$#" -lt 1 ]; then - echo "CMake project directory argument required" - exit 1 -fi - -project_dir=$1 -shift - -targets="" -cmake_args="" - -for arg in "$@"; do - #echo $arg - case $arg in - *=*) cmake_args+=" \"-D$arg\"" ;; - *) targets+=" $arg" ;; - esac -done - -echo "CMake args: $cmake_args" -echo "Build targets: $targets" -echo "" - -set -e -set -x - -# to run OpenMPI in docker as root -export OMPI_ALLOW_RUN_AS_ROOT=1 -export OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1 -export OMPI_MCA_btl_vader_single_copy_mechanism="none" - -eval "cmake $project_dir $cmake_args" - -for target in $targets; do - echo "Building target $target" - eval "cmake --build . --target $target" -done diff --git a/ci/.build-project b/ci/.build-project new file mode 100755 index 0000000000..7b6f4d0b3a --- /dev/null +++ b/ci/.build-project @@ -0,0 +1,97 @@ +#!/bin/bash + +set -e + +build_dir="" +metrics="" + +var=" " +targets=" " + +while [ $# -gt 0 ]; do + case $1 in + --build) shift; build_dir=$1 ;; + --metrics) shift; metrics=$1 ;; + -*) echo "Invalid option $arg"; exit 1 ;; + CXX=*) eval "export $1" ;; + *=*) vars+="\"-D$1\" " + # NB unset vars from s.t. CMake doesn't see env vars, eg BLA_VENDOR + unset $(echo "$1" | cut -d= -f1) + ;; + *) targets+="$1 ";; + esac + shift +done + +if [ -z "$build_dir" ]; then + echo "--build is required" + exit 1 +fi + +xtime="/usr/bin/time" + +if [ -n "$metrics" ]; then + #sudo apt install time + if [ ! -x $xtime ]; then + echo >&2 "${xtime} is not executable, metrics disabled" + metrics="" + fi + rm -f "${metrics}" +fi + +function time_cmd { + step=$1; shift + cmd="$@" + echo "+ $cmd" + if [ -n "$metrics" ]; then + format="'${step}.memory %Mk\n${step}.time %E\n'" + cmd="${xtime} -f ${format} -a -o $metrics $cmd" + #echo "$cmd" + fi + eval "$cmd" +} + +function cmd { + echo "+ $@" + eval "$@" +} + +# NB Gitlab section: https://docs.gitlab.com/ee/ci/jobs/#custom-collapsible-sections +function section_start { + echo -e "section_start:`date +%s`:$1\r\e[0K$2" +} + +function section_end { + echo -e "section_end:`date +%s`:$1\r\e[0K" +} + +echo "" +section_start "host_system_info[collapsed=true]" "Host system info" +cmd "cmake -P ci/host_system_info.cmake" +section_end host_system_info + +section_start "preparing_system_section[collapsed=true]" "Preparing system" +cmd "source ci/openmpi.env" +cmd "echo 'localhost slots=2' > /etc/openmpi/openmpi-default-hostfile" +if [[ "$vars" =~ \"-DBLA_VENDOR=Intel ]]; then + cmd "make -C /home/ValeevGroup install/intel-mkl" + cmd "source /opt/intel/mkl/bin/mklvars.sh intel64" + cmd "echo MKLROOT=\$MKLROOT" +fi +if [[ "$vars" =~ \"-D([a-zA-Z]+_)?ENABLE_CUDA=(ON|TRUE|1|YES)\" ]]; then + cmd "make -C /home/ValeevGroup install/cuda" + cmd "export CUDACXX=/usr/local/cuda/bin/nvcc" +fi +section_end preparing_system_section + +section_start configure_section "Configure" +cmd mkdir -p ${build_dir} +time_cmd configure "cmake -B${build_dir} $vars" +section_end configure_section + +for target in ${targets}; do + section_start build_${target}_section "Build ${target}" + time_cmd ${target} "cmake --build ${build_dir} --target ${target}" + section_end build_${target}_section +done + diff --git a/ci/README.md b/ci/README.md new file mode 100644 index 0000000000..b97e8154a4 --- /dev/null +++ b/ci/README.md @@ -0,0 +1,14 @@ +To run CI in docker use `docker-run-ci` and give build parameters, eg: + +``` +$ ./ci/docker-run-ci TA_PYTHON=OFF ENABLE_CUDA=ON all check +Removing previous build container: andrey.tiledarray.build + +Running new build of /home/andrey/github/tiledarray on andrey.tiledarray.build +* Use CTRL-p CTRL-q to dettach +* To reattach use: docker start -a -i andrey.tiledarray.build +... +``` + +This builds targets `all check` on current Git branch in a docker container named `${USER}.$(basename $PWD).build` + diff --git a/ci/docker-run-ci b/ci/docker-run-ci new file mode 100755 index 0000000000..32aedfcfa3 --- /dev/null +++ b/ci/docker-run-ci @@ -0,0 +1,39 @@ +#!/bin/bash + +# build project via docker run, eg +# usage: docker-run-ci [ VAR=VALUE ... ] [ target ... ] +# example: ./ci/docker-run-ci ./build-dir MPQC_BUILD_DEPENDENCIES_FROM_SOURCE=OFF ENABLE_CUDA=ON all check + +project=$(basename $PWD) +image=valeevgroup/ubuntu +name=$USER.${project}.build +project_source_dir=$PWD + +script="cd /builds/ValeevGroup/${project} + +echo '# git checkout .' +git checkout . +echo + +echo '# git log -1' +git log -1 +echo + +./ci/.build-project --build ./build --metrics ./build/metrics.txt $@; + +bash +" + +echo -n "Removing previous build container: " +docker rm -f ${name} + +echo " +Running new build of ${project_source_dir} on ${name} +* Use CTRL-p CTRL-q to dettach +* To reattach use: docker start -a -i ${name} +" +#sleep 1 + +docker run --name ${name} -ti \ + -v ${project_source_dir}/.git:/builds/ValeevGroup/${project}/.git \ + ${image} bash -c "$script" diff --git a/ci/host_system_info.cmake b/ci/host_system_info.cmake new file mode 100644 index 0000000000..4e10a30121 --- /dev/null +++ b/ci/host_system_info.cmake @@ -0,0 +1,22 @@ +set( + keys + + OS_NAME + OS_RELEASE + OS_VERSION + OS_PLATFORM + + + PROCESSOR_DESCRIPTION + NUMBER_OF_PHYSICAL_CORES + + TOTAL_VIRTUAL_MEMORY + AVAILABLE_VIRTUAL_MEMORY + TOTAL_PHYSICAL_MEMORY + AVAILABLE_PHYSICAL_MEMORY + ) + +foreach (key ${keys}) + cmake_host_system_information(RESULT result QUERY ${key}) + message(STATUS "${key}: ${result}") +endforeach() diff --git a/ci/openmpi.env b/ci/openmpi.env new file mode 100644 index 0000000000..50ea751bea --- /dev/null +++ b/ci/openmpi.env @@ -0,0 +1,5 @@ +# to run OpenMPI in docker as root +export OMPI_ALLOW_RUN_AS_ROOT=1 +export OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1 +export OMPI_MCA_btl_vader_single_copy_mechanism="none" +