Find where a search spends its time¶
A search that runs longer than expected spends its time in the oracle, in
GP fitting, in prediction or in the surrounding control code. This page shows
how to read the time split that gprn and gprd print, how to switch on the
finer timers, and how to attach an MPI or cache profiler. For a measured
split on one system and the reasons it looks that way, see
Where the time goes.
Status: the log summaries and the --profile-* flags are implemented and
the first example below runs as part of the documentation tests. The mpiP, TAU,
cachegrind, flame-graph and roofline wrappers are shell scripts under
scripts/. They need tools and builds that the documentation tests do not
provide, so those steps are described from the scripts and have not been run
for this page.
Read the summary at the end of a gprn run¶
gprn prints a time summary on standard output every time it finishes. The
example below runs a seven-image Lennard-Jones band on a five-atom cluster. The
Lennard-Jones oracle is cheap, so the split shows the GP side of a run.
examples="$GPRIDGE_ROOT/examples/lj-pentamer"
cp "$examples/reactant.con" "$examples/product.con" .
The endpoints are the two orientations of the relaxed bipyramid from the Lennard-Jones pentamer tutorial. The run below adds the two split flags described in the next section so that one log shows every summary.
gprn --reactant reactant.con --product product.con --potential lj \
--nimages 7 --gp-model-profile gprd_zbl --gp-observation-archive off \
--profile-energy-split true --profile-gradient-split true \
> gprn.log 2>&1
grep -E '^(Elapsed time|Oracle time|GP kernel times|GP phase times|Hyperparameter fits)' gprn.log
The lines have this form. Each <s> is a time in seconds and each <n> a
count.
Elapsed time: <s>s
Oracle time: <s>s (<p>% of wall, <n> calls); GP/host time: <s>s
GP kernel times: factor <s>s, solve <s>s, eigenpairs <s>s
GP phase times: objective <s>s across <n> evaluations (assembly <s>s, gradient <s>s); factorization <s>s across <n> (cholesky <s>s); predict <s>s across <n> (variance <s>s across <n>); residual <s>s, correction <s>s, conditioning <s>s, subset <s>s
Hyperparameter fits: <n> (<n> objective evaluations); ending within the step tolerance of their start: <n> (<n> evaluations)
Line |
What it measures |
|---|---|
|
Wall time of the whole run. |
|
Time spent in oracle calls and the number of calls that count towards convergence. |
|
Wall time in the factorisation kernels, in the solve kernels and in eigenpair computations. |
|
Accumulators of the GP model. The objective is the hyperparameter objective, one covariance assembly and one factorisation per evaluation. The remaining fields are the factorisations of the conditioned model, the mean and variance predictions and the residual model. |
|
Number of hyperparameter fits and objective evaluations, and how many fits ended within the step tolerance of their start. |
The phase times do not add up to GP/host time. Time that no accumulator
covers, such as band relaxation and certificate checks, is in the host time
only.
Split the hyperparameter objective¶
--profile-energy-split true and --profile-gradient-split true time the
parts of each hyperparameter objective evaluation. Both flags exist in gprn
and gprd, and both default to false. gprn prints the result as
GP profile split summary:
Energy objective: covariance=<s>s factor=<s>s posterior=<s>s energy_calls=<n>
Gradient objective: alpha_solve=<s>s inverse_cache=<s>s const_cf=<s>s sexpat_cf=<s>s gradient_calls=<n>
The timers add work to every evaluation. In the PET-MAD d016 benchmark fixture, the arm that adds both flags needed 5.677 s of wall time against 4.916 s for the arm without them (Performance). Use the split to find which part dominates and switch it off before comparing wall times.
Time a gprd search by phase¶
--profile-dimer-times makes gprd print a phase summary after the search.
The bare flag means true.
gprd --pos pos.con --orient direction.dat --potential <name> \
--profile-dimer-times
The summary has this form.
Phase timing summary:
Accurate potential: <s>s across <n> calls
GP optimize: <s>s across <n> calls
GP fixed-theta refresh: <s>s across <n> calls
GP predict: <s>s across <n> calls
GP mode: <s>s across <n> calls
mean: <s>s across <n> calls
variance: <s>s across <n> calls
Variance-gated skips: <n>
IMSPE soft skips: <n>
IMSPE EMD-gray admissions: <n>
Active-frozen-set changes: <n> (final active frozen atoms: <n>)
Search control / geometry: <s>s
Search control / geometry is the remainder of the elapsed time after the
five timed phases are subtracted. When the energy and gradient split flags
are also set, the GP profile split summary described above is printed
after the GP mode rows.
Time the predict-mean path¶
--profile-predict-mean true (gprn) times the cross-covariance products of
the mean prediction. The summary is printed to standard error when the process
exits:
[predict-profile] calls=<n> total=<s>s const=<s>s sexpat=<s>s
The code that prints it is compiled only when linalg_backend is scalapack
or slate (gpr/ml/gp/Predict.cpp). A build with the default eigen
backend accepts the flag and prints nothing. The same switch is the parameter
profilePredictMean in the Cap’n Proto schema and profile_predict_mean in
the Python parameter dictionary.
Profile an MPI run with mpiP¶
The mpiP tasks live in the scalapack pixi environment and need an MPI
compiler.
pixi run -e scalapack install-mpip
pixi run -e scalapack profile-mpi-training
install-mpip downloads mpiP 3.5, applies the patches in
scripts/patches/mpip/ and builds it with BFD support into
.pixi/profilers/mpip-3.5-bfd/ (scripts/install_mpip_pixi.sh). The profile
scripts look for libmpiP.so in that directory by default
(scripts/profile_mpi_training_mpip.sh,
scripts/profile_petmad_uncertainty_mpip.sh); set GPR_MPIP_PREFIX to
override the prefix.
Task |
Profiled run |
Report directory |
|---|---|---|
|
The synthetic ScaLAPACK scaling test of |
|
|
The PET-MAD d016 |
|
|
The same run with the modes |
|
|
The same run in mode |
|
GPR_MPIP_OUT_DIR overrides the report directory. The PET-MAD tasks read
GPR_PETMAD_UQ_MODES (default laplace), GPR_PETMAD_UQ_RANKS (default
8) and GPR_PETMAD_UQ_REPS (default 1), and expect gprd in
build-scalapack-real/ unless GPR_PETMAD_UQ_BUILD_DIR names another build
(scripts/bench_petmad_uncertainty.sh).
Read an mpiP report¶
mpiP writes one report per run, named <binary>.<ranks>.<pid>.1.mpiP. Three
sections answer most questions.
The per-task table of
AppTime,MPITimeandMPI%. A wide spread between ranks means load imbalance.Aggregate Time, the MPI call sites with the largest time summed over ranks. A largeBcastorRecvsite shows where ranks wait.Aggregate Sent Message Size, the call sites that move the most bytes.
mpiP lists the source file and line of each call site only when the binary
has debug symbols. Configure the build with -Dbuildtype=debugoptimized
before profiling.
Use TAU, cachegrind, flame graphs or roofline counters¶
These tasks are also in the scalapack environment. The scripts that expect
a build tree read it from the variable named in the last column.
Task |
Tool |
Profiled run |
Build variable |
|---|---|---|---|
|
TAU 2.34 source build |
Installs into |
|
|
TAU |
The synthetic ScaLAPACK scaling test. |
|
|
TAU |
The PET-MAD d016 run, as for mpiP. |
|
|
TAU |
Modes |
|
|
valgrind cachegrind |
The synthetic scaling test on one rank. |
|
|
valgrind cachegrind |
The HS-SVD solve micro-benchmark, without MPI or a potential. |
|
|
valgrind cachegrind |
The layered RFF dimer path on one rank. |
|
|
|
The layered RFF dimer path on one rank. |
|
|
|
The layered RFF dimer path on one rank. |
|
Cachegrind slows a run by a factor that the script header gives as 10 to 50. Run it on one rank only.
Compare two versions of the code¶
pixi run -e python bench builds the base branch (default main) and the
current checkout in separate worktrees and virtual environments, runs the
airspeed-velocity benchmarks of benchmarks/bench_gpr.py on both and compares
them with asv-spyglass (scripts/bench_compare.nim). To name another base
branch or keep the environments for inspection:
pixi run -e python -- nim r scripts/bench_compare.nim develop
pixi run -e python -- nim r scripts/bench_compare.nim main --keep-venvs
To time one benchmark inside the interpreter profiler:
import cProfile
from benchmarks.bench_gpr import TimeGPTraining
b = TimeGPTraining()
b.setup(40)
cProfile.run("b.time_gp_train(40)", sort="cumulative")
TimeGPTraining takes the number of observations as its parameter. The
benchmark defines the values 5, 10, 20 and 40.