@@ -13,6 +13,43 @@ sbd_ncu_profile_mode() {
1313 printf ' %s\n' " ${BK_SBD_NCU_PROFILE_MODE:- discovery} "
1414}
1515
16+ sbd_ncu_profile_timeout_seconds () {
17+ local timeout_seconds=" ${BK_SBD_NCU_PROFILE_TIMEOUT_SECONDS:- 0} "
18+
19+ case " $timeout_seconds " in
20+ ' ' |* [!0-9]* )
21+ echo " SBD NCU profile timeout must be a non-negative integer: ${timeout_seconds} " >&2
22+ return 1
23+ ;;
24+ esac
25+
26+ printf ' %s\n' " $timeout_seconds "
27+ }
28+
29+ sbd_strip_ncu_launch_count_args () {
30+ local filtered_args=()
31+
32+ while [ " $# " -gt 0 ]; do
33+ case " $1 " in
34+ --launch-count)
35+ shift
36+ if [ " $# " -gt 0 ]; then
37+ shift
38+ fi
39+ ;;
40+ --launch-count=* )
41+ shift
42+ ;;
43+ * )
44+ filtered_args+=(" $1 " )
45+ shift
46+ ;;
47+ esac
48+ done
49+
50+ printf ' %s\n' " ${filtered_args[*]} "
51+ }
52+
1653sbd_supports_ncu_profile () {
1754 case " $1 " in
1855 RIKYU|RC_DGXSP|RC_GH200) return 0 ;;
@@ -24,6 +61,7 @@ sbd_configure_ncu_profile_from_run_env() {
2461 local system_name=" $1 "
2562 local profiler_tool
2663 local profiler_level
64+ local default_profiler_level=" detailed"
2765
2866 if ! sbd_supports_ncu_profile " $system_name " ; then
2967 return 0
@@ -44,8 +82,20 @@ sbd_configure_ncu_profile_from_run_env() {
4482 if [ -z " ${BK_SBD_NCU_PROFILE:- } " ]; then
4583 export BK_SBD_NCU_PROFILE=true
4684 fi
85+ if [ " $system_name " = " RIKYU" ]; then
86+ default_profiler_level=" single"
87+ if [ -z " ${BK_SBD_NCU_PLAN_TOP_K:- } " ]; then
88+ export BK_SBD_NCU_PLAN_TOP_K=1
89+ fi
90+ if [ -z " ${BK_SBD_NCU_PLAN_LAUNCH_COUNT:- } " ]; then
91+ export BK_SBD_NCU_PLAN_LAUNCH_COUNT=1
92+ fi
93+ if [ -z " ${BK_SBD_NCU_PROFILE_TIMEOUT_SECONDS:- } " ]; then
94+ export BK_SBD_NCU_PROFILE_TIMEOUT_SECONDS=1800
95+ fi
96+ fi
4797 if [ -z " ${BK_SBD_NCU_PROFILER_LEVEL:- } " ]; then
48- profiler_level=$( bk_resolve_profiler_level detailed SBD_PROFILER_LEVEL)
98+ profiler_level=$( bk_resolve_profiler_level " $default_profiler_level " SBD_PROFILER_LEVEL)
4999 export BK_SBD_NCU_PROFILER_LEVEL=" $profiler_level "
50100 fi
51101}
@@ -280,6 +330,8 @@ sbd_run_rank0_ncu_profile() {
280330 local report_file
281331 local profiler_status
282332 local archive_status
333+ local profile_timeout_seconds
334+ local profile_cmd=()
283335
284336 results_dir=$( sbd_profile_results_dir)
285337 archive_path=" ${results_dir} /padata_${profile_slug} .tgz"
@@ -298,39 +350,56 @@ sbd_run_rank0_ncu_profile() {
298350
299351 ncu_level_arg_text=$( bk_profiler_ncu_level_args " $profiler_level " ) || return 1
300352 read -r -a ncu_level_args <<< " $ncu_level_arg_text"
353+ ncu_level_arg_text=$( sbd_strip_ncu_launch_count_args " ${ncu_level_args[@]} " ) || return 1
354+ read -r -a ncu_level_args <<< " $ncu_level_arg_text"
355+ profile_timeout_seconds=$( sbd_ncu_profile_timeout_seconds) || return 1
301356
302357 rm -rf " $raw_dir " " $stage_dir "
303358 mkdir -p " $rep_dir " " $stage_dir /raw" " $stage_dir /reports"
304359
305360 echo " SBD NCU profile: profile='${profile_name} ' kernel='${kernel_regex} ' skip=${launch_skip} count=${launch_count} " >&2
306361 echo " bk_profiler[ncu]: starting ${rep_name} level=${profiler_level} on rank 0" >&2
307- set +e
308- mpirun -np " $n_ranks " bash -lc '
309- rank=${OMPI_COMM_WORLD_RANK:-${PMIX_RANK:-${SLURM_PROCID:-0}}}
310- local_rank=${OMPI_COMM_WORLD_LOCAL_RANK:-${SLURM_LOCALID:-0}}
311- export CUDA_VISIBLE_DEVICES="${local_rank}"
312- profile_base="$1"
313- level_argc="$2"
314- shift 2
315- level_args=()
316- i=0
317- while [ "$i" -lt "$level_argc" ]; do
318- level_args+=("$1")
319- shift
320- i=$((i + 1))
321- done
322- kernel_regex="$1"
323- launch_skip="$2"
324- launch_count="$3"
325- shift 3
326- if [ "$rank" = 0 ]; then
327- exec ncu -o "$profile_base" --target-processes all "${level_args[@]}" \
328- --kernel-name-base demangled --kernel-name "$kernel_regex" \
329- --launch-skip "$launch_skip" --launch-count "$launch_count" ./diag "$@"
362+ if [ " $profile_timeout_seconds " -gt 0 ]; then
363+ echo " SBD NCU profile timeout: ${profile_timeout_seconds} s" >&2
364+ if ! command -v timeout > /dev/null 2>&1 ; then
365+ echo " SBD NCU profile timeout requested but timeout command is not available." >&2
366+ return 1
330367 fi
331- exec ./diag "$@"
332- ' bash " $profile_base " " ${# ncu_level_args[@]} " " ${ncu_level_args[@]} " \
333- " $kernel_regex " " $launch_skip " " $launch_count " " $@ " > " $profile_log " 2>&1
368+ fi
369+ profile_cmd=(
370+ mpirun -np " $n_ranks " bash -lc '
371+ rank=${OMPI_COMM_WORLD_RANK:-${PMIX_RANK:-${SLURM_PROCID:-0}}}
372+ local_rank=${OMPI_COMM_WORLD_LOCAL_RANK:-${SLURM_LOCALID:-0}}
373+ export CUDA_VISIBLE_DEVICES="${local_rank}"
374+ profile_base="$1"
375+ level_argc="$2"
376+ shift 2
377+ level_args=()
378+ i=0
379+ while [ "$i" -lt "$level_argc" ]; do
380+ level_args+=("$1")
381+ shift
382+ i=$((i + 1))
383+ done
384+ kernel_regex="$1"
385+ launch_skip="$2"
386+ launch_count="$3"
387+ shift 3
388+ if [ "$rank" = 0 ]; then
389+ exec ncu -o "$profile_base" --target-processes all "${level_args[@]}" \
390+ --kernel-name-base demangled --kernel-name "$kernel_regex" \
391+ --launch-skip "$launch_skip" --launch-count "$launch_count" ./diag "$@"
392+ fi
393+ exec ./diag "$@"
394+ ' bash " $profile_base " " ${# ncu_level_args[@]} " " ${ncu_level_args[@]} " \
395+ " $kernel_regex " " $launch_skip " " $launch_count " " $@ "
396+ )
397+ set +e
398+ if [ " $profile_timeout_seconds " -gt 0 ]; then
399+ timeout --kill-after=60s " $profile_timeout_seconds " " ${profile_cmd[@]} " > " $profile_log " 2>&1
400+ else
401+ " ${profile_cmd[@]} " > " $profile_log " 2>&1
402+ fi
334403 profiler_status=$?
335404 set -e
336405
455524 fi
456525}
457526
527+ sbd_run_optional_ncu_profiles () {
528+ local system_name=" $1 "
529+ local n_ranks=" $2 "
530+ local profile_status
531+ shift 2
532+
533+ if ! sbd_ncu_profile_enabled; then
534+ return 0
535+ fi
536+
537+ profile_status=0
538+ sbd_run_configured_ncu_profiles " $system_name " " $n_ranks " " $@ " || profile_status=$?
539+ if [ " $profile_status " -ne 0 ]; then
540+ echo " SBD NCU profile acquisition failed with status ${profile_status} ; continuing with benchmark result." >&2
541+ fi
542+ return 0
543+ }
544+
458545sbd_run_configured_ncu_profiles () {
459546 local system_name=" $1 "
460547 local n_ranks=" $2 "
0 commit comments