Skip to content

Commit

Permalink
Benchmarks report grind time (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryleberre authored Aug 25, 2024
1 parent 3aac2c3 commit cbbc8ec
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 30 deletions.
4 changes: 2 additions & 2 deletions benchmarks/5eq_rk3_weno3_hllc/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
# Configuring case dictionary
print(json.dumps({
# Logistics ================================================
'run_time_info' : 'T',
'run_time_info' : 'F',
# ==========================================================

# Computational Domain Parameters ==========================
Expand All @@ -193,7 +193,7 @@
'dt' : dt,
't_step_start' : 0,
't_step_stop' : int(60*(95*size + 5)),
't_step_save' : int(12*(95*size + 5)),
't_step_save' : int(60*(95*size + 5)),
# ==========================================================

# Simulation Algorithm Parameters ==========================
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/hypo_hll/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# Configuring case dictionary
print(json.dumps({
# Logistics ================================================
'run_time_info' : 'T',
'run_time_info' : 'F',
# ==========================================================

# Computational Domain Parameters ==========================
Expand All @@ -46,7 +46,7 @@
'dt' : 1e-8,
't_step_start' : 0,
't_step_stop' : int(60*(95*size + 5)),
't_step_save' : int(12*(95*size + 5)),
't_step_save' : int(60*(95*size + 5)),
# ==========================================================

# Simulation Algorithm Parameters ==========================
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/ibm/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
'dt' : mydt,
't_step_start' : 0,
't_step_stop' : int(40*(95*size + 5)),
't_step_save' : int(8*(95*size + 5)),
't_step_save' : int(40*(95*size + 5)),
# ==========================================================

# Simulation Algorithm Parameters ==========================
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/viscous_weno5_sgb_acoustic/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@

# Configuring case dictionary
print(json.dumps({
# Logistics ================================================
'run_time_info' : 'T',
# Logistics ================================================
'run_time_info' : 'F',
# ==========================================================

# Computational Domain Parameters ==========================
Expand All @@ -112,9 +112,9 @@
'dt' : dt,
't_step_start' : 0,
't_step_stop' : int(30*(25*size + 5)),
't_step_save' : int(6*(25*size + 5)),
't_step_save' : int(30*(25*size + 5)),
# ==========================================================

# Simulation Algorithm Parameters ==========================
'num_patches' : 2,
'model_eqns' : 2,
Expand Down
24 changes: 15 additions & 9 deletions src/simulation/m_start_up.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,8 @@ contains
real(kind(0d0)), intent(inout) :: start, finish
integer, intent(inout) :: nt

real(kind(0d0)) :: grind_time

call s_mpi_barrier()

if (num_procs > 1) then
Expand All @@ -1152,29 +1154,33 @@ contains
time_final = maxval(proc_time)
io_time_final = maxval(io_proc_time)
end if
print *, "Performance: ", time_final*1.0d9/(sys_size*maxval((/1,m_glb/))*maxval((/1,n_glb/))*maxval((/1,p_glb/))), " ns/gp/eq/rhs"

grind_time = time_final*1.0d9/(sys_size*maxval((/1,m_glb/))*maxval((/1,n_glb/))*maxval((/1,p_glb/)))

print *, "Performance:", grind_time, "ns/gp/eq/rhs"
inquire (FILE='time_data.dat', EXIST=file_exists)
if (file_exists) then
open (1, file='time_data.dat', position='append', status='old')
write (1, *) num_procs, time_final
close (1)
else
open (1, file='time_data.dat', status='new')
write (1, *) num_procs, time_final
close (1)
write (1, '(A10, A15, A15)') "Ranks", "s/step", "ns/gp/eq/rhs"
end if

write (1, '(I10, 2(F15.8))') num_procs, time_final, grind_time

close (1)

inquire (FILE='io_time_data.dat', EXIST=file_exists)
if (file_exists) then
open (1, file='io_time_data.dat', position='append', status='old')
write (1, *) num_procs, io_time_final
close (1)
else
open (1, file='io_time_data.dat', status='new')
write (1, *) num_procs, io_time_final
close (1)
write (1, '(A10, A15)') "Ranks", "s/step"
end if

write (1, '(I10, F15.8)') num_procs, io_time_final
close (1)

end if

end subroutine s_save_performance_metrics
Expand Down
2 changes: 1 addition & 1 deletion toolchain/bootstrap/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

log "(venv) Running$MAGENTA pylint$COLOR_RESET on$MAGENTA MFC$COLOR_RESET's $MAGENTA""toolchain$COLOR_RESET."

pylint -d R1722,W0718,C0301,C0116,C0115,C0114,C0410,W0622,W0640,C0103,W1309,C0411,W1514,R0401 "$(pwd)/toolchain/"
pylint -d R1722,W0718,C0301,C0116,C0115,C0114,C0410,W0622,W0640,C0103,W1309,C0411,W1514,R0401,W0511 "$(pwd)/toolchain/"

exit $?
32 changes: 26 additions & 6 deletions toolchain/mfc/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .printer import cons
from .state import ARG, CFG
from .build import get_targets, DEFAULT_TARGETS
from .build import get_targets, DEFAULT_TARGETS, SIMULATION
from .common import system, MFC_BENCH_FILEPATH, MFC_SUBDIR, format_list_to_string
from .common import file_load_yaml, file_dump_yaml, create_directory
from .common import MFCException
Expand Down Expand Up @@ -77,6 +77,9 @@ def bench(targets = None):
cons.unindent()


# TODO: This function is too long and not nicely written at all. Someone should
# refactor it...
# pylint: disable=too-many-branches
def diff():
lhs, rhs = file_load_yaml(ARG("lhs")), file_load_yaml(ARG("rhs"))

Expand Down Expand Up @@ -132,15 +135,32 @@ def _lock_to_str(lock):

continue

if (float(f"{lhs_summary[target.name]}") <= 0.0) or math.isnan(float(f"{lhs_summary[target.name]}")):
if not math.isfinite(lhs_summary[target.name]["exec"]) or not math.isfinite(rhs_summary[target.name]["exec"]):
err = 1
cons.print(f"lhs_summary reports non-positive or NaN runtime for {target.name} - Case: {slug}")
cons.print(f"lhs_summary or rhs_summary reports non-real exec time for {target.name} - Case: {slug}")

if (float(f"{rhs_summary[target.name]}") <= 0.0) or math.isnan(float(f"{rhs_summary[target.name]}")):
exec_time_speedup = "N/A"
try:
exec_time_speedup = f'{lhs_summary[target.name]["exec"] / rhs_summary[target.name]["exec"]:.2f}'
except Exception as _:
err = 1
cons.print(f"rhs_summary reports non-positive or NaN runtime for {target.name} - Case: {slug}")
cons.print(f"lhs_summary or rhs_summary reports non-real exec time for {target.name} - Case: {slug}")

speedups[i] = f"{lhs_summary[target.name] / rhs_summary[target.name]:.2f}x"
speedups[i] = f"Exec: {exec_time_speedup}"

if target == SIMULATION:
grind_time_speedup = "N/A"
if not math.isfinite(lhs_summary[target.name]["grind"]) or not math.isfinite(rhs_summary[target.name]["grind"]):
err = 1
cons.print(f"lhs_summary or rhs_summary reports non-real grind time for {target.name} - Case: {slug}")

try:
grind_time_speedup = f'{lhs_summary[target.name]["grind"] / rhs_summary[target.name]["grind"]:.2f}'
except Exception as _:
err = 1
cons.print(f"lhs_summary or rhs_summary reports non-real grind time for {target.name} - Case: {slug}")

speedups[i] += f" & Grind: {grind_time_speedup}"

table.add_row(f"[magenta]{slug}[/magenta]", *speedups)

Expand Down
3 changes: 2 additions & 1 deletion toolchain/mfc/run/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from mako.lookup import TemplateLookup
from mako.template import Template

from ..build import get_targets, build, REQUIRED_TARGETS
from ..build import get_targets, build, REQUIRED_TARGETS, SIMULATION
from ..printer import cons
from ..state import ARG, ARGS, CFG
from ..common import MFCException, isspace, file_read, does_command_exist
Expand Down Expand Up @@ -101,6 +101,7 @@ def __generate_job_script(targets, case: input.MFCInputFile):
env=env,
case=case,
MFC_ROOTDIR=MFC_ROOTDIR,
SIMULATION=SIMULATION,
qsystem=queues.get_system(),
profiler=shlex.join(__profiler_prepend())
)
Expand Down
12 changes: 8 additions & 4 deletions toolchain/templates/include/helpers.mako
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ END
export CRAY_ACC_MODULE='${target.get_staging_dirpath(case)}/simulation-wg256.lld.exe'
fi
cd "${os.path.dirname(input)}"
cd '${os.path.dirname(input)}'
t_${target.name}_start=$(python3 -c 'import time; print(time.time())')
% else:
Expand Down Expand Up @@ -102,10 +102,14 @@ END
% if output_summary:
cd "${MFC_ROOTDIR}"
cd '${MFC_ROOTDIR}'
cat >>"${output_summary}" <<EOL
${target.name}: $(echo "$t_${target.name}_stop - $t_${target.name}_start" | bc -l)
cat >>'${output_summary}' <<EOL
${target.name}:
exec: $(echo "$t_${target.name}_stop - $t_${target.name}_start" | bc -l)
% if target == SIMULATION:
grind: $(cat '${os.path.join(os.path.dirname(input), 'time_data.dat')}' | tail -n 1 | awk '{print $NF}')
% endif
EOL
cd - > /dev/null
Expand Down

0 comments on commit cbbc8ec

Please sign in to comment.