-
Notifications
You must be signed in to change notification settings - Fork 61
/
run
executable file
·819 lines (700 loc) · 25.8 KB
/
run
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
#!/bin/bash
#
# Copyright (c) 2020-2021, NVIDIA CORPORATION.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
init_globals() {
if [ "$0" != "/bin/bash" ]; then
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
export RUN_SCRIPT_FILE="$(readlink -f "$0")"
else
export RUN_SCRIPT_FILE="$(readlink -f "${BASH_SOURCE[0]}")"
fi
export TOP=$(git rev-parse --show-toplevel || $(dirname "${RUN_SCRIPT_FILE}"))
}
################################################################################
# Utility functions
################################################################################
#######################################
# Get list of available commands from a given input file.
#
# Available commands and command summary are extracted by checking a pattern
# "_desc() { echo '".
# Section title is extracted by checking a pattern "# Section: ".
# This command is used for listing available commands in CLI.
#
# e.g.)
# "# Section: String/IO functions"
# => "# String/IO functions"
# "to_lower_desc() { echo 'Convert to lower case"
# => "to_lower ----------------- Convert to lower case"
#
# Arguments:
# $1 - input file that defines commands
# Returns:
# Print list of available commands from $1
#######################################
get_list_of_available_commands() {
local file_name="$1"
if [ ! -e "$1" ]; then
echo "$1 doesn't exist!"
fi
local line_str='--------------------------------'
local IFS= cmd_lines="$(IFS= cat "$1" | grep -E -e "^(([[:alpha:]_[:digit:]]+)_desc\(\)|# Section: )" | sed "s/_desc() *{ *echo '/ : /")"
local line
while IFS= read -r line; do
local cmd=$(echo "$line" | cut -d":" -f1)
local desc=$(echo "$line" | cut -d":" -f2-)
if [ "$cmd" = "# Section" ]; then
c_echo B "${desc}"
else
# there is no substring operation in 'sh' so use 'cut'
local dash_line="$(echo "${line_str}" | cut -c ${#cmd}-)" # = "${line_str:${#cmd}}"
c_echo Y " ${cmd}" w " ${dash_line} ${desc}"
fi
# use <<EOF, not '<<<"$cmd_lines"' to be executable in sh
done <<EOF
$cmd_lines
EOF
}
my_cat_prefix() {
local IFS
local prefix="$1"
local line
while IFS= read -r line; do
echo "${prefix}${line}" # -e option doesn't work in 'sh' so disallow escaped characters
done <&0
}
c_str() {
local old_color=39
local old_attr=0
local color=39
local attr=0
local text=""
#local no_change=0
for i in "$@"; do
case "$i" in
r|R)
color=31
;;
g|G)
color=32
;;
y|Y)
color=33
;;
b|B)
color=34
;;
p|P)
color=35
;;
c|C)
color=36
;;
w|W)
color=37
;;
z|Z)
color=0
;;
esac
case "$i" in
l|L|R|G|Y|B|P|C|W)
attr=1
;;
n|N|r|g|y|b|p|c|w)
attr=0
;;
z|Z)
attr=0
;;
*)
text="${text}$i"
esac
if [ ${old_color} -ne ${color} ] || [ ${old_attr} -ne ${attr} ]; then
text="${text}\033[${attr};${color}m"
old_color=$color
old_attr=$attr
fi
done
/bin/echo -en "$text"
}
c_echo() {
local old_opt="$(shopt -op xtrace)" # save old xtrace option
set +x # unset xtrace
local text="$(c_str "$@")"
/bin/echo -e "$text\033[0m"
eval "${old_opt}" # restore old xtrace option
}
echo_err() {
>&2 echo "$@"
}
c_echo_err() {
>&2 c_echo "$@"
}
printf_err() {
>&2 printf "$@"
}
get_item_ranges() {
local indexes="$1"
local list="$2"
echo -n "$(echo "${list}" | xargs | cut -d " " -f "${indexes}")"
return $?
}
get_unused_ports() {
local num_of_ports=${1:-1}
local start=${2:-49152}
local end=${3:-61000}
comm -23 \
<(seq ${start} ${end} | sort) \
<(ss -tan | awk '{print $4}' | while read line; do echo ${line##*\:}; done | grep '[0-9]\{1,5\}' | sort -u) \
| shuf | tail -n ${num_of_ports} # use tail instead head to avoid broken pipe in VSCode terminal
}
newline() {
echo
}
info() {
c_echo W "$(date -u '+%Y-%m-%d %H:%M:%S') [INFO] " Z "$@"
}
error() {
echo R "$(date -u '+%Y-%m-%d %H:%M:%S') [ERROR] " Z "$@"
}
fatal() {
echo R "$(date -u '+%Y-%m-%d %H:%M:%S') [FATAL] " Z "$@"
echo
if [ -n "${SCRIPT_DIR}" ]; then
exit 1
fi
}
run_command() {
local status=0
local cmd="$*"
c_echo B "$(date -u '+%Y-%m-%d %H:%M:%S') " W "\$ " G "${cmd}"
[ "$(echo -n "$@")" = "" ] && return 1 # return 1 if there is no command available
"$@"
status=$?
unset IFS
return $status
}
retry() {
local retries=$1
shift
local count=0
until run_command "$@"; do
exit=$?
wait=$((2 ** count))
count=$((count + 1))
if [ $count -lt $retries ]; then
info "Retry $count/$retries. Exit code=$exit, Retrying in $wait seconds..."
sleep $wait
else
fatal "Retry $count/$retries. Exit code=$exit, no more retries left."
return 1
fi
done
return 0
}
get_arch() {
local platform="${1:-$(uname -p)}"
local platform_str
case "${platform}" in
amd64|x86_64|x86|linux/amd64)
platform_str="x86_64"
;;
arm64|aarch64|arm|linux/arm64)
platform_str="aarch64"
;;
esac
echo -n "${platform_str}"
}
is_aarch64() {
get_arch | grep -q "aarch64" && return 0 || return 1
}
is_x86_64() {
get_arch | grep -q "x86_64" && return 0 || return 1
}
#==================================================================================
# Section: Build
#==================================================================================
build_local_libcucim_() {
local source_folder=${1:-${TOP}}
local build_type=${2:-debug}
local build_type_str=${3:-Debug}
local prefix=${4:-}
local build_folder=${source_folder}/build-${build_type}
local CMAKE_CMD=${CMAKE_CMD:-cmake}
pushd ${source_folder} > /dev/null
# Copy cufile SDK from host system to temp/cuda
copy_gds_files_ $source_folder
# Copy libjpeg SDK from host system to temp/cuda
copy_nvjpeg_files_ $source_folder
${CMAKE_CMD} -S ${source_folder} -B ${build_folder} -G "Unix Makefiles" \
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE \
-DCMAKE_PREFIX_PATH=${prefix} \
-DCMAKE_BUILD_TYPE=${build_type_str} \
-DCMAKE_INSTALL_PREFIX=${source_folder}/install
${CMAKE_CMD} --build ${build_folder} --config ${build_type_str} --target cucim -- -j $(nproc)
${CMAKE_CMD} --build ${build_folder} --config ${build_type_str} --target install -- -j $(nproc)
popd
}
build_local_cuslide_() {
local source_folder=${1:-${TOP}/cpp/plugins/cucim.kit.cuslide}
local build_type=${2:-debug}
local build_type_str=${3:-Debug}
local prefix=${4:-}
local build_folder=${source_folder}/build-${build_type}
local CMAKE_CMD=${CMAKE_CMD:-cmake}
pushd ${source_folder} > /dev/null
${CMAKE_CMD} -S ${source_folder} -B ${build_folder} -G "Unix Makefiles" \
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE \
-DCMAKE_BUILD_TYPE=${build_type_str} \
-DCMAKE_PREFIX_PATH=${prefix} \
-DCMAKE_INSTALL_PREFIX=${source_folder}/install
${CMAKE_CMD} --build ${build_folder} --config ${build_type_str} --target cucim.kit.cuslide -- -j $(nproc)
${CMAKE_CMD} --build ${build_folder} --config ${build_type_str} --target install -- -j $(nproc)
popd
}
build_local_cumed_() {
local source_folder=${1:-${TOP}/cpp/plugins/cucim.kit.cumed}
local build_type=${2:-debug}
local build_type_str=${3:-Debug}
local prefix=${4:-}
local build_folder=${source_folder}/build-${build_type}
local CMAKE_CMD=${CMAKE_CMD:-cmake}
pushd ${source_folder} > /dev/null
${CMAKE_CMD} -S ${source_folder} -B ${build_folder} -G "Unix Makefiles" \
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE \
-DCMAKE_BUILD_TYPE=${build_type_str} \
-DCMAKE_PREFIX_PATH=${prefix} \
-DCMAKE_INSTALL_PREFIX=${source_folder}/install
${CMAKE_CMD} --build ${build_folder} --config ${build_type_str} --target cucim.kit.cumed -- -j $(nproc)
${CMAKE_CMD} --build ${build_folder} --config ${build_type_str} --target install -- -j $(nproc)
popd
}
build_local_cucim_() {
local source_folder=${1:-${TOP}/python}
local build_type=${2:-debug}
local build_type_str=${3:-Debug}
local prefix=${4:-}
local build_folder=${source_folder}/build-${build_type}
local CMAKE_CMD=${CMAKE_CMD:-cmake}
pushd ${source_folder} > /dev/null
local python_library=$(python3 -c "import distutils.sysconfig as sysconfig, os; print(os.path.join(sysconfig.get_config_var('LIBDIR'), sysconfig.get_config_var('LDLIBRARY')))")
local python_include_dir=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())")
${CMAKE_CMD} -S ${source_folder} -B ${build_folder} -G "Unix Makefiles" \
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE \
-DCMAKE_BUILD_TYPE=${build_type_str} \
-DCMAKE_PREFIX_PATH=${prefix} \
-DCMAKE_INSTALL_PREFIX=${source_folder}/install \
-DPYTHON_EXECUTABLE=$(which python3) \
-DPYTHON_LIBRARY=${python_library} \
-DPYTHON_INCLUDE_DIR=${python_include_dir}
${CMAKE_CMD} --build ${build_folder} --config ${build_type_str} --target cucim -- -j $(nproc)
${CMAKE_CMD} --build ${build_folder} --config ${build_type_str} --target install -- -j $(nproc)
popd
}
build_local_desc() { echo 'Build locally
Compile binaries locally
Arguments:
$1 - subcommand [all|clean_cache|clean|libcucim|cuslide|cumed|cucim] (default: all)
$2 - build type [debug|release|rel-debug] (default: debug)
'
}
build_local() {
local subcommand="${1:-all}"
local build_type="${2:-debug}"
local build_type_str="Debug"
local prefix=${3:-}
local major_version="$(cat ${TOP}/VERSION | cut -d. -f1)" # major version number
[ "$build_type" = "debug" ] && build_type_str="Debug"
[ "$build_type" = "release" ] && build_type_str="Release"
[ "$build_type" = "rel-debug" ] && build_type_str="RelWithDebInfo"
local old_opt="$(shopt -op errexit);$(shopt -op nounset)" # save old shopts
set -eu
if [ "$subcommand" = "clean_cache" ]; then
rm -f ${TOP}/build-*/CMakeCache.txt
rm -f ${TOP}/cpp/plugins/cucim.kit.cuslide/build-*/CMakeCache.txt
rm -f ${TOP}/cpp/plugins/cucim.kit.cumed/build-*/CMakeCache.txt
rm -f ${TOP}/python/build-*/CMakeCache.txt
fi
if [ "$subcommand" = "clean" ]; then
rm -rf ${TOP}/build-*
rm -rf ${TOP}/install
rm -rf ${TOP}/cpp/plugins/cucim.kit.cuslide/build-*/
rm -rf ${TOP}/cpp/plugins/cucim.kit.cuslide/install
rm -rf ${TOP}/cpp/plugins/cucim.kit.cumed/build-*/
rm -rf ${TOP}/cpp/plugins/cucim.kit.cumed/install
rm -rf ${TOP}/python/build-*
rm -rf ${TOP}/python/install
fi
if [ "$subcommand" = "all" ] || [ "$subcommand" = "libcucim" ]; then
build_local_libcucim_ ${TOP} ${build_type} ${build_type_str} ${prefix}
fi
if [ "$subcommand" = "all" ] || [ "$subcommand" = "cuslide" ]; then
build_local_cuslide_ ${TOP}/cpp/plugins/cucim.kit.cuslide ${build_type} ${build_type_str} ${prefix}
fi
if [ "$subcommand" = "all" ] || [ "$subcommand" = "cumed" ]; then
build_local_cumed_ ${TOP}/cpp/plugins/cucim.kit.cumed ${build_type} ${build_type_str} ${prefix}
fi
if [ "$subcommand" = "all" ] || [ "$subcommand" = "cucim" ]; then
build_local_cucim_ ${TOP}/python ${build_type} ${build_type_str} ${prefix}
fi
# Remove existing library files at python/cucim/src/cucim/clara
rm -f ${TOP}/python/cucim/src/cucim/clara/*.so*
if [ "$subcommand" = "all" ] || [ "$subcommand" = "cucim" ]; then
# We don't need to copy binary if executed by conda-build
if [ "${CONDA_BUILD:-}" != "1" ]; then
# Copy .so files from libcucim & cuslide/cumed's build folders to cuCIM's Python source folder
# Since wheel file doesn't support symbolic link (https://github.com/pypa/wheel/issues/203),
# we don't need to copy symbolic links. Instead copy only libcucim.so.${major_version} (without symbolic link)
cp ${TOP}/build-$build_type/lib*/libcucim.so.${major_version} ${TOP}/python/cucim/src/cucim/clara/
cp -P ${TOP}/cpp/plugins/cucim.kit.cuslide/build-$build_type/lib*/cucim* ${TOP}/python/cucim/src/cucim/clara/
cp -P ${TOP}/cpp/plugins/cucim.kit.cumed/build-$build_type/lib*/cucim* ${TOP}/python/cucim/src/cucim/clara/
# Copy .so files from pybind's build folder to cuCIM's Python source folder
cp ${TOP}/python/build-$build_type/lib/cucim/_cucim.*.so ${TOP}/python/cucim/src/cucim/clara/
fi
fi
eval "${old_opt}" # restore old shopts
}
copy_gds_files_() {
local root_folder=${1:-${TOP}}
local cufile_search="${root_folder}/temp/cuda/include:${root_folder}/temp/cuda/lib64"
local targets_dir=""
if is_x86_64; then
targets_dir="targets/x86_64-linux"
elif is_aarch64; then
targets_dir="targets/sbsa-linux"
else
echo "Unknown architecture"
exit 1
fi
if [ ! -z "${CONDA_PREFIX+x}" ]; then
cufile_search="${CONDA_PREFIX:-}/include:${CONDA_PREFIX:-}/lib ${CONDA_PREFIX:-}/${targets_dir}/include:${CONDA_PREFIX:-}/${targets_dir}/lib ${cufile_search}"
fi
if [ ! -z "${PREFIX+x}" ]; then
cufile_search="${PREFIX:-}/include:${PREFIX:-}/lib ${PREFIX:-}/${targets_dir}/include:${PREFIX:-}/${targets_dir}/lib ${cufile_search}"
fi
local gds_version=1.0.0
local candidate
local cufile_include
local cufile_lib
for candidate in ${cufile_search}; do
cufile_include="$(echo $candidate | cut -d: -f1)"
cufile_lib="$(echo $candidate | cut -d: -f2)"
if [ -f ${cufile_include}/cufile.h ] && [ -f ${cufile_lib}/libcufile.so ]; then
c_echo W "GDS client library is available at '${cufile_include}/cufile.h' and '${cufile_lib}/libcufile.so'"
break
fi
cufile_include=""
cufile_lib=""
done
if [ ! -f ${cufile_include}/cufile.h ]; then
c_echo_err Y "GDS client library is not available! Downloading the redistributable package to get cufile.h and libraries."
run_command rm -rf ${root_folder}/temp/cuda
run_command mkdir -p ${root_folder}/temp/cuda/include ${root_folder}/temp/cuda/lib64
local temp_tgz_dir=$(mktemp -d)
pushd ${temp_tgz_dir}
run_command wget https://developer.download.nvidia.com/gds/redist/rel-${gds_version}/gds-redistrib-${gds_version}.tgz
run_command tar xzvf gds-redistrib-${gds_version}.tgz
# There are no GDS binaries for aarch64 SBSA yet, but we need cufile.h for building cufile_stub
run_command cp -P gds-redistrib-${gds_version}/targets/x86_64-linux/include/cufile.h ${root_folder}/temp/cuda/include/
if is_x86_64; then
run_command cp -P gds-redistrib-${gds_version}/targets/x86_64-linux/lib/* ${root_folder}/temp/cuda/lib64/
fi
popd > /dev/null
run_command rm -r ${temp_tgz_dir}
else
run_command mkdir -p ${root_folder}/temp/cuda/include ${root_folder}/temp/cuda/lib64
if [ "${cufile_include}" != "${root_folder}/temp/cuda/include" ]; then
run_command cp -Pf ${cufile_include}/cufile.h ${root_folder}/temp/cuda/include/ || true
run_command cp -Pf ${cufile_lib}/libcufile* ${root_folder}/temp/cuda/lib64/ || true
fi
fi
}
get_arch_name_() {
architecture="unknown"
case $(uname -m) in
x86_64) architecture="x86_64" ;;
arm|aarch64) lscpu | awk '/Architecture:/{print $2}' | grep -i -q "aarch64" && architecture="sbsa";;
esac
echo "${architecture}"
}
copy_nvjpeg_files_() {
local root_folder=${1:-${TOP}}
local arch_name="$(get_arch_name_)"
local nvjpeg_search="${root_folder}/temp/cuda/include:${root_folder}/temp/cuda/lib64"
local targets_dir=""
if is_x86_64; then
targets_dir="targets/x86_64-linux"
elif is_aarch64; then
targets_dir="targets/sbsa-linux"
else
echo "Unknown architecture"
exit 1
fi
if [ ! -z "${CONDA_PREFIX+x}" ]; then
nvjpeg_search="${CONDA_PREFIX:-}/include:${CONDA_PREFIX:-}/lib ${CONDA_PREFIX:-}/${targets_dir}/include:${CONDA_PREFIX:-}/${targets_dir}/lib ${nvjpeg_search}"
fi
if [ ! -z "${PREFIX+x}" ]; then
nvjpeg_search="${PREFIX:-}/include:${PREFIX:-}/lib ${PREFIX:-}/${targets_dir}/include:${PREFIX:-}/${targets_dir}/lib ${nvjpeg_search}"
fi
local cuda_version="11.6"
local nvjpeg_version="11-6_11.6.0.55-1"
local candidate
local nvjpeg_include
local nvjpeg_lib
for candidate in ${nvjpeg_search}; do
nvjpeg_include="$(echo $candidate | cut -d: -f1)"
nvjpeg_lib="$(echo $candidate | cut -d: -f2)"
if [ -f ${nvjpeg_include}/nvjpeg.h ] && [ -f ${nvjpeg_lib}/libnvjpeg_static.a ]; then
c_echo W "nvJPEG client library is available at '${nvjpeg_include}/nvjpeg.h' and '${nvjpeg_lib}/libnvjpeg_static.a'"
break
fi
nvjpeg_include=""
nvjpeg_lib=""
done
if [ ! -f ${nvjpeg_include}/nvjpeg.h ]; then
c_echo_err Y "nvJPEG library is not available! Downloading the redistributable package to get nvjpeg.h and libraries."
run_command rm -rf ${root_folder}/temp/cuda/include/*nvjpeg*
run_command rm -rf ${root_folder}/temp/cuda/lib64/*nvjpeg*
run_command mkdir -p ${root_folder}/temp/cuda/include ${root_folder}/temp/cuda/lib64
local temp_tgz_dir=$(mktemp -d)
pushd ${temp_tgz_dir}
c_echo W "Arch name: " G "${arch_name}"
if [ "${arch_name}" = "sbsa" ]; then
run_command wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/${arch_name}/libnvjpeg-dev-${nvjpeg_version}_arm64.deb
else
run_command wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/${arch_name}/libnvjpeg-dev-${nvjpeg_version}_amd64.deb
fi
mkdir -p libnvjpeg-dev
mv libnvjpeg-dev-${nvjpeg_version}*.deb libnvjpeg-dev/
pushd libnvjpeg-dev > /dev/null
run_command ar x libnvjpeg-dev-${nvjpeg_version}*.deb
run_command xz --decompress data.tar.xz
run_command tar xvf data.tar
popd > /dev/null
run_command cp libnvjpeg-dev/usr/local/cuda-${cuda_version}/include/nvjpeg.h ${root_folder}/temp/cuda/include/
run_command cp libnvjpeg-dev/usr/local/cuda-${cuda_version}/lib64/libnvjpeg_static.a ${root_folder}/temp/cuda/lib64/
popd > /dev/null
run_command rm -r ${temp_tgz_dir}
else
run_command mkdir -p ${root_folder}/temp/cuda/include ${root_folder}/temp/cuda/lib64
if [ "${nvjpeg_include}" != "${root_folder}/temp/cuda/include" ]; then
run_command cp -Pf ${nvjpeg_include}/*nvjpeg* ${root_folder}/temp/cuda/include/ || true
run_command cp -Pf ${nvjpeg_lib}/*nvjpeg* ${root_folder}/temp/cuda/lib64/ || true
fi
fi
}
#==================================================================================
# Section: Test
#==================================================================================
test_desc() { echo 'Execute test cases
Arguments:
$1 - subcommand [all|python|c++] (default: all)
$2 - test_type [all|unit|integration|system|performance] (default: all)
$3 - test_component [all|clara|skimage] (default: all)
'
}
test() {
local subcommand="${1:-all}"
local test_type="${2:-all}"
shift;
if [ "$subcommand" = "all" ] || [ "$subcommand" = "python" ]; then
test_python "$@"
fi
}
install_python_test_deps_() {
if [ -n "${CONDA_PREFIX}" ]; then
# Install test dependencies from pip because conda does not have all the dependencies (e.g., opencv-python).
# (https://github.com/rapidsai/cucim/pull/433)
run_command pip install -r ${TOP}/python/cucim/requirements-test.txt
else
pushd "${TOP}/python/cucim"
if [ -n "${VIRTUAL_ENV}" ]; then
run_command pip3 install -e .[test]
else
run_command pip3 install --user -e .[test]
fi
popd
fi
hash -r
}
test_python_desc() { echo 'Execute Python test cases
Arguments:
$1 - test_type [all|unit|integration|system|performance] (default: all)
$2 - test_component [all|clara|skimage] (default: all)
'
}
test_python() {
local test_type="${1:-all}"
local test_component="${2:-all}"
local result=0
local testsuite=""
local testsuite_unit_skimage="src"
local testsuite_unit_clara="tests/unit"
local testsuite_performance="tests/performance"
install_python_test_deps_
if [ "$test_type" = "all" ] || [ "$test_type" = "unit" ]; then
local testsuite="${testsuite_unit_skimage} ${testsuite_unit_clara}"
[ "$test_component" = "skimage" ] && testsuite="${testsuite_unit_skimage}"
[ "$test_component" = "clara" ] && testsuite="${testsuite_unit_clara}"
fi
if [ "$test_type" = "all" ] || [ "$test_type" = "performance" ]; then
testsuite="${testsuite} ${testsuite_performance}"
fi
pushd $TOP/python/cucim
run_command py.test --cache-clear -vv \
--cov=cucim \
--junitxml="$TOP/junit-cucim.xml" \
--cov-config=$TOP/python/cucim/.coveragerc \
--cov-report=xml:"$TOP/cucim-coverage.xml" \
--cov-report term \
${testsuite}
result=$?
popd
return $result
}
#==================================================================================
# Section: Example
#==================================================================================
download_testdata_desc() { echo 'Download test data from Docker Hub
'
}
download_testdata() {
c_echo W "Downloading test data..."
run_command mkdir -p "${TOP}/notebooks/input"
if [ ! -e "${TOP}/notebooks/input/image.tif" ]; then
run_command rm -rf "${TOP}/notebooks/input"
id=$(docker create gigony/svs-testdata:little-big)
run_command docker cp $id:/input "${TOP}/notebooks"
run_command docker rm -v $id
c_echo G "Test data is downloaded to '${TOP}/notebooks/input'!"
else
c_echo G "Test data already exists at '${TOP}/notebooks/input'!"
fi
}
#==================================================================================
# Section: Release
#==================================================================================
update_version_desc() { echo 'Update version
Executes ci/release/update-version.sh which updates some version-related
files based on VERSION file.
Returns:
Outputs executed by update-version.sh
Exit code:
exit code returned from update-version.sh
'
}
update_version() {
local new_version=${1:-}
local ret=0
[ -z "${new_version}" ] && c_echo_err R "Please specify '[new version]' (e.g., '21.06.00')!" && return 1
$TOP/ci/release/update-version.sh "$@"
ret=$?
return $ret
}
parse_args() {
local OPTIND
while getopts 'yh' option;
do
case "${option}" in
# a)
# VALUE=${OPTARG}
# ;;
y)
ALWAYS_YES=true;
;;
h)
print_usage
exit 1
;;
*)
;;
esac
done
shift $((OPTIND-1))
CMD="$1"
shift
ARGS=("$@")
}
print_usage() {
set +x
echo_err
echo_err "USAGE: $0 [command] [arguments]..."
echo_err ""
c_echo_err W "Global Arguments"
echo_err
c_echo_err W "Command List"
c_echo_err Y " help " w "---------------------------- Print detailed description for a given argument (command name)"
echo_err "$(get_list_of_available_commands "${RUN_SCRIPT_FILE}" | my_cat_prefix " ")"
echo_err
}
print_cmd_help_messages() {
local cmd="$1"
if [ -n "${cmd}" ]; then
if type ${cmd}_desc > /dev/null 2>&1; then
${cmd}_desc
exit 0
else
c_echo_err R "Command '${cmd}' doesn't exist!"
exit 1
fi
fi
print_usage
return 0
}
main() {
local ret=0
parse_args "$@"
case "$CMD" in
help)
print_cmd_help_messages "${ARGS[@]}"
exit 0
;;
''|main)
print_usage
;;
*)
if type ${CMD} > /dev/null 2>&1; then
"$CMD" "${ARGS[@]}"
else
print_usage
exit 1
fi
;;
esac
ret=$?
if [ -n "${SCRIPT_DIR}" ]; then
exit $ret
fi
}
init_globals
if [ -n "${SCRIPT_DIR}" ]; then
main "$@"
fi
# Description template
# Globals:
# CS_OS
# CS_TARGET
# CS_USER (used if CS_OS is "l4t")
# CS_HOST (used if CS_OS is "l4t")
# CS_OBSCURA_MODE (used in Obscura server)
# Arguments:
# Command line to execute
# Returns:
# Outputs print messages during the execution (stdout->stdout, stderr->stderr).
# Note:
# This command removes "\r" characters from stdout.
# Exit code:
# exit code returned from executing a given command