Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tools for standardize formatting & sanity-check #63

Merged
merged 13 commits into from
Mar 4, 2019
17 changes: 16 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,31 @@ us**
It is recommended that development is done in the latest
`nightly-custom-op` docker image.
```
docker run --rm -it -v ${PWD}:/working_dir -w /working_dir tensorflow/tensorflow:nightly-custom-op /bin/bash
docker run --rm -it -v ${PWD}:/addons -w /addons tensorflow/tensorflow:nightly-custom-op /bin/bash
```

Try those commands below:

0. Format codes automatically: `make code-format`
1. Sanity check: `make sanity-check`
2. Run unit test: `make unit-test`
3. All of the above: `make`


## Code Testing
#### CI Testing
We're in the process of setting up our nightly CI testing. Because this
project will contain CUDA kernels, we need to make sure that the
hardware will be available from our CI provider.

#### Locally Testing

```
docker run --rm -it -v ${PWD}:/addons -w /addons tensorflow/tensorflow:nightly-custom-op make unit-test
```

or run manually:

```
./configure.sh # Links project with TensorFlow dependency

Expand Down
12 changes: 10 additions & 2 deletions ci_testing/addons_cpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
# limitations under the License.
#
# ==============================================================================
# Make sure we're in the project root path.
SCRIPT_DIR=$( cd ${0%/*} && pwd -P )
ROOT_DIR=$( cd "$SCRIPT_DIR/.." && pwd -P )
if [[ ! -d "tensorflow_addons" ]]; then
echo "ERROR: PWD: $PWD is not project root"
exit 1
fi

set -x

Expand All @@ -27,12 +34,13 @@ 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`
/bin/bash configure.sh
# Use default configuration here.
yes 'y' | ./configure.sh

## Run bazel test command. Double test timeouts to avoid flakes.
bazel test -c opt -k \
--jobs=${N_JOBS} --test_timeout 300,450,1200,3600 \
--test_output=errors --local_test_jobs=8 \
//tensorflow_addons/...

exit $?
exit $?
30 changes: 30 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
seanpmorgan marked this conversation as resolved.
Show resolved Hide resolved
#
# 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.
# ==============================================================================
.PHONY: all

all: code-format sanity-check unit-test

# TODO: install those dependencies in docker image (dockerfile).
install-ci-dependency:
bash tools/ci_build/install/install_ci_dependency.sh --quiet
seanpmorgan marked this conversation as resolved.
Show resolved Hide resolved

code-format: install-ci-dependency
bash tools/ci_build/code_format.sh --incremental --in-place

sanity-check: install-ci-dependency
bash tools/ci_build/ci_sanity.sh --incremental

unit-test:
bash ci_testing/addons_cpu.sh
131 changes: 131 additions & 0 deletions tools/ci_build/builds/builds_common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/usr/bin/env bash
seanpmorgan marked this conversation as resolved.
Show resolved Hide resolved
# 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.
# ==============================================================================
#
# Common Bash functions used by build scripts

COLOR_NC='\033[0m'
COLOR_BOLD='\033[1m'
COLOR_LIGHT_GRAY='\033[0;37m'
COLOR_GREEN='\033[0;32m'
COLOR_RED='\033[0;31m'

die() {
# Print a message and exit with code 1.
#
# Usage: die <error_message>
# e.g., die "Something bad happened."

echo $@
exit 1
}

num_cpus() {
# Get the number of CPUs
N_CPUS=$(grep -c ^processor /proc/cpuinfo)
if [[ -z ${N_CPUS} ]]; then
die "ERROR: Unable to determine the number of CPUs"
fi

echo ${N_CPUS}
}

# List files changed (i.e., added, or revised).
# Usage: get_changed_files_from_master_branch
get_changed_files_from_master_branch() {
git diff origin/master --diff-filter=d --name-only "$@"
seanpmorgan marked this conversation as resolved.
Show resolved Hide resolved
}

# List bazel files changed that still exist,
# i.e., not removed.
# Usage: get_bazel_files_to_check [--incremental]
get_bazel_files_to_check() {
if [[ "$1" == "--incremental" ]]; then
get_changed_files_from_master_branch -- 'BUILD*'
elif [[ -z "$1" ]]; then
find . -name 'BUILD*'
else
die "Found unsupported args: $@ for get_bazel_files_to_check."
fi
}

# List python files changed that still exist,
# i.e., not removed.
# Usage: get_py_files_to_check [--incremental]
get_py_files_to_check() {
if [[ "$1" == "--incremental" ]]; then
get_changed_files_from_master_branch -- '*.py'
elif [[ -z "$1" ]]; then
find . -name '*.py'
else
die "Found unsupported args: $@ for get_py_files_to_check."
fi
}

# List .h|.cc files changed that still exist,
# i.e., not removed.
# Usage: get_clang_files_to_check [--incremental]
get_clang_files_to_check() {
if [[ "$1" == "--incremental" ]]; then
get_changed_files_from_master_branch -- '*.h' '*.cc'
elif [[ -z "$1" ]]; then
find . -name '*.h' -o -name '*.cc'
else
die "Found unsupported args: $@ for get_clang_files_to_check."
fi
}

realpath() {
# Get the real path of a file
# Usage: realpath <file_path>

if [[ $# != "1" ]]; then
die "realpath: incorrect usage"
fi

[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}

to_lower () {
# Convert string to lower case.
# Usage: to_lower <string>

echo "$1" | tr '[:upper:]' '[:lower:]'
}

calc_elapsed_time() {
# Calculate elapsed time. Takes nanosecond format input of the kind output
# by date +'%s%N'
#
# Usage: calc_elapsed_time <START_TIME> <END_TIME>

if [[ $# != "2" ]]; then
die "calc_elapsed_time: incorrect usage"
fi

START_TIME=$1
END_TIME=$2

if [[ ${START_TIME} == *"N" ]]; then
# Nanosecond precision not available
START_TIME=$(echo ${START_TIME} | sed -e 's/N//g')
END_TIME=$(echo ${END_TIME} | sed -e 's/N//g')
ELAPSED="$(expr ${END_TIME} - ${START_TIME}) s"
else
ELAPSED="$(expr $(expr ${END_TIME} - ${START_TIME}) / 1000000) ms"
fi

echo ${ELAPSED}
}
Loading