Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ repos:
hooks:
- id: shellcheck
args: ["--severity=warning"]
files: ^ci/

default_language_version:
python: python3
126 changes: 72 additions & 54 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ARGS=$*

# NOTE: ensure all dir changes are relative to the location of this
# script, and that this script resides in the repo dir!
REPODIR=$(cd $(dirname $0); pwd)
REPODIR=$(cd "$(dirname "$0")"; pwd)
LIBCUOPT_BUILD_DIR=${LIBCUOPT_BUILD_DIR:=${REPODIR}/cpp/build}
LIBMPS_PARSER_BUILD_DIR=${LIBMPS_PARSER_BUILD_DIR:=${REPODIR}/cpp/libmps_parser/build}

Expand Down Expand Up @@ -77,8 +77,8 @@ INSTALL_TARGET=install
BUILD_DISABLE_DEPRECATION_WARNING=ON
BUILD_ALL_GPU_ARCH=0
BUILD_CI_ONLY=0
CACHE_ARGS=""
PYTHON_ARGS_FOR_INSTALL="-m pip install --no-build-isolation --no-deps"
CACHE_ARGS=()
PYTHON_ARGS_FOR_INSTALL=("-m" "pip" "install" "--no-build-isolation" "--no-deps")
LOGGING_ACTIVE_LEVEL="INFO"
FETCH_RAPIDS=ON

Expand All @@ -91,53 +91,53 @@ BUILD_ABI=${BUILD_ABI:=ON}
export CMAKE_GENERATOR=Ninja

function hasArg {
(( ${NUMARGS} != 0 )) && (echo " ${ARGS} " | grep -q " $1 ")
(( NUMARGS != 0 )) && (echo " ${ARGS} " | grep -q " $1 ")
}

function buildAll {
(( ${NUMARGS} == 0 )) || !(echo " ${ARGS} " | grep -q " [^-]\+ ")
(( NUMARGS == 0 )) || ! (echo " ${ARGS} " | grep -q " [^-]\+ ")
}

