Skip to content

Commit

Permalink
Enable additional arguments in build_common.sh (#236)
Browse files Browse the repository at this point in the history
* Enable some extra argument parsing in build_common.sh

* Fixup arg parsing and when bash modes are set
  • Loading branch information
wmaxey committed Jul 18, 2023
1 parent ce6a462 commit b3bf3c2
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions ci/build_common.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,52 @@
#!/bin/bash

set -euo pipefail
set -eo pipefail

# Ensure the script is being executed in its containing directory
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";

# Script defaults
CUDA_COMPILER=nvcc

# Check if the correct number of arguments has been provided
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <HOST_COMPILER> <CXX_STANDARD> <GPU_ARCHS>"
function usage {
echo "Usage: $0 [OPTIONS] <HOST_COMPILER> <CXX_STANDARD> <GPU_ARCHS>"
echo "The PARALLEL_LEVEL environment variable controls the amount of build parallelism. Default is the number of cores."
echo "Example: PARALLEL_LEVEL=8 $0 g++-8 14 \"70\" "
echo "Example: $0 clang++-8 17 \"70;75;80-virtual\" "
echo "Possible options: "
echo " -nvcc: path/to/nvcc"
echo " -v/--verbose: enable shell echo for debugging"
exit 1
}

# Check for extra options
# While there are more than 3 arguments, parse switches/options
while [ "$#" -gt 3 ]
do
case "${1}" in
-h) usage ;;
-help) usage ;;
--help) usage ;;
--verbose) VERBOSE=1; shift ;;
-v) VERBOSE=1; shift ;;
-nvcc) CUDA_COMPILER="${2}"; shift 2;;
*) usage ;;
esac
done

if [ $VERBOSE ]; then
set -x
fi

if [ "$#" -ne 3 ]; then
echo "Invalid number of arguments"
usage
fi

# Begin processing unsets after option parsing
set -u

# Assign command line arguments to variables
readonly HOST_COMPILER=$(which $1)
readonly CXX_STANDARD=$2
Expand All @@ -22,7 +55,7 @@ readonly CXX_STANDARD=$2
readonly GPU_ARCHS=$(echo $3 | tr ' ,' ';')

readonly PARALLEL_LEVEL=${PARALLEL_LEVEL:=$(nproc)}
readonly NVCC_VERSION=$(nvcc --version | grep release | awk '{print $6}' | cut -c2-)
readonly NVCC_VERSION=$($CUDA_COMPILER --version | grep release | awk '{print $6}' | cut -c2-)

if [ -z ${DEVCONTAINER_NAME+x} ]; then
BUILD_DIR=../build/local
Expand All @@ -40,6 +73,7 @@ COMMON_CMAKE_OPTIONS="
-DCMAKE_CXX_STANDARD=${CXX_STANDARD} \
-DCMAKE_CUDA_STANDARD=${CXX_STANDARD} \
-DCMAKE_CXX_COMPILER=${HOST_COMPILER} \
-DCMAKE_CUDA_COMPILER=${CUDA_COMPILER} \
-DCMAKE_CUDA_HOST_COMPILER=${HOST_COMPILER} \
-DCMAKE_CUDA_ARCHITECTURES=${GPU_ARCHS} \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
Expand Down

0 comments on commit b3bf3c2

Please sign in to comment.