Skip to content

Commit fec89f1

Browse files
Michael Richard MckinseyMichael Richard Mckinsey
authored andcommitted
Add doc files from 254
1 parent 144160e commit fec89f1

3 files changed

Lines changed: 240 additions & 0 deletions

File tree

docs/sphinx/user_guide/build.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,46 @@ sizes. The CMake option for this is
210210

211211
will build versions of GPU kernels that use 64, 128, 256, 512, and 1024 threads
212212
per GPU thread-block.
213+
214+
Building with Caliper
215+
---------------------
216+
217+
RAJAPerf Suite may also use Caliper instrumentation, with per variant & tuning output into .cali files. While Caliper is low-overhead
218+
it is not zero, so it will add a small amount of timing skew in its data as
219+
compared to the original. Caliper output enables usage of performance analysis tools like Hatchet and Thicket.
220+
For much more on Caliper, Hatchet and Thicket, read their documentation here:
221+
222+
| - `Caliper Documentation <http://software.llnl.gov/Caliper/>`_
223+
| - `Hatchet User Guide <https://llnl-hatchet.readthedocs.io/en/latest/user_guide.html>`_
224+
| - `Thicket User Guide <https://thicket.readthedocs.io/en/latest/>`_
225+
226+
227+
Caliper *annotation* is in the following tree structure::
228+
229+
RAJAPerf
230+
Group
231+
Kernel
232+
233+
| Build against these Caliper versions
234+
|
235+
| **caliper@2.9.0** (preferred target)
236+
| **caliper@master** (if using older Spack version)
237+
238+
In Cmake scripts add
239+
**-DRAJA_PERFSUITE_USE_CALIPER=On**
240+
241+
Add to **-DCMAKE_PREFIX_PATH**
242+
;${CALIPER_PREFIX}/share/cmake/caliper;${ADIAK_PREFIX}/lib/cmake/adiak
243+
244+
or use
245+
-Dcaliper_DIR -Dadiak_DIR package prefixes
246+
247+
For Spack : raja_perf +caliper ^caliper@2.9.0
248+
249+
For Uberenv: python3 scripts/uberenv/uberenv.py --spec +caliper ^caliper@2.9.0
250+
251+
If you intend on passing nvtx or roctx annotation to Nvidia or AMD profiling tools,
252+
build Caliper with +cuda cuda_arch=XX or +rocm respectively. Then you can specify
253+
an additional Caliper service for nvtx or roctx like so: roctx example:
254+
255+
CALI_SERVICES_ENABLE=roctx rocprof --roctx-trace --hip-trace raja-perf.exe

