Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# Makefile

LIBCUOPT_BUILD_DIR ?= cpp/build
VERBOSE_FLAG ?=
PARALLEL_LEVEL ?=

.PHONY: all ninja-build

all: ninja-build

ninja-build:
cmake --build $(LIBCUOPT_BUILD_DIR) $(VERBOSE_FLAG) $(if $(PARALLEL_LEVEL),-j$(PARALLEL_LEVEL),)
35 changes: 32 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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}

VALIDARGS="clean libcuopt libmps_parser cuopt_mps_parser cuopt cuopt_server cuopt_sh_client docs deb -a -b -g -fsanitize -v -l= --verbose-pdlp --build-lp-only --no-fetch-rapids --skip-c-python-adapters --skip-tests-build --skip-routing-build --skip-fatbin-write --host-lineinfo [--cmake-args=\\\"<args>\\\"] [--cache-tool=<tool>] -n --allgpuarch --ci-only-arch --show_depr_warn -h --help"
VALIDARGS="clean libcuopt libmps_parser cuopt_mps_parser cuopt cuopt_server cuopt_sh_client docs deb -a -b -g -fsanitize -v -j -l= --verbose-pdlp --build-lp-only --no-fetch-rapids --skip-c-python-adapters --skip-tests-build --skip-routing-build --skip-fatbin-write --host-lineinfo [--cmake-args=\\\"<args>\\\"] [--cache-tool=<tool>] -n --allgpuarch --ci-only-arch --show_depr_warn -h --help"
HELP="$0 [<target> ...] [<flag> ...]
where <target> is:
clean - remove all existing build artifacts and configuration (start over)
Expand All @@ -34,6 +34,7 @@ HELP="$0 [<target> ...] [<flag> ...]
-b - Build with benchmark settings
-fsanitize - Build with sanitizer
-n - no install step
-j - parallel build jobs (unlimited if no value, or -j<N> for N threads)
--no-fetch-rapids - don't fetch rapids dependencies
-l= - log level. Options are: TRACE | DEBUG | INFO | WARN | ERROR | CRITICAL | OFF. Default=INFO
--verbose-pdlp - verbose mode for pdlp solver
Expand Down Expand Up @@ -85,6 +86,7 @@ CACHE_ARGS=()
PYTHON_ARGS_FOR_INSTALL=("-m" "pip" "install" "--no-build-isolation" "--no-deps")
LOGGING_ACTIVE_LEVEL="INFO"
FETCH_RAPIDS=ON
PARALLEL_LEVEL=""

# Set defaults for vars that may not have been defined externally
# FIXME: if PREFIX is not set, check CONDA_PREFIX, but there is no fallback
Expand Down Expand Up @@ -172,6 +174,26 @@ function cmakeArgs {
read -ra EXTRA_CMAKE_ARGS <<< "$EXTRA_CMAKE_ARGS"
}

function parallelArgs {
# Check for -j option
if [[ -n $(echo "$ARGS" | { grep -E "\-j" || true; } ) ]]; then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a hasArg function doing this:

cuopt/build.sh

Lines 97 to 99 in 7543358

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

Using that might make this a bit easier to read, would you consider it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And actually instead of doing all this command-line parsing and needing to care about spellings like -j2, -j 2, -j=2 etc. I think you might find it easier to just allow the shell variable PARALLEL_LEVEL to be overridden by an environment variable, like cudf does:

PARALLEL_LEVEL=${PARALLEL_LEVEL:=$(nproc)}

(cudf build.sh)

Would you consider that?

And in CI if you explicitly want to use GNU Make, you could override it here:

export CMAKE_GENERATOR=Ninja

With

CMAKE_GENERATOR="Unix Makefiles"

docs: https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#makefile-generators

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shell variable override approach sounds good, thanks for the suggestion! Will implement it.

# Extract -j with optional number (e.g., -j, -j8, -j16)
PARALLEL_ARG=$(echo "$ARGS" | { grep -Eo "\-j[0-9]*" || true; } | head -1)
if [[ -n ${PARALLEL_ARG} ]]; then
# Remove the -j argument from list of args so that it passes validArgs function
ARGS=${ARGS//$PARALLEL_ARG/}
# Extract the number if present
PARALLEL_NUM=$(echo "$PARALLEL_ARG" | sed 's/-j//')
if [[ -z ${PARALLEL_NUM} ]]; then
# If no number specified, use nproc
PARALLEL_LEVEL=$(nproc)
else
PARALLEL_LEVEL=${PARALLEL_NUM}
fi
fi
fi
}


if hasArg -h || hasArg --help; then
echo "${HELP}"
Expand All @@ -183,6 +205,7 @@ if (( NUMARGS != 0 )); then
cacheTool
cmakeArgs
loggingArgs
parallelArgs
for a in ${ARGS}; do
if ! (echo " ${VALIDARGS} " | grep -q " ${a} "); then
echo "Invalid option: ${a}"
Expand Down Expand Up @@ -349,13 +372,19 @@ if buildAll || hasArg libcuopt; then
-DSKIP_ROUTING_BUILD=${SKIP_ROUTING_BUILD} \
-DWRITE_FATBIN=${WRITE_FATBIN} \
-DHOST_LINEINFO=${HOST_LINEINFO} \
-DPARALLEL_LEVEL="${PARALLEL_LEVEL}" \
"${CACHE_ARGS[@]}" \
"${EXTRA_CMAKE_ARGS[@]}" \
"${REPODIR}"/cpp
if hasArg -n; then
cmake --build "${LIBCUOPT_BUILD_DIR}" ${VERBOSE_FLAG}
# Manual make invocation to start its jobserver
make -j${PARALLEL_LEVEL} -C "${REPODIR}" LIBCUOPT_BUILD_DIR="${LIBCUOPT_BUILD_DIR}" VERBOSE_FLAG="${VERBOSE_FLAG}" PARALLEL_LEVEL="${PARALLEL_LEVEL}" ninja-build
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
else
cmake --build "${LIBCUOPT_BUILD_DIR}" --target ${INSTALL_TARGET} ${VERBOSE_FLAG} -j"${PARALLEL_LEVEL}"
if [[ -n "${PARALLEL_LEVEL}" ]]; then
cmake --build "${LIBCUOPT_BUILD_DIR}" --target ${INSTALL_TARGET} ${VERBOSE_FLAG} -j"${PARALLEL_LEVEL}"
else
cmake --build "${LIBCUOPT_BUILD_DIR}" --target ${INSTALL_TARGET} ${VERBOSE_FLAG}
fi
fi
fi

Expand Down
1 change: 1 addition & 0 deletions conda/recipes/libcuopt/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ cache:
- ${{ stdlib("c") }}
- cuda-version =${{ cuda_version }}
- cmake ${{ cmake_version }}
- make
- ninja
- tbb-devel
- zlib
Expand Down
5 changes: 5 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 12.9 AND CMAKE_CUDA_COMPILE
endif()
list(APPEND CUOPT_CUDA_FLAGS -fopenmp)

# Add jobserver flags for parallel compilation if PARALLEL_LEVEL is set
if(PARALLEL_LEVEL AND NOT "${PARALLEL_LEVEL}" STREQUAL "")
message(STATUS "Enabling nvcc jobserver support for parallel builds")
list(APPEND CUOPT_CUDA_FLAGS --threads=0 --split-compile=0 --jobserver)
endif()

if(NOT DISABLE_OPENMP)
find_package(OpenMP)
Expand Down
Loading