Skip to content

Commit 34b28fc

Browse files
authored
Merge pull request #285 from intel/develop
Develop
2 parents 389f325 + 8fdf4fd commit 34b28fc

File tree

8 files changed

+298
-186
lines changed

8 files changed

+298
-186
lines changed

docs/YASK-logo.png

210 KB
Loading

docs/YASK-tutorial.pdf

17.9 KB
Binary file not shown.

src/common/common_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace yask {
4747
// https://semver.org/.
4848

4949
// Format: "major.minor.patch[-alpha|-beta]".
50-
const string version = "4.04.07";
50+
const string version = "4.04.08";
5151

5252
string yask_get_version_string() {
5353
return version;

src/kernel/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ YK_SCRIPT_FLAGS += "-stencil" $(YK_STENCIL) "-arch" $(YK_ARCH)
280280
ifeq ($(mpi),0)
281281
YK_SCRIPT_FLAGS += -ranks 1
282282
endif
283+
ifeq ($(offload),1)
284+
YK_SCRIPT_FLAGS += -offload
285+
endif
283286

284287
# Additional flags for building kernel lib.
285288
# These are not used for building apps that use only the APIs.
@@ -1128,12 +1131,12 @@ single-stencil-tests:
11281131
$(MAKE) clean; $(STENCIL_TEST) stencil=iso3dfd radius=3 $(call FOLD,x=2 y=2) domain_dims=z,x,y
11291132
$(MAKE) clean; $(STENCIL_TEST) stencil=iso3dfd_sponge radius=6 $(call FOLD,x=2 z=2)
11301133
$(MAKE) clean; $(STENCIL_TEST) stencil=ssg $(call FOLD,x=2 y=2)
1131-
$(MAKE) clean; $(STENCIL_TEST) stencil=ssg_merged $(call FOLD,x=2 y=2)
1134+
$(MAKE) clean; $(STENCIL_TEST) stencil=ssg2 $(call FOLD,x=2 y=2)
11321135
$(MAKE) clean; $(STENCIL_TEST) stencil=awp $(call FOLD,x=2 y=2)
11331136
$(MAKE) clean; $(STENCIL_TEST) stencil=awp_abc $(call FOLD,x=2 z=2)
11341137
$(MAKE) clean; $(STENCIL_TEST) stencil=tti $(call FOLD,x=2 y=2)
1135-
$(MAKE) clean; $(STENCIL_TEST) stencil=fsg_merged $(call FOLD,x=2 y=2)
1136-
$(MAKE) clean; $(STENCIL_TEST) stencil=fsg_merged_abc $(call FOLD,x=2 y=2)
1138+
$(MAKE) clean; $(STENCIL_TEST) stencil=fsg2 $(call FOLD,x=2 y=2)
1139+
$(MAKE) clean; $(STENCIL_TEST) stencil=fsg2_abc $(call FOLD,x=2 y=2)
11371140

11381141
# 3D tests w/seismic stencils that may generate too many kernel parameters for offload.
11391142
3d-tests4:

src/kernel/lib/soln_apis.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,9 @@ namespace yask {
531531
" throughput (num-writes/sec): " << make_num_str(p->writes_ps) << endl <<
532532
" throughput (est-FLOPS): " << make_num_str(p->flops) << endl <<
533533
" throughput (num-points/sec): " << make_num_str(p->pts_ps));
534+
535+
#if 0
536+
// TODO: Fix this: the reported stage rates are often much too high, esp. for offload.
534537
if (psteps != steps_done) {
535538
DEBUG_MSG(" Rate breakdown by stage(s):");
536539
for (auto& sp : st_stages) {
@@ -543,6 +546,7 @@ namespace yask {
543546

544547
}
545548
}
549+
#endif
546550
}
547551

548552
// Clear counters.

src/kernel/yask.sh

Lines changed: 121 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,35 @@ else
5454
def_arch=intel64
5555
fi
5656
arch=$def_arch
57+
arch_is_def_cpu=1 # arch has been set for CPU default only.
5758

5859
# Default nodes.
5960
nnodes=1
60-
if [[ ! -z ${SLURM_JOB_NUM_NODES:+x} ]]; then
61-
nnodes=$SLURM_JOB_NUM_NODES
61+
if [[ ! -z ${SLURM_NNODES:+x} ]]; then
62+
nnodes=$SLURM_NNODES
6263
fi
6364

65+
# Default type and number of GPUs.
66+
ngpus=0
67+
arch_offload="offload"
68+
if command -v xpu-smi >/dev/null; then
69+
arch_offload="$def_arch.offload-spir64"
70+
ngpus=`xpu-smi topology -m | grep -c '^GPU'`
71+
elif command -v nvidia-smi >/dev/null; then
72+
arch_offload="$def_arch.offload-nv"
73+
ngpus=`nvidia-smi topo -m | grep -c '^GPU'`
74+
fi
75+
is_offload=0
76+
6477
# Default MPI ranks.
6578
# Try Slurm var, then numactl, then lscpu.
6679
# For latter two, the goal is to count only NUMA nodes with CPUs.
6780
# (Systems with HBM may have NUMA nodes without CPUs.)
68-
nranks=1
81+
nranks=$nnodes
82+
nranks_is_def_cpu=1 # nranks has been set for CPU default only.
6983
if [[ ! -z ${SLURM_NTASKS:+x} && $SLURM_NTASKS > $nnodes ]]; then
7084
nranks=$SLURM_NTASKS
85+
nranks_is_def_cpu=0
7186
elif command -v numactl >/dev/null; then
7287
ncpubinds=`numactl -s | awk '/^cpubind:/ { print NF-1 }'`
7388
if [[ -n "$ncpubinds" ]]; then
@@ -79,10 +94,15 @@ elif command -v lscpu >/dev/null; then
7994
nranks=$(( $nnumas * $nnodes ))
8095
fi
8196
fi
97+
nranks_offload=$nnodes
98+
if [[ $ngpus > 0 ]]; then
99+
nranks_offload=$(( $ngpus * $nnodes ))
100+
fi
101+
force_mpi=0
82102

83103
# Other defaults.
84-
pre_cmd=":"
85-
post_cmd=""
104+
pre_cmd=":" # "colon" command is a no-op.
105+
post_cmd=":"
86106
helping=0
87107
opts=""
88108
bindir=`dirname $0`
@@ -127,13 +147,17 @@ while true; do
127147
echo " This will run the YASK executable with the '-help' option."
128148
echo " -arch <name>"
129149
echo " Specify the architecture-name part of the YASK executable."
130-
echo " Overrides the default architecture determined from /proc/cpuinfo flags."
131-
echo " The default arch for this host is '$def_arch'."
150+
echo " Overrides the default architecture determined from /proc/cpuinfo flags"
151+
echo " or the GPU system manangement software for offload kernels."
132152
echo " Should correspond to arch=<name> used during compilation"
133-
echo " with '.offload-<offload_arch>' appended when built with 'offload=1',"
153+
echo " with '.offload-<offload_arch>' appended if built with 'offload=1',"
134154
echo " or YK_ARCH=<name> if that was used to override the default."
135155
echo " In any case, the '-stencil' and '-arch' args required to launch"
136156
echo " any executable are printed at the end of a successful compilation."
157+
echo " The default for this host is '$def_arch' for CPU kernels"
158+
echo " and '$arch_offload' for offload kernels."
159+
echo " -offload"
160+
echo " Use an offloaded YASK kernel executable, built with 'offload=1'."
137161
echo " -host <hostname>"
138162
echo " Specify host to run YASK executable on."
139163
echo " Run sub-shell under 'ssh <hostname>'."
@@ -149,24 +173,27 @@ while true; do
149173
echo " Run YASK executable as an argument to <command>, e.g., 'numactl -N 0'."
150174
echo " -mpi_cmd <command>"
151175
echo " Run YASK executable as an argument to <command>, e.g., 'mpiexec.hydra -n 4'."
152-
echo " If -mpi_cmd is used, the -ranks option is used only for computing the"
153-
echo " default number of OpenMP threads to use."
154176
echo " If -mpi_cmd and -exe_prefix are both specified, this one is used first."
155-
echo " -ranks <N>"
156-
echo " Run the YASK executable on <N> MPI ranks."
157-
echo " Shortcut for the following option if <N> > 1:"
158-
echo " -mpi_cmd 'mpirun -np <N>'"
159-
echo " If a different MPI command is needed, use -mpi_cmd <command> explicitly."
160-
echo " If the env var SLURM_NTASKS is set AND if it greater than the number of nodes,"
161-
echo " the default is its value."
162-
echo " Otherwise, the default is based on the number of NUMA nodes on the current host."
163-
echo " The current default is $nranks."
177+
echo " The default command is based on the number of nodes and ranks (see below)."
178+
echo " -force_mpi"
179+
echo " Generate a default 'mpirun' prefix even if there is only 1 rank to run."
164180
echo " -nodes <N>"
165181
echo " Set the number of nodes."
166-
echo " This is used to compute the default number of OpenMP threads to use per rank."
167-
echo " If the env var SLURM_JOB_NUM_NODES is set, the default is its value."
182+
echo " If the env var SLURM_NNODES is set, the default is its value."
168183
echo " Otherwise, the default is one (1)."
169184
echo " The current default is $nnodes."
185+
echo " -ranks <R>"
186+
echo " Run the YASK executable on <R> MPI ranks."
187+
echo " This value, along with the number of nodes, <N>, is used to set these defaults:"
188+
echo " - Number of MPI ranks per node to <R>/<N>."
189+
echo " - Number of OpenMP threads per rank based on core count (for CPU kernels only)."
190+
echo " - Default MPI command to 'mpirun -np <R> -ppn <R>/<N>'."
191+
echo " If a different MPI command is needed, use -mpi_cmd <command> explicitly."
192+
echo " If the env var SLURM_NTASKS is set AND if it greater than the number of nodes,"
193+
echo " the default is its value."
194+
echo " Otherwise, the default is based on the number of NUMA nodes on the current host"
195+
echo " for CPU kernels or the number of GPUs on the current host for offload kernels."
196+
echo " The current default is $nranks for CPU kernels and $nranks_offload for offload kernels."
170197
echo " -pre_cmd <command(s)>"
171198
echo " One or more commands to run before YASK executable."
172199
echo " -post_cmd <command(s)>"
@@ -200,6 +227,7 @@ while true; do
200227
elif [[ "$1" == "-help" ]]; then
201228
helping=1
202229
nranks=1
230+
nranks_is_def_cpu=0
203231
logfile='/dev/null'
204232

205233
# Pass option to executable.
@@ -217,7 +245,15 @@ while true; do
217245

218246
elif [[ "$1" == "-arch" && -n ${2+set} ]]; then
219247
arch=$2
248+
arch_is_def_cpu=0
249+
if [[ $arch =~ "offload" ]]; then
250+
is_offload=1
251+
fi
252+
shift
220253
shift
254+
255+
elif [[ "$1" == "-offload" ]]; then
256+
is_offload=1
221257
shift
222258

223259
elif [[ "$1" == "-host" && -n ${2+set} ]]; then
@@ -271,9 +307,14 @@ while true; do
271307

272308
elif [[ "$1" == "-ranks" && -n ${2+set} ]]; then
273309
nranks=$2
310+
nranks_is_def_cpu=0
274311
shift
275312
shift
276313

314+
elif [[ "$1" == "-force_mpi" ]]; then
315+
force_mpi=1
316+
shift
317+
277318
elif [[ "$1" == "-nodes" && -n ${2+set} ]]; then
278319
nnodes=$2
279320
shift
@@ -332,9 +373,24 @@ if [[ -z ${stencil:+x} ]]; then
332373
show_stencils
333374
fi
334375

376+
# Offload settings.
377+
if [[ $is_offload == 1 ]]; then
378+
379+
# Heuristics for MPI ranks for offload.
380+
if [[ $nranks_is_def_cpu == 1 ]]; then
381+
nranks=$nranks_offload
382+
fi
383+
384+
# Heuristics for offload arch.
385+
if [[ $arch_is_def_cpu == 1 ]]; then
386+
arch=$arch_offload
387+
fi
388+
fi
389+
335390
# Set MPI command default.
336-
if [[ $nranks > 1 ]]; then
337-
: ${mpi_cmd="mpirun -np $nranks"}
391+
ppn=$(( $nranks / $nnodes ))
392+
if [[ $nranks > 1 || $force_mpi == 1 ]]; then
393+
: ${mpi_cmd="mpirun -np $nranks -ppn $ppn"}
338394

339395
# Add default Intel MPI settings.
340396
envs+=" I_MPI_PRINT_VERSION=1 I_MPI_DEBUG=5"
@@ -375,12 +431,6 @@ tag=$stencil.$arch
375431
make_report="$bindir/../build/yask_kernel.$tag.make-report.txt"
376432
yc_report="$bindir/../build/yask_kernel.$tag.yask_compiler-report.txt"
377433

378-
# Heuristic to determine if this is an offload kernel.
379-
is_offload=0
380-
if [[ $arch =~ "offload" ]]; then
381-
is_offload=1
382-
fi
383-
384434
# Double-check that exe exists.
385435
if [[ ! -x $exe ]]; then
386436
echo "error: '$exe' not found or not executable." | tee -a $logfile
@@ -420,20 +470,14 @@ fi
420470
# Output some vars.
421471
echo "Num nodes:" $nnodes | tee -a $logfile
422472
echo "Num MPI ranks:" $nranks | tee -a $logfile
423-
echo "Num MPI ranks per node:" $(( $nranks / $nnodes )) | tee -a $logfile
473+
echo "Num MPI ranks per node:" $ppn | tee -a $logfile
424474
echo "sh_prefix='$sh_prefix'" | tee -a $logfile
425475
echo "mpi_cmd='$mpi_cmd'" | tee -a $logfile
426476
echo "exe_prefix='$exe_prefix'" | tee -a $logfile
427477
echo "exe='$exe'" | tee -a $logfile
428478
echo "pre_cmd='$pre_cmd'" | tee -a $logfile
429479
echo "post_cmd='$post_cmd'" | tee -a $logfile
430480

431-
# Output the SLURM env.
432-
if [[ `env | grep -c SLURM` > 0 ]]; then
433-
echo "Slurm vars:" | tee -a $logfile
434-
env | grep -E 'SBATCH|SLURM'
435-
fi
436-
437481
# Dump most recent reports.
438482
if [[ -e $make_report ]]; then
439483
$dump $make_report >> $logfile
@@ -448,34 +492,62 @@ if [[ $doval == 1 ]]; then
448492
fi
449493

450494
# Commands to capture some important system status and config info for benchmark documentation.
451-
config_cmds="sleep 1; uptime; lscpu; cpuinfo -A; sed '/^$/q' /proc/cpuinfo; cpupower frequency-info; uname -a; $dump /etc/system-release; $dump /proc/cmdline; $dump /proc/meminfo; free -gt; numactl -H; ulimit -a; ipcs -l; module list; env | awk '/YASK/ { print \"env:\", \$1 }'"
495+
config_cmds="sleep 1"
496+
if command -v module >/dev/null; then
497+
config_cmds+="; module list"
498+
fi
499+
config_cmds+="; echo 'Selected env vars:'; env | sort | awk '/YASK|SLURM|SBATCH|MPI|OMP/ { print \"env:\", \$1 }'"
500+
501+
config_cmds+="; set -x" # Start echoing commands before running them.
502+
config_cmds+="; uptime; uname -a; ulimit -a; $dump /etc/system-release; $dump /proc/cmdline; $dump /proc/meminfo; free -gt"
503+
if [[ -r /etc/system-release ]]; then
504+
config_cmds+="; $dump /etc/system-release"
505+
fi
506+
if command -v lscpu >/dev/null; then
507+
config_cmds+="; lscpu"
508+
fi
509+
if command -v cpuinfo >/dev/null; then
510+
config_cmds+="; cpuinfo -A"
511+
fi
512+
if command -v cpupower >/dev/null; then
513+
config_cmds+="; cpupower frequency-info"
514+
fi
515+
config_cmds+="; sed '/^$/q' /proc/cpuinfo"
516+
if command -v numactl >/dev/null; then
517+
config_cmds+="; numactl -H"
518+
fi
519+
if command -v ipcx >/dev/null; then
520+
config_cmds+="; ipcs -l"
521+
fi
452522

453523
# Add settings for offload kernel.
454524
if [[ $is_offload == 1 ]]; then
455-
config_cmds+="; clinfo -l";
456-
if [[ $nranks > 1 ]]; then
457-
envs+=" I_MPI_OFFLOAD_TOPOLIB=level_zero I_MPI_OFFLOAD=2"
458-
else
459-
envs+=" EnableImplicitScaling=1"
525+
if command -v clinfo >/dev/null; then
526+
config_cmds+="; clinfo -l";
527+
fi
528+
if command -v xpu-smi >/dev/null; then
529+
config_cmds+="; xpu-smi discovery; xpu-smi topology -m";
530+
fi
531+
if command -v nvidia-smi >/dev/null; then
532+
config_cmds+="; nvidia-smi";
533+
fi
534+
if [[ ! -z "$mpi_cmd" ]]; then
535+
envs+=" I_MPI_OFFLOAD=2"
460536
fi
461537
fi
462538

463539
# Command sequence to be run in a shell.
464540
exe_str="$mpi_cmd $exe_prefix $exe $opts"
465-
cmds="cd $dir; ulimit -s unlimited; $config_cmds; ldd $exe; date; $pre_cmd; env $envs $envs2 $exe_str"
466-
if [[ -n "$post_cmd" ]]; then
467-
cmds+="; $post_cmd"
468-
fi
469-
cmds+="; date"
541+
cmds="cd $dir; ulimit -s unlimited; $config_cmds; ldd $exe; date; $pre_cmd; env $envs $envs2 $exe_str; $post_cmd; date"
470542

471543
# Finally, invoke the binary in a shell.
472544
if [[ $dodry == 0 ]]; then
473545
echo "===================" | tee -a $logfile
474546
if [[ -z "$sh_prefix" ]]; then
475-
sh -c -x "$cmds" 2>&1 | tee -a $logfile
547+
sh -c "$cmds" 2>&1 | tee -a $logfile
476548
else
477549
echo "Running shell under '$sh_prefix'..."
478-
$sh_prefix "sh -c -x '$cmds'" 2>&1 | tee -a $logfile
550+
$sh_prefix "sh -c '$cmds'" 2>&1 | tee -a $logfile
479551
fi
480552
echo "===================" | tee -a $logfile
481553
fi

0 commit comments

Comments
 (0)