From 34810910c12ec268f85dda8bbf474322d5407c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Sch=C3=BCtt?= Date: Sun, 21 Mar 2021 21:52:21 +0100 Subject: [PATCH] Docker: Add Cuda performance test --- tools/docker/Dockerfile.test_performance | 4 +- tools/docker/Dockerfile.test_performance_cuda | 21 +++++++ tools/docker/scripts/install_performance.sh | 9 ++- tools/docker/scripts/plot_performance.py | 45 ++++++------- tools/docker/scripts/test_performance.sh | 63 ++++++++++++++----- 5 files changed, 98 insertions(+), 44 deletions(-) create mode 100644 tools/docker/Dockerfile.test_performance_cuda diff --git a/tools/docker/Dockerfile.test_performance b/tools/docker/Dockerfile.test_performance index 848ce7b168..ea73ca23e5 100644 --- a/tools/docker/Dockerfile.test_performance +++ b/tools/docker/Dockerfile.test_performance @@ -9,13 +9,13 @@ COPY ./scripts/install_basics.sh . RUN ./install_basics.sh COPY ./scripts/install_performance.sh . -RUN ./install_performance.sh +RUN ./install_performance.sh "local" COPY ./scripts/ci_entrypoint.sh \ ./scripts/test_performance.sh \ ./scripts/plot_performance.py \ ./ -CMD ["./ci_entrypoint.sh", "./test_performance.sh"] +CMD ["./ci_entrypoint.sh", "./test_performance.sh", "local"] #EOF diff --git a/tools/docker/Dockerfile.test_performance_cuda b/tools/docker/Dockerfile.test_performance_cuda new file mode 100644 index 0000000000..70273e31dc --- /dev/null +++ b/tools/docker/Dockerfile.test_performance_cuda @@ -0,0 +1,21 @@ +ARG TOOLCHAIN=cp2k/toolchain:latest +FROM ${TOOLCHAIN} + +# author: Ole Schuett + +WORKDIR /workspace + +COPY ./scripts/install_basics.sh . +RUN ./install_basics.sh + +COPY ./scripts/install_performance.sh . +RUN ./install_performance.sh "local_cuda" + +COPY ./scripts/ci_entrypoint.sh \ + ./scripts/test_performance.sh \ + ./scripts/plot_performance.py \ + ./ + +CMD ["./ci_entrypoint.sh", "./test_performance.sh", "local_cuda"] + +#EOF diff --git a/tools/docker/scripts/install_performance.sh b/tools/docker/scripts/install_performance.sh index 834b08135f..fe44110b25 100755 --- a/tools/docker/scripts/install_performance.sh +++ b/tools/docker/scripts/install_performance.sh @@ -2,6 +2,13 @@ # author: Ole Schuett +if (($# != 1)); then + echo "Usage: install_performance.sh " + exit 1 +fi + +ARCH=$1 + # setup arch files cd /workspace/cp2k/arch ln -vs /opt/cp2k-toolchain/install/arch/local* . @@ -12,7 +19,7 @@ source /opt/cp2k-toolchain/install/setup # pre-build cp2k cd /workspace/cp2k echo -n "Warming cache by trying to compile cp2k... " -if make -j VERSION="psmp" &> /dev/null; then +if make -j ARCH="${ARCH}" VERSION="psmp" &> /dev/null; then echo 'done.' else echo 'failed.' diff --git a/tools/docker/scripts/plot_performance.py b/tools/docker/scripts/plot_performance.py index 4bdf554e0e..7515659ccb 100755 --- a/tools/docker/scripts/plot_performance.py +++ b/tools/docker/scripts/plot_performance.py @@ -8,39 +8,32 @@ from collections import OrderedDict # ====================================================================================== def main(): - if len(sys.argv) != 6: + if len(sys.argv) < 4 or (len(sys.argv) - 1) % 3 != 0: print( - "Usage: plot_performance.py <label> <output_omp> <output_mpi>" + "Usage: plot_performance.py <title_1> <plot_1> <file_1> ... " + "<title_N> <plot_N> <file_N>" ) sys.exit(1) - nprocs, title, label, output_omp, output_mpi = sys.argv[1:] - timings_omp = parse_timings(output_omp) - timings_mpi = parse_timings(output_mpi) - routines = list(set(list(timings_omp.keys())[:6] + list(timings_mpi.keys())[:6])) + titles, plots, timings = [], [], [] + for i in range((len(sys.argv) - 1) // 3): + titles.append(sys.argv[3 * i + 1]) + plots.append(sys.argv[3 * i + 2]) + timings.append(parse_timings(sys.argv[3 * i + 3])) + + routines = list(set([r for t in timings for r in list(t.keys())[:6]])) routines.remove("total") - routines.sort(reverse=True, key=lambda r: timings_omp.get(r, 0.0)) + routines.sort(reverse=True, key=lambda r: timings[0].get(r, 0.0)) - sum_routines_omp = sum([timings_omp.get(r, 0.0) for r in routines]) - sum_routines_mpi = sum([timings_mpi.get(r, 0.0) for r in routines]) - timings_omp["rest"] = timings_omp["total"] - sum_routines_omp - timings_mpi["rest"] = timings_mpi["total"] - sum_routines_mpi + for titel, plot, timing in zip(titles, plots, timings): + timing["rest"] = timing["total"] - sum([timing.get(r, 0.0) for r in routines]) - full_title = f"Timings of {title} with {nprocs} OpenMP Threads" - plot = f"{label}_timings_{nprocs}omp" - print(f'Plot: name="{plot}", title="{full_title}", ylabel="time [s]"') - for r in ["rest"] + routines: - t = timings_omp.get(r, 0.0) - print(f'PlotPoint: plot="{plot}", name="{r}", label="{r}", y={t}, yerr=0.0') - print("") - - full_title = f"Timings of {title} with {nprocs} MPI Ranks" - plot = f"{label}_timings_{nprocs}mpi" - print(f'Plot: name="{plot}", title="{full_title}", ylabel="time [s]"') - for r in ["rest"] + routines: - t = timings_mpi.get(r, 0.0) - print(f'PlotPoint: plot="{plot}", name="{r}", label="{r}", y={t}, yerr=0.0') - print("") + full_title = f"Timings of {titel}" + print(f'Plot: name="{plot}", title="{full_title}", ylabel="time [s]"') + for r in ["rest"] + routines: + t = timing.get(r, 0.0) + print(f'PlotPoint: plot="{plot}", name="{r}", label="{r}", y={t}, yerr=0.0') + print("") # ====================================================================================== diff --git a/tools/docker/scripts/test_performance.sh b/tools/docker/scripts/test_performance.sh index eaf8967b10..486ec93caa 100755 --- a/tools/docker/scripts/test_performance.sh +++ b/tools/docker/scripts/test_performance.sh @@ -2,6 +2,13 @@ # author: Ole Schuett +if (($# != 1)); then + echo "Usage: test_performance.sh <ARCH>" + exit 1 +fi + +ARCH=$1 + function run_benchmark { set +e #disable error trapping OMP_THREADS=$1 @@ -10,7 +17,7 @@ function run_benchmark { OUTPUT=$4 echo -n "Running ${INPUT} with ${OMP_THREADS} threads and ${MPI_RANKS} ranks... " if OMP_NUM_THREADS="${OMP_THREADS}" mpiexec -np "${MPI_RANKS}" \ - /workspace/cp2k/exe/local/cp2k.psmp "${INPUT}" &> "${OUTPUT}"; then + "/workspace/cp2k/exe/${ARCH}/cp2k.psmp" "${INPUT}" &> "${OUTPUT}"; then echo "done." else echo -e "failed.\n\n" @@ -28,7 +35,7 @@ source /opt/cp2k-toolchain/install/setup echo -e '\n========== Compiling CP2K ==========' cd /workspace/cp2k echo -n "Compiling cp2k... " -if make -j VERSION="psmp" &> make.out; then +if make -j ARCH="${ARCH}" VERSION="psmp" &> make.out; then echo "done." else echo -e "failed.\n\n" @@ -50,19 +57,45 @@ BENCHMARKS=( "QS_single_node/dbcsr.inp" ) -for INPUT in "${BENCHMARKS[@]}"; do - INPUT_BASENAME=$(basename "${INPUT}") - LABEL=${INPUT_BASENAME%.*} - OUTPUT_MPI="/workspace/artifacts/${LABEL}_32mpi.out" - OUTPUT_OMP="/workspace/artifacts/${LABEL}_32omp.out" - cd "$(dirname "${INPUT}")" - run_benchmark 1 32 "${INPUT_BASENAME}" "${OUTPUT_MPI}" - run_benchmark 32 1 "${INPUT_BASENAME}" "${OUTPUT_OMP}" - cd .. - echo "" - /workspace/plot_performance.py 32 "${LABEL}" "${LABEL}" "${OUTPUT_OMP}" "${OUTPUT_MPI}" - echo "" -done +if [[ "${ARCH}" == "local" ]]; then + for INPUT in "${BENCHMARKS[@]}"; do + INPUT_BASENAME=$(basename "${INPUT}") + LABEL=${INPUT_BASENAME%.*} + OUTPUT_MPI="/workspace/artifacts/${LABEL}_32mpi.out" + OUTPUT_OMP="/workspace/artifacts/${LABEL}_32omp.out" + cd "$(dirname "${INPUT}")" + run_benchmark 1 32 "${INPUT_BASENAME}" "${OUTPUT_MPI}" + run_benchmark 32 1 "${INPUT_BASENAME}" "${OUTPUT_OMP}" + cd .. + echo "" + /workspace/plot_performance.py \ + "${LABEL} with 32 OpenMP Threads" "${LABEL}_timings_32omp" "${OUTPUT_OMP}" \ + "${LABEL} with 32 MPI Ranks" "${LABEL}_timings_32mpi" "${OUTPUT_MPI}" + echo "" + done + +elif [[ "${ARCH}" == "local_cuda" ]]; then + for INPUT in "${BENCHMARKS[@]}"; do + if [[ "$INPUT" == "QS_single_node/H2O-hyb.inp" ]]; then + continue # Has no gpu acceleration, yet. + fi + INPUT_BASENAME=$(basename "${INPUT}") + LABEL=${INPUT_BASENAME%.*} + OUTPUT="/workspace/artifacts/${LABEL}_6cpu_1gpu.out" + cd "$(dirname "${INPUT}")" + export CUDA_VISIBLE_DEVICES=0 + run_benchmark 3 2 "${INPUT_BASENAME}" "${OUTPUT}" + cd .. + echo "" + /workspace/plot_performance.py \ + "${LABEL} with 6 CPU Cores and 1 GPU" "${LABEL}_timings_6cpu_1gpu" "${OUTPUT}" + echo "" + done + +else + echo "Unknown ARCH: ${ARCH}" + exit 1 +fi echo -e "\nSummary: Performance test works fine." echo -e "Status: OK\n"