Skip to content

Commit

Permalink
add run_docker.sh script (#328)
Browse files Browse the repository at this point in the history
* BLD: add run_docker script
  • Loading branch information
facaiy authored and seanpmorgan committed Jul 10, 2019
1 parent d16b407 commit cf5404d
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 2 deletions.
3 changes: 3 additions & 0 deletions makefile
Expand Up @@ -28,3 +28,6 @@ sanity-check: install-ci-dependency

unit-test:
bash tools/ci_testing/addons_cpu.sh

gpu-unit-test:
bash tools/ci_testing/addons_gpu.sh
4 changes: 3 additions & 1 deletion tools/ci_testing/addons_cpu.sh 100644 → 100755
Expand Up @@ -16,7 +16,8 @@
# ==============================================================================
# Make sure we're in the project root path.
SCRIPT_DIR=$( cd ${0%/*} && pwd -P )
ROOT_DIR=$( cd "$SCRIPT_DIR/.." && pwd -P )
ROOT_DIR=$( cd "$SCRIPT_DIR/../.." && pwd -P )
cd $ROOT_DIR
if [[ ! -d "tensorflow_addons" ]]; then
echo "ERROR: PWD: $PWD is not project root"
exit 1
Expand All @@ -41,6 +42,7 @@ export CC_OPT_FLAGS='-mavx'
export TF_NEED_CUDA=0 # TODO: Verify this is used in GPU custom-op

export PYTHON_BIN_PATH=`which python`
ls -alh $PYTHON_BIN_PATH
# Use default configuration here.
yes 'y' | ./configure.sh

Expand Down
4 changes: 3 additions & 1 deletion tools/ci_testing/addons_gpu.sh 100644 → 100755
Expand Up @@ -16,7 +16,8 @@
# ==============================================================================
# Make sure we're in the project root path.
SCRIPT_DIR=$( cd ${0%/*} && pwd -P )
ROOT_DIR=$( cd "$SCRIPT_DIR/.." && pwd -P )
ROOT_DIR=$( cd "$SCRIPT_DIR/../.." && pwd -P )
cd $ROOT_DIR
if [[ ! -d "tensorflow_addons" ]]; then
echo "ERROR: PWD: $PWD is not project root"
exit 1
Expand All @@ -34,6 +35,7 @@ export CC_OPT_FLAGS='-mavx'
export TF_NEED_CUDA=1

export PYTHON_BIN_PATH=`which python`
ls -alh $PYTHON_BIN_PATH
# Use default configuration here.
yes 'y' | ./configure.sh

Expand Down
98 changes: 98 additions & 0 deletions tools/run_docker.sh
@@ -0,0 +1,98 @@
#!/usr/bin/env bash
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ==============================================================================
# Detect the project root path.
SCRIPT_DIR=$( cd ${0%/*} && pwd -P )
ROOT_DIR=$( cd "$SCRIPT_DIR/.." && pwd -P )
if [[ ! -d "${ROOT_DIR}/tensorflow_addons" ]]; then
echo "ERROR: $ROOT_DIR is not project root"
exit 1
fi

SYSTEM=linux
DEVICE=cpu
PYTHON=py3

while getopts ":s:d:p:c:h" opt; do
case ${opt} in
s) SYSTEM=$OPTARG;;
d) DEVICE=$OPTARG;;
p) PYTHON=$OPTARG;;
c) COMMAND=$OPTARG;;
h)
echo -n "usage: run_docker.sh [-s SYSTEM] [-d DEVICE] "
echo "[-p PYTHON] -c string"
echo "available commands:"
echo " -s select operating system: 'linux'"
echo " -d select device: 'cpu', 'gpu'"
echo " -p select python version: 'py2', 'py3'"
echo " -c command string, eg: 'make unit-test'"
echo " -h print this help and exit"
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Invalid option: Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done

if [[ "$SYSTEM" != "linux" ]]; then
echo "System $SYSTEM is not supported yet"
exit 1
fi

DOCKER_OPTS=''
case ${DEVICE} in
cpu)
DOCKER_IMAGE=tensorflow/tensorflow:custom-op
;;
gpu)
DOCKER_IMAGE=tensorflow/tensorflow:custom-op-gpu
DOCKER_OPTS="--runtime=nvidia ${DOCKER_OPTS}"
;;
*)
echo "Invalid or missing device $OPTARG"
exit 1
;;
esac

case ${PYTHON} in
py2) PYTHON_LIB=/usr/bin/python2;;
py3) PYTHON_LIB=/usr/bin/python3;;
*)
echo "Invalid or missing python $OPTARG"
exit 1
;;
esac

if [[ -z "${COMMAND}" ]]; then
echo "command string cannot be empty"
exit 1
fi

DOCKER_CMD="ln -sf ${PYTHON_LIB} /usr/bin/python && ${COMMAND}"
echo "Docker image: ${DOCKER_IMAGE}"
echo "Docker command: ${DOCKER_CMD}"
docker run ${DOCKER_OPTS} \
--network=host \
--rm -v ${ROOT_DIR}:/addons -w /addons \
${DOCKER_IMAGE} \
/bin/bash -c "${DOCKER_CMD}"

0 comments on commit cf5404d

Please sign in to comment.