-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
parallel_gpu_execute.sh
to build_tools/ci
PiperOrigin-RevId: 718115722
- Loading branch information
1 parent
427aaaa
commit 153ff32
Showing
6 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2016 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. | ||
# ============================================================================== | ||
# | ||
# | ||
# A script to run multiple GPU tests in parallel controlled with an environment | ||
# variable. | ||
# | ||
# Required environment variables: | ||
# TF_GPU_COUNT = Number of GPUs available. | ||
|
||
TF_GPU_COUNT=${TF_GPU_COUNT:-4} | ||
TF_TESTS_PER_GPU=${TF_TESTS_PER_GPU:-8} | ||
|
||
# This function is used below in rlocation to check that a path is absolute | ||
function is_absolute { | ||
[[ "$1" = /* ]] || [[ "$1" =~ ^[a-zA-Z]:[/\\].* ]] | ||
} | ||
|
||
export TF_PER_DEVICE_MEMORY_LIMIT_MB=${TF_PER_DEVICE_MEMORY_LIMIT_MB:-2048} | ||
|
||
# ******************************************************************* | ||
# This section of the script is needed to | ||
# make things work on windows under msys. | ||
# ******************************************************************* | ||
RUNFILES_MANIFEST_FILE="${TEST_SRCDIR}/MANIFEST" | ||
function rlocation() { | ||
if is_absolute "$1" ; then | ||
# If the file path is already fully specified, simply return it. | ||
echo "$1" | ||
elif [[ -e "$TEST_SRCDIR/$1" ]]; then | ||
# If the file exists in the $TEST_SRCDIR then just use it. | ||
echo "$TEST_SRCDIR/$1" | ||
elif [[ -e "$RUNFILES_MANIFEST_FILE" ]]; then | ||
# If a runfiles manifest file exists then use it. | ||
echo "$(grep "^$1 " "$RUNFILES_MANIFEST_FILE" | sed 's/[^ ]* //')" | ||
fi | ||
} | ||
|
||
TEST_BINARY="$(rlocation $TEST_WORKSPACE/${1#./})" | ||
shift | ||
# ******************************************************************* | ||
|
||
mkdir -p /var/lock | ||
# Try to acquire any of the TF_GPU_COUNT * TF_TESTS_PER_GPU | ||
# slots to run a test at. | ||
# | ||
# Prefer to allocate 1 test per GPU over 4 tests on 1 GPU. | ||
# So, we iterate over TF_TESTS_PER_GPU first. | ||
for j in `seq 0 $((TF_TESTS_PER_GPU-1))`; do | ||
for i in `seq 0 $((TF_GPU_COUNT-1))`; do | ||
exec {lock_fd}>/var/lock/gpulock${i}_${j} || exit 1 | ||
if flock -n "$lock_fd"; | ||
then | ||
( | ||
# This export only works within the brackets, so it is isolated to one | ||
# single command. | ||
export CUDA_VISIBLE_DEVICES=$i | ||
export HIP_VISIBLE_DEVICES=$i | ||
echo "Running test $TEST_BINARY $* on GPU $CUDA_VISIBLE_DEVICES" | ||
"$TEST_BINARY" $@ | ||
) | ||
return_code=$? | ||
flock -u "$lock_fd" | ||
exit $return_code | ||
fi | ||
done | ||
done | ||
|
||
echo "Cannot find a free GPU to run the test $* on, exiting with failure..." | ||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters