-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathrun
More file actions
executable file
·2006 lines (1794 loc) · 67.3 KB
/
Copy pathrun
File metadata and controls
executable file
·2006 lines (1794 loc) · 67.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# SPDX-FileCopyrightText: Copyright (c) 2022-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# Error out if a command fails or a variable is not defined
set -eu
#===============================================================================
# Default values for environment variables.
#===============================================================================
init_globals() {
# Paths
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
CALLER=$(readlink -f "$0")
fi
export RUN_SCRIPT_FILE="$(readlink -f "${BASH_SOURCE[0]}")"
export TOP=$(dirname "${RUN_SCRIPT_FILE}")
# Versions
export SUPPORTED_CUDA_VERSIONS=("12" "13")
export CUDA_DEFAULT_VERSION="12"
# Executables
export HOLOSCAN_PY_EXE=${HOLOSCAN_PY_EXE:-"python3"}
export HOLOSCAN_DOCKER_EXE=${HOLOSCAN_DOCKER_EXE:-"docker"}
# Options
export DO_DRY_RUN="false" # print commands but do not execute them. Used by run_command
export DO_STANDALONE="false" # do not run prerequisite functions
export NO_CACHE="" # by default, use cache
# Define default img and dir names
export SDK_BUILD_IMG="holoscan-sdk-build"
export SDK_RUN_IMG="holoscan-sdk-run"
export SDK_BUILD_DIR="build"
export SDK_INSTALL_DIR="install"
# Use buildkit for docker build
export DOCKER_BUILDKIT=1
# Only enabled TTY if supported
[ -t 1 ] && export USE_TTY="--tty" || export USE_TTY=""
}
#===============================================================================
# Utility functions
#===============================================================================
# Build Type ===================================================================
get_buildtype_str() {
local build_type="${1:-}"
local build_type_str
case "${build_type}" in
debug|Debug)
build_type_str="Debug"
;;
release|Release)
build_type_str="Release"
;;
rel-debug|RelWithDebInfo)
build_type_str="RelWithDebInfo"
;;
*)
build_type_str="${CMAKE_BUILD_TYPE:-Release}"
;;
esac
echo -n "${build_type_str}"
}
# Boolean ======================================================================
get_boolean() {
local bool_in="${1:-}"
local bool_out
case "${bool_in}" in
true|yes|1)
bool_out=true
;;
false|no|0)
bool_out=false
;;
*)
return 1
esac
echo -n "${bool_out}"
}
# Archs, GPUs, CUDA =================================================================
checkif_x86_64() {
if [ $(get_host_arch) == "x86_64" ]; then
return 0
else
return 1
fi
}
checkif_aarch64() {
if [ $(get_host_arch) == "aarch64" ]; then
return 0
else
return 1
fi
}
get_host_arch() {
echo -n "$(uname -m)"
}
is_cross_compiling() {
[ "$ARCH" != $(get_host_arch) ]
}
get_gnu_arch_str() {
local arch="${1:-}"
local arch_str
case "${arch}" in
amd64|x86_64|x86|linux/amd64)
arch_str="x86_64"
;;
arm64|aarch64|arm|linux/arm64)
arch_str="aarch64"
;;
*)
return 1
esac
echo -n "${arch_str}"
}
get_docker_arch_str() {
local arch="${1:-}"
local arch_str
case "${arch}" in
amd64|x86_64|x86|linux/amd64)
arch_str="amd64"
;;
arm64|aarch64|arm|linux/arm64)
arch_str="arm64"
;;
*)
return 1
esac
echo -n "${arch_str}"
}
get_platform_str() {
echo -n "linux/$(get_docker_arch_str $ARCH)"
}
get_gpu_str() {
local gpu="${1:-}"
local gpu_str=$gpu
case "${gpu}" in
igpu|iGPU|integrated|Jetson)
gpu_str="igpu"
;;
dgpu|dGPU|discrete|RTX)
gpu_str="dgpu"
;;
esac
echo -n "${gpu_str}"
}
get_host_gpu() {
if ! command -v nvidia-smi >/dev/null; then
c_echo_err Y "Could not find any GPU drivers on host. Defaulting build to target dGPU/CPU stack."
echo -n "dgpu"
elif nvidia-smi 2>/dev/null | grep nvgpu -q; then
echo -n "igpu"
else
echo -n "dgpu"
fi
}
is_cross_gpu() {
[ "$GPU" != $(get_host_gpu) ]
}
get_default_cuda_major_version() {
echo -n "${CUDA_DEFAULT_VERSION}"
}
validate_cuda_major_version() {
local cuda_major="${1:-}"
# Check if cuda_major is in the supported list
local found=0
for version in "${SUPPORTED_CUDA_VERSIONS[@]}"; do
if [[ "$cuda_major" == "$version" ]]; then
found=1
break
fi
done
if [[ $found -eq 0 ]]; then
c_echo_err R "Invalid CUDA version: '${cuda_major}'. Supported versions are: ${SUPPORTED_CUDA_VERSIONS[*]}"
return 1
fi
echo -n "${cuda_major}"
}
get_build_flavor_str() {
local suffix="cu${CUDA_MAJOR}"
if [ "$ARCH" = "aarch64" ]; then
suffix+="-$ARCH-$GPU"
else
suffix+="-$ARCH"
fi
echo -n "$suffix"
}
get_build_img_name() {
echo -n "${SDK_BUILD_IMG}-$(get_build_flavor_str)"
}
get_run_img_name() {
echo -n "${SDK_RUN_IMG}-$(get_build_flavor_str)"
}
get_build_dir() {
echo -n "${SDK_BUILD_DIR}-$(get_build_flavor_str)"
}
get_install_dir() {
echo -n "${SDK_INSTALL_DIR}-$(get_build_flavor_str)"
}
get_driver_version() {
if command -v nvidia-smi >/dev/null 2>&1; then
# Pick the first unique driver version reported (covers multi-GPU setups).
nvidia-smi --query-gpu=driver_version --format=csv,noheader 2>/dev/null \
| head -n1 | tr -d ' \n'
else
echo -n "" # No driver found – let the caller decide what to do.
fi
}
# CUDA =========================================================================
get_cuda_archs() {
local cuda_archs="${1:-}"
# match https://cmake.org/cmake/help/latest/prop_tgt/CUDA_ARCHITECTURES.html
case "${cuda_archs}" in
native|NATIVE)
cuda_archs_str="native"
;;
all|ALL)
cuda_archs_str="all"
;;
all-major|ALL-MAJOR|major|MAJOR)
cuda_archs_str="all-major"
;;
*)
cuda_archs_str="${1:-}"
;;
esac
echo -n "${cuda_archs_str}"
}
# ID ===========================================================================
get_group_id() {
local group=$1
cat /etc/group | grep $group | cut -d: -f3
}
# Version ======================================================================
get_git_sha() {
echo -n "$(git rev-parse --short=9 HEAD)"
}
get_git_branch() {
# Can't use "/" in tag, convert to "-"
echo -n "$(git branch --show-current | sed 's|/|_|g')"
}
get_git_tag() {
echo -n "$(git tag --points-at HEAD)"
}
get_version() {
echo -n "$(cat $TOP/VERSION)"
}
get_image_tag_flags() {
local img_name=$1
local tags=("latest" $(get_version) $(get_git_branch) $(get_git_tag) $(get_git_sha))
local flags=""
for tag in "${tags[@]}"; do
flags+="-t ${img_name}:${tag} "
done
echo -n "$flags"
}
#===============================================================================
# Section: CLI
#===============================================================================
install_python_dev_deps() {
if [ -n "${VIRTUAL_ENV-}" ] || [ -n "${CONDA_PREFIX-}" ]; then
run_command ${HOLOSCAN_PY_EXE} -m pip install -q -r ${TOP}/python/requirements.cu${CUDA_MAJOR}.txt
run_command ${HOLOSCAN_PY_EXE} -m pip install -q -r ${TOP}/python/requirements.dev.txt
else
c_echo_err R "You must be in a virtual environment to install dependencies."
if [ ! -e "$TOP/.venv/dev/bin/python3" ]; then
c_echo_err W "Installing a virtual environment at " G "$TOP/.venv/dev" W " ..."
run_command ${HOLOSCAN_PY_EXE} -m venv "$TOP/.venv/dev"
fi
c_echo_err W "Please activate the virtual environment at " G "$TOP/.venv/dev" W " and execute this command again."
c_echo_err
c_echo_err G " source $TOP/.venv/dev/bin/activate"
c_echo_err G " $0 $@"
exit 1
fi
}
setup_cli_dev_desc() { c_echo 'Setup development environment for Holoscan CLI
'
}
setup_cli_dev() {
c_echo W "Setup Holoscan CLI development environment..."
if [ -f "/.dockerenv" ]; then
c_echo_err "WARNING: devcontainer is not supported for CLI development"
exit
fi
install_python_dev_deps
local build_path=$TOP/$(get_build_dir)/python/lib/holoscan
if [ -d "${build_path}" ]; then
c_echo "Found build directory: $build_path"
else
c_echo_err "Build directory ${build_path} not found, please run ./run build first"
exit
fi
DEST=$TOP/python/holoscan
c_echo "Removing existing symlinks from $DEST/**/*.so"
find $DEST -name *.so -delete
c_echo "Creating symlinks from $build_path/* to $DEST"
cp -as $build_path/* $DEST &> /dev/null
}
#===============================================================================
# Section: Build
#===============================================================================
clear_cache_desc() { c_echo 'Clear cache folders (including build/install folders)
'
}
clear_cache() {
c_echo W "Clearing cache..."
run_command rm -rf ${TOP}/build
run_command rm -rf ${TOP}/install
run_command rm -rf ${TOP}/build-*
run_command rm -rf ${TOP}/install-*
run_command rm -rf ${TOP}/src/core/distributed/generated/*
run_command rm -rf ${TOP}/.cache/ccache
run_command rm -rf ${TOP}/.cache/cpm
run_command rm -rf ${TOP}/.cache/gxf
# Clean up old build images, keeping only IDs associated with a ':latest' tag
c_echo W "Cleaning up old '${SDK_BUILD_IMG}-*' images and docker buildx cache..."
local base_img_pattern="${SDK_BUILD_IMG}-*"
local latest_ids=$(docker images -q --filter="reference=${base_img_pattern}:latest" | sort -u)
local all_ids=$(docker images -q --filter="reference=${base_img_pattern}" | sort -u)
local ids_to_delete=$(echo "$all_ids" | grep -v -f <(echo "$latest_ids"))
if [ -n "$ids_to_delete" ]; then
run_command docker rmi -f $ids_to_delete || true
fi
run_command docker buildx prune -f --filter 'type=regular' # don't delete cache mounts
}
check_system_deps_desc() { c_echo 'Check system dependencies
Ensure that the system has all adequate prerequisites to be
able to build the Holoscan SDK.
'
}
check_system_deps() {
c_echo W "Setup development environment..."
if ! command -v ${HOLOSCAN_DOCKER_EXE} > /dev/null; then
fatal G "${HOLOSCAN_DOCKER_EXE}" W " doesn't exists. Please install Docker:
https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository"
fi
if ! $(${HOLOSCAN_DOCKER_EXE} buildx version &> /dev/null) ; then
fatal G "${HOLOSCAN_DOCKER_EXE} buildx plugin" W " is missing. Please install " G "docker-buildx-plugin" W ":
https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository"
fi
if ! groups | grep -e docker -e root -q; then
c_echo_err G "groups" W " doesn't contain 'docker' group. Please add 'docker' group to your user."
fatal G "groups" W " doesn't contain 'docker' group. Please add 'docker' group to your user." B '
# Create the docker group.
sudo groupadd docker
# Add your user to the docker group.
sudo usermod -aG docker $USER
newgrp docker
docker run hello-world'
fi
if checkif_x86_64 && is_cross_compiling && [ ! -f /proc/sys/fs/binfmt_misc/qemu-aarch64 ]; then
fatal G "qemu-aarch64" W " doesn't exists. Please install qemu with binfmt-support to run Docker container with aarch64 platform" B '
# Install the qemu packages
sudo apt-get install qemu binfmt-support qemu-user-static
# Execute the registering scripts
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes'
fi
# Check NVIDIA CTK version
min_ctk_version="1.12.0"
recommended_ctk_version="1.14.1"
if ! command -v nvidia-ctk > /dev/null; then
fatal G "nvidia-ctk" W " not found. Please install the NVIDIA Container Toolkit."
fi
ctk_version_output=$(nvidia-ctk --version | grep version)
ctk_version_pattern="([0-9]+\.[0-9]+\.[0-9]+)"
if [[ "$ctk_version_output" =~ $ctk_version_pattern ]]; then
ctk_version="${BASH_REMATCH[1]}"
if [[ "$(echo -e "$ctk_version\n$min_ctk_version" | sort -V | head -n1)" == "$ctk_version" ]]; then
fatal "Found nvidia-ctk Version $ctk_version. Version $min_ctk_version+ is required ($recommended_ctk_version+ recommended)."
fi
else
c_echo_err R "Could not extract nvidia-ctk version number."
c_echo_err " Version $min_ctk_version+ required."
c_echo_err " Version $recommended_ctk_version+ recommended."
fi
}
build_image_desc() { c_echo 'Build the image where we can build the SDK
This will generate an image will the following tags:
- `latest`
- from VERSION file
- from git branch name
- from git tag, if any
- from git commit sha - used in the build and launch methods
'
}
build_image() {
# Prerequisite steps
if [ "$DO_STANDALONE" != "true" ]; then
check_system_deps
fi
# Error if requesting iGPU and x86_64 when cross-compiling
if [ "$ARCH" = "x86_64" ] && [ "$GPU" = "igpu" ]; then
fatal R "Can't combine 'x86_64' arch with 'igpu' GPU type"
fi
# Docker tags (-t name:versions)
local docker_tags=$(get_image_tag_flags $(get_build_img_name))
# Docker build
local extra_args="$@"
run_command $HOLOSCAN_DOCKER_EXE build \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg GPU_TYPE=${GPU} \
--build-arg CUDA_MAJOR=${CUDA_MAJOR} \
--platform $(get_platform_str) \
--network=host \
${NO_CACHE} \
${docker_tags} \
${extra_args} \
${TOP}
}
build_desc() { c_echo 'Build the SDK with CMake
This command will build the SDK with optional configuration arguments.
Arguments:
--build_libtorch [true | false] : Build the SDK with libtorch support
Default: true
Associated environment variable: HOLOSCAN_BUILD_LIBTORCH
--config : Use this option to specify additional CMake configuration options.
Example: --config "-DHOLOSCAN_BUILD_EXAMPLES:BOOL=ON"
--cudaarchs [native | all | <custom_arch_list>]
Default: "native" when building for host architecture, "all" otherwise
Associated environment variable: CMAKE_CUDA_ARCHITECTURES
--type [debug | release | rel-debug] : Specify the type of build
Default: release
Associated environment variable: CMAKE_BUILD_TYPE
--parallel, -j <njobs> : Specify the maximum number of concurrent processes to be used when building
Default: maximum (number of CPUs, using 'nproc')
Associated environment variable: CMAKE_BUILD_PARALLEL_LEVEL
--buildpath, -d <build_directory> : Change the build path.
Default: build-<arch>[-<gpu>]
Associated environment variable: CMAKE_BUILD_PATH
--installprefix, -i <install_directory> : Specify the install directory
Default: install-<arch>[-<gpu>]
Associated environment variable: CMAKE_INSTALL_PREFIX
--reconfigure, -f: Force reconfiguration of the CMake project. By default CMake is only run if
a CMakeCache.txt does not exist in the build directory or if CMake detects a reconfigure
is needed.
Default: false
--tidy [true | false] : Build the SDK with clang-tidy (will be slower)
Default: false
Associated environment variable: HOLOSCAN_ENABLE_CLANG_TIDY
--tidy-headers [true | false] : Also check project headers with clang-tidy (requires --tidy true)
Default: false
Associated environment variable: HOLOSCAN_CLANG_TIDY_CHECK_HEADERS
--build-python [true | false] : Build the SDK without python support
Default: true
Associated environment variable: HOLOSCAN_BUILD_PYTHON
--sccache [true | false] : Use sccache for build caching (speeds up rebuilds)
Default: true
Associated environment variable: HOLOSCAN_USE_SCCACHE
Optional: Set SCCACHE_MEMCACHED_ENDPOINT for distributed caching (e.g., server:11211)
'
}
build() {
# Prerequisite steps
if [ "$DO_STANDALONE" != "true" ]; then
build_image
fi
# Default cuda architecture
local default_cuda_archs="native"
if is_cross_compiling || is_cross_gpu; then
default_cuda_archs="all"
fi
# Parse env variables first or set default values
local cuda_archs=$(get_cuda_archs "${CMAKE_CUDA_ARCHITECTURES:-$default_cuda_archs}")
local build_type=$(get_buildtype_str "${CMAKE_BUILD_TYPE:-release}")
local build_njobs="${CMAKE_BUILD_PARALLEL_LEVEL:-$(nproc)}"
local build_path="${CMAKE_BUILD_PATH:-$(get_build_dir)}"
local install_prefix="${CMAKE_INSTALL_PREFIX:-$(get_install_dir)}"
local reconfigure=false
local build_libtorch="${HOLOSCAN_BUILD_LIBTORCH:-ON}"
local build_python="${HOLOSCAN_BUILD_PYTHON:-ON}"
local enable_clang_tidy="${HOLOSCAN_ENABLE_CLANG_TIDY:-OFF}"
local clang_tidy_check_headers="${HOLOSCAN_CLANG_TIDY_CHECK_HEADERS:-OFF}"
local use_sccache="${HOLOSCAN_USE_SCCACHE:-ON}"
local config_args=""
# Mount sccache directory to container.
local sccache_rel_dir="/.cache/sccache"
local sccache_host_dir
if [[ -n "${SCCACHE_DIR:-}" ]]; then
sccache_host_dir="$SCCACHE_DIR"
else
sccache_host_dir="${HOME}${sccache_rel_dir}"
fi
local sccache_dir_opt=""
if [[ "$use_sccache" == "ON" ]]; then
mkdir -p "$sccache_host_dir"
sccache_dir_opt="-v $sccache_host_dir:$sccache_rel_dir -e SCCACHE_DIR=$sccache_rel_dir"
fi
# Check if memcached endpoint is reachable before passing it to container
local sccache_memcached_opt=""
if [ -n "${SCCACHE_MEMCACHED_ENDPOINT-}" ]; then
local endpoint="${SCCACHE_MEMCACHED_ENDPOINT}"
local host="${endpoint%:*}"
local port="${endpoint##*:}"
# Test if the endpoint is reachable (timeout after 5 seconds)
if timeout 5 bash -c "echo -n > /dev/tcp/${host}/${port}" 2>/dev/null; then
sccache_memcached_opt="-e SCCACHE_MEMCACHED_ENDPOINT"
else
c_echo_err Y "Warning: SCCACHE_MEMCACHED_ENDPOINT is set to ${endpoint} but server is not reachable."
c_echo_err Y " Proceeding without distributed caching."
fi
fi
# Parse args
local extra_args=""
while [[ $# -gt 0 ]]; do
case $1 in
--build-python)
build_python_val=$(get_boolean "$2")
if [ "$build_python_val" == "false" ]; then
build_python='OFF'
fi
reconfigure=true
shift
shift
;;
--build_libtorch)
build_libtorch_val=$(get_boolean "$2")
if [ "$build_libtorch_val" == "false" ]; then
build_libtorch='OFF'
fi
reconfigure=true
shift
shift
;;
--tidy)
tidy_val=$(get_boolean "$2")
if [ "$tidy_val" == "true" ]; then
enable_clang_tidy='ON'
fi
reconfigure=true
shift
shift
;;
--tidy-headers)
tidy_headers_val=$(get_boolean "$2")
if [ "$tidy_headers_val" == "true" ]; then
clang_tidy_check_headers='ON'
fi
reconfigure=true
shift
shift
;;
--sccache)
sccache_val=$(get_boolean "$2")
if [ "$sccache_val" == "true" ]; then
use_sccache='ON'
else
use_sccache='OFF'
fi
reconfigure=true
shift
shift
;;
--cudaarchs)
cuda_archs=$(get_cuda_archs "$2")
reconfigure=true
shift
shift
;;
--type)
build_type=$(get_buildtype_str "$2")
reconfigure=true
shift
shift
;;
--parallel|-j)
build_njobs="$2"
shift
shift
;;
--buildpath|-d)
build_path="$2"
shift
shift
;;
--installprefix|-i)
install_prefix="$2"
shift
shift
;;
--reconfigure|-f)
reconfigure=true
shift
;;
--config | -c)
config_args+=("$2")
reconfigure=true
shift
shift
;;
*)
extra_args+=("$1")
shift
;;
esac
done
# Error if requesting native cuda arch explicitly when cross-compiling
if [ "$cuda_archs" = "native" ] && (is_cross_compiling || is_cross_gpu); then
fatal Y "Cross-compiling " W "(host: $(get_host_arch), target: $ARCH)" R " does not support 'native' cuda architecture."
fi
# Native means we need the container to access the GPU for CMake to choose the architecture
# to use for nvcc.
if [ "$cuda_archs" = "native" ]; then
runtime=nvidia
else
runtime=runc
fi
# DOCKER PARAMETERS
#
# --rm
# Deletes the container after the command runs
#
# --net=host
# Provide access to the host network
#
# --ulimit memlock=-1
# --ulimit stack=67108864
# Set resource limits for memory locking (unlimited) and stack size (64MB), to prevent
# out-of-memory issues on systems with high core counts during parallel builds.
#
# --interactive (-i)
# Making the container interactive allows cancelling the build
#
# ${USE_TTY}
# Set --tty (-t) when TTY is possible only
#
# --entrypoint=bash
# Override the default entrypoint to hide the regular message from the base image
#
# --runtime ${runtime}
# Docker runtime. Should ideally be runc for build (no need for drivers).
#
# --platform $(get_platform_str)
# Platform to build
#
# -u $(id -u):$(id -g)
# Ensures the generated files (build, install...) are owned by $USER and not root
#
# -v ${TOP}:/workspace/holoscan-sdk
# Mount the source directory
#
# -w /workspace/holoscan-sdk
# Start in the source directory
#
#
# CMAKE PARAMETERS
#
# -S . -B ${build_path}
# Generic configuration
#
# -D CMAKE_BUILD_TYPE=${build_type}
# Define the build type (release, debug...). Can be passed as env to docker also.
#
# -D CMAKE_CUDA_ARCHITECTURES=${cuda_archs}
# Define the cuda architectures to build for (native, all, all-major, custom). Apart from
# native, the last arch will be used for real and virtual architectures (PTX, forward
# compatible) while the previous archs will be real only.
#
# CMAKE BUILD COMMAND
#
# cmake --build ${build_path} -j ${build_njobs}
# Builds the SDK using the build path at ${build_path} with number of concurrent
# jobs given by -j ${build_njobs}
#
img="$(get_build_img_name):$(get_git_sha)"
config_args="${config_args[@]}"
run_command $HOLOSCAN_DOCKER_EXE run \
--rm \
--net=host \
--ulimit memlock=-1 \
--ulimit stack=67108864 \
--interactive \
${USE_TTY} \
--entrypoint=bash \
--runtime=${runtime} \
--platform $(get_platform_str) \
-u $(id -u):$(id -g) \
-v ${TOP}:/workspace/holoscan-sdk \
-w /workspace/holoscan-sdk \
${sccache_dir_opt} \
${sccache_memcached_opt} \
${extra_args[@]} \
$img \
-c "set -e
if [ ! -f '${build_path}/build.ninja' ] || ${reconfigure} ; then
cmake -S . -B ${build_path} -G Ninja \
-D HOLOSCAN_CUDA_MAJOR_VERSION=${CUDA_MAJOR} \
-D HOLOSCAN_BUILD_LIBTORCH=${build_libtorch} \
-D HOLOSCAN_BUILD_PYTHON=${build_python} \
-D HOLOSCAN_PYTHON_EXAMPLES=${build_python} \
-D HOLOSCAN_ENABLE_CLANG_TIDY=${enable_clang_tidy} \
-D HOLOSCAN_CLANG_TIDY_CHECK_HEADERS=${clang_tidy_check_headers} \
-D HOLOSCAN_USE_SCCACHE=${use_sccache} \
-D CMAKE_CUDA_ARCHITECTURES='${cuda_archs}' \
-D CMAKE_BUILD_TYPE=${build_type} \
${config_args}
fi
cmake --build ${build_path} -j ${build_njobs}
if [ '${use_sccache}' = 'ON' ]; then
sccache --show-stats > ${build_path}/sccache-stats.txt
fi
# Install Holoscan SDK and its dependencies
cmake --install ${build_path} --prefix ${install_prefix} --component holoscan
cmake --install ${build_path} --prefix ${install_prefix} --component holoscan-core
cmake --install ${build_path} --prefix ${install_prefix} --component holoscan-gxf_extensions
cmake --install ${build_path} --prefix ${install_prefix} --component holoscan-examples
cmake --install ${build_path} --prefix ${install_prefix} --component holoscan-gxf_libs
cmake --install ${build_path} --prefix ${install_prefix} --component holoscan-gxf_bins
cmake --install ${build_path} --prefix ${install_prefix} --component holoscan-modules
cmake --install ${build_path} --prefix ${install_prefix} --component holoscan-dependencies
cmake --install ${build_path} --prefix ${install_prefix} --component holoscan-python_libs
cmake --install ${build_path} --prefix ${install_prefix} --component cli11
cmake --install ${build_path} --prefix ${install_prefix} --component concurrentqueue
cmake --install ${build_path} --prefix ${install_prefix} --component dlpack
cmake --install ${build_path} --prefix ${install_prefix} --component fmt_core
cmake --install ${build_path} --prefix ${install_prefix} --component matx
cmake --install ${build_path} --prefix ${install_prefix} --component nvtx3
cmake --install ${build_path} --prefix ${install_prefix} --component rapids_logger
cmake --install ${build_path} --prefix ${install_prefix} --component rmm
cmake --install ${build_path} --prefix ${install_prefix} --component spdlog
cmake --install ${build_path} --prefix ${install_prefix} --component tl-expected
cmake --install ${build_path} --prefix ${install_prefix} --component ucxx
# CCCL libraries
cmake --install ${build_path} --prefix ${install_prefix} --component CCCL
cmake --install ${build_path} --prefix ${install_prefix} --component CUB
cmake --install ${build_path} --prefix ${install_prefix} --component cudax
cmake --install ${build_path} --prefix ${install_prefix} --component libcudacxx
cmake --install ${build_path} --prefix ${install_prefix} --component Thrust
# Install Holoscan Sensor Bridge (if enabled)
if grep -q "HOLOSCAN_BUILD_HOLOLINK:BOOL=ON" ${build_path}/CMakeCache.txt; then
hololink_install_prefix=${install_prefix}/../install-hololink
mkdir -p \${hololink_install_prefix}
hololink_install_prefix=\$(realpath \${hololink_install_prefix})
for component in \
hololink-camera-sensor \
hololink-cmake \
hololink-common \
hololink-core \
hololink-emulation \
hololink-emulation-sensors \
hololink-examples \
hololink-module \
hololink-modules \
hololink-module-tools \
hololink-operators \
hololink-python_libs \
hololink-python_tools \
hololink-roce-operators \
hololink-scripts \
hololink-sensors \
hololink-tools
do
cmake --install ${build_path} --prefix \${hololink_install_prefix} --component \$component
done
else
echo \"Hololink is not built, skipping installation\"
fi
"
}
build_run_image_desc() { c_echo 'Build the runtime image
Build a lightweight docker image meant for running applications only.
Arguments:
--cpp : Only build with C++ dependencies
--cpp-no-mkl : (x86_64 only) Only build with C++ dependencies apart from MKL (torch dependency)
'
}
build_run_image() {
# Prerequisite steps
if [ "$DO_STANDALONE" != "true" ]; then
build $@
fi
# Parse args
local stage="runtime_cpp_py"
local extra_args=""
while [[ $# -gt 0 ]]; do
case $1 in
--cpp)
stage="runtime_cpp"
shift
;;
--cpp-no-mkl)
stage="runtime_cpp_no_mkl"
shift
;;
*)
extra_args+=("$1")
shift
;;
esac
done
# Current build image to copy from some stages
local current_build_img="$(get_build_img_name):$(get_git_sha)"
# Run image tags (-t name:versions)
local docker_tags=$(get_image_tag_flags $(get_run_img_name))
# Build the runtime image
run_command $HOLOSCAN_DOCKER_EXE build \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg BUILD_IMAGE=${current_build_img} \
--build-arg HOST_INSTALL_DIR=$(get_install_dir) \
--build-arg GPU_TYPE=${GPU} \
--platform $(get_platform_str) \
--network=host \
--target ${stage} \
${NO_CACHE} \
${docker_tags} \
${extra_args[@]} \
-f ${TOP}/runtime_docker/Dockerfile \
${TOP}
}
#===============================================================================
# Section: Documentation
#===============================================================================
build_docs_desc() { c_echo 'Build and validate the Fern user guide
Runs the repository documentation pipeline from the current checkout. Any
remaining arguments are passed to docs/scripts/build_holoscan_docs.py.
With no arguments and no FERN_TOKEN, generated library MDX is skipped; when no
local API tree exists, validation omits the API-reference section.
Examples:
./public/run build_docs
./run build_docs # public repository layout
./public/run build_docs --skip-library-mdx
'
}
build_docs() {
local docs_args=("$@")
if [[ $# -eq 0 && -z "${FERN_TOKEN:-}" ]]; then
docs_args=(--skip-library-mdx)
fi
run_command "${HOLOSCAN_PY_EXE}" \
"${TOP}/docs/scripts/build_holoscan_docs.py" "${docs_args[@]}"
}
live_docs_desc() { c_echo 'Start a foreground local Fern user-guide preview
Runs the same documentation pipeline with --preview. Any remaining arguments
are passed to docs/scripts/build_holoscan_docs.py after --preview.
With no arguments and no FERN_TOKEN, the local preview omits the API-reference
section when no generated library MDX exists.
Examples:
./public/run live_docs
./run live_docs # public repository layout
./public/run live_docs --skip-library-mdx
'
}
live_docs() {
local docs_args=(--preview "$@")
if [[ $# -eq 0 && -z "${FERN_TOKEN:-}" ]]; then
docs_args+=(--skip-library-mdx)
fi
build_docs "${docs_args[@]}"
}
#===============================================================================
# Section: Test
#===============================================================================
lint_desc() { c_echo 'Lint the repository (via pre-commit)
Runs all pre-commit hooks (copyright, ruff, cpplint, cmakelint, codespell, markdownlint)
on the whole repo. Configuration is in .pre-commit-config.yaml at repo root.
pre-commit is resolved automatically:
1. uvx pre-commit -- if uvx (from uv) is available (isolated, no pip pollution)
2. pre-commit -- if already installed
3. pip install -- as a last resort
Arguments:
When no arguments are given, runs all hooks with --all-files.
When arguments are given, they are passed directly to pre-commit run.
Examples:
./run lint # all hooks, all files
./run lint update-notice-files --all-files # single hook, all files
./run lint ruff-check --all-files # single hook, all files
'
}
lint() {
local REPO_ROOT
REPO_ROOT="$(git -C "${TOP}" rev-parse --show-toplevel 2>/dev/null)" || REPO_ROOT="$(dirname "${TOP}")"
if [ ! -f "${REPO_ROOT}/.pre-commit-config.yaml" ]; then
c_echo_err R "Not found: ${REPO_ROOT}/.pre-commit-config.yaml"
return 1
fi
local pre_commit_cmd
if command -v uvx &>/dev/null; then
pre_commit_cmd="uvx pre-commit"
else
if ! command -v pre-commit &>/dev/null; then
c_echo W "Neither pre-commit nor uvx available, installing pre-commit via pip..."
run_command ${HOLOSCAN_PY_EXE} -m pip install pre-commit
fi
pre_commit_cmd="pre-commit"
fi
c_echo W "Running pre-commit (copyright + lint hooks) on all files"