docs/sphinx/user_guide/output.rst

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,83 @@ storing the result in matrix A (N_i X N_j). Problem size could be chosen to be
159159
the maximum number of entries in matrix B or C. We choose the size of matrix
160160
A (N_i * N_j), which is more closely aligned with the number of independent
161161
operations (i.e., the amount of parallel work) in the kernels.
162+
163+
164+
===========================
165+
Caliper output files
166+
===========================
167+
168+
If you've built RAJAPerf with Caliper support turned on, then in addition to the
169+
outputs mentioned above, we also save a .cali file for each variant run, such as:
170+
Base_OpenMP.cali, Lambda_OpenMP.cali, RAJA_OpenMP.cali, etc.
171+
172+
Also, by using the `--variants` and `--tunings` flag when running, you can generate
173+
single variant/tuning runs. These work optimally with Hatchet/Thicket.
174+
175+
There are several techniques to display the Caliper trees (Timing Hierarchy)
176+
177+
| 1: Caliper's cali-query tool.
178+
| The first technique is with Caliper's own tool cali-query, we run it with
179+
| **-T** to display tree, or you can specify **--tree**.
180+
|
181+
| cali-query -T $HOME/data/default_problem_size/gcc/RAJA_Seq.cali
182+
183+
2: Caliper's Python module *caliperreader*::
184+
185+
import os
186+
import caliperreader as cr
187+
DATA_DIR = os.getenv('HOME')+"/data/default_problem_size/gcc"
188+
os.chdir(DATA_DIR)
189+
r = cr.CaliperReader()
190+
r.read("RAJA_Seq.cali")
191+
metric = 'avg#inclusive#sum#time.duration'
192+
for rec in r.records:
193+
path = rec['path'] if 'path' in rec else 'UNKNOWN'
194+
time = rec[metric] if metric in rec else '0'
195+
if not 'UNKNOWN' in path:
196+
if (isinstance(path, list)):
197+
path = "/".join(path)
198+
print("{0}: {1}".format(path, time))
199+
200+
You can add a couple of lines to view the metadata keys captured by Caliper/Adiak::
201+
202+
for g in r.globals:
203+
print(g)
204+
205+
You can also add a line to display metadata value in the dictionary **r.globals**
206+
207+
For example print out the OpenMP Max Threads value recorded at runtime::
208+
209+
print('OMP Max Threads: ' + r.globals['omp_max_threads'])`
210+
211+
or the variant represented in this file::
212+
213+
print('Variant: ' + r.globals['variant'])
214+
215+
216+
.. note:: The script above was written using caliper-reader 0.3.0,
217+
but is fairly generic. Other version usage notes may be
218+
found at the link below
219+
220+
`caliper-reader <https://pypi.org/project/caliper-reader/>`_
221+
222+
223+
3: Using the *Hatchet* Python module for single files::
224+
225+
import hatchet as ht
226+
DATA_DIR = os.getenv('HOME')+"/data/default_problem_size/gcc"
227+
os.chdir(DATA_DIR)
228+
gf1 = ht.GraphFrame.from_caliperreader("RAJA_Seq.cali")
229+
print(gf1.tree())
230+
231+
`Find out more on hatchet <https://github.com/LLNL/hatchet>`_
232+
233+
3: Using the *Thicket* Python module for multiple files::
234+
235+
import thicket as th
236+
DATA_DIR = os.getenv('HOME')+"/data/default_problem_size/gcc"
237+
os.chdir(DATA_DIR)
238+
th1 = th.Thicket.from_caliperreader(["RAJA_Seq-default.cali", "Base_Seq-default.cali", "Base_CUDA-block_128", "Base_CUDA-block_256"])
239+
print(th1.tree())
240+
241+
`Find out more on thicket <https://github.com/LLNL/thicket>`_