function cacheTool {
# Check for multiple cache options
if [[ $(echo $ARGS | { grep -Eo "\-\-cache\-tool" || true; } | wc -l ) -gt 1 ]]; then
if [[ $(echo "$ARGS" | { grep -Eo "\-\-cache\-tool" || true; } | wc -l ) -gt 1 ]]; then
echo "Multiple --cache-tool options were provided, please provide only one: ${ARGS}"
exit 1
fi
# Check for cache tool option
if [[ -n $(echo $ARGS | { grep -E "\-\-cache\-tool" || true; } ) ]]; then
if [[ -n $(echo "$ARGS" | { grep -E "\-\-cache\-tool" || true; } ) ]]; then
# There are possible weird edge cases that may cause this regex filter to output nothing and fail silently
# the true pipe will catch any weird edge cases that may happen and will cause the program to fall back
# on the invalid option error
CACHE_TOOL=$(echo $ARGS | sed -e 's/.*--cache-tool=//' -e 's/ .*//')
CACHE_TOOL=$(echo "$ARGS" | sed -e 's/.*--cache-tool=//' -e 's/ .*//')
if [[ -n ${CACHE_TOOL} ]]; then
# Remove the full CACHE_TOOL argument from list of args so that it passes validArgs function
ARGS=${ARGS//--cache-tool=$CACHE_TOOL/}
CACHE_ARGS="-DCMAKE_CUDA_COMPILER_LAUNCHER=${CACHE_TOOL} -DCMAKE_C_COMPILER_LAUNCHER=${CACHE_TOOL} -DCMAKE_CXX_COMPILER_LAUNCHER=${CACHE_TOOL}"
CACHE_ARGS=("-DCMAKE_CUDA_COMPILER_LAUNCHER=${CACHE_TOOL}" "-DCMAKE_C_COMPILER_LAUNCHER=${CACHE_TOOL}" "-DCMAKE_CXX_COMPILER_LAUNCHER=${CACHE_TOOL}")
fi
fi
}

function loggingArgs {
if [[ $(echo $ARGS | { grep -Eo "\-l" || true; } | wc -l ) -gt 1 ]]; then
if [[ $(echo "$ARGS" | { grep -Eo "\-l" || true; } | wc -l ) -gt 1 ]]; then
echo "Multiple -l logging options were provided, please provide only one: ${ARGS}"
exit 1
fi

LOG_LEVEL_LIST=("TRACE" "DEBUG" "INFO" "WARN" "ERROR" "CRITICAL" "OFF")

# Check for logging option
if [[ -n $(echo $ARGS | { grep -E "\-l" || true; } ) ]]; then
LOGGING_ARGS=$(echo $ARGS | { grep -Eo "\-l=\S+" || true; })
if [[ -n $(echo "$ARGS" | { grep -E "\-l" || true; } ) ]]; then
LOGGING_ARGS=$(echo "$ARGS" | { grep -Eo "\-l=\S+" || true; })
if [[ -n ${LOGGING_ARGS} ]]; then
# Remove the full log argument from list of args so that it passes validArgs function
ARGS=${ARGS//$LOGGING_ARGS/}
# Filter the full argument down to just the extra string that will be added to cmake call
LOGGING_ARGS=$(echo $LOGGING_ARGS | sed -e 's/^"//' -e 's/"$//' | cut -c4- | grep -Eo "\S+" | tr '[:lower:]' '[:upper:]')
if [[ "${LOG_LEVEL_LIST[@]}" =~ $LOGGING_ARGS ]]; then
LOGGING_ARGS=$(echo "$LOGGING_ARGS" | sed -e 's/^"//' -e 's/"$//' | cut -c4- | grep -Eo "\S+" | tr '[:lower:]' '[:upper:]')
if [[ "${LOG_LEVEL_LIST[*]}" =~ $LOGGING_ARGS ]]; then
LOGGING_ACTIVE_LEVEL=$LOGGING_ARGS
else
echo "Invalid logging arg $LOGGING_ARGS, expected any of ${LOG_LEVEL_LIST[@]}"
echo "Invalid logging arg $LOGGING_ARGS, expected any of ${LOG_LEVEL_LIST[*]}"
exit 1
fi
fi
Expand All @@ -146,24 +146,26 @@ function loggingArgs {

function cmakeArgs {
# Check for multiple cmake args options
if [[ $(echo $ARGS | { grep -Eo "\-\-cmake\-args" || true; } | wc -l ) -gt 1 ]]; then
if [[ $(echo "$ARGS" | { grep -Eo "\-\-cmake\-args" || true; } | wc -l ) -gt 1 ]]; then
echo "Multiple --cmake-args options were provided, please provide only one: ${ARGS}"
exit 1
fi

# Check for cmake args option
if [[ -n $(echo $ARGS | { grep -E "\-\-cmake\-args" || true; } ) ]]; then
if [[ -n $(echo "$ARGS" | { grep -E "\-\-cmake\-args" || true; } ) ]]; then
# There are possible weird edge cases that may cause this regex filter to output nothing and fail silently
# the true pipe will catch any weird edge cases that may happen and will cause the program to fall back
# on the invalid option error
EXTRA_CMAKE_ARGS=$(echo $ARGS | { grep -Eo "\-\-cmake\-args=\".+\"" || true; })
EXTRA_CMAKE_ARGS=$(echo "$ARGS" | { grep -Eo "\-\-cmake\-args=\".+\"" || true; })
if [[ -n ${EXTRA_CMAKE_ARGS} ]]; then
# Remove the full EXTRA_CMAKE_ARGS argument from list of args so that it passes validArgs function
ARGS=${ARGS//$EXTRA_CMAKE_ARGS/}
# Filter the full argument down to just the extra string that will be added to cmake call
EXTRA_CMAKE_ARGS=$(echo $EXTRA_CMAKE_ARGS | grep -Eo "\".+\"" | sed -e 's/^"//' -e 's/"$//')
EXTRA_CMAKE_ARGS=$(echo "$EXTRA_CMAKE_ARGS" | grep -Eo "\".+\"" | sed -e 's/^"//' -e 's/"$//')
fi
fi

read -ra EXTRA_CMAKE_ARGS <<< "$EXTRA_CMAKE_ARGS"
}


Expand All @@ -173,7 +175,7 @@ if hasArg -h || hasArg --help; then
fi

# Check for valid usage
if (( ${NUMARGS} != 0 )); then
if (( NUMARGS != 0 )); then
cacheTool
cmakeArgs
loggingArgs
Expand Down Expand Up @@ -215,12 +217,27 @@ if hasArg --show_depr_warn; then
BUILD_DISABLE_DEPRECATION_WARNING=OFF
fi

function contains_string {
local search_string="$1"
shift
local array=("$@")

for element in "${array[@]}"; do
if [[ "$element" == *"$search_string"* ]]; then
return 0
fi
done

return 1
}

# Append `-DFIND_CUOPT_CPP=ON` to CMAKE_ARGS unless a user specified the option.
if [[ "${EXTRA_CMAKE_ARGS}" != *"DFIND_CUOPT_CPP"* ]]; then
EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DFIND_CUOPT_CPP=ON"
if ! contains_string "DFIND_CUOPT_CPP" "${EXTRA_CMAKE_ARGS[@]}"; then
EXTRA_CMAKE_ARGS+=("-DFIND_CUOPT_CPP=ON")
fi
if [[ "${EXTRA_CMAKE_ARGS}" != *"DFIND_MPS_PARSER_CPP"* ]]; then
EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DFIND_MPS_PARSER_CPP=ON"

if ! contains_string "DFIND_MPS_PARSER_CPP" "${EXTRA_CMAKE_ARGS[@]}"; then
EXTRA_CMAKE_ARGS+=("-DFIND_MPS_PARSER_CPP=ON")
fi

# If clean given, run it prior to any other steps
Expand All @@ -230,14 +247,14 @@ if hasArg clean; then
# The find removes all contents but leaves the dirs, the rmdir
# attempts to remove the dirs but can fail safely.
for bd in ${BUILD_DIRS}; do
if [ -d ${bd} ]; then
find ${bd} -mindepth 1 -delete
rmdir ${bd} || true
if [ -d "${bd}" ]; then
find "${bd}" -mindepth 1 -delete
rmdir "${bd}" || true
fi
done

# Cleaning up python artifacts
find ${REPODIR}/python/ | grep -E "(__pycache__|\.pyc|\.pyo|\.so|\_skbuild$)" | xargs rm -rf
find "${REPODIR}"/python/ | grep -E "(__pycache__|\.pyc|\.pyo|\.so|\_skbuild$)" | xargs rm -rf

fi

Expand All @@ -249,7 +266,7 @@ fi
if [ ${BUILD_ALL_GPU_ARCH} -eq 1 ]; then
CUOPT_CMAKE_CUDA_ARCHITECTURES="RAPIDS"
echo "Building for *ALL* supported GPU architectures..."
else
else
if [ ${BUILD_CI_ONLY} -eq 1 ]; then
if [[ ${CUDA_VERSION} == 11* ]]; then
CUOPT_CMAKE_CUDA_ARCHITECTURES="70-real;80"
Expand All @@ -267,12 +284,12 @@ fi
################################################################################
# Configure, build, and install libmps_parser
if buildAll || hasArg libmps_parser; then
mkdir -p ${LIBMPS_PARSER_BUILD_DIR}
cd ${LIBMPS_PARSER_BUILD_DIR}
mkdir -p "${LIBMPS_PARSER_BUILD_DIR}"
cd "${LIBMPS_PARSER_BUILD_DIR}"
cmake -DDEFINE_ASSERT=${DEFINE_ASSERT} \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
${CACHE_ARGS} \
${REPODIR}/cpp/libmps_parser/
-DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \
"${CACHE_ARGS[@]}" \
"${REPODIR}"/cpp/libmps_parser/

if hasArg -n; then
cmake --build "${LIBMPS_PARSER_BUILD_DIR}" ${VERBOSE_FLAG}
Expand All @@ -284,61 +301,62 @@ fi
################################################################################
# Configure, build, and install libcuopt
if buildAll || hasArg libcuopt; then
mkdir -p ${LIBCUOPT_BUILD_DIR}
cd ${LIBCUOPT_BUILD_DIR}
mkdir -p "${LIBCUOPT_BUILD_DIR}"
cd "${LIBCUOPT_BUILD_DIR}"
cmake -DDEFINE_ASSERT=${DEFINE_ASSERT} \
-DDEFINE_BENCHMARK=${DEFINE_BENCHMARK} \
-DDEFINE_BENCHMARK="${DEFINE_BENCHMARK}" \
-DDEFINE_PDLP_VERBOSE_MODE=${DEFINE_PDLP_VERBOSE_MODE} \
-DLIBCUOPT_LOGGING_LEVEL=${LOGGING_ACTIVE_LEVEL} \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
-DLIBCUOPT_LOGGING_LEVEL="${LOGGING_ACTIVE_LEVEL}" \
-DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \
-DCMAKE_CUDA_ARCHITECTURES=${CUOPT_CMAKE_CUDA_ARCHITECTURES} \
-DDISABLE_DEPRECATION_WARNING=${BUILD_DISABLE_DEPRECATION_WARNING} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DFETCH_RAPIDS=${FETCH_RAPIDS} \
${EXTRA_CMAKE_ARGS} \
${REPODIR}/cpp
"${EXTRA_CMAKE_ARGS[@]}" \
"${REPODIR}"/cpp
if hasArg -n; then
cmake --build "${LIBCUOPT_BUILD_DIR}" ${VERBOSE_FLAG}
else
cmake --build "${LIBCUOPT_BUILD_DIR}" --target ${INSTALL_TARGET} ${VERBOSE_FLAG} -j${PARALLEL_LEVEL}
cmake --build "${LIBCUOPT_BUILD_DIR}" --target ${INSTALL_TARGET} ${VERBOSE_FLAG} -j"${PARALLEL_LEVEL}"
fi
fi


# Build and install the cuopt Python package
if buildAll || hasArg cuopt; then
cd ${REPODIR}/python/cuopt
cd "${REPODIR}"/python/cuopt

SKBUILD_CMAKE_ARGS="-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX};-DCMAKE_LIBRARY_PATH=${LIBCUOPT_BUILD_DIR};-DCMAKE_CUDA_ARCHITECTURES=${CUOPT_CMAKE_CUDA_ARCHITECTURES};${EXTRA_CMAKE_ARGS}" \
python ${PYTHON_ARGS_FOR_INSTALL} .
# $EXTRA_CMAKE_ARGS gets concatenated into a string with [*] and then we find/replace spaces with semi-colons
SKBUILD_CMAKE_ARGS="-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX};-DCMAKE_LIBRARY_PATH=${LIBCUOPT_BUILD_DIR};-DCMAKE_CUDA_ARCHITECTURES=${CUOPT_CMAKE_CUDA_ARCHITECTURES};${EXTRA_CMAKE_ARGS[*]// /;}" \
python "${PYTHON_ARGS_FOR_INSTALL[@]}" .
fi

# Build and install the cuopt MPS parser Python package
if buildAll || hasArg cuopt_mps_parser; then
cd ${REPODIR}/python/cuopt/cuopt/linear_programming
cd "${REPODIR}"/python/cuopt/cuopt/linear_programming

SKBUILD_CMAKE_ARGS="-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX};-DCMAKE_LIBRARY_PATH=${LIBCUOPT_BUILD_DIR};-DCMAKE_CUDA_ARCHITECTURES=${CUOPT_CMAKE_CUDA_ARCHITECTURES};${EXTRA_CMAKE_ARGS}" \
python ${PYTHON_ARGS_FOR_INSTALL} .
SKBUILD_CMAKE_ARGS="-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX};-DCMAKE_LIBRARY_PATH=${LIBCUOPT_BUILD_DIR};-DCMAKE_CUDA_ARCHITECTURES=${CUOPT_CMAKE_CUDA_ARCHITECTURES};${EXTRA_CMAKE_ARGS[*]// /;}" \
python "${PYTHON_ARGS_FOR_INSTALL[@]}" .
fi

# Build and install the cuopt_server Python package
if buildAll || hasArg cuopt_server; then
cd ${REPODIR}/python/cuopt_server
python ${PYTHON_ARGS_FOR_INSTALL} .
cd "${REPODIR}"/python/cuopt_server
python "${PYTHON_ARGS_FOR_INSTALL[@]}" .
fi

# Build and install the cuopt_sh_client Python package
if buildAll || hasArg cuopt_sh_client; then
cd ${REPODIR}/python/cuopt_self_hosted/
python ${PYTHON_ARGS_FOR_INSTALL} .
cd "${REPODIR}"/python/cuopt_self_hosted/
python "${PYTHON_ARGS_FOR_INSTALL[@]}" .
fi

# Build the docs
if buildAll || hasArg docs; then
cd ${REPODIR}/cpp/doxygen
cd "${REPODIR}"/cpp/doxygen
doxygen Doxyfile

cd ${REPODIR}/docs/cuopt
cd "${REPODIR}"/docs/cuopt
make clean
make html
fi
27 changes: 15 additions & 12 deletions datasets/get_test_data.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
Expand Down Expand Up @@ -86,7 +87,7 @@ ALL_DATASET_DATA="${TSP_DATASET_DATA} ${CVRP_DATASET_DATA} ${ACVRP_DATASET_DATA}
NUMARGS=$#
ARGS=$*
function hasArg {
(( ${NUMARGS} != 0 )) && (echo " ${ARGS} " | grep -q " $1 ")
(( NUMARGS != 0 )) && (echo " ${ARGS} " | grep -q " $1 ")
}

if hasArg -h || hasArg --help; then
Expand All @@ -111,7 +112,9 @@ else
DATASET_DATA="${ALL_DATASET_DATA}"
fi

# shellcheck disable=SC2207
URLS=($(echo "$DATASET_DATA"|awk '{if (NR%4 == 3) print $0}')) # extract 3rd fields to a bash array
# shellcheck disable=SC2207
DESTDIRS=($(echo "$DATASET_DATA"|awk '{if (NR%4 == 0) print $0}')) # extract 4th fields to a bash array

echo Downloading ...
Expand All @@ -121,7 +124,7 @@ rm -rf tmp
mkdir tmp
cd tmp
# Loop through URLs with error handling
for url in ${URLS[*]}; do
for url in "${URLS[@]}"; do
# Try up to 3 times with continue option
wget -4 --tries=3 --continue --progress=dot:mega --retry-connrefused "${url}" || {
echo "Failed to download: ${url}"
Expand All @@ -132,10 +135,10 @@ cd ..

# Setup the destination dirs, removing any existing ones first!
for index in ${!DESTDIRS[*]}; do
rm -rf ${DESTDIRS[$index]}
rm -rf "${DESTDIRS[$index]}"
done
for index in ${!DESTDIRS[*]}; do
mkdir -p ${DESTDIRS[$index]}
mkdir -p "${DESTDIRS[$index]}"
done

# Iterate over the arrays and untar the nth tarfile to the nth dest directory.
Expand All @@ -144,18 +147,18 @@ echo Decompressing ...
set +e # Disable exit on error for the entire script

for index in ${!DESTDIRS[*]}; do
tfname=$(basename ${URLS[$index]})
tfname=$(basename "${URLS[$index]}")

if file --mime-type "tmp/${tfname}" | grep -q gzip$; then
tar xvzf tmp/${tfname} -C ${DESTDIRS[$index]} || true
elif file --mime-type "tmp/${tfname}" | grep -q zip$; then
unzip tmp/${tfname} -d ${DESTDIRS[$index]} || true
if file --mime-type "tmp/${tfname}" | grep -q gzip$; then
tar xvzf tmp/"${tfname}" -C "${DESTDIRS[$index]}" || true
elif file --mime-type "tmp/${tfname}" | grep -q zip$; then
unzip tmp/"${tfname}" -d "${DESTDIRS[$index]}" || true
else
tar xvf tmp/${tfname} -C ${DESTDIRS[$index]} || true
tar xvf tmp/"${tfname}" -C "${DESTDIRS[$index]}" || true
fi

if ls ${DESTDIRS[$index]}/*.gz >/dev/null 2>&1; then
gzip -d ${DESTDIRS[$index]}/* || true
if ls "${DESTDIRS[$index]}"/*.gz >/dev/null 2>&1; then
gzip -d "${DESTDIRS[$index]}"/* || true
fi
done

Expand Down
5 changes: 1 addition & 4 deletions datasets/linear_programming/download_pdlp_test_dataset.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
Expand All @@ -13,10 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

#!/bin/bash



set -euo pipefail

# 10 easiest Mittleman instances
Expand Down
Loading