#!/bin/bash

if [ "$#" -le 1 ] ; then
  echo "Usage: $0 <test> <num_gpus> [<bs>]" >&2
  echo -e "\ttest: < caffe | tf1.1 | tf1.8 | tf-horo | keras >" >&2
  echo -e "\tnum_gpus: < prepo | 1 | 2 | 4 >" >&2
  echo -e "\tbs: batch size to be used: by default 32" >&2
  exit 1
elif [ "$#" -le 2 ] ; then
  bs=32
else
  bs=$3
fi

source set_environment.sh


#Caffe
if [ "$1" = "caffe" ]; then

if [ "$2" = "prepro" ]; then
$ILSVRC2012_BASEDIR/Caffe/Preprocessing/preprocessing_step.sh
elif [ "$2" -eq 1 ]; then
$ILSVRC2012_BASEDIR/Caffe/Training/train_imagenet_vgg.sh $bs 40036 1
elif [ "$2" -eq 2 ]; then
$ILSVRC2012_BASEDIR/Caffe/Training/train_imagenet_vgg.sh $bs 20018 2
elif [ "$2" -eq 4 ]; then
$ILSVRC2012_BASEDIR/Caffe/Training/train_imagenet_vgg.sh $bs 10009 4
else
echo "Experiment with that number of GPUs not implemented" >&2
fi


#Tensorflow r1.1
elif [ "$1" = "tf1.1" ]; then

if [ "$2" = "prepro" ]; then
$ILSVRC2012_BASEDIR/Tensorflow1.1/Preprocessing/preprocessing_step.sh
elif [ "$2" -eq 1 ]; then
$ILSVRC2012_BASEDIR/Tensorflow1.1/Training/train_imagenet_resnet.sh $bs 40036 1
elif [ "$2" -eq 2 ]; then
$ILSVRC2012_BASEDIR/Tensorflow1.1/Training/train_imagenet_resnet.sh $bs 20018 2
elif [ "$2" -eq 4 ]; then
$ILSVRC2012_BASEDIR/Tensorflow1.1/Training/train_imagenet_resnet.sh $bs 10009 4
else
echo "Experiment with that number of GPUs not implemented" >&2
fi

#Tensorflow r1.8
elif [ "$1" = "tf1.8" ]; then

if [ "$2" = "prepro" ]; then
$ILSVRC2012_BASEDIR/Tensorflow1.8/Preprocessing/preprocessing_step.sh
elif [ "$2" -eq 1 ]; then
$ILSVRC2012_BASEDIR/Tensorflow1.8/Training/train_imagenet_resnet.sh $bs 1 1
elif [ "$2" -eq 2 ]; then
$ILSVRC2012_BASEDIR/Tensorflow1.8/Training/train_imagenet_resnet.sh $bs 1 2
elif [ "$2" -eq 4 ]; then
$ILSVRC2012_BASEDIR/Tensorflow1.8/Training/train_imagenet_resnet.sh $bs 1 4
else
echo "Experiment with that number of GPUs not implemented" >&2
fi

#Tensorflow r1.8-distributed horovod-protocol
elif [ "$1" = "tf-horo" ]; then

if [ "$2" = "prepro" ]; then
$ILSVRC2012_BASEDIR/Tensorflow1.8/Preprocessing/preprocessing_step.sh
elif [ "$2" -eq 8 ]; then
$ILSVRC2012_BASEDIR/Tensorflow1.8/Training/train_imagenet_resnet_horovod.sh $bs 1 8
elif [ "$2" -eq 16 ]; then
$ILSVRC2012_BASEDIR/Tensorflow1.8/Training/train_imagenet_resnet_horovod.sh $bs 1 16
elif [ "$2" -eq 32 ]; then
$ILSVRC2012_BASEDIR/Tensorflow1.8/Training/train_imagenet_resnet_horovod.sh $bs 1 32
else
echo "Experiment with that number of GPUs not implemented" >&2
fi

#Tensorflow r1.8 distributed gRPC-protocol
elif [ "$1" = "tf-grpc" ]; then

echo "Use case not implemented yet" >&2
#if [ "$2" = "prepro" ]; then
#$ILSVRC2012_BASEDIR/Tensorflow1.8/Preprocessing/preprocessing_step.sh
#elif [ "$2" -eq 8 ]; then
#$ILSVRC2012_BASEDIR/Tensorflow1.8/Training/train_imagenet_resnet_grpc.sh $bs 1 8
#elif [ "$2" -eq 16 ]; then
#$ILSVRC2012_BASEDIR/Tensorflow1.8/Training/train_imagenet_resnet_grpc.sh $bs 1 16
#elif [ "$2" -eq 32 ]; then
#$ILSVRC2012_BASEDIR/Tensorflow1.8/Training/train_imagenet_resnet_grpc.sh $bs 1 32
#else
#echo "Number of GPUs not implemented" >&2
#fi

#Keras TF 1.8 and Horovod
elif [ "$1" = "keras" ]; then

if [ "$2" = "prepro" ]; then
$ILSVRC2012_BASEDIR/KerasHorovod/Preprocessing/preprocessing_step.sh
elif [ "$2" -eq 8 ]; then
$ILSVRC2012_BASEDIR/KerasHorovod/Training/train_imagenet_resnet.sh $bs 1 8
elif [ "$2" -eq 16 ]; then
$ILSVRC2012_BASEDIR/KerasHorovod/Training/train_imagenet_resnet.sh $bs 1 16
elif [ "$2" -eq 32 ]; then
$ILSVRC2012_BASEDIR/KerasHorovod/Training/train_imagenet_resnet.sh $bs 1 32
else
echo "Experiment with that number of GPUs not implemented" >&2
fi

else
echo "Test not implemented" >&2
fi