docs/sphinx/user_guide/run.rst

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,120 @@ was not possible for them to co-exist in the same executable as CUDA
138138
variants, for example. In the future, the build system may be reworked so
139139
that the OpenMP target variants can be run from the same executable as the
140140
other variants.
141+
142+
============================
143+
Additional Caliper Use Cases
144+
============================
145+
146+
If you specified building with Caliper (``-DRAJA_PERFSUITE_USE_CALIPER=On``),
147+
the generation of Caliper .cali files are automated for the most part.
148+
149+
However, there are a couple of other supported use cases.
150+
151+
Collecting PAPI topdown statistics on Intel Architectures
152+
---------------------------------------------------------
153+
154+
On Intel systems, you can collect topdown PAPI counter statistics by using
155+
command line arguments
156+
157+
``--add-to-spot-config, -atsc <string> [Default is none]``
158+
159+
This appends additional parameters to the built-in Caliper spot config.
160+
161+
To include some PAPI counters (Intel arch), add the following to the command
162+
line
163+
164+
``-atsc topdown.all``
165+
166+
Caliper's topdown service generates derived metrics from raw PAPI counters;
167+
a hierarchy of metrics to identify bottlenecks in out-of-order processors.
168+
This is based on an an approach described in Ahmad Yasin's paper
169+
*A Top-Down Method for Performance Analysis and Counters Architecture*. The
170+
top level of the hierarchy has a reliable set of four derived metrics or
171+
starting weights (sum to 1.0) which include:
172+
173+
#. **Frontend Bound.** Stalls attributed to the front end which is responsible for fetching and decoding program code.
174+
#. **Bad Speculation.** Fraction of the workload that is affected by incorrect execution paths, i.e. branch misprediction penalties
175+
#. **Retiring.** Increases in this category reflects overall Instructions Per Cycle (IPC) fraction which is good in general. However, a large retiring fraction for non-vectorized code could also be a hint to the user to vectorize their code (see Yasin's paper)
176+
#. **Backend Bound.** Memory Bound where execution stalls are related to the memory subsystem, or Core Bound where execution unit occupancy is sub-optimal lowering IPC (more compiler dependent)
177+
178+
.. note:: Backend Bound = 1 - (Frontend Bound + Bad Speculation + Retiring)
179+
180+
.. note:: Caveats:
181+
182+
#. When collecting PAPI data in this way you'll be limited to running only one variant, since Caliper maintains only one PAPI context.
183+
#. Small kernels should be run at large problem sizes to minimize
184+
anomalous readings.
185+
#. Measured values are only relevant for the innermost level of the
186+
Caliper tree hierarchy, i.e. Kernel.Tuning under investigation.
187+
#. Some lower level derived quantities may appear anomalous
188+
with negative values. Collecting raw counters can help identify
189+
the discrepancy.
190+
191+
``-atsc topdown-counters.all``
192+
193+
.. note:: Other caveats: Raw counter values are often noisy and require a lot
194+
of accommodation to collect accurate data including:
195+
196+
* Turning off Hyperthreading
197+
* Turning off Prefetch as is done in Intel's Memory Latency
198+
Checker (requires root access)
199+
* Adding LFENCE instruction to serialize and bracket code under
200+
test
201+
* Disabling preemption and hard interrupts
202+
203+
See Andreas Abel's dissertation `Automatic Generation of Models of
204+
Microarchitectures` for more info on this and for a comprehensive
205+
look at the nanobench machinery.
206+
207+
Some helpful references:
208+
209+
`Yasin's Paper <https://www.researchgate.net/publication/269302126_A_Top-Down_method_for_performance_analysis_and_counters_architecture>`_
210+
211+
`Vtune-cookbook topdown method <https://www.intel.com/content/www/us/en/develop/documentation/vtune-cookbook/top/methodologies/top-down-microarchitecture-analysis-method.html>`_
212+
213+
`Automatic Generation of Models of Microarchitectures <https://uops.info/dissertation.pdf>`_
214+
215+
Generating trace events (time-series) for viewing in chrome://tracing or Perfetto
216+
---------------------------------------------------------------------------------
217+
218+
`Perfetto <https://ui.perfetto.dev/>`_
219+
220+
Use Caliper's event trace service to collect timestamp info, where kernel
221+
timing can be viewed using browser trace profile views. For example,
222+
223+
``CALI_CONFIG=event-trace,event.timestamps ./raja-perf.exe -ek PI_ATOMIC INDEXLIST -sp``
224+
225+
This will produce a separate .cali file with date prefix which looks something
226+
like ``221108-100718_724_ZKrHC68b77Yd.cali``
227+
228+
Then, we need to convert this .cali file to JSON records. But first, we need
229+
to make sure Caliper's python reader is available in the ``PYTHONPATH``
230+
environment variable
231+
232+
``export PYTHONPATH=caliper-source-dir/python/caliper-reader``
233+
234+
then run ``cali2traceevent.py``. For example,
235+
236+
``python3 ~/workspace/Caliper/python/cali2traceevent.py 221108-102406_956_9WkZo6xvetnu.cali RAJAPerf.trace.json``
237+
238+
You can then load the resulting JSON file either in Chrome by going to
239+
``chrome://tracing`` or in ``Perfetto``.
240+
241+
For CUDA, assuming you built Caliper with CUDA support, you can collect and
242+
combine trace information for memcpy, kernel launch, synchronization, and
243+
kernels. For example,
244+
245+
``CALI_CONFIG="event-trace(event.timestamps,trace.cuda=true,cuda.activities)" ./raja-perf.exe -v RAJA_CUDA Base_CUDA -k Algorithm_REDUCE_SUM -sp``
246+
247+
.. warning::
248+
When you run cali2traceevent.py you need to add --sort option before the filenames.
249+
This is needed because the trace.cuda event records need to be sorted before processing.
250+
Failing to do so may result in a Python traceback.
251+
New versions of the Caliper Python package have this option built in by default to avoid this issue.
252+
253+
``~/workspace/Caliper/python/cali2traceevent.py --sort file.cali file.json``
254+
255+
For HIP, substitute ``rocm.activities`` for ``cuda.activities``.
256+
257+
.. note:: Currently there is no analog ``trace.rocm``.

0 commit comments

Comments
 (0)