=================================== 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 :doc:`Where the time goes <../explanation/performance>`. **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. .. code:: bash 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 :doc:`Lennard-Jones pentamer tutorial <../tutorials/gprn_lj_pentamer>`. The run below adds the two split flags described in the next section so that one log shows every summary. .. code:: bash 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 ```` is a time in seconds and each ```` a count. :: Elapsed time: s Oracle time: s (

% of wall, calls); GP/host time: s GP kernel times: factor s, solve s, eigenpairs s GP phase times: objective s across evaluations (assembly s, gradient s); factorization s across (cholesky s); predict s across (variance s across ); residual s, correction s, conditioning s, subset s Hyperparameter fits: ( objective evaluations); ending within the step tolerance of their start: ( evaluations) .. table:: +-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Line | What it measures | +=========================+============================================================================================================================================================================================================================================================================+ | ``Elapsed time`` | Wall time of the whole run. | +-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``Oracle time`` | Time spent in oracle calls and the number of calls that count towards convergence. ``GP/host time`` is ``Elapsed time`` minus ``Oracle time``, so it contains every other step. | +-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``GP kernel times`` | Wall time in the factorisation kernels, in the solve kernels and in eigenpair computations. | +-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``GP phase times`` | 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. | +-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``Hyperparameter fits`` | 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 factor=s posterior=s energy_calls= Gradient objective: alpha_solve=s inverse_cache=s const_cf=s sexpat_cf=s gradient_calls= 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 (:doc:`Performance <../explanation/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. .. code:: bash gprd --pos pos.con --orient direction.dat --potential \ --profile-dimer-times The summary has this form. :: Phase timing summary: Accurate potential: s across calls GP optimize: s across calls GP fixed-theta refresh: s across calls GP predict: s across calls GP mode: s across calls mean: s across calls variance: s across calls Variance-gated skips: IMSPE soft skips: IMSPE EMD-gray admissions: Active-frozen-set changes: (final active frozen atoms: ) Search control / geometry: 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= total=s const=s sexpat=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. .. code:: bash 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. .. table:: +----------------------------+---------------------------------------------------------------------------------+-------------------------------------------+ | Task | Profiled run | Report directory | +============================+=================================================================================+===========================================+ | ``profile-mpi-training`` | The synthetic ScaLAPACK scaling test of ``scripts/bench_scalapack_scaling.sh``. | ``.pixi/profilers/reports/mpip/`` | +----------------------------+---------------------------------------------------------------------------------+-------------------------------------------+ | ``profile-petmad-laplace`` | The PET-MAD d016 ``gprd`` run of ``scripts/bench_petmad_uncertainty.sh``. | ``.pixi/profilers/reports/mpip-laplace/`` | +----------------------------+---------------------------------------------------------------------------------+-------------------------------------------+ | ``profile-rff-mpip`` | The same run with the modes ``map delta rff_512``. | ``.pixi/profilers/reports/mpip-rff/`` | +----------------------------+---------------------------------------------------------------------------------+-------------------------------------------+ | ``profile-hssvd-mpip`` | The same run in mode ``map`` with ``--gp-hssvd true --gp-no-output-norm true``. | ``.pixi/profilers/reports/mpip-hssvd/`` | +----------------------------+---------------------------------------------------------------------------------+-------------------------------------------+ ``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 ``...1.mpiP``. Three sections answer most questions. - The per-task table of ``AppTime``, ``MPITime`` and ``MPI%``. A wide spread between ranks means load imbalance. - ``Aggregate Time``, the MPI call sites with the largest time summed over ranks. A large ``Bcast`` or ``Recv`` site 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. .. table:: +--------------------------------+-------------------------+---------------------------------------------------------------+--------------------------------+ | Task | Tool | Profiled run | Build variable | +================================+=========================+===============================================================+================================+ | ``install-tau`` | TAU 2.34 source build | Installs into ``.pixi/profilers/``. | \ | +--------------------------------+-------------------------+---------------------------------------------------------------+--------------------------------+ | ``profile-mpi-training-tau`` | TAU | The synthetic ScaLAPACK scaling test. | \ | +--------------------------------+-------------------------+---------------------------------------------------------------+--------------------------------+ | ``profile-petmad-laplace-tau`` | TAU | The PET-MAD d016 run, as for mpiP. | ``GPR_PETMAD_UQ_BUILD_DIR`` | +--------------------------------+-------------------------+---------------------------------------------------------------+--------------------------------+ | ``profile-rff-tau`` | TAU | Modes ``map delta rff_512`` at 8 ranks. | ``GPR_PETMAD_UQ_BUILD_DIR`` | +--------------------------------+-------------------------+---------------------------------------------------------------+--------------------------------+ | ``profile-cachegrind`` | valgrind cachegrind | The synthetic scaling test on one rank. | ``GPR_CACHEGRIND_BUILD`` | +--------------------------------+-------------------------+---------------------------------------------------------------+--------------------------------+ | ``profile-hssvd-cachegrind`` | valgrind cachegrind | The HS-SVD solve micro-benchmark, without MPI or a potential. | ``GPR_HSSVD_CACHEGRIND_BUILD`` | +--------------------------------+-------------------------+---------------------------------------------------------------+--------------------------------+ | ``profile-rff-cachegrind`` | valgrind cachegrind | The layered RFF dimer path on one rank. | ``BUILD_DIR`` | +--------------------------------+-------------------------+---------------------------------------------------------------+--------------------------------+ | ``profile-rff-flamegraph`` | ``perf`` and FlameGraph | The layered RFF dimer path on one rank. | ``BUILD_DIR`` | +--------------------------------+-------------------------+---------------------------------------------------------------+--------------------------------+ | ``profile-rff-roofline`` | ``perf stat`` counters | The layered RFF dimer path on one rank. | ``BUILD_DIR`` | +--------------------------------+-------------------------+---------------------------------------------------------------+--------------------------------+ 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: .. code:: bash 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: .. code:: python 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. Related ------- - :doc:`Where the time goes <../explanation/performance>`: a measured split and the structure of the hot path. - :doc:`Performance development guidelines <../development/developer/performance>`: rules for changes to the hot path. - :doc:`Build options <../reference/build_options>`: backend and parallelism switches. - :doc:`MPI-parallel saddle point search ` and :doc:`Check run-to-run determinism `.