forked from hengjiew/amrex_profiling_analyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze.py
121 lines (99 loc) · 5.11 KB
/
analyze.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#%%
import sys
import matplotlib.pyplot as plt
import numpy as np
from amrex_profiling_parser import *
#%%
# build one call tree per process
# In most cases, we have one top level function e.g., main(), solve(), etc.
# We can specify its name via the argument "main". If not specified, a dummy
# node will used as the tree root.
# This module aims at analyzing the overall performance statistics instead of
# individual function calls. The call tree merges call paths with same function
# names e.g., calls of the same function at different iterations.
roots = build_calltree_list(path='./bl_prof_bin', nProc=18)
# this also works if you profile the main function and name the profiler 'main()'.
# roots = build_calltree_list(path='./bl_prof_bin', nProc=18, main='main()')
#%%
# From base profiling (or tiny profiling), we can see the most expensive functions
# at the end of program's output. These functions may be called multiple times at
# different locations. The following API helps to find where exactly these expsensive
# functions are called.
# More usage of `print_callpath` can be found in its doc in amrex_prifliing_parser.py
searchPath = ['FabArray::ParallelCopy_finish()']
print_callpath(roots, searchPath, sortBy='time', pid=0, nPrint=4)
#%%
# In some cases, we know a specfic high level function is very expensive. The following
# API helps to detail what child functions it calls including their call counts and costs.
# The second, third, and fouth columns of the stdout are the time cost, cost percentage of
# the parent function, and the call counts, respectively.
# Note that if multiple full pathes are found, they will merged into # one path.
# Unless intended, it is better to specify the input path # with sufficient functions
# so that only the full path of interest is matched. Fox instance, the following example
# outputs the costs the MG solver in mac projector. If the third function is omitted, it
# will output MG sovler's statistics collected from both the mac and nodal projectors.
# MG performance in mac projector
callPath = ['mfix_solve','mfix::EvolveFluid',
'mfix::compute_MAC_projected_velocities()',
'MLMG::mgVcycle()']
print_runtime(roots, callPath, depth=1, pid=4)
# Each function's cost are is the sum over its calls in both mac and nodal projector.
callPath = ['mfix_solve','mfix::EvolveFluid',
'MLMG::mgVcycle()']
print_runtime(roots, callPath, depth=1, pid=4)
# %%
# This module comes handy when one wants to generate performance plots for slides/reports.
# The following examples shows how to plot the time usage of a function across different
# processes (to identify load imbalances) and visualize the time breakdown of a particular
# solver.
# Assuming we indentifies the hotspots of the particle solver from previous steps, we can
# plot the per process usage for further analysis.
callPaths = [
['mfix_solve', 'mfix_dem::EvolveParticles()',],
['mfix_solve', 'mfix_dem::EvolveParticles()','particles_computation'],
['mfix_solve', 'mfix_dem::EvolveParticles()', 'NeighborParticleContainer::updateNeighborsGPU'],
]
times = extract_runtime(roots, callPaths)
fig =plt.figure(figsize=(8,4))
nProc = 18 # number of process
x = [i for i in range(nProc)]
plt.xticks(x, x)
plt.title("Particle Solver's Performance")
plt.ylabel('Time(s)', fontsize=12)
plt.xlabel('Rank, 1 GPU per rank', fontsize=12)
plt.plot(times[0], 'b-', label='EvolveParticles', fillstyle='none')
plt.plot(times[1], 'bs', label='computation', markersize=6, fillstyle='none')
plt.plot(times[2], 'bo', label='updateNeighborGPU', markersize=6, fillstyle='none')
plt.legend(fontsize=12, bbox_to_anchor=(1.02, 1))
# %%
# The following **roughly** estimates MG solver in the mac projection with embed
# boundaris, including the computation and communication cost of levels above
# the coarest grid and the bottom solver's cost.
# Note that due to AMReX's grid aggregation the bottom solver may only be called
# by part of the processes. So the plot may present a significant imbalance, which
# is not necessarily a performance hit.
callPaths = [
['mfix::compute_MAC_projected_velocities()', 'MLMG::mgVcycle()',],
['mfix::compute_MAC_projected_velocities()', 'MLMG::mgVcycle()',
'MLMG::mgVcycle_bottom',],
['mfix::compute_MAC_projected_velocities()', 'MLMG::mgVcycle()',
'MLEBABecLap::applyBC()',],
['mfix::compute_MAC_projected_velocities()', 'MLMG::mgVcycle()',
'MLEBABecLap::Fsmooth()',],
]
times = extract_runtime(roots, callPaths)
nProc = 18
w = 0.6
ranks = [repr(i) for i in range(nProc)]
others = times[0]-times[1]-times[2]-times[3]
fig = plt.figure(figsize=(8,4))
plt.bar(ranks, times[2], label='gmg comm', width=w)
plt.bar(ranks, times[3], bottom=times[2], label='gmg comp', width=w)
plt.bar(ranks, times[1], bottom=times[2]+times[3], label='bottom', width=w)
plt.bar(ranks, others, bottom=times[1]+times[2]+times[3], label='other',
color='gray', width=w)
plt.legend(fontsize=16)
plt.ylabel('Time(s)', fontsize=16)
plt.xlabel('Rank',fontsize=16)
plt.title('MG Breakdown', fontsize=16)
# %%