#!/bin/bash
# cuda_memtest on selected cards in parallel. Usage: ./memtest-sel.sh <passes> <gpu,gpu,...>
# Expects ./cuda_memtest/build/cuda_memtest next to this script: https://github.com/ComputationalRadiationPhysics/cuda_memtest
PASSES=${1:-1}; GPUS=${2:?gpu list}
cd "$(dirname "$0")" || exit 1
TS=$(date +%H%M%S)
echo "start $(date +%T) passes=$PASSES gpus=$GPUS"
for i in ${GPUS//,/ }; do
  ./cuda_memtest/build/cuda_memtest --device $i --num_passes "$PASSES" --verbose 1 > memtest-$TS-gpu$i.log 2>&1 &
done
wait
echo "end $(date +%T)"
for i in ${GPUS//,/ }; do
  f=memtest-$TS-gpu$i.log
  echo "GPU$i: lines=$(wc -l < "$f") error_lines=$(grep -ciE 'ERROR|FAIL|mismatch' "$f")"
  grep -iE 'ERROR|FAIL|mismatch' "$f" | head -n 3
done
