Skip to content

Commit

Permalink
Add option to specify # of jobs for CMake build, for both run and dev…
Browse files Browse the repository at this point in the history
…_container

* Limit the number of CMake jobs to one less than the host CPU count

Signed-off-by: M Q <mingmelvinq@nvidia.com>

* Add option to specify # of jobs for CMake build, for both run and dev_container

Signed-off-by: M Q <mingmelvinq@nvidia.com>

---------

Signed-off-by: M Q <mingmelvinq@nvidia.com>
  • Loading branch information
MMelQin authored Dec 2, 2024
1 parent 1302671 commit c09c35a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 13 additions & 1 deletion dev_container
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ build_and_run_desc() { c_echo 'Build and run a requested application in a Docker
--run_args : Run the app with additional args
--verbose : Print extra output to console
--dryrun : View build and run commands without doing anything
--parallel_jobs: Set the # of parallel build jobs, e.g. $(($(nproc)-1))
'
}

Expand All @@ -892,6 +893,7 @@ build_and_run() {
local run_app=1
local install=""
local configure_args=""
local parallel_jobs=""

# Parse CLI arguments next
while [[ $# -gt 0 ]]; do
Expand Down Expand Up @@ -1014,6 +1016,16 @@ build_and_run() {
exit 1
fi
;;
--parallel_jobs)
if [[ -n "$2" ]]; then
parallel_jobs="--parallel '$2'"
shift 2
else
echo "Error: --parallel_jobs requires a value"
build_and_run_desc
exit 1
fi
;;
*)
if [[ -z "$app_name" ]]; then
app_name="$1"
Expand Down Expand Up @@ -1057,7 +1069,7 @@ build_and_run() {
run_command ${SCRIPT_DIR}/dev_container build "${container_build_args[@]}"
if [[ $build_app == 1 ]]; then
c_echo "Building application..."
run_command ${SCRIPT_DIR}/dev_container launch $container_launch_args --docker_opts "$docker_opts" -- -c "./run build $app_name $install $extra_build_with $extra_build_args"
run_command ${SCRIPT_DIR}/dev_container launch $container_launch_args --docker_opts "$docker_opts" -- -c "./run build $app_name $install $parallel_jobs $extra_build_with $extra_build_args"
fi

if [[ $run_app == 1 ]]; then
Expand Down
11 changes: 10 additions & 1 deletion run
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,9 @@ build_desc() {
echo " --configure-args <extra_args> : Additional configuration arguments"
echo " multiple arguments can be passed between quotes"
echo " or using several --configure-args in the command line"
echo " --parallel <jobs> : Build in parallel using the given number of jobs."
echo " Only needed to override the native build tool's default."
echo " Example: --parallel $(($(nproc)-1))"
echo ""
echo "Prior to the first build use './run setup' to install the required dependencies"
echo ""
Expand Down Expand Up @@ -619,6 +622,7 @@ build() {
local build_path="${CMAKE_BUILD_PATH}"
local benchmark=false
local install=false
local parallel_jobs=""

for i in "${!ARGS[@]}"; do
arg="${ARGS[i]}"
Expand Down Expand Up @@ -650,6 +654,10 @@ build() {
elif [ "$arg" = "--buildpath" ]; then
build_path="${ARGS[i+1]}"
skipnext=1
elif [ "$arg" = "--parallel" ]; then
parallel_jobs="${ARGS[i+1]}"
echo "Setting the number of parallel build jobs: ${ARGS[i+1]}"
skipnext=1
elif [[ $arg = -* ]]; then
print_error "Unknown option $arg"
exit 1
Expand Down Expand Up @@ -692,7 +700,8 @@ build() {
run_command cmake -S . -B ${build_path} ${cmake_extra_args} -DCMAKE_BUILD_TYPE=${build_type} ${holoscan_sdk} ${application}
ret=$?
check_exit_code $ret "Error building application."
run_command cmake --build ${build_path} -j
# Job concurrency determined by the underlying build tool unless a number is specified
run_command cmake --build ${build_path} -j ${parallel_jobs}
ret=$?
check_exit_code $ret "Error building application."

Expand Down

0 comments on commit c09c35a

Please sign in to comment